PluginProbe
Bubble Menu – Floating Button Menu with Sticky Navigation / 3.1.1
Bubble Menu – Floating Button Menu with Sticky Navigation v3.1.1
trunk 1.3 2.0 2.2 2.2.1 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.1 4.1.1
bubble-menu / admin / assets / js / script.js

script.js in Bubble Menu – Floating Button Menu with Sticky Navigation 3.1.1, at admin/assets/js/script.js

536 lines 14.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 'use strict';
2
3 (function($) {
4
5 // Submit Form for save
6 $('#wow-plugin').on('submit', function(event) {
7 event.preventDefault();
8 get_tinymce_content();
9 const dataform = $(this).serialize();
10 let prefix = $('#prefix').val();
11 let data = 'action=' + prefix + '_item_save&' + dataform;
12 $('.wow-plugin .saving').animate({opacity: '0.75'});
13 $.post(ajaxurl, data, function(response) {
14 if (response.status == 'OK') {
15 $('#wow-message').addClass('notice notice-success is-dismissible');
16 $('#wow-message').html('<p>' + response.message + '</p>');
17 $('#add_action').val(2);
18 let tool_id = $('#tool_id').val();
19 $('.nav-tab.nav-tab-active').text('Update #' + tool_id);
20 }
21 $('.wow-plugin .saving').animate({opacity: '0'});
22 });
23 });
24
25 // Get Tinymce contetn
26 function get_tinymce_content() {
27 if ($('#wp-popupcontent-wrap').hasClass('tmce-active')) {
28 let content = tinyMCE.activeEditor.getContent();
29 $('#popupcontent').val(content);
30 }
31 }
32
33 // Tabs
34 $('#tab li').on('click', function() {
35 const selected = $(this).data('tab');
36 $('#tab li').removeClass('is-active');
37 $(this).addClass('is-active');
38 $('.tab-content').addClass('is-hidden');
39 $('[data-content="' + selected + '"]').removeClass('is-hidden');
40 });
41
42 // Tooltip
43 wow_attach_tooltips($('.wow-help'));
44
45 function wow_attach_tooltips(selector) {
46 selector.tooltip({
47 content: function() {
48 return $(this).prop('title');
49 },
50 tooltipClass: 'wow-ui-tooltip',
51 position: {
52 my: 'center top',
53 at: 'center bottom+10',
54 collision: 'flipfit',
55 },
56 hide: {
57 duration: 200,
58 },
59 show: {
60 duration: 200,
61 },
62 });
63 }
64
65 // CheckLabel
66
67 $('.checkLabel').each(function() {
68 checkLabel(this);
69 }).on('click', function() {
70 checkLabel(this);
71 });
72
73 function checkLabel(el) {
74 const check = $(el).find('input');
75 if (check.prop('checked')) {
76 $(el).parent().find('.field').removeClass('is-hidden');
77 } else {
78 $(el).parent().find('.field').addClass('is-hidden');
79 }
80 }
81
82 // CheckBLock
83 $('.checkBlock').each(function() {
84 checkBlock(this);
85 }).on('click', function() {
86 checkBlock(this);
87 });
88
89 function checkBlock(el) {
90 const check = $(el).find('input');
91 if (check.prop('checked')) {
92 $(el).closest('.columns').children('.blockHidden').removeClass('is-hidden');
93 } else {
94 $(el).closest('.columns').children('.blockHidden').addClass('is-hidden');
95 }
96 }
97
98 // Publish
99 publish();
100 $('#show').on('change', publish);
101
102 function publish() {
103 const type = $('#show').val();
104 $('#taxonomy, #id-post, #shortcode').hide();
105 switch (type) {
106 case 'shortecode':
107 $('#shortcode').fadeIn();
108 break;
109 case 'taxonomy':
110 $('#taxonomy, #id-post').fadeIn();
111 break;
112 case 'posts':
113 case 'pages':
114 case 'expost':
115 case 'expage':
116 case 'postsincat':
117 $('#id-post').fadeIn();
118 break;
119 default:
120 $('#taxonomy, #id-post, #shortcode').hide();
121 break;
122 }
123 }
124
125 // Set value in input hidden for checkbox
126 $('.wow-plugin input:checkbox:checked').each(function() {
127 $(this).siblings('input[type="hidden"]').val('1');
128 });
129
130 $('body').on('click', '.wow-plugin input:checkbox', function() {
131 checkboxchecked(this);
132 });
133
134 function checkboxchecked(el) {
135 if ($(el).prop('checked')) {
136 $(el).siblings('input[type="hidden"]').val('1');
137 } else {
138 $(el).siblings('input[type="hidden"]').val('0');
139 }
140 }
141
142 // Change user role
143 usersroles();
144 $('#item_user').on('change', function() {
145 usersroles();
146 });
147
148 function usersroles() {
149 const type = $('#item_user').val();
150 $('.item-user').fadeOut('200');
151 if (type == '2') {
152 $('.item-user').fadeIn('200');
153 }
154 }
155
156 // Select Item type
157 $('select.item-type').each(function() {
158 itemtype(this);
159 });
160
161 $('body').on('change', '.item-type', function() {
162 itemtype(this);
163 });
164
165 function itemtype(el) {
166 const type = $(el).val();
167 const typeText = $(el).find('option:selected').text();
168 const parent = $(el).parents('.tabs-content');
169 const itemLink = $(parent).find('.item-link');
170 const itemShare = $(parent).find('.item-share');
171 const itemTranslate = $(parent).find('.item-translate');
172 const itemLinkBlank = $(parent).find('.item-link-blank');
173 const itemModal = $(parent).find('.item-modal');
174 const itemText = $(parent).find('.item-link-text');
175 $(el).parents('.panel').find('.element-type').text(typeText);
176 $(itemLink).hide();
177 $(itemShare).hide();
178 $(itemTranslate).hide();
179 $(itemLinkBlank).hide();
180 $(itemModal).hide();
181 switch (type) {
182 case 'link':
183 case 'smoothscroll':
184 case 'email':
185 case 'telephone':
186 case 'login':
187 case 'logout':
188 case 'lostpassword':
189 $(itemLink).show();
190 break;
191 case 'share':
192 $(itemShare).show();
193 break;
194 case 'id':
195 case 'class':
196 case 'modal':
197 $(itemModal).show();
198 break;
199 case 'translate':
200 $(itemTranslate).show();
201 break;
202 }
203
204 switch (type) {
205 case 'link':
206 case 'smoothscroll':
207 case 'login':
208 case 'logout':
209 case 'lostpassword':
210 $(itemText).text('Link');
211 break;
212 case 'email':
213 $(itemText).text('Email');
214 break;
215 case 'telephone':
216 $(itemText).text('Telephone');
217 break;
218 }
219
220 if (type === 'link' || type === 'dynamic') {
221 $(itemLinkBlank).show();
222 }
223
224 }
225
226 // Color Picker
227 $('.wp-color-picker-field').wpColorPicker({
228 change: function(event, ui) { panelHeadingIconColor(this); },
229 });
230
231 // Label keydown
232 $('body').on('keyup', '.item-tooltip', function() {
233 const val = $(this).val();
234 const parent = $(this).parents('.panel');
235 $(parent).find('.item-label-text').html(val);
236 if (val == '') {
237 $(parent).find('.item-label-text').html('(no label)');
238 }
239 });
240
241 // Toogle menu item
242
243 $('body').on('click', '.toogle-element .dashicons-arrow-down', function() {
244 const parent = $(this).parents('.panel');
245 $(parent).find('.toogle-content').removeClass('is-hidden');
246 $(this).addClass('is-hidden');
247 $(parent).find('.dashicons-arrow-up').removeClass('is-hidden');
248 });
249
250 $('body').on('click', '.toogle-element .dashicons-arrow-up', function() {
251 const parent = $(this).parents('.panel');
252 $(parent).find('.toogle-content').addClass('is-hidden');
253 $(this).addClass('is-hidden');
254 $(parent).find('.dashicons-arrow-down').removeClass('is-hidden');
255 });
256
257 // Check sub-item
258 $('input.sub-item:checkbox').each(function() {
259 subitem(this);
260 });
261 $('body').on('change', 'input.sub-item', function() {
262 subitem(this);
263 });
264
265 function subitem(el) {
266 const parent = $(el).parents('.panel');
267 if ($(el).prop('checked')) {
268 $(parent).find('.is-submenu').removeClass('is-hidden');
269 } else {
270 $(parent).find('.is-submenu').addClass('is-hidden');
271 }
272 }
273
274 // Check custom icon
275 $('.icons').fontIconPicker({
276 theme: 'fip-darkgrey',
277 emptyIcon: false,
278 allCategoryText: 'Show all',
279 });
280
281 $('input.custom-icon:checkbox').each(function() {
282 customicon(this);
283 });
284 $('body').on('click', '.custom-icon', function() {
285 customicon(this);
286 });
287
288 function customicon(el) {
289 const parent = $(el).parents('.tabs-content');
290 const iconDefault = $(parent).find('.icon-default');
291 const iconCustom = $(parent).find('.icon-custom');
292 const iconText = $(parent).find('.icon-text');
293 const iconTextField = $(parent).find('.icon-text-field');
294 const checkText = $(parent).find('.custom-icon-text');
295 if ($(el).prop('checked')) {
296 $(iconDefault).hide();
297 $(iconCustom).show();
298 $(iconText).hide();
299 $(checkText).prop('checked', false);
300 $(iconTextField).addClass('is-hidden');
301 } else {
302 $(iconDefault).show();
303 $(iconCustom).hide();
304 $(iconText).show();
305 }
306
307 }
308
309 $('input.custom-icon-text:checkbox').each(function() {
310 customIconText(this);
311 });
312 $('body').on('click', '.custom-icon-text', function() {
313 customIconText(this);
314 });
315
316 function customIconText(el) {
317 const parent = $(el).parents('.tabs-content');
318 const iconDefault = $(parent).find('.icon-default');
319 const iconCustom = $(parent).find('.icon-custom');
320 const iconText = $(parent).find('.icon-text-field');
321 const checkCustomIcon = $(parent).find('.custom-icon');
322 if ($(el).prop('checked')) {
323 $(iconDefault).hide();
324 $(iconCustom).hide();
325 $(iconText).removeClass('is-hidden');
326 $(checkCustomIcon).prop('checked', false);
327 } else {
328 $(iconText).addClass('is-hidden');
329 $(iconDefault).show();
330 }
331 }
332
333 // Hide plugin message
334
335 $(document).on('click', '.wow-plugin-message .notice-dismiss', function() {
336 $.ajax({
337 url: ajaxurl, data: {
338 action: 'float_menu_message',
339 },
340 });
341 });
342
343 // Add new Menu item
344 $('.add-item').on('click', function() {
345 const element = document.getElementById('clone').innerHTML;
346 document.querySelector('.menu-items').insertAdjacentHTML('beforeend', element);
347 refreashel();
348 });
349
350 // Refreash the functions
351 function refreashel() {
352 $('select.item-type').each(function() {
353 itemtype(this);
354 });
355 $('input.custom-icon:checkbox').each(function() {
356 customicon(this);
357 });
358 $('.wp-color-picker-field').wpColorPicker({
359 change: function(event, ui) { panelHeadingIconColor(this); },
360 });
361
362 wow_attach_tooltips($('.wow-help'));
363 $('.icons').fontIconPicker({
364 theme: 'fip-darkgrey',
365 emptyIcon: false,
366 allCategoryText: 'Show all',
367 });
368
369 $('.icons-selector').on('click', function() {
370 const parent = $(this).parents('.panel');
371 selectIcon(parent);
372 });
373
374 $('body').on('click keyup', '[data-tab-content="2"]', function() {
375 const parent = $(this).parents('.panel');
376 selectIcon(parent);
377 });
378
379 iconShapes();
380
381 }
382
383 // Remove Items
384 $('body').on('click', '.item-delete', function() {
385 const parent = $(this).parents('.panel');
386 $(parent).remove();
387 });
388
389 // Panel tabs
390 $('body').on('click', '.panel-tabs a', function() {
391 panelTab(this);
392 });
393
394 function panelTab(el) {
395 const selected = $(el).data('tab');
396 const parent = $(el).parents('.panel');
397 $(parent).find('.panel-tabs a').removeClass('is-active');
398 $(el).addClass('is-active');
399 $(parent).find('.tabs-content').addClass('is-hidden');
400 $(parent).find('[data-tab-content="' + selected + '"]').removeClass('is-hidden');
401 }
402
403 $('.wp-color-picker-field').each(function() {
404 panelHeadingIconColor(this);
405 });
406 $('body').on('change', '.wp-color-picker-field', function() {
407 panelHeadingIconColor(this);
408 });
409
410 function panelHeadingIconColor(el) {
411 const attr = $(el).attr('name');
412 const color = $(el).val();
413 const parent = $(el).parents('.panel');
414 if (attr.includes('[color]')) {
415 $(parent).find('.icon-select').css('color', color);
416 } else {
417 $(parent).find('.icon-select').css('background-color', color);
418 }
419 }
420
421 $('.item-bgcolor, .item-color').each(function() {
422 panelHeadingIconItemColor(this);
423 });
424 $('body').on('change', '.item-bgcolor, .item-color', function() {
425 panelHeadingIconItemColor(this);
426 });
427
428 function panelHeadingIconItemColor(el) {
429 const colors = {
430 white: '#ffffff',
431 grey: '#808080',
432 black: '#000000',
433 red: '#e3001b',
434 orange: '#ff6600',
435 yellow: '#ffcc01',
436 lime: '#b1c903',
437 green: '#27a22d',
438 cyan: '#00b1e5',
439 blue: '#006bb3',
440 purple: '#ad007c',
441 pink: '#ea4c89',
442
443 };
444 const parent = $(el).parents('.panel');
445 const color = $(el).val();
446 if ($(el).hasClass('item-bgcolor')) {
447 $(parent).find('.icon-select').css('background-color', colors[color]);
448 } else if ($(el).hasClass('item-color')) {
449 $(parent).find('.icon-select').css('color', colors[color]);
450 }
451 }
452
453
454 $('body').on('change', '#shapes', function() {
455 iconShapes();
456 });
457 iconShapes();
458 function iconShapes() {
459 const shape = $('#shapes').val();
460 switch (shape) {
461 case "wow-bmp-shape-rsquare":
462 $('.icon-select').css('border-radius', '25%');
463 break;
464 case "wow-bmp-shape-ellipse":
465 $('.icon-select').css('border-radius', '25% 75%');
466 break;
467 case "wow-bmp-shape-square":
468 $('.icon-select').css('border-radius', '0%');
469 break;
470 default:
471 $('.icon-select').css('border-radius', '50%');
472 }
473
474 }
475
476 $('.icons-selector').on('click', function() {
477 const parent = $(this).parents('.panel');
478 selectIcon(parent);
479 });
480
481 $('body').on('click keyup', '[data-tab-content="2"]', function() {
482 const parent = $(this).parents('.panel');
483 selectIcon(parent);
484 });
485
486 $('.panel').each(function() {
487 selectIcon(this);
488 });
489
490 function selectIcon(el) {
491 let icon;
492 const iconCustom = $(el).find('.custom-icon');
493 const iconText = $(el).find('.custom-icon-text');
494 const iconDefault = $(el).find('.icons').val();
495 if ($(iconCustom).prop('checked')) {
496 const img = $(el).find('.custom-icon-url').val();
497 icon = '<img src="' + img + '">';
498 } else if ($(iconText).prop('checked')) {
499 const text = $(el).find('.icon-custom-text').val();
500 icon = text;
501 } else {
502 icon = '<i class="' + iconDefault + '"></i>';
503 }
504 $(el).find('.icon-select').html(icon);
505
506 }
507
508 $('.menu-items').sortable();
509
510 scrollOption();
511 $('#scroll-option').on('change', function() {
512 scrollOption();
513 });
514
515 function scrollOption() {
516 const scroll = $('#scroll-option').val();
517 if (scroll === 'show' || scroll === 'hide') {
518 $('.scroll-position').removeClass('is-hidden');
519 } else {
520 $('.scroll-position').addClass('is-hidden');
521 }
522 }
523
524
525 $('body').on('change', '#select_icon, #icon_position', function() {
526 menuicon();
527 });
528
529 function menuicon() {
530 var icon = $('#select_icon').val();
531 var position = $('#icon_position').val();
532 $('#icon_class').text(icon + position);
533 }
534
535 })(jQuery);
536