PluginProbe
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder / 1.0.6.1
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder v1.0.6.1
3.6.0 3.5.0 trunk 1.0.10 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.6.1 1.0.7 1.0.8 1.0.9 1.1 1.1.1 1.2 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5 1.5.1 All 110 releases
buttonizer-multifunctional-button / js / dashboard.js

dashboard.js in Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder 1.0.6.1, at js/dashboard.js

891 lines 36.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1
2 var buttonizer = {
3 settings: {
4 wpButtonSaveKey: 'buttonizer_buttons',
5 wpCategorySaveKey: 'buttonizer_page_categories',
6 windowNumber: 0,
7 hasChanges: false,
8 clickedButton: false
9 },
10
11 setTimouts: {
12 a: function() {
13 return setTimeout(function() { }, 0)
14 },
15 b: function() {
16 return setTimeout(function() { }, 0)
17 },
18 },
19
20 init: function() {
21 buttonizer.overwriteFavIcon();
22 buttonizer.faInit();
23 buttonizer.initButtons();
24
25 // WP color picker
26 jQuery('#button_unpushed').wpColorPicker();
27 jQuery('#button_pushed').wpColorPicker();
28 jQuery('#icon_color').wpColorPicker();
29
30 jQuery(".savebutton").each(function() {
31 jQuery(this).click(buttonizer.saveAnimation);
32 });
33
34 jQuery("input, textarea, select").change(function() {
35 buttonizer.settings.hasChanges = true;
36 });
37
38 setTimeout(function() {
39 // Init preview button
40 jQuery('.button-preview').css({
41 'background-color': jQuery("#button_unpushed").val()
42 });
43
44 jQuery(".button-preview").hover(function() {
45 jQuery(this).css({
46 'background-color': jQuery("#button_pushed").val()
47 });
48 }, function() {
49 jQuery(this).css({
50 'background-color': jQuery("#button_unpushed").val()
51 });
52 });
53 }, 500);
54
55 jQuery(".vertical-tabs .icon-or-image").each(function() {
56 buttonizer.iconImageHandler(jQuery(this));
57 });
58
59 // Remove the spam from other plugins
60 setTimeout(function() {
61 var foundOurContent = false;
62 if(jQuery(".buttonizerWarning").length > 0) {
63 foundOurContent = true;
64 var buttonizerData = jQuery(".buttonizerWarning").html();
65 var buttonizerStyle = jQuery(".buttonizerWarning").attr('class');
66 }
67
68 jQuery("#wordpress-plugin-message-spam").remove();
69
70 if(foundOurContent) {
71 jQuery(".nav-tab-wrapper").after('<div class="'+ buttonizerStyle +'">'+ buttonizerData +'</div>');
72 }
73 }, 1000);
74
75 // Hash
76 if(document.location.hash != "") {
77 var tabKey = document.location.hash;
78 buttonizer.tabNavigate(tabKey.replace("#tab_", ""));
79 }
80
81 jQuery(".buttonizer-click-to-pro").each(function() {
82 jQuery(this).click(function(e) {
83 e.preventDefault();
84 buttonizer.proInfoWindow();
85 });
86 });
87
88 buttonizer.loadPageCategorie();
89
90 if(!jQuery(".button-row").hasClass("is_category")) {
91 buttonizer.addSortable();
92 }
93 },
94
95 proInfoWindow: function() {
96 buttonizer.createWindow({
97 title: 'You like Buttonizer?',
98 text: '<p>Are you ready to try Buttonizer PRO?</p><p><b class="color-buttonizer">What do you get?</b></p>'+
99
100 '<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Show on opening hours</div>' +
101 '<div class="color-buttonizer-orange buttonizer-pro-checklist"><i class="fa fa-check"></i> Show buttons on specific pages: Use page rules</div>' +
102 '<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Unlimited page rules</div>' +
103 '<div class="color-buttonizer-orange buttonizer-pro-checklist"><i class="fa fa-check"></i> Add custom image or button-icon</div>' +
104 '<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Exit intend</div>' +
105 '<div class="color-buttonizer-orange buttonizer-pro-checklist"><i class="fa fa-check"></i> Show on scroll</div>' +
106 '<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Show on timeout</div>' +
107 '<br />' +
108 '<p class="color-buttonizer text-right"><b>Do you <span><i class="fa fa-heart"></i></span> these features?</b></p>',
109 confirmText: 'Upgrade',
110 onConfirm: function() {
111 document.location.href = 'admin.php?page=Buttonizer-pricing';
112 }
113 });
114 },
115
116 overwriteFavIcon: function() {
117 (function() {
118 var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
119 link.type = 'image/x-icon';
120 link.rel = 'shortcut icon';
121 link.href = faviconUrl;
122 document.getElementsByTagName('head')[0].appendChild(link);
123 })();
124 },
125
126 tabNavigate: function(key) {
127 jQuery(".vertical-tabs .tab-container").each(function() {
128 if(jQuery(this).attr('id') == "tab_container_" + key) {
129 jQuery(this).show();
130 }else{
131 jQuery(this).hide();
132 }
133 });
134
135 jQuery(".vertical-tabs .tabs a").each(function() {
136 if(jQuery(this).attr('id') == "tab_container_" + key) {
137 jQuery(this).addClass('nav-tab-active');
138 }else{
139 jQuery(this).removeClass('nav-tab-active');
140 }
141 });
142
143 // jQuery("type[name=_wp_http_referer]").val();
144 },
145
146 iconImageHandler: function(currentContainer) {
147 var type = currentContainer.data("type");
148
149 // Chooser
150 currentContainer.find(".placeholder-choose a").click(function() {
151 if(type == 'image') {
152 type = 'icon';
153
154 currentContainer.find(".image-placeholder").hide();
155 currentContainer.find(".icon-placeholder").show();
156
157 currentContainer.find("input").val("");
158 }else {
159 type = 'image';
160
161 currentContainer.find(".image-placeholder").show();
162 currentContainer.find(".icon-placeholder").hide();
163 }
164 });
165
166 // Insert image and icon type
167 currentContainer.find(".image-uploader-button").click(function(e) {
168 e.preventDefault();
169
170 var custom_uploader = wp.media({
171 title: 'Choose button icon',
172 multiple: false
173 })
174 .on('select', function() {
175 var attachment = custom_uploader.state().get('selection').first().toJSON();
176 currentContainer.find('.button-preview img').attr( 'src', attachment.url).show();
177 currentContainer.find(".button-preview").show();
178
179 currentContainer.find('input').val(attachment.url);
180 })
181 .open();
182 });
183 },
184
185 colorPaletHandler: function(colorPalet) {
186 var buttonId = colorPalet.attr("data-btnid");
187 var customColors = false;
188 var currentColors = {
189 default: buttonizer.rgb2hex(colorPalet.find(".color.default").css('background-color')),
190 pushed: buttonizer.rgb2hex(colorPalet.find(".color.pushed").css('background-color')),
191 icon: buttonizer.rgb2hex(colorPalet.find(".color.icon").css('background-color'))
192 };
193
194 jQuery("#btn_row_"+ buttonId +" .button-preview").css({ 'background-color': currentColors.default });
195
196 colorPalet.click(function() {
197 var randomText = (buttonizer.settings.windowNumber + 1);
198
199 buttonizer.createWindow({
200 title: 'Choose colors',
201 text:
202 '<p>Choose the colors here of your button. You can give every button different colors.</p>' +
203 '<table width="100%" class="color-chooser-table">' +
204 '<tr><td width="150">' +
205 '<b>Button color</b>' +
206 '</td><td>' +
207 '<input type="text" class="colorpalet-initializer" value="'+ currentColors.default +'" id="color_default_'+ randomText +'" />' +
208 '</td></tr>' +
209
210 '<tr><td>' +
211 '<b>Pushed/hover color</b>' +
212 '</td><td>' +
213 '<input type="text" class="colorpalet-initializer" value="'+ currentColors.pushed +'" id="color_pushed_'+ randomText +'" />' +
214 '</td></tr>' +
215
216 '<tr><td>' +
217 '<b>Icon color</b>' +
218 '</td><td>' +
219 '<input type="text" class="colorpalet-initializer" value="'+ currentColors.icon +'" id="color_icon_'+ randomText +'" />' +
220 '</td></tr>' +
221 '</table>',
222
223 confirmText: 'Choose',
224
225 afterInit: function() {
226 jQuery(".colorpalet-initializer").wpColorPicker();
227 },
228
229 onConfirm: function() {
230 currentColors.default = jQuery("#color_default_" + randomText).val();
231 currentColors.pushed = jQuery("#color_pushed_" + randomText).val();
232 currentColors.icon = jQuery("#color_icon_" + randomText).val();
233 jQuery("#btn_row_"+ buttonId +" .button-preview").css({ 'background-color': currentColors.default });
234 customColors = true;
235
236 jQuery("#reset_colors_" + buttonId).show();
237 updatePalet();
238 }
239 });
240 });
241
242 jQuery("#reset_colors_" + buttonId).click(function() {
243 buttonizer.createWindow({
244 title: 'Back to default colors',
245 text: '<p>The button colors will reset to the choosen default button colors (from the general settings).</p>' +
246 '<p>Are you sure you want to get the default colors for this button?</p>',
247
248 canCancel: true,
249 cancelText: 'Cancel',
250 confirmText: '<i class="fa fa-thumbs-o-up"></i>&nbsp; Yes, I am',
251
252 onConfirm: function() {
253 customColors = false;
254 currentColors.default = colorPalet.find(".color.default").attr("data-default");
255 currentColors.pushed = colorPalet.find(".color.pushed").attr("data-default");
256 currentColors.icon = colorPalet.find(".color.icon").attr("data-default");
257 updatePalet();
258 jQuery("#reset_colors_" + buttonId).hide();
259 jQuery("#btn_row_"+ buttonId +" .button-preview").css({ 'background-color': currentColors.default });
260 }
261 });
262 });
263
264 function updatePalet() {
265 colorPalet.find(".color.default").css({ 'background-color': currentColors.default});
266 colorPalet.find(".color.pushed").css({ 'background-color': currentColors.pushed});
267 colorPalet.find(".color.icon").css({ 'background-color': currentColors.icon});
268
269 colorPalet.find("input.custom").val(customColors ? '1' : '0').change();
270 colorPalet.find("input.default").val(currentColors.default);
271 colorPalet.find("input.pushed").val(currentColors.pushed);
272 colorPalet.find("input.icon").val(currentColors.icon);
273 }
274 },
275
276 rgb2hex: function(rgb) {
277 if(rgb == null || typeof rgb == "null") {
278 return '#eeeeee';
279 }
280
281 rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
282 function hex(x) {
283 return ("0" + parseInt(x).toString(16)).slice(-2);
284 }
285
286 if(rgb == null || typeof rgb == "null") {
287 return '#eeeeee';
288 }
289
290 return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
291 },
292
293 loadPageCategorie: function() {
294 jQuery(".page-categorie-styling").each(function() {
295 var maxLoaded = 10;
296 var isLoaded = 10;
297 var table = jQuery(this);
298 jQuery(this).addClass("initialized")
299
300 table.find("tr").each(function() {
301 jQuery(this).click(function(e) {
302 buttonizer.settings.hasChanges = true;
303 if(jQuery(e.target).attr("type") != "checkbox") {
304 jQuery(this).find("input").click();
305 }
306 });
307 });
308
309 jQuery(".categories-load-more[data-id="+ jQuery(this).attr("data-id") +"]").click(function() {
310 maxLoaded += 10;
311 isLoaded = 0;
312
313 table.find("tr").each(function() {
314 isLoaded++;
315 if(isLoaded <= maxLoaded) {
316 jQuery(this).show();
317 }else{
318 return;
319 }
320 });
321
322 if(jQuery(".page-categorie-styling[data-id="+ jQuery(this).attr("data-id") +"] tr").length < maxLoaded) {
323 jQuery(this).hide();
324 }
325 });
326 });
327 },
328
329 addSortable: function() {
330 var sortable = new Sortable(document.getElementById("button-rows"), {
331 group: "button-rows",
332 sort: true,
333 animation: 150,
334 scroll: true,
335 scrollSensitivity: 30,
336 scrollSpeed: 10,
337
338 onSort: function (evt) {
339 jQuery("#" + evt.clone.children[0].id + " .row-info").css({
340 opacity: .45,
341 }).delay(500).animate({
342 opacity: 1,
343 }, 500);
344 }
345 });
346 },
347
348 saveAnimation: function() {
349 jQuery(".savebutton").each(function() {
350 jQuery(this).html('<i class="fa fa-cog fa-spin"></i> <span>Saving</span>');
351 });
352 buttonizer.settings.clickedButton = true;
353 jQuery('form#buttonizer').submit();
354 },
355
356 /*
357 * Buttons
358 */
359 initButtons: function() {
360 jQuery(".button-row .savebutton").each(function() {
361 jQuery(this).click(buttonizer.saveAnimation);
362 });
363
364 jQuery(".button-row").each(function() {
365 if(jQuery(this).attr("button-id") == '-1') {
366 return;
367 }
368
369 var rowObj = jQuery(this);
370 var rowId = jQuery(this).attr("button-id");
371 var buttonTitle = rowObj.find(".row-info span .row-title");
372 var buttonEdit = rowObj.find(".row-info .pencil-edit");
373 var buttonTitleField = rowObj.find(".button_title");
374 var doubleClick = setTimeout(function() {}, 100);
375 var isCategory = rowObj.hasClass('is_category');
376 var clicked = 0;
377
378 buttonEdit.click(function(e) {
379 e.preventDefault();
380 buttonTitle.dblclick();
381 });
382
383 buttonTitle.html(buttonTitleField.val());
384
385 rowObj.find(".row-info").click(function(e) {
386 if(
387 jQuery(e.target).hasClass('fa-desktop') ||
388 jQuery(e.target).hasClass('fa-mobile') ||
389 jQuery(e.target).hasClass('fa-pencil') ||
390 jQuery(e.target).hasClass('mobiledesktop') ||
391 jQuery(e.target).hasClass('is-live-button') ||
392 jQuery(e.target).hasClass('must-save-button')
393 ) {
394 return;
395 }
396
397 clicked = 0;
398 clearInterval(doubleClick);
399 doubleClick = setTimeout(function() {
400 if(clicked == 0) {
401 if(rowObj.hasClass("opened")) {
402 rowObj.removeClass("opened");
403 }else{
404 rowObj.addClass("opened");
405 }
406 }
407 clicked = 0;
408 }, 100);
409 });
410
411 buttonTitle.dblclick(function() {
412 buttonizer.updateTitle(buttonTitle, buttonTitleField, false);
413
414 clicked++;
415 });
416
417 rowObj.find(".button_showonphone").change(function(e) {
418 var isSelected = jQuery(this).is(":checked");
419
420 if(!isSelected) {
421 jQuery("#btn_row_" + rowId + " .row-info .mobile-button").addClass("selected");
422 }else {
423 jQuery("#btn_row_" + rowId + " .row-info .mobile-button").removeClass("selected");
424 }
425 });
426
427 rowObj.find('.button_title').change(function() {
428 newTitle = jQuery(this).val();
429
430 if(buttonizer.checkTitleDuplicate(newTitle, rowId)) {
431 buttonizer.updateTitle(buttonTitle, buttonTitleField, true, newTitle);
432 return;
433 }
434
435 buttonTitle.html(newTitle);
436 });
437
438 rowObj.find(".button_showondesktop").change(function(e) {
439 var isSelected = jQuery(this).is(":checked");
440
441 if(!isSelected) {
442 jQuery("#btn_row_" + rowId + " .row-info .desktop-button").addClass("selected");
443 }else {
444 jQuery("#btn_row_" + rowId + " .row-info .desktop-button").removeClass("selected");
445 }
446 });
447
448 jQuery("#button_"+ rowId +"_icon").change(function(e) {
449 rowObj.find(".button-icon").attr('class', "fa "+ jQuery(this).val() +" button-icon");
450 });
451
452 jQuery("#btn_row_" + rowId + " input").change(function() {
453 jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide();
454 jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show();
455 });
456
457 if(isCategory) {
458 var checked = false;
459 rowObj.find(".select-all").click(function() {
460 if(!checked) {
461 checked = true;
462 rowObj.find(".page-categorie-styling input[type=checkbox]").attr("checked", "checked");
463 }else{
464 checked = false;
465 rowObj.find(".page-categorie-styling input[type=checkbox]").removeAttr("checked");
466 }
467 });
468 }else{
469 // Image icon handler
470 buttonizer.iconImageHandler(rowObj.find(".icon-or-image"));
471 buttonizer.colorPaletHandler(rowObj.find(".button-color-palet"));
472 }
473 });
474 },
475
476 updateTitle: function(buttonTitle, buttonTitleField, isDuplicate, text) {
477 if(!text) {
478 var text = '';
479 }
480
481 if(!isDuplicate) {
482 var newTitle = prompt("You can change the title of the button.\n\nNote: The visitor won't see this text - for internal use only:", buttonTitleField.val());
483 }else{
484 var newTitle = prompt("You can change the title of the button.\n\nNote: The visitor won't see this text - for internal use only:\n\nWARNING: This name is already in use. Please change the name of the button. Duplicates are not allowed due Google Analytics event names.", text);
485 }
486
487 if(!newTitle || newTitle == "") {
488 if(isDuplicate) {
489 buttonTitleField.val(buttonTitle.html());
490 }
491 return;
492 }
493
494 if(buttonizer.checkTitleDuplicate(newTitle)) {
495 buttonizer.updateTitle(buttonTitle, buttonTitleField, true, newTitle);
496 return;
497 }
498
499 buttonTitle.html(newTitle);
500 buttonTitleField.val(newTitle);
501 },
502
503 checkTitleDuplicate: function(text, allowRowId) {
504 isDuplicate = false;
505 if(!allowRowId) {
506 var allowRowId = -1;
507 }
508
509 jQuery(".button-row").each(function() {
510 if(jQuery(this).find('.button_title').val() == text && jQuery(this).attr("button-id") != allowRowId) {
511 isDuplicate = true;
512 }
513 });
514
515 return isDuplicate;
516 },
517
518 removeRow: function(id) {
519 var buttonName = jQuery("#btn_row_" +id + " .row-info span .row-title").html();
520 var wasCategory = jQuery("#btn_row_" + id).hasClass('is_category');
521
522 if(confirm("Are you sure you want to remove the row with the text: '"+ buttonName +"'?\n\nThis is not recoverable.")) {
523 jQuery("#btn_row_" +id).remove();
524
525 if(jQuery(".button-row").length > 1) {
526 jQuery(".buttonizer-no-buttons").hide();
527 }else{
528 jQuery(".buttonizer-no-buttons").show();
529 }
530 }
531 },
532
533 toggleMobile: function(id) {
534 var isSelected = jQuery("#button_"+ id +"_show_on_phone").is(":checked");
535
536 if(!isSelected) {
537 jQuery("#btn_row_" + id + " .row-info .mobile-button").removeClass("selected");
538 jQuery("#button_"+ id +"_show_on_phone").click();
539 }else {
540 jQuery("#btn_row_" + id + " .row-info .mobile-button").addClass("selected");
541 jQuery("#button_"+ id +"_show_on_phone").click();
542 }
543
544 jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide();
545 jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show();
546 },
547
548 toggleDesktop: function(id) {
549 var isSelected = jQuery("#button_"+ id +"_show_on_desktop").is(":checked");
550
551 if(!isSelected) {
552 jQuery("#btn_row_" + id + " .row-info .desktop-button").removeClass("selected");
553 jQuery("#button_"+ id +"_show_on_desktop").click();
554 }else {
555 jQuery("#btn_row_" + id + " .row-info .desktop-button").addClass("selected");
556 jQuery("#button_"+ id +"_show_on_desktop").click();
557 }
558
559 jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide();
560 jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show();
561 },
562
563 addRow: function() {
564 if(jQuery("#new-button").hasClass('disabled')) {
565 return;
566 }
567 buttonizer.settings.hasChanges = true;
568
569 jQuery(".buttonizer-no-buttons").hide();
570
571 var isCategory = jQuery(".button-row[button-id=-1]").hasClass("is_category");
572
573 jQuery("#new-button").attr('disabled', 'disabled').addClass('disabled');
574 var defaultRow = jQuery(".button-row[button-id=-1]").html();
575 var numberOfButtons = jQuery(".button-row").length - (isCategory ? 1 : 0);
576
577 numberOfButtons = Math.floor(Date.now() / 1000);
578 numberOfButtons = numberOfButtons + "-" + Math.floor((Math.random() * 999) + 100);
579 numberOfButtons = numberOfButtons.replace('-', '');
580
581 var newData = defaultRow.replace('/-1/g', numberOfButtons);
582 newData = newData.replace('-1', numberOfButtons);
583
584 jQuery("#button-rows, #page-categories").append((!isCategory ? '<li>' : '') + '<div class="button-row ' + (isCategory ? 'is_category' : '') + '" id="btn_row_'+ numberOfButtons +'" button-id="'+ numberOfButtons +'">' + newData + '</div>' + (!isCategory ? '</li>' : ''));
585
586 clearInterval(buttonizer.setTimouts.a);
587 clearInterval(buttonizer.setTimouts.b);
588
589 buttonizer.setTimouts.a = setTimeout(function() {
590 jQuery(".button-row *").unbind("click");
591 jQuery(".button-row").removeClass("opened");
592 jQuery(".fontawesome-searcher-clicker").remove();
593 jQuery("#btn_row_"+ numberOfButtons +" .button_title").val("New button " + numberOfButtons);
594
595 if(isCategory) {
596 jQuery("#btn_row_"+ numberOfButtons +" input").each(function() {
597 jQuery(this).attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"][]");
598 });
599
600 jQuery("#btn_row_"+ numberOfButtons + " select").attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"_type]");
601 }
602 }, 100);
603
604
605 buttonizer.setTimouts.b = setTimeout(function() {
606 buttonizer.initButtons();
607 if(!isCategory) {
608 buttonizer.updateRowInputNames(numberOfButtons);
609 jQuery("#btn_row_"+ numberOfButtons).addClass('opened');
610 jQuery("#btn_row_"+ numberOfButtons + " input.button_title").focus();
611 }else{
612 console.log("Initialize new page category");
613 jQuery("#btn_row_"+ numberOfButtons + " #categoryIsUsed").val(numberOfButtons);
614 jQuery("#btn_row_"+ numberOfButtons + " #categoryIsUsed").attr("name", buttonizer.settings.wpCategorySaveKey + '[categorieOrder][]');
615 jQuery("#btn_row_"+ numberOfButtons + " .delete-button").attr("href", "javascript:buttonizer.removeRow("+ numberOfButtons +")");
616 jQuery("#btn_row_"+ numberOfButtons + " .button_title").attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"_title]").val('New page category ' + (jQuery(".button-row").length - 1));
617 jQuery("#btn_row_"+ numberOfButtons + " .row-title").html("New page category " + (jQuery(".button-row").length - 1));
618 }
619 buttonizer.faInit();
620 buttonizer.loadPageCategorie();
621 jQuery("#new-button").removeAttr('disabled').removeClass('disabled');
622
623 jQuery("#btn_row_"+ numberOfButtons + " .savebutton").show();
624 }, 400);
625 },
626
627 updateRowInputNames: function(buttonId) {
628 // Textfield
629 jQuery("#btn_row_"+ buttonId + " .button_textfield")
630 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_text]")
631 .attr("id", "button_"+ buttonId +"_text").val("");
632
633 // Iconfield
634 jQuery("#btn_row_"+ buttonId + " .icon-placeholder select").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_icon]");
635
636 // Iconfield
637 jQuery("#btn_row_"+ buttonId + " .image-placeholder input").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_image]");
638
639 // Button title
640 jQuery("#btn_row_"+ buttonId + " .button_title").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_title]");
641
642 // Button show on page category
643 jQuery("#btn_row_"+ buttonId + " #button_category").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_pages]");
644
645 // Color palets
646 jQuery("#btn_row_"+ buttonId + " input.custom").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_using_custom_colors]");
647
648 jQuery("#btn_row_"+ buttonId + " input.default").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_colors_button]");
649 jQuery("#btn_row_"+ buttonId + " input.pushed").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_colors_pushed]");
650 jQuery("#btn_row_"+ buttonId + " input.icon").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_colors_icon]");
651
652 // Show on phone
653 jQuery("#btn_row_"+ buttonId + " .button_showonphone")
654 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_phone]")
655 .attr("id", "button_"+ buttonId +"_show_on_phone");
656
657 jQuery("label[for='button_"+ -1 +"_show_on_phone']").attr("for", "button_"+ buttonId +"_show_on_phone");
658
659 // Show on desktop
660 jQuery("#btn_row_"+ buttonId + " .button_showondesktop")
661 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_desktop]")
662 .attr("id", "button_"+ buttonId +"_show_on_desktop");
663
664 jQuery("label[for='button_"+ -1 +"_show_on_desktop']").attr("for", "button_"+ buttonId +"_show_on_desktop");
665
666 // Url
667 jQuery("#btn_row_"+ buttonId + " .button_isurl")
668 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_url]")
669 .attr("id", "button_"+ buttonId +"_url");
670
671 jQuery("label[for='button_"+ -1 +"_url']").attr("for", "button_"+ buttonId +"_url");
672
673 // Is phone buttonId
674 jQuery("#btn_row_"+ buttonId + " .button_isphonenumber")
675 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_is_phonenumber]")
676 .attr("id", "button_"+ buttonId +"_is_phonenumber");
677
678 jQuery("label[for='button_"+ -1 +"_is_phonenumber']").attr("for", "button_"+ buttonId +"_is_phonenumber");
679
680 // New tab
681 jQuery("#btn_row_"+ buttonId + " .button_isnewtab")
682 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_url_newtab]")
683 .attr("id", "button_"+ buttonId +"_url_newtab");
684
685 jQuery("label[for='button_"+ -1 +"_url_newtab']").attr("for", "button_"+ buttonId +"_url_newtab");
686
687
688 // Show only on opening hours
689 jQuery("#btn_row_"+ buttonId + " .button_showwhenopened")
690 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_when_opened]")
691 .attr("id", "button_"+ buttonId +"_show_when_opened");
692
693 jQuery("label[for='button_"+ -1 +"_show_when_opened']").attr("for", "button_"+ buttonId +"_show_when_opened");
694
695 // Show only on opening hours
696 jQuery("#btn_row_"+ buttonId + " .button_hidelabel")
697 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_hide_label]")
698 .attr("id", "button_"+ buttonId +"_hide_label");
699
700 jQuery("label[for='button_"+ -1 +"_hide_label']").attr("for", "button_"+ buttonId +"_hide_label");
701
702 /*
703 * Link fixes
704 */
705 // Delete button link
706 jQuery("#btn_row_"+ buttonId + " .delete-button").attr("href", "javascript:buttonizer.removeRow("+ buttonId +")");
707
708 // Show on mobile button link
709 jQuery("#btn_row_"+ buttonId + " .mobiledesktop.mobile-button").attr("href", "javascript:buttonizer.toggleMobile("+ buttonId +")");
710
711 // Show on desktop button link
712 jQuery("#btn_row_"+ buttonId + " .mobiledesktop.desktop-button").attr("href", "javascript:buttonizer.toggleDesktop("+ buttonId +")");
713 },
714
715 createWindow: function(data) {
716 this.settings.windowNumber++;
717 var currentWindow = this.settings.windowNumber;
718
719 if(!data.title) {
720 data.title = '';
721 }
722
723 if(!data.text) {
724 data.text = '<p>This dialog has not text.</p><p>Weird, isn\'t it?</p>';
725 }
726
727 if(!data.confirmText) {
728 data.confirmText = 'Close';
729 }
730
731 if(!data.canCancel) {
732 data.canCancel = false;
733 }
734
735 if(!data.cancelText) {
736 data.cancelText = 'Cancel';
737 }
738
739 if(!data.onConfirm) {
740 data.onConfirm = function() {};
741 }
742
743 if(!data.onClose) {
744 data.onClose = function() {};
745 }
746
747 if(!data.afterInit) {
748 data.afterInit = function() {};
749 }
750
751 var windowStyle = '<div class="fs-modal active" id="buttonizer-window-'+ currentWindow +'"><div class="fs-modal-dialog">';
752
753 windowStyle += '<div class="fs-modal-header"><h4>'+ data.title +'</h4><a href="!#" class="fs-close"><i class="dashicons dashicons-no" title="Dismiss"></i></a></div>';
754
755 windowStyle += '<div class="fs-modal-body"><div class="fs-modal-panel active">';
756 windowStyle += data.text;
757 windowStyle += '</div></div>';
758
759 windowStyle += '<div class="fs-modal-footer">' + (data.canCancel ? '<button class="button cancel" tabindex="3">'+ data.cancelText +'</button> ' : '') +' <button class="button button-primary confirm" tabindex="4">'+ data.confirmText +'</button></div>';
760
761 windowStyle += '</div></div>';
762
763 jQuery("body").append(windowStyle);
764
765 jQuery(document).ready(data.afterInit);
766
767 jQuery("#buttonizer-window-"+ currentWindow + " .fs-close, #buttonizer-window-"+ currentWindow + " button").click(function(e) {
768 e.preventDefault();
769 jQuery("#buttonizer-window-"+ currentWindow).fadeOut();
770
771 if(jQuery(this).hasClass("confirm")) {
772 data.onConfirm();
773 }
774
775 data.onClose();
776 })
777 },
778
779 /*
780 * Font awesome searcher
781 */
782 faSettings: {
783 objects: 0,
784 currentSelect: {},
785 currentObject: {},
786 isGenerated: false,
787 isOpened: false
788 },
789 faInit: function() {
790 buttonizer.faSettings.isOpened = false;
791
792 if(buttonizer.faSettings.isGenerated == false) {
793 buttonizer.faSettings.isGenerated = true;
794 fontAwesome = jQuery.map(fontAwesome, function(value, index) {
795 return [index];
796 });
797 }
798
799 jQuery("body").click(function(e){
800 if(!jQuery(e.target).closest('.fontawesome-searcher').length && !jQuery(e.target).closest('.fontawesome-searcher-clicker').length){
801 jQuery(".fontawesome-searcher").hide();
802 buttonizer.faSettings.isOpened = false;
803 }
804 });
805
806 var typeTimeOut = setTimeout(function() { buttonizer.faSearchWord(''); }, 300);
807
808 var adminBody = jQuery("#wpbody");
809
810 jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").keyup(function() {
811 clearInterval(typeTimeOut);
812
813 typeTimeOut = setTimeout(function() { buttonizer.faSearchWord(jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").val()); }, 300);
814 });
815
816 jQuery("select.fa-chooser").each(function() {
817 buttonizer.faSettings.objects++;
818 var obj = jQuery(this);
819
820 obj.hide();
821 obj.parent().append("<a href=\"javascript:void(0)\" class=\"fontawesome-searcher-clicker\" id=\"fa-chooser_"+ buttonizer.faSettings.objects +"\">Icon: "+ obj.val() +" &nbsp; <i class=\"fa "+ obj.val() +"\"></i></a>");
822
823 var newObject = jQuery("#fa-chooser_" + buttonizer.faSettings.objects);
824 newObject.click(function(e) {
825 if(buttonizer.faSettings.isOpened == false || buttonizer.faSettings.currentSelect != obj) {
826 jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").focus();
827 buttonizer.faSettings.isOpened = true;
828
829 // Update process
830 jQuery(".fontawesome-searcher").css({
831 "top": newObject.offset().top - 20 + newObject.height(),
832 "left": newObject.offset().left - adminBody.offset().left,
833 "width": newObject.width()
834 }).show();
835
836 buttonizer.faSettings.currentSelect = obj;
837 buttonizer.faSettings.currentObject = newObject;
838 }else{
839 buttonizer.faSettings.isOpened = false;
840 jQuery(".fontawesome-searcher").hide();
841 }
842
843 e.preventDefault();
844 });
845 });
846 },
847 faSearchWord: function(word) {
848 var foundMatches = [];
849
850 for(var i = 0; i < fontAwesome.length; i++) {
851 if(fontAwesome[i].indexOf(word) !== -1) {
852 foundMatches.push(fontAwesome[i]);
853 }
854 };
855
856 if(foundMatches.length == 0) {
857 jQuery(".fontawesome-searcher .no-matches-found").show();
858 jQuery(".fontawesome-searcher .fontawesome-searcher-icons").hide();
859 }else{
860 jQuery(".fontawesome-searcher .no-matches-found").hide();
861 jQuery(".fontawesome-searcher .fontawesome-searcher-icons").show();
862
863 var text = '<table><tr>';
864 for(var b = 0; b < foundMatches.length; b++) {
865 if(b % 4 == 0) {
866 text += "</tr><tr>";
867 }
868
869 text += '<td><a href="javascript:buttonizer.faChooseIcon(\''+ foundMatches[b] +'\')"><i class="fa '+ foundMatches[b] +'"></i></a></td>';
870 };
871
872 text += '</tr>';
873
874 jQuery(".fontawesome-searcher .fontawesome-searcher-icons").html(text);
875 }
876 },
877 faChooseIcon: function(icon) {
878 buttonizer.faSettings.currentSelect.val(icon).change();
879 buttonizer.faSettings.currentObject.html("Icon: "+ icon +" &nbsp; <i class=\"fa "+ icon +"\"></i>");
880 jQuery("#" + buttonizer.faSettings.currentObject.attr("id")).click();
881 }
882 }
883
884 document.addEventListener('DOMContentLoaded', buttonizer.init, false);
885
886 window.onbeforeunload = function(){
887 if(buttonizer.settings.hasChanges && !buttonizer.settings.clickedButton) {
888 return 'You have unsaved data. Are you sure you want to leave?';
889 }
890 };
891