PluginProbe
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder / 1.0.8
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder v1.0.8
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.8, at js/dashboard.js

892 lines 36.6 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 colorPalet.find(".text").html(customColors ? 'Custom colors' : 'Default colors');
269
270 colorPalet.find("input.custom").val(customColors ? '1' : '0').change();
271 colorPalet.find("input.default").val(currentColors.default);
272 colorPalet.find("input.pushed").val(currentColors.pushed);
273 colorPalet.find("input.icon").val(currentColors.icon);
274 }
275 },
276
277 rgb2hex: function(rgb) {
278 if(rgb == null || typeof rgb == "null") {
279 return '#eeeeee';
280 }
281
282 rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
283 function hex(x) {
284 return ("0" + parseInt(x).toString(16)).slice(-2);
285 }
286
287 if(rgb == null || typeof rgb == "null") {
288 return '#eeeeee';
289 }
290
291 return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
292 },
293
294 loadPageCategorie: function() {
295 jQuery(".page-categorie-styling").each(function() {
296 var maxLoaded = 10;
297 var isLoaded = 10;
298 var table = jQuery(this);
299 jQuery(this).addClass("initialized")
300
301 table.find("tr").each(function() {
302 jQuery(this).click(function(e) {
303 buttonizer.settings.hasChanges = true;
304 if(jQuery(e.target).attr("type") != "checkbox") {
305 jQuery(this).find("input").click();
306 }
307 });
308 });
309
310 jQuery(".categories-load-more[data-id="+ jQuery(this).attr("data-id") +"]").click(function() {
311 maxLoaded += 10;
312 isLoaded = 0;
313
314 table.find("tr").each(function() {
315 isLoaded++;
316 if(isLoaded <= maxLoaded) {
317 jQuery(this).show();
318 }else{
319 return;
320 }
321 });
322
323 if(jQuery(".page-categorie-styling[data-id="+ jQuery(this).attr("data-id") +"] tr").length < maxLoaded) {
324 jQuery(this).hide();
325 }
326 });
327 });
328 },
329
330 addSortable: function() {
331 var sortable = new Sortable(document.getElementById("button-rows"), {
332 group: "button-rows",
333 sort: true,
334 animation: 150,
335 scroll: true,
336 scrollSensitivity: 30,
337 scrollSpeed: 10,
338
339 onSort: function (evt) {
340 jQuery("#" + evt.clone.children[0].id + " .row-info").css({
341 opacity: .45,
342 }).delay(500).animate({
343 opacity: 1,
344 }, 500);
345 }
346 });
347 },
348
349 saveAnimation: function() {
350 jQuery(".savebutton").each(function() {
351 jQuery(this).html('<i class="fa fa-cog fa-spin"></i> <span>Saving</span>');
352 });
353 buttonizer.settings.clickedButton = true;
354 jQuery('form#buttonizer').submit();
355 },
356
357 /*
358 * Buttons
359 */
360 initButtons: function() {
361 jQuery(".button-row .savebutton").each(function() {
362 jQuery(this).click(buttonizer.saveAnimation);
363 });
364
365 jQuery(".button-row").each(function() {
366 if(jQuery(this).attr("button-id") == '-1') {
367 return;
368 }
369
370 var rowObj = jQuery(this);
371 var rowId = jQuery(this).attr("button-id");
372 var buttonTitle = rowObj.find(".row-info span .row-title");
373 var buttonEdit = rowObj.find(".row-info .pencil-edit");
374 var buttonTitleField = rowObj.find(".button_title");
375 var doubleClick = setTimeout(function() {}, 100);
376 var isCategory = rowObj.hasClass('is_category');
377 var clicked = 0;
378
379 buttonEdit.click(function(e) {
380 e.preventDefault();
381 buttonTitle.dblclick();
382 });
383
384 buttonTitle.html(buttonTitleField.val());
385
386 rowObj.find(".row-info").click(function(e) {
387 if(
388 jQuery(e.target).hasClass('fa-desktop') ||
389 jQuery(e.target).hasClass('fa-mobile') ||
390 jQuery(e.target).hasClass('fa-pencil') ||
391 jQuery(e.target).hasClass('mobiledesktop') ||
392 jQuery(e.target).hasClass('is-live-button') ||
393 jQuery(e.target).hasClass('must-save-button')
394 ) {
395 return;
396 }
397
398 clicked = 0;
399 clearInterval(doubleClick);
400 doubleClick = setTimeout(function() {
401 if(clicked == 0) {
402 if(rowObj.hasClass("opened")) {
403 rowObj.removeClass("opened");
404 }else{
405 rowObj.addClass("opened");
406 }
407 }
408 clicked = 0;
409 }, 100);
410 });
411
412 buttonTitle.dblclick(function() {
413 buttonizer.updateTitle(buttonTitle, buttonTitleField, false);
414
415 clicked++;
416 });
417
418 rowObj.find(".button_showonphone").change(function(e) {
419 var isSelected = jQuery(this).is(":checked");
420
421 if(!isSelected) {
422 jQuery("#btn_row_" + rowId + " .row-info .mobile-button").addClass("selected");
423 }else {
424 jQuery("#btn_row_" + rowId + " .row-info .mobile-button").removeClass("selected");
425 }
426 });
427
428 rowObj.find('.button_title').change(function() {
429 newTitle = jQuery(this).val();
430
431 if(buttonizer.checkTitleDuplicate(newTitle, rowId)) {
432 buttonizer.updateTitle(buttonTitle, buttonTitleField, true, newTitle);
433 return;
434 }
435
436 buttonTitle.html(newTitle);
437 });
438
439 rowObj.find(".button_showondesktop").change(function(e) {
440 var isSelected = jQuery(this).is(":checked");
441
442 if(!isSelected) {
443 jQuery("#btn_row_" + rowId + " .row-info .desktop-button").addClass("selected");
444 }else {
445 jQuery("#btn_row_" + rowId + " .row-info .desktop-button").removeClass("selected");
446 }
447 });
448
449 jQuery("#button_"+ rowId +"_icon").change(function(e) {
450 rowObj.find(".button-icon").attr('class', "fa "+ jQuery(this).val() +" button-icon");
451 });
452
453 jQuery("#btn_row_" + rowId + " input").change(function() {
454 jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide();
455 jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show();
456 });
457
458 if(isCategory) {
459 var checked = false;
460 rowObj.find(".select-all").click(function() {
461 if(!checked) {
462 checked = true;
463 rowObj.find(".page-categorie-styling input[type=checkbox]").attr("checked", "checked");
464 }else{
465 checked = false;
466 rowObj.find(".page-categorie-styling input[type=checkbox]").removeAttr("checked");
467 }
468 });
469 }else{
470 // Image icon handler
471 buttonizer.iconImageHandler(rowObj.find(".icon-or-image"));
472 buttonizer.colorPaletHandler(rowObj.find(".button-color-palet"));
473 }
474 });
475 },
476
477 updateTitle: function(buttonTitle, buttonTitleField, isDuplicate, text) {
478 if(!text) {
479 var text = '';
480 }
481
482 if(!isDuplicate) {
483 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());
484 }else{
485 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);
486 }
487
488 if(!newTitle || newTitle == "") {
489 if(isDuplicate) {
490 buttonTitleField.val(buttonTitle.html());
491 }
492 return;
493 }
494
495 if(buttonizer.checkTitleDuplicate(newTitle)) {
496 buttonizer.updateTitle(buttonTitle, buttonTitleField, true, newTitle);
497 return;
498 }
499
500 buttonTitle.html(newTitle);
501 buttonTitleField.val(newTitle);
502 },
503
504 checkTitleDuplicate: function(text, allowRowId) {
505 isDuplicate = false;
506 if(!allowRowId) {
507 var allowRowId = -1;
508 }
509
510 jQuery(".button-row").each(function() {
511 if(jQuery(this).find('.button_title').val() == text && jQuery(this).attr("button-id") != allowRowId) {
512 isDuplicate = true;
513 }
514 });
515
516 return isDuplicate;
517 },
518
519 removeRow: function(id) {
520 var buttonName = jQuery("#btn_row_" +id + " .row-info span .row-title").html();
521 var wasCategory = jQuery("#btn_row_" + id).hasClass('is_category');
522
523 if(confirm("Are you sure you want to remove the row with the text: '"+ buttonName +"'?\n\nThis is not recoverable.")) {
524 jQuery("#btn_row_" +id).remove();
525
526 if(jQuery(".button-row").length > 1) {
527 jQuery(".buttonizer-no-buttons").hide();
528 }else{
529 jQuery(".buttonizer-no-buttons").show();
530 }
531 }
532 },
533
534 toggleMobile: function(id) {
535 var isSelected = jQuery("#button_"+ id +"_show_on_phone").is(":checked");
536
537 if(!isSelected) {
538 jQuery("#btn_row_" + id + " .row-info .mobile-button").removeClass("selected");
539 jQuery("#button_"+ id +"_show_on_phone").click();
540 }else {
541 jQuery("#btn_row_" + id + " .row-info .mobile-button").addClass("selected");
542 jQuery("#button_"+ id +"_show_on_phone").click();
543 }
544
545 jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide();
546 jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show();
547 },
548
549 toggleDesktop: function(id) {
550 var isSelected = jQuery("#button_"+ id +"_show_on_desktop").is(":checked");
551
552 if(!isSelected) {
553 jQuery("#btn_row_" + id + " .row-info .desktop-button").removeClass("selected");
554 jQuery("#button_"+ id +"_show_on_desktop").click();
555 }else {
556 jQuery("#btn_row_" + id + " .row-info .desktop-button").addClass("selected");
557 jQuery("#button_"+ id +"_show_on_desktop").click();
558 }
559
560 jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide();
561 jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show();
562 },
563
564 addRow: function() {
565 if(jQuery("#new-button").hasClass('disabled')) {
566 return;
567 }
568 buttonizer.settings.hasChanges = true;
569
570 jQuery(".buttonizer-no-buttons").hide();
571
572 var isCategory = jQuery(".button-row[button-id=-1]").hasClass("is_category");
573
574 jQuery("#new-button").attr('disabled', 'disabled').addClass('disabled');
575 var defaultRow = jQuery(".button-row[button-id=-1]").html();
576 var numberOfButtons = jQuery(".button-row").length - (isCategory ? 1 : 0);
577
578 numberOfButtons = Math.floor(Date.now() / 1000);
579 numberOfButtons = numberOfButtons + "-" + Math.floor((Math.random() * 999) + 100);
580 numberOfButtons = numberOfButtons.replace('-', '');
581
582 var newData = defaultRow.replace('/-1/g', numberOfButtons);
583 newData = newData.replace('-1', numberOfButtons);
584
585 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>' : ''));
586
587 clearInterval(buttonizer.setTimouts.a);
588 clearInterval(buttonizer.setTimouts.b);
589
590 buttonizer.setTimouts.a = setTimeout(function() {
591 jQuery(".button-row *").unbind("click");
592 jQuery(".button-row").removeClass("opened");
593 jQuery(".fontawesome-searcher-clicker").remove();
594 jQuery("#btn_row_"+ numberOfButtons +" .button_title").val("New button " + numberOfButtons);
595
596 if(isCategory) {
597 jQuery("#btn_row_"+ numberOfButtons +" input").each(function() {
598 jQuery(this).attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"][]");
599 });
600
601 jQuery("#btn_row_"+ numberOfButtons + " select").attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"_type]");
602 }
603 }, 100);
604
605
606 buttonizer.setTimouts.b = setTimeout(function() {
607 buttonizer.initButtons();
608 if(!isCategory) {
609 buttonizer.updateRowInputNames(numberOfButtons);
610 jQuery("#btn_row_"+ numberOfButtons).addClass('opened');
611 jQuery("#btn_row_"+ numberOfButtons + " input.button_title").focus();
612 }else{
613 console.log("Initialize new page category");
614 jQuery("#btn_row_"+ numberOfButtons + " #categoryIsUsed").val(numberOfButtons);
615 jQuery("#btn_row_"+ numberOfButtons + " #categoryIsUsed").attr("name", buttonizer.settings.wpCategorySaveKey + '[categorieOrder][]');
616 jQuery("#btn_row_"+ numberOfButtons + " .delete-button").attr("href", "javascript:buttonizer.removeRow("+ numberOfButtons +")");
617 jQuery("#btn_row_"+ numberOfButtons + " .button_title").attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"_title]").val('New page category ' + (jQuery(".button-row").length - 1));
618 jQuery("#btn_row_"+ numberOfButtons + " .row-title").html("New page category " + (jQuery(".button-row").length - 1));
619 }
620 buttonizer.faInit();
621 buttonizer.loadPageCategorie();
622 jQuery("#new-button").removeAttr('disabled').removeClass('disabled');
623
624 jQuery("#btn_row_"+ numberOfButtons + " .savebutton").show();
625 }, 400);
626 },
627
628 updateRowInputNames: function(buttonId) {
629 // Textfield
630 jQuery("#btn_row_"+ buttonId + " .button_textfield")
631 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_text]")
632 .attr("id", "button_"+ buttonId +"_text").val("");
633
634 // Iconfield
635 jQuery("#btn_row_"+ buttonId + " .icon-placeholder select").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_icon]");
636
637 // Iconfield
638 jQuery("#btn_row_"+ buttonId + " .image-placeholder input").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_image]");
639
640 // Button title
641 jQuery("#btn_row_"+ buttonId + " .button_title").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_title]");
642
643 // Button show on page category
644 jQuery("#btn_row_"+ buttonId + " #button_category").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_pages]");
645
646 // Color palets
647 jQuery("#btn_row_"+ buttonId + " input.custom").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_using_custom_colors]");
648
649 jQuery("#btn_row_"+ buttonId + " input.default").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_colors_button]");
650 jQuery("#btn_row_"+ buttonId + " input.pushed").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_colors_pushed]");
651 jQuery("#btn_row_"+ buttonId + " input.icon").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_colors_icon]");
652
653 // Show on phone
654 jQuery("#btn_row_"+ buttonId + " .button_showonphone")
655 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_phone]")
656 .attr("id", "button_"+ buttonId +"_show_on_phone");
657
658 jQuery("label[for='button_"+ -1 +"_show_on_phone']").attr("for", "button_"+ buttonId +"_show_on_phone");
659
660 // Show on desktop
661 jQuery("#btn_row_"+ buttonId + " .button_showondesktop")
662 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_desktop]")
663 .attr("id", "button_"+ buttonId +"_show_on_desktop");
664
665 jQuery("label[for='button_"+ -1 +"_show_on_desktop']").attr("for", "button_"+ buttonId +"_show_on_desktop");
666
667 // Url
668 jQuery("#btn_row_"+ buttonId + " .button_isurl")
669 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_url]")
670 .attr("id", "button_"+ buttonId +"_url");
671
672 jQuery("label[for='button_"+ -1 +"_url']").attr("for", "button_"+ buttonId +"_url");
673
674 // Is phone buttonId
675 jQuery("#btn_row_"+ buttonId + " .button_isphonenumber")
676 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_is_phonenumber]")
677 .attr("id", "button_"+ buttonId +"_is_phonenumber");
678
679 jQuery("label[for='button_"+ -1 +"_is_phonenumber']").attr("for", "button_"+ buttonId +"_is_phonenumber");
680
681 // New tab
682 jQuery("#btn_row_"+ buttonId + " .button_isnewtab")
683 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_url_newtab]")
684 .attr("id", "button_"+ buttonId +"_url_newtab");
685
686 jQuery("label[for='button_"+ -1 +"_url_newtab']").attr("for", "button_"+ buttonId +"_url_newtab");
687
688
689 // Show only on opening hours
690 jQuery("#btn_row_"+ buttonId + " .button_showwhenopened")
691 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_when_opened]")
692 .attr("id", "button_"+ buttonId +"_show_when_opened");
693
694 jQuery("label[for='button_"+ -1 +"_show_when_opened']").attr("for", "button_"+ buttonId +"_show_when_opened");
695
696 // Show only on opening hours
697 jQuery("#btn_row_"+ buttonId + " .button_hidelabel")
698 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_hide_label]")
699 .attr("id", "button_"+ buttonId +"_hide_label");
700
701 jQuery("label[for='button_"+ -1 +"_hide_label']").attr("for", "button_"+ buttonId +"_hide_label");
702
703 /*
704 * Link fixes
705 */
706 // Delete button link
707 jQuery("#btn_row_"+ buttonId + " .delete-button").attr("href", "javascript:buttonizer.removeRow("+ buttonId +")");
708
709 // Show on mobile button link
710 jQuery("#btn_row_"+ buttonId + " .mobiledesktop.mobile-button").attr("href", "javascript:buttonizer.toggleMobile("+ buttonId +")");
711
712 // Show on desktop button link
713 jQuery("#btn_row_"+ buttonId + " .mobiledesktop.desktop-button").attr("href", "javascript:buttonizer.toggleDesktop("+ buttonId +")");
714 },
715
716 createWindow: function(data) {
717 this.settings.windowNumber++;
718 var currentWindow = this.settings.windowNumber;
719
720 if(!data.title) {
721 data.title = '';
722 }
723
724 if(!data.text) {
725 data.text = '<p>This dialog has not text.</p><p>Weird, isn\'t it?</p>';
726 }
727
728 if(!data.confirmText) {
729 data.confirmText = 'Close';
730 }
731
732 if(!data.canCancel) {
733 data.canCancel = false;
734 }
735
736 if(!data.cancelText) {
737 data.cancelText = 'Cancel';
738 }
739
740 if(!data.onConfirm) {
741 data.onConfirm = function() {};
742 }
743
744 if(!data.onClose) {
745 data.onClose = function() {};
746 }
747
748 if(!data.afterInit) {
749 data.afterInit = function() {};
750 }
751
752 var windowStyle = '<div class="fs-modal active" id="buttonizer-window-'+ currentWindow +'"><div class="fs-modal-dialog">';
753
754 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>';
755
756 windowStyle += '<div class="fs-modal-body"><div class="fs-modal-panel active">';
757 windowStyle += data.text;
758 windowStyle += '</div></div>';
759
760 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>';
761
762 windowStyle += '</div></div>';
763
764 jQuery("body").append(windowStyle);
765
766 jQuery(document).ready(data.afterInit);
767
768 jQuery("#buttonizer-window-"+ currentWindow + " .fs-close, #buttonizer-window-"+ currentWindow + " button").click(function(e) {
769 e.preventDefault();
770 jQuery("#buttonizer-window-"+ currentWindow).fadeOut();
771
772 if(jQuery(this).hasClass("confirm")) {
773 data.onConfirm();
774 }
775
776 data.onClose();
777 })
778 },
779
780 /*
781 * Font awesome searcher
782 */
783 faSettings: {
784 objects: 0,
785 currentSelect: {},
786 currentObject: {},
787 isGenerated: false,
788 isOpened: false
789 },
790 faInit: function() {
791 buttonizer.faSettings.isOpened = false;
792
793 if(buttonizer.faSettings.isGenerated == false) {
794 buttonizer.faSettings.isGenerated = true;
795 fontAwesome = jQuery.map(fontAwesome, function(value, index) {
796 return [index];
797 });
798 }
799
800 jQuery("body").click(function(e){
801 if(!jQuery(e.target).closest('.fontawesome-searcher').length && !jQuery(e.target).closest('.fontawesome-searcher-clicker').length){
802 jQuery(".fontawesome-searcher").hide();
803 buttonizer.faSettings.isOpened = false;
804 }
805 });
806
807 var typeTimeOut = setTimeout(function() { buttonizer.faSearchWord(''); }, 300);
808
809 var adminBody = jQuery("#wpbody");
810
811 jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").keyup(function() {
812 clearInterval(typeTimeOut);
813
814 typeTimeOut = setTimeout(function() { buttonizer.faSearchWord(jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").val()); }, 300);
815 });
816
817 jQuery("select.fa-chooser").each(function() {
818 buttonizer.faSettings.objects++;
819 var obj = jQuery(this);
820
821 obj.hide();
822 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>");
823
824 var newObject = jQuery("#fa-chooser_" + buttonizer.faSettings.objects);
825 newObject.click(function(e) {
826 if(buttonizer.faSettings.isOpened == false || buttonizer.faSettings.currentSelect != obj) {
827 jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").focus();
828 buttonizer.faSettings.isOpened = true;
829
830 // Update process
831 jQuery(".fontawesome-searcher").css({
832 "top": newObject.offset().top - 20 + newObject.height(),
833 "left": newObject.offset().left - adminBody.offset().left,
834 "width": newObject.width()
835 }).show();
836
837 buttonizer.faSettings.currentSelect = obj;
838 buttonizer.faSettings.currentObject = newObject;
839 }else{
840 buttonizer.faSettings.isOpened = false;
841 jQuery(".fontawesome-searcher").hide();
842 }
843
844 e.preventDefault();
845 });
846 });
847 },
848 faSearchWord: function(word) {
849 var foundMatches = [];
850
851 for(var i = 0; i < fontAwesome.length; i++) {
852 if(fontAwesome[i].indexOf(word) !== -1) {
853 foundMatches.push(fontAwesome[i]);
854 }
855 };
856
857 if(foundMatches.length == 0) {
858 jQuery(".fontawesome-searcher .no-matches-found").show();
859 jQuery(".fontawesome-searcher .fontawesome-searcher-icons").hide();
860 }else{
861 jQuery(".fontawesome-searcher .no-matches-found").hide();
862 jQuery(".fontawesome-searcher .fontawesome-searcher-icons").show();
863
864 var text = '<table><tr>';
865 for(var b = 0; b < foundMatches.length; b++) {
866 if(b % 4 == 0) {
867 text += "</tr><tr>";
868 }
869
870 text += '<td><a href="javascript:buttonizer.faChooseIcon(\''+ foundMatches[b] +'\')"><i class="fa '+ foundMatches[b] +'"></i></a></td>';
871 };
872
873 text += '</tr>';
874
875 jQuery(".fontawesome-searcher .fontawesome-searcher-icons").html(text);
876 }
877 },
878 faChooseIcon: function(icon) {
879 buttonizer.faSettings.currentSelect.val(icon).change();
880 buttonizer.faSettings.currentObject.html("Icon: "+ icon +" &nbsp; <i class=\"fa "+ icon +"\"></i>");
881 jQuery("#" + buttonizer.faSettings.currentObject.attr("id")).click();
882 }
883 }
884
885 document.addEventListener('DOMContentLoaded', buttonizer.init, false);
886
887 window.onbeforeunload = function(){
888 if(buttonizer.settings.hasChanges && !buttonizer.settings.clickedButton) {
889 return 'You have unsaved data. Are you sure you want to leave?';
890 }
891 };
892