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

1,497 lines 63.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 if(document.location.href.indexOf('page=Buttonizer') === -1) {
22 return;
23 }
24
25 buttonizer.overwriteFavIcon();
26 buttonizer.faInit();
27 buttonizer.initButtons();
28 buttonizer.initIntro();
29
30 // WP color picker
31 jQuery('#button_unpushed').wpColorPicker();
32 jQuery('#button_pushed').wpColorPicker();
33 jQuery('#icon_color').wpColorPicker();
34 jQuery('.icon_label_color').wpColorPicker();
35
36 jQuery(".savebutton").each(function() {
37 jQuery(this).click(buttonizer.saveAnimation);
38 });
39
40 jQuery("input, textarea, select").change(function() {
41 buttonizer.settings.hasChanges = true;
42 });
43
44 setTimeout(function() {
45 // Init preview button
46 jQuery('.button-preview').css({
47 'background-color': jQuery("#button_unpushed").val()
48 });
49
50 jQuery(".button-preview").hover(function() {
51 jQuery(this).css({
52 'background-color': jQuery("#button_pushed").val()
53 });
54 }, function() {
55 jQuery(this).css({
56 'background-color': jQuery("#button_unpushed").val()
57 });
58 });
59 }, 500);
60
61 jQuery(".vertical-tabs .icon-or-image").each(function() {
62 buttonizer.iconImageHandler(jQuery(this));
63 });
64
65 // Remove the spam from other plugins
66 setTimeout(function() {
67 var foundOurContent = false;
68 if(jQuery(".buttonizerWarning").length > 0) {
69 foundOurContent = true;
70 var buttonizerData = jQuery(".buttonizerWarning").html();
71 var buttonizerStyle = jQuery(".buttonizerWarning").attr('class');
72 }
73
74 jQuery("#wordpress-plugin-message-spam").remove();
75
76 if(foundOurContent) {
77 jQuery(".nav-tab-wrapper").after('<div class="'+ buttonizerStyle +'">'+ buttonizerData +'</div>');
78 }
79 }, 1000);
80
81 // Hash
82 if(document.location.hash != "") {
83 if(document.location.hash != "#buttonizer-tour") {
84 var tabKey = document.location.hash;
85 buttonizer.tabNavigate(tabKey.replace("#tab_", ""));
86 }
87 }
88
89 jQuery(".buttonizer-click-to-pro").each(function() {
90 jQuery(this).click(function(e) {
91 e.preventDefault();
92 buttonizer.proInfoWindow();
93 });
94 });
95
96 buttonizer.loadPageCategorie();
97
98 if(document.getElementById("button-rows") != null) {
99 buttonizer.addSortable();
100 }
101 },
102
103 proInfoWindow: function() {
104 buttonizer.createWindow({
105 title: 'You like Buttonizer?',
106 text: '<p>Are you ready to try Buttonizer PRO?</p><p><b class="color-buttonizer">What do you get?</b></p>'+
107
108 '<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Show on opening hours</div>' +
109 '<div class="color-buttonizer-orange buttonizer-pro-checklist"><i class="fa fa-check"></i> Show buttons on specific pages: Use page rules</div>' +
110 '<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Unlimited page rules</div>' +
111 '<div class="color-buttonizer-orange buttonizer-pro-checklist"><i class="fa fa-check"></i> Add custom image or button-icon</div>' +
112 '<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Exit intend</div>' +
113 '<div class="color-buttonizer-orange buttonizer-pro-checklist"><i class="fa fa-check"></i> Show on scroll</div>' +
114 '<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Show on timeout</div>' +
115 '<div class="color-buttonizer-orange buttonizer-pro-checklist"><i class="fa fa-check"></i> Custom class names</div>' +
116 '<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Change the label background and color</div>' +
117 '<br />' +
118 '<p class="color-buttonizer text-right"><b>Do you <span><i class="fa fa-heart"></i></span> these features?</b></p>',
119 confirmText: 'Upgrade',
120 onConfirm: function() {
121 document.location.href = 'admin.php?page=Buttonizer-pricing';
122 }
123 });
124 },
125
126 overwriteFavIcon: function() {
127 if(typeof faviconUrl != 'undefined') {
128 (function () {
129 var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
130 link.type = 'image/x-icon';
131 link.rel = 'shortcut icon';
132 link.href = faviconUrl;
133 document.getElementsByTagName('head')[0].appendChild(link);
134 })();
135 }
136 },
137
138 tabNavigate: function(key) {
139 jQuery(".vertical-tabs .tab-container").each(function() {
140 if(jQuery(this).attr('id') == "tab_container_" + key) {
141 jQuery(this).show();
142 }else{
143 jQuery(this).hide();
144 }
145 });
146
147 jQuery(".vertical-tabs .tabs a").each(function() {
148 if(jQuery(this).attr('id') == "tab_container_" + key) {
149 jQuery(this).addClass('nav-tab-active');
150 }else{
151 jQuery(this).removeClass('nav-tab-active');
152 }
153 });
154
155 // jQuery("type[name=_wp_http_referer]").val();
156 },
157
158 iconImageHandler: function(currentContainer) {
159 var type = currentContainer.data("type");
160
161 // Init
162 if(currentContainer.find(".image-background-checkbox").is(":checked")) {
163 currentContainer.find('.button-preview').css({
164 'background-image': "url('"+ currentContainer.find(".field_image_data").val() +"')",
165 'background-size': 'cover',
166 'background-position': 'center center'
167 });
168 currentContainer.find('.button-preview img').hide();
169 }
170
171 // Chooser
172 currentContainer.find(".placeholder-choose a").click(function() {
173 if(type == 'image') {
174 type = 'icon';
175
176 currentContainer.find(".image-placeholder").hide();
177 currentContainer.find(".icon-placeholder").show();
178
179 currentContainer.find("input").val("");
180 }else {
181 type = 'image';
182
183 currentContainer.find(".image-placeholder").show();
184 currentContainer.find(".icon-placeholder").hide();
185 }
186 });
187
188 // Insert image and icon type
189 currentContainer.find(".image-uploader-button").click(function(e) {
190 e.preventDefault();
191
192 var custom_uploader = wp.media({
193 title: 'Choose button icon',
194 multiple: false
195 })
196 .on('select', function() {
197 var attachment = custom_uploader.state().get('selection').first().toJSON();
198 currentContainer.find('.button-preview img').attr( 'src', attachment.url).show();
199 currentContainer.find(".button-preview").show();
200
201 currentContainer.find('.field_image_data').val(attachment.url);
202
203 if(currentContainer.find(".image-background-checkbox").is(":checked")) {
204 currentContainer.find('.button-preview').css({
205 'background-image': "url('"+ attachment.url +"')",
206 'background-size': 'cover',
207 'background-position': 'center center'
208 });
209 currentContainer.find('.button-preview img').hide();
210 }
211 })
212 .open();
213 });
214
215 // Insert image and icon type
216 currentContainer.find(".image-background-checkbox").click(function(e) {
217 var attachment = currentContainer.find(".field_image_data").val();
218
219 console.log(attachment);
220
221 if(!jQuery(this).is(":checked")) {
222 currentContainer.find('img').attr('src', attachment).show();
223
224 currentContainer.find('.button-preview').css({
225 'background-image': "",
226 'background-size': 'cover'
227 });
228 }else{
229 currentContainer.find('img').hide();
230 currentContainer.find('.button-preview').css({
231 'background-image': "url('"+ attachment +"')",
232 'background-size': 'cover',
233 'background-position': 'center center'
234 });
235 }
236 });
237 },
238
239 colorPaletHandler: function(colorPalet) {
240 var buttonId = colorPalet.attr("data-btnid");
241 var customColors = false;
242 var currentColors = {
243 default: buttonizer.rgb2hex(colorPalet.find(".color.default").css('background-color')),
244 pushed: buttonizer.rgb2hex(colorPalet.find(".color.pushed").css('background-color')),
245 icon: buttonizer.rgb2hex(colorPalet.find(".color.icon").css('background-color'))
246 };
247
248 jQuery("#btn_row_"+ buttonId +" .button-preview").css({ 'background-color': currentColors.default });
249
250 colorPalet.click(function() {
251 var randomText = (buttonizer.settings.windowNumber + 1);
252
253 buttonizer.createWindow({
254 title: 'Choose colors',
255 text:
256 '<p>Choose the colors here of your button. You can give every button different colors.</p>' +
257 '<table width="100%" class="color-chooser-table">' +
258 '<tr><td width="150">' +
259 '<b>Button color</b>' +
260 '</td><td>' +
261 '<input type="text" class="colorpalet-initializer" value="'+ currentColors.default +'" id="color_default_'+ randomText +'" />' +
262 '</td></tr>' +
263
264 '<tr><td>' +
265 '<b>Pushed/hover color</b>' +
266 '</td><td>' +
267 '<input type="text" class="colorpalet-initializer" value="'+ currentColors.pushed +'" id="color_pushed_'+ randomText +'" />' +
268 '</td></tr>' +
269
270 '<tr><td>' +
271 '<b>Icon color</b>' +
272 '</td><td>' +
273 '<input type="text" class="colorpalet-initializer" value="'+ currentColors.icon +'" id="color_icon_'+ randomText +'" />' +
274 '</td></tr>' +
275 '</table>',
276
277 confirmText: 'Choose',
278
279 afterInit: function() {
280 jQuery(".colorpalet-initializer").wpColorPicker();
281 },
282
283 onConfirm: function() {
284 currentColors.default = jQuery("#color_default_" + randomText).val();
285 currentColors.pushed = jQuery("#color_pushed_" + randomText).val();
286 currentColors.icon = jQuery("#color_icon_" + randomText).val();
287 jQuery("#btn_row_"+ buttonId +" .button-preview").css({ 'background-color': currentColors.default });
288 customColors = true;
289
290 jQuery("#reset_colors_" + buttonId).show();
291 updatePalet();
292 }
293 });
294 });
295
296 jQuery("#reset_colors_" + buttonId).click(function() {
297 buttonizer.createWindow({
298 title: 'Back to default colors',
299 text: '<p>The button colors will reset to the choosen default button colors (from the general settings).</p>' +
300 '<p>Are you sure you want to get the default colors for this button?</p>',
301
302 canCancel: true,
303 cancelText: 'Cancel',
304 confirmText: '<i class="fa fa-thumbs-o-up"></i>&nbsp; Yes, I am',
305
306 onConfirm: function() {
307 customColors = false;
308 currentColors.default = colorPalet.find(".color.default").attr("data-default");
309 currentColors.pushed = colorPalet.find(".color.pushed").attr("data-default");
310 currentColors.icon = colorPalet.find(".color.icon").attr("data-default");
311 updatePalet();
312 jQuery("#reset_colors_" + buttonId).hide();
313 jQuery("#btn_row_"+ buttonId +" .button-preview").css({ 'background-color': currentColors.default });
314 }
315 });
316 });
317
318 function updatePalet() {
319 colorPalet.find(".color.default").css({ 'background-color': currentColors.default});
320 colorPalet.find(".color.pushed").css({ 'background-color': currentColors.pushed});
321 colorPalet.find(".color.icon").css({ 'background-color': currentColors.icon});
322 colorPalet.find(".text").html(customColors ? 'Custom colors' : 'Default colors');
323
324 colorPalet.find("input.custom").val(customColors ? '1' : '0').change();
325 colorPalet.find("input.default").val(currentColors.default);
326 colorPalet.find("input.pushed").val(currentColors.pushed);
327 colorPalet.find("input.icon").val(currentColors.icon);
328 }
329 },
330
331 rgb2hex: function(rgb) {
332 if(rgb == null || typeof rgb == "null") {
333 return '#eeeeee';
334 }
335
336 rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
337 function hex(x) {
338 return ("0" + parseInt(x).toString(16)).slice(-2);
339 }
340
341 if(rgb == null || typeof rgb == "null") {
342 return '#eeeeee';
343 }
344
345 return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
346 },
347
348 loadPageCategorie: function() {
349
350 },
351
352 addSortable: function() {
353 var sortable = new Sortable(document.getElementById("button-rows"), {
354 group: "button-rows",
355 sort: true,
356 animation: 150,
357 scroll: true,
358 scrollSensitivity: 30,
359 scrollSpeed: 10,
360 handle: ".drag-handle",
361
362 onSort: function (evt) {
363 jQuery("#" + evt.clone.children[0].id + " .row-info").css({
364 opacity: .45,
365 }).delay(500).animate({
366 opacity: 1,
367 }, 500);
368 }
369 });
370 },
371
372 saveAnimation: function() {
373 jQuery(".savebutton").each(function() {
374 jQuery(this).html('<i class="fa fa-cog fa-spin"></i> <span>Saving</span>');
375 });
376 buttonizer.settings.clickedButton = true;
377 jQuery('form#buttonizer').submit();
378 },
379
380 /*
381 * Buttons
382 */
383 initButtons: function() {
384 jQuery(".button-row .savebutton").each(function() {
385 jQuery(this).click(buttonizer.saveAnimation);
386 });
387
388 jQuery(".button-row").each(function() {
389 if(jQuery(this).attr("button-id") == '-1') {
390 return;
391 }
392
393 var rowObj = jQuery(this);
394 var rowId = jQuery(this).attr("button-id");
395 var buttonTitle = rowObj.find(".row-info span .row-title");
396 var buttonEdit = rowObj.find(".row-info .pencil-edit");
397 var buttonTitleField = rowObj.find(".button_title");
398 var doubleClick = setTimeout(function() {}, 100);
399 var isCategory = rowObj.hasClass('is_category');
400 var clicked = 0;
401
402 buttonEdit.click(function(e) {
403 e.preventDefault();
404 buttonTitle.dblclick();
405 });
406
407 buttonTitle.html(buttonTitleField.val());
408
409 rowObj.find(".row-info").click(function(e) {
410 if(
411 jQuery(e.target).hasClass('fa-desktop') ||
412 jQuery(e.target).hasClass('fa-mobile') ||
413 jQuery(e.target).hasClass('fa-pencil') ||
414 jQuery(e.target).hasClass('mobiledesktop') ||
415 jQuery(e.target).hasClass('is-live-button') ||
416 jQuery(e.target).hasClass('must-save-button')
417 ) {
418 return;
419 }
420
421 clicked = 0;
422 clearInterval(doubleClick);
423 doubleClick = setTimeout(function() {
424 if(clicked == 0) {
425 if(rowObj.hasClass("opened")) {
426 rowObj.removeClass("opened");
427 }else{
428 rowObj.addClass("opened");
429 }
430 }
431 clicked = 0;
432 }, 100);
433 });
434
435 buttonTitle.dblclick(function() {
436 buttonizer.updateTitle(buttonTitle, buttonTitleField, false);
437
438 clicked++;
439 });
440
441 rowObj.find(".button_showonphone").change(function(e) {
442 var isSelected = jQuery(this).is(":checked");
443
444 if(!isSelected) {
445 jQuery("#btn_row_" + rowId + " .row-info .mobile-button").addClass("selected");
446 }else {
447 jQuery("#btn_row_" + rowId + " .row-info .mobile-button").removeClass("selected");
448 }
449 });
450
451 rowObj.find('.button_title').change(function() {
452 newTitle = jQuery(this).val();
453
454 if(buttonizer.checkTitleDuplicate(newTitle, rowId)) {
455 buttonizer.updateTitle(buttonTitle, buttonTitleField, true, newTitle);
456 return;
457 }
458
459 buttonTitle.html(newTitle);
460 });
461
462 rowObj.find(".button_showondesktop").change(function(e) {
463 var isSelected = jQuery(this).is(":checked");
464
465 if(!isSelected) {
466 jQuery("#btn_row_" + rowId + " .row-info .desktop-button").addClass("selected");
467 }else {
468 jQuery("#btn_row_" + rowId + " .row-info .desktop-button").removeClass("selected");
469 }
470 });
471
472 jQuery("#button_"+ rowId +"_icon").change(function(e) {
473 rowObj.find(".button-icon").attr('class', "fa "+ jQuery(this).val() +" button-icon");
474 });
475
476 jQuery("#btn_row_" + rowId + " input").change(function() {
477 jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide();
478 jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show();
479 });
480
481 if(isCategory) {
482
483 }else{
484 // Image icon handler
485 buttonizer.iconImageHandler(rowObj.find(".icon-or-image"));
486 buttonizer.colorPaletHandler(rowObj.find(".button-color-palet"));
487
488 buttonizer.buttonTypeHandler(rowObj);
489 }
490 });
491 },
492
493 updateTitle: function(buttonTitle, buttonTitleField, isDuplicate, text) {
494 if(!text) {
495 var text = '';
496 }
497
498 if(!isDuplicate) {
499 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());
500 }else{
501 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);
502 }
503
504 if(!newTitle || newTitle == "") {
505 if(isDuplicate) {
506 buttonTitleField.val(buttonTitle.html());
507 }
508 return;
509 }
510
511 if(buttonizer.checkTitleDuplicate(newTitle)) {
512 buttonizer.updateTitle(buttonTitle, buttonTitleField, true, newTitle);
513 return;
514 }
515
516 buttonTitle.html(newTitle);
517 buttonTitleField.val(newTitle);
518 },
519
520 checkTitleDuplicate: function(text, allowRowId) {
521 isDuplicate = false;
522 if(!allowRowId) {
523 var allowRowId = -1;
524 }
525
526 jQuery(".button-row").each(function() {
527 if(jQuery(this).find('.button_title').val() == text && jQuery(this).attr("button-id") != allowRowId) {
528 isDuplicate = true;
529 }
530 });
531
532 return isDuplicate;
533 },
534
535 removeRow: function(id) {
536 var buttonName = jQuery("#btn_row_" +id + " .row-info span .row-title").html();
537 var wasCategory = jQuery("#btn_row_" + id).hasClass('is_category');
538
539 if(confirm("Are you sure you want to remove the row with the text: '"+ buttonName +"'?\n\nThis is not recoverable.")) {
540 jQuery("#btn_row_" +id).remove();
541
542 if(jQuery(".button-row").length > 1) {
543 jQuery(".buttonizer-no-buttons").hide();
544 }else{
545 jQuery(".buttonizer-no-buttons").show();
546 }
547 }
548 },
549
550 toggleMobile: function(id) {
551 var isSelected = jQuery("#button_"+ id +"_show_on_phone").is(":checked");
552
553 if(!isSelected) {
554 jQuery("#btn_row_" + id + " .row-info .mobile-button").removeClass("selected");
555 jQuery("#button_"+ id +"_show_on_phone").click();
556 }else {
557 jQuery("#btn_row_" + id + " .row-info .mobile-button").addClass("selected");
558 jQuery("#button_"+ id +"_show_on_phone").click();
559 }
560
561 jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide();
562 jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show();
563 },
564
565 toggleDesktop: function(id) {
566 var isSelected = jQuery("#button_"+ id +"_show_on_desktop").is(":checked");
567
568 if(!isSelected) {
569 jQuery("#btn_row_" + id + " .row-info .desktop-button").removeClass("selected");
570 jQuery("#button_"+ id +"_show_on_desktop").click();
571 }else {
572 jQuery("#btn_row_" + id + " .row-info .desktop-button").addClass("selected");
573 jQuery("#button_"+ id +"_show_on_desktop").click();
574 }
575
576 jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide();
577 jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show();
578 },
579
580 addRow: function(copyButton) {
581 if(jQuery("#new-button").hasClass('disabled')) {
582 return;
583 }
584 buttonizer.settings.hasChanges = true;
585
586 jQuery(".buttonizer-no-buttons").hide();
587
588 var isCategory = jQuery(".button-row[button-id=-1]").hasClass("is_category");
589
590 jQuery("#new-button").attr('disabled', 'disabled').addClass('disabled');
591
592 var defaultRow = "";
593 if(!copyButton) {
594 defaultRow = jQuery(".button-row[button-id=-1]").html();
595 }else{
596 defaultRow = jQuery(".button-row[button-id="+ copyButton +"]").html();
597 }
598 var numberOfButtons = jQuery(".button-row").length - (isCategory ? 1 : 0);
599
600 numberOfButtons = Math.floor(Date.now() / 1000);
601 numberOfButtons = numberOfButtons + "-" + Math.floor((Math.random() * 999) + 100);
602 numberOfButtons = numberOfButtons.replace('-', '');
603
604 var newData = defaultRow.replace('/'+ copyButton +'/g', numberOfButtons);
605 newData = newData.replace(copyButton, numberOfButtons);
606
607 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>' : ''));
608
609 clearInterval(buttonizer.setTimouts.a);
610 clearInterval(buttonizer.setTimouts.b);
611
612 buttonizer.setTimouts.a = setTimeout(function() {
613 jQuery(".button-row *").unbind("click");
614 jQuery(".button-row").removeClass("opened");
615 jQuery(".fontawesome-searcher-clicker").remove();
616 jQuery("#btn_row_"+ numberOfButtons +" .button_title").val("New button " + numberOfButtons);
617
618 if(isCategory) {
619 jQuery("#btn_row_"+ numberOfButtons +" input").each(function() {
620 jQuery(this).attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"][]");
621 });
622
623 jQuery("#btn_row_"+ numberOfButtons + " select").attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"_type]");
624 }
625 }, 100);
626
627
628 buttonizer.setTimouts.b = setTimeout(function() {
629 buttonizer.initButtons();
630 buttonizer.updateRowInputNames(numberOfButtons);
631 jQuery("#btn_row_"+ numberOfButtons).addClass('opened');
632 jQuery("#btn_row_"+ numberOfButtons + " input.button_title").focus();
633 buttonizer.faInit();
634 buttonizer.loadPageCategorie();
635 jQuery("#new-button").removeAttr('disabled').removeClass('disabled');
636
637 jQuery("#btn_row_"+ numberOfButtons + " .savebutton").show();
638 }, 400);
639 },
640
641 copyRow: function(id) {
642 this.addRow(id);
643 },
644
645 updateRowInputNames: function(buttonId) {
646 // Textfield
647 jQuery("#btn_row_"+ buttonId + " .button_textfield")
648 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_text]")
649 .attr("id", "button_"+ buttonId +"_text").val("");
650
651 // Iconfield
652 jQuery("#btn_row_"+ buttonId + " .icon-placeholder select").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_icon]");
653
654 // Iconfield
655 jQuery("#btn_row_"+ buttonId + " .image-placeholder input").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_image]");
656
657 // Button title
658 jQuery("#btn_row_"+ buttonId + " .button_title").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_title]");
659
660 // Button show on page category
661 jQuery("#btn_row_"+ buttonId + " #button_category").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_pages]");
662
663 // Color palets
664 jQuery("#btn_row_"+ buttonId + " input.custom").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_using_custom_colors]");
665
666 jQuery("#btn_row_"+ buttonId + " input.default").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_colors_button]");
667 jQuery("#btn_row_"+ buttonId + " input.pushed").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_colors_pushed]");
668 jQuery("#btn_row_"+ buttonId + " input.icon").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_colors_icon]");
669
670 // Button action
671 jQuery("#btn_row_"+ buttonId + " .button_action").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_action]");
672
673 // Button value
674 jQuery("#btn_row_"+ buttonId + " .button_input").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_url]");
675
676
677 // Show on phone
678 jQuery("#btn_row_"+ buttonId + " .button_showonphone")
679 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_phone]")
680 .attr("id", "button_"+ buttonId +"_show_on_phone");
681
682 jQuery("label[for='button_"+ buttonId +"_show_on_phone']").attr("for", "button_"+ buttonId +"_show_on_phone");
683
684 // Show on desktop
685 jQuery("#btn_row_"+ buttonId + " .button_showondesktop")
686 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_desktop]")
687 .attr("id", "button_"+ buttonId +"_show_on_desktop");
688
689 jQuery("label[for='button_"+ buttonId +"_show_on_desktop']").attr("for", "button_"+ buttonId +"_show_on_desktop");
690
691 // Url
692 jQuery("#btn_row_"+ buttonId + " .button_isurl")
693 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_url]")
694 .attr("id", "button_"+ buttonId +"_url");
695
696 jQuery("label[for='button_"+ buttonId +"_url']").attr("for", "button_"+ buttonId +"_url");
697
698 // Is phone buttonId
699 jQuery("#btn_row_"+ buttonId + " .button_isphonenumber")
700 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_is_phonenumber]")
701 .attr("id", "button_"+ buttonId +"_is_phonenumber");
702
703 jQuery("label[for='button_"+ buttonId +"_is_phonenumber']").attr("for", "button_"+ buttonId +"_is_phonenumber");
704
705 // New tab
706 jQuery("#btn_row_"+ buttonId + " .button_isnewtab")
707 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_url_newtab]")
708 .attr("id", "button_"+ buttonId +"_url_newtab");
709
710 jQuery("label[for='button_"+ buttonId +"_url_newtab']").attr("for", "button_"+ buttonId +"_url_newtab");
711
712
713 // Show only on opening hours
714 jQuery("#btn_row_"+ buttonId + " .button_showwhenopened")
715 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_when_opened]")
716 .attr("id", "button_"+ buttonId +"_show_when_opened");
717
718 jQuery("label[for='button_"+ buttonId +"_show_when_opened']").attr("for", "button_"+ buttonId +"_show_when_opened");
719
720 // Show only on opening hours
721 jQuery("#btn_row_"+ buttonId + " .button_showlabelonhover")
722 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_label_on_hover]")
723 .attr("id", "button_"+ buttonId +"_show_label_on_hover");
724
725 jQuery("label[for='button_"+ buttonId +"_show_label_on_hover']").attr("for", "button_"+ buttonId +"_show_label_on_hover");
726
727 // Custom class
728 jQuery("#btn_row_"+ buttonId + " .button_custom_class")
729 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_custom_class]")
730 .attr("id", "button_"+ buttonId +"_custom_class");
731
732 jQuery("label[for='button_"+ buttonId +"_custom_class']").attr("for", "button_"+ buttonId +"_custom_class");
733
734 // Change background
735 jQuery("#btn_row_"+ buttonId + " .image-background-checkbox")
736 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_image_background]")
737 .attr("id", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_image_background]");
738
739 jQuery("#btn_row_"+ buttonId + " .icon-or-image label").attr("for", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_image_background]")
740 /*
741 * Link fixes
742 */
743 // Delete button link
744 jQuery("#btn_row_"+ buttonId + " .delete-button").attr("href", "javascript:buttonizer.removeRow("+ buttonId +")");
745
746 jQuery("#btn_row_"+ buttonId + " .copy-button").attr("href", "javascript:buttonizer.copyRow("+ buttonId +")");
747
748 // Show on mobile button link
749 jQuery("#btn_row_"+ buttonId + " .mobiledesktop.mobile-button").attr("href", "javascript:buttonizer.toggleMobile("+ buttonId +")");
750
751 // Show on desktop button link
752 jQuery("#btn_row_"+ buttonId + " .mobiledesktop.desktop-button").attr("href", "javascript:buttonizer.toggleDesktop("+ buttonId +")");
753 },
754
755 /* Button type handler */
756 buttonTypeHandler: function(rowObj) {
757 var currentButtonType = rowObj.find(".button_action");
758 var currentButtonInput = rowObj.find(".button_input");
759 var currentSocialInput = rowObj.find(".social_input");
760 var newTab = rowObj.find(".setting-new-tab");
761
762 var isInitializing = true;
763
764 var waitUntilTriggering = setTimeout(function() {});
765
766 // The button type
767 currentButtonType.change(function() {
768 isInitializing = true;
769 checkInput();
770 });
771
772 currentButtonInput.keyup(function() {
773 clearInterval(waitUntilTriggering);
774
775 waitUntilTriggering = setTimeout(function(){
776 isInitializing = true;
777 checkInput();
778 }, 250);
779 });
780
781 currentButtonInput.change(checkInput);
782 currentSocialInput.change(checkInput);
783
784 //
785 // Checkbox validation
786
787
788
789 function checkInput() {
790 var inputError = false;
791 var currentAction = currentButtonType.val();
792 var currentValueText = currentButtonInput.val();
793
794 if(currentAction == 'backtotop') {
795 currentButtonInput.removeAttr("hidden", "hidden");
796 currentButtonInput.attr("disabled", "disabled");
797 currentSocialInput.hide();
798 }else if(currentAction == 'gobackpage') {
799 currentButtonInput.attr("hidden", "hidden");
800 currentButtonInput.attr("disabled", "disabled");
801 currentSocialInput.hide();
802
803 }else if(currentAction == 'socialsharing'){
804 currentButtonInput.attr("hidden", "hidden");
805 currentSocialInput.show();
806
807 } else {
808 currentButtonInput.removeAttr("hidden", "hidden");
809 currentButtonInput.removeAttr("disabled", "disabled");
810 currentSocialInput.hide();
811
812 }
813
814 // if(!isInitializing && currentValueText == '') {
815 // isInitializing = false;
816 // rowObj.find(".input_error").html('Hello there... You left the input empty here... Do you want to fill him up? It\'s up to you.').show();
817 // return;
818 // }
819
820 if(currentButtonType.val() == 'url') {
821 newTab.show();
822 }else{
823 newTab.hide();
824 }
825
826 if(currentAction === "socialsharing"){
827 rowObj.find(".input_error").hide();
828 rowObj.find(".extra_info").hide();
829 return;
830 }
831
832 if(!isInitializing && currentAction == 'url' && currentValueText == '#') {
833 inputError = true;
834 rowObj.find(".input_error").html('<p>You only have #... That doesn\'t open anything...</p>');
835 }else if(!isInitializing && currentAction == 'url' && !buttonizer.buttonTypeInputController(currentValueText, 'url')) {
836 inputError = true;
837 rowObj.find(".input_error").html('<p>This looks like an invalid URL. The button may not work as expected.</p><p>&nbsp;</p><p>Do you miss <b>http://</b> or <b>https://</b>? A space somewhere on the wrong place?</p>');
838 }
839 1
840 if((currentAction == 'phone' || currentAction == 'whatsapp') && !/^(?=.*\d)[\d ]+$/.test(currentValueText)) {
841 inputError = true;
842 rowObj.find(".input_error").html('Invalid phone number. Please use only the number format. Omit any zeroes, brackets or dashes when adding the phone number in international format.');
843 }
844
845 if(currentAction == 'mail' && !buttonizer.buttonTypeInputController(currentValueText, 'mail')) {
846 inputError = true;
847 rowObj.find(".input_error").html('<p>This looks like an invalid mail address. Make sure the mail address looks like <b><i>user</i>@domain.com</b></p>');
848 }
849
850
851 /* Premium Code Stripped by Freemius */
852
853
854
855 if(!isInitializing && currentValueText == '') {
856 rowObj.find(".input_error").html('Uhm... You forgot something to fill in...').show();
857 return;
858 }
859
860 // Stay here
861 if(!isInitializing) {
862 if(currentAction != 'phone' && currentAction != 'whatsapp' && /^(?=.*\d)[\d ]+$/.test(currentValueText)) {
863 buttonizer.createWindow({
864 title: 'Uhm? Shall I call you?',
865 text:
866 '<p>It\'s looks like you are having a phone number as value. Do you want to let this button behave as a call button?</p>' +
867 '<p>If it\'s not a phone number, you can click \'No thanks\'. If you click \'Yes please\' I will change it for you.</p>',
868
869 confirmText: 'Yes please',
870 canCancel: true,
871 cancelText: 'No thanks',
872
873 onConfirm: function() {
874 currentButtonType.val('phone');
875 rowObj.find(".input_error").hide();
876 }
877 });
878 }
879
880 if(currentAction != 'url' && buttonizer.buttonTypeInputController(currentValueText, 'url')) {
881 buttonizer.createWindow({
882 title: 'Uhm? WWW.?',
883 text:
884 '<p>It\'s looks like you are having a website URL as value. Do you want to let this button behave as a link?</p>' +
885 '<p>If you just about to change that, you can click \'No thanks\'. If you click \'Yes please\' I will change it for you.</p>',
886
887 confirmText: 'Yes please',
888 canCancel: true,
889 cancelText: 'No thanks',
890
891 onConfirm: function() {
892 currentButtonType.val('url');
893 rowObj.find(".input_error").hide();
894 }
895 });
896 }
897
898 if(currentAction != 'mail' && buttonizer.buttonTypeInputController(currentValueText, 'mail')) {
899 buttonizer.createWindow({
900 title: 'Uhm? That\'s a mail address?',
901 text:
902 '<p>It\'s looks like you are having a mail address as value. Do you want to change the button action to open the mail program?</p>' +
903 '<p>If you just about to change that, you can click \'No thanks\'. If you click \'Yes please\' I will change it for you.</p>',
904
905 confirmText: 'Yes please',
906 canCancel: true,
907 cancelText: 'No thanks',
908
909 onConfirm: function() {
910 currentButtonType.val('mail');
911 currentButtonInput.val(currentValueText.replace("mailto:", ""));
912 rowObj.find(".input_error").hide();
913 }
914 });
915 }
916
917
918 /* Premium Code Stripped by Freemius */
919
920 }
921
922 if(inputError) {
923 rowObj.find(".input_error").show();
924 }else{
925 rowObj.find(".input_error").hide();
926 }
927
928 isInitializing = false;
929 };
930
931 // Start
932 checkInput();
933 },
934
935 buttonTypeInputController: function(inputValue, action) {
936 var websiteUrlPattern = /(http|https):\/\/(\w+:{0,1}\w*)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%!\-\/]))?/;
937 var mailUrlPattern = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
938
939 // URL
940 if(action == 'url') {
941 if(websiteUrlPattern.test(inputValue) || inputValue.substring(0, 1) == '#' || inputValue.substring(0, 1) == '/') {
942 return true;
943 } else {
944 return false;
945 }
946 }else
947
948 // E-mail
949 if(action == 'mail') {
950 if(!mailUrlPattern.test(inputValue) && inputValue.indexOf("mailto:") == -1) {
951 return false;
952 } else {
953 return true;
954 }
955 }
956 },
957
958 createWindow: function(data) {
959 this.settings.windowNumber++;
960 var currentWindow = this.settings.windowNumber;
961
962 if(!data.title) {
963 data.title = '';
964 }
965
966 if(!data.text) {
967 data.text = '<p>This dialog has not text.</p><p>Weird, isn\'t it?</p>';
968 }
969
970 if(!data.confirmText) {
971 data.confirmText = 'Close';
972 }
973
974 if(!data.canCancel) {
975 data.canCancel = false;
976 }
977
978 if(!data.cancelText) {
979 data.cancelText = 'Cancel';
980 }
981
982 if(!data.onConfirm) {
983 data.onConfirm = function() {};
984 }
985
986 if(!data.onCancel) {
987 data.onCancel = function() {};
988 }
989
990 if(!data.onClose) {
991 data.onClose = function() {};
992 }
993
994 if(!data.afterInit) {
995 data.afterInit = function() {};
996 }
997
998 var windowStyle = '<div class="fs-modal active" id="buttonizer-window-'+ currentWindow +'"><div class="fs-modal-dialog">';
999
1000 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>';
1001
1002 windowStyle += '<div class="fs-modal-body"><div class="fs-modal-panel active">';
1003 windowStyle += data.text;
1004 windowStyle += '</div></div>';
1005
1006 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>';
1007
1008 windowStyle += '</div></div>';
1009
1010 jQuery("body").append(windowStyle);
1011
1012 jQuery(document).ready(data.afterInit);
1013
1014 jQuery("#buttonizer-window-"+ currentWindow + " .fs-close, #buttonizer-window-"+ currentWindow + " .fs-modal-footer button").click(function(e) {
1015 e.preventDefault();
1016 jQuery("#buttonizer-window-"+ currentWindow).fadeOut();
1017
1018 if(jQuery(this).hasClass("confirm")) {
1019 data.onConfirm();
1020 }
1021
1022 if(jQuery(this).hasClass("cancel")) {
1023 data.onCancel();
1024 }
1025
1026 data.onClose();
1027 })
1028 },
1029
1030 /*
1031 * Font awesome searcher
1032 */
1033 faSettings: {
1034 objects: 0,
1035 currentSelect: {},
1036 currentObject: {},
1037 isGenerated: false,
1038 isOpened: false
1039 },
1040 faInit: function() {
1041 buttonizer.faSettings.isOpened = false;
1042
1043 if(buttonizer.faSettings.isGenerated == false && typeof fontAwesome != 'undefined') {
1044 buttonizer.faSettings.isGenerated = true;
1045 fontAwesome = jQuery.map(fontAwesome, function(value, index) {
1046 return [index];
1047 });
1048 }
1049
1050 jQuery("body").click(function(e){
1051 if(!jQuery(e.target).closest('.fontawesome-searcher').length && !jQuery(e.target).closest('.fontawesome-searcher-clicker').length){
1052 jQuery(".fontawesome-searcher").hide();
1053 buttonizer.faSettings.isOpened = false;
1054 }
1055 });
1056
1057 var typeTimeOut = setTimeout(function() { buttonizer.faSearchWord(''); }, 300);
1058
1059 var adminBody = jQuery("#wpbody");
1060
1061 jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").keyup(function() {
1062 clearInterval(typeTimeOut);
1063
1064 typeTimeOut = setTimeout(function() { buttonizer.faSearchWord(jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").val()); }, 300);
1065 });
1066
1067 jQuery("select.fa-chooser").each(function() {
1068 buttonizer.faSettings.objects++;
1069 var obj = jQuery(this);
1070
1071 obj.hide();
1072 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>");
1073
1074 var newObject = jQuery("#fa-chooser_" + buttonizer.faSettings.objects);
1075 newObject.click(function(e) {
1076 if(buttonizer.faSettings.isOpened == false || buttonizer.faSettings.currentSelect != obj) {
1077 jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").focus();
1078 buttonizer.faSettings.isOpened = true;
1079
1080 // Update process
1081 jQuery(".fontawesome-searcher").css({
1082 "top": newObject.offset().top - 20 + newObject.height(),
1083 "left": newObject.offset().left - adminBody.offset().left,
1084 "width": newObject.width()
1085 }).show();
1086
1087 buttonizer.faSettings.currentSelect = obj;
1088 buttonizer.faSettings.currentObject = newObject;
1089 }else{
1090 buttonizer.faSettings.isOpened = false;
1091 jQuery(".fontawesome-searcher").hide();
1092 }
1093
1094 e.preventDefault();
1095 });
1096 });
1097 },
1098 faSearchWord: function(word) {
1099 var foundMatches = [];
1100
1101 for(var i = 0; i < fontAwesome.length; i++) {
1102 if(fontAwesome[i].indexOf(word) !== -1) {
1103 foundMatches.push(fontAwesome[i]);
1104 }
1105 };
1106
1107 if(foundMatches.length == 0) {
1108 jQuery(".fontawesome-searcher .no-matches-found").show();
1109 jQuery(".fontawesome-searcher .fontawesome-searcher-icons").hide();
1110 }else{
1111 jQuery(".fontawesome-searcher .no-matches-found").hide();
1112 jQuery(".fontawesome-searcher .fontawesome-searcher-icons").show();
1113
1114 var text = '<table><tr>';
1115 for(var b = 0; b < foundMatches.length; b++) {
1116 if(b % 4 == 0) {
1117 text += "</tr><tr>";
1118 }
1119
1120 text += '<td><a href="javascript:buttonizer.faChooseIcon(\''+ foundMatches[b] +'\')"><i class="fa '+ foundMatches[b] +'"></i></a></td>';
1121 };
1122
1123 text += '</tr>';
1124
1125 jQuery(".fontawesome-searcher .fontawesome-searcher-icons").html(text);
1126 }
1127 },
1128 faChooseIcon: function(icon) {
1129 buttonizer.faSettings.currentSelect.val(icon).change();
1130 buttonizer.faSettings.currentObject.html("Icon: "+ icon +" &nbsp; <i class=\"fa "+ icon +"\"></i>");
1131 jQuery("#" + buttonizer.faSettings.currentObject.attr("id")).click();
1132 },
1133
1134 /* intro */
1135 initIntro: function() {
1136 var openedDesign = false;
1137
1138 if(RegExp("welcome-splash", "gi").test(document.location.href)) {
1139 buttonizer.createWindow({
1140 title: 'Welcome to Buttonizer',
1141 text:
1142 '<img src="'+ jQuery(".buttonizer-logo img").attr("src").replace("logo.png", "plugin-icon.png") +'" width="100" align="left" style="margin-right: 20px; margin-bottom: 50px;" />' +
1143 '<p>We are pleased to welcome you to Buttonizer!</p>' +
1144 '<p>We\'ve created a tour for our new users, would you like to take the tour? We will make your first Buttonizer button there and show some things how it works!</p>' +
1145 '<p>Would you like to take the tour?</p>',
1146
1147 confirmText: 'Yes please <i class="fa fa-chevron-right" style="margin-left: 10px; vertical-align: middle;" aria-hidden="true"></i>',
1148 canCancel: true,
1149 cancelText: 'No thanks, I know how it works',
1150
1151 onConfirm: function() {
1152 document.location.href = '?page=Buttonizer&tab=buttonizer_general_settings#buttonizer-tour';
1153 },
1154
1155 onCancel: function() {
1156 document.location.href = '?page=Buttonizer';
1157 }
1158 });
1159 }
1160
1161 // Check if we need to send the user to the next page
1162 if(RegExp("buttonizer_tour_ready=toStep2", "gi").test(document.cookie)) {
1163 var d = new Date();
1164 d.setTime(d.getTime() - 10);
1165 document.cookie = "buttonizer_tour_ready=toStep2;expires="+ d.toUTCString() + ";path=/";
1166
1167 document.location.href = './admin.php?page=Buttonizer&tab=buttonizer_buttons#buttonizer-tour';
1168 return;
1169 }
1170
1171 jQuery("#take-the-tour").click(function() {
1172 setTimeout(function() {
1173 if (RegExp("buttonizer_general_settings", "gi").test(window.location.href)) {
1174 buttonizer.initIntro();
1175 }
1176 }, 250);
1177 });
1178
1179 if (RegExp("buttonizer-tour", "gi").test(window.location.href)) {
1180
1181 // Page one: General settings
1182 if(document.location.href.indexOf('buttonizer_general_settings') != -1) {
1183 var buttonizer_tour_1 = buttonizer.startTour('design');
1184 buttonizer.tabNavigate('design');
1185
1186 buttonizer_tour_1.onbeforechange(function(targetElement) {
1187 if (buttonizer_tour_1._currentStep == 5 && buttonizer_tour_1._direction == "forward") {
1188 buttonizer.tabNavigate('placing');
1189 openedDesign = true;
1190 }else if(buttonizer_tour_1._currentStep == 4 && buttonizer_tour_1._direction == "backward") {
1191 buttonizer.tabNavigate('design');
1192
1193 openedDesign = false;
1194 }
1195 }).oncomplete(function() {
1196 document.querySelector('.button.savebutton').click();
1197 }).setOptions({
1198 doneLabel: 'Save &rarr;'
1199 }).start();
1200
1201 jQuery("#tab_container_placing").click(function() {
1202 buttonizer_tour_1.nextStep();
1203 });
1204
1205 jQuery('.button.savebutton').click(function() {
1206 var d = new Date();
1207 d.setTime(d.getTime() + (2*24*60*60*1000));
1208 document.cookie = "buttonizer_tour_ready=toStep2;expires="+ d.toUTCString() + ";path=/";
1209 });
1210 }
1211
1212 if(document.location.href.indexOf('buttonizer_buttons') != -1) {
1213 var buttonizer_tour_2 = buttonizer.startTour('buttons');
1214 var buttonCreated = true;
1215
1216 buttonizer_tour_2.onchange(function(targetElement) {
1217 if(buttonizer_tour_2._currentStep == 4) {
1218 jQuery("#new-button").click();
1219 }
1220 }).setOptions({
1221 doneLabel: 'Next',
1222 hidePrev: true,
1223 hideNext: true,
1224 }).start();
1225
1226 // Create button
1227 var buttonCreated = false;
1228 jQuery("#new-button").click(function() {
1229 if(buttonCreated) {
1230 alert("Please finish the tour first.")
1231 return;
1232 }
1233 buttonCreated = true;
1234 buttonizer.addRow();
1235
1236 setTimeout(function() {
1237 var id = jQuery("#button-rows .button-row.opened").attr("id");
1238 buttonizer_tour_2.exit(true);
1239
1240 var buttonizer_tour_3 = buttonizer.startTour('edit-button', id);
1241
1242 buttonizer_tour_3.onchange(function(targetElement) {
1243 if(buttonizer_tour_3._currentStep == 1) {
1244 // buttonizer_tour_3.nextStep();
1245 }
1246 }).setOptions({
1247 doneLabel: 'Finish tour',
1248 hidePrev: true,
1249 hideNext: true,
1250 }).start();
1251 }, 400);
1252 });
1253 }
1254 }
1255 },
1256
1257 startTour: function(type, newButtonId) {
1258 var intro = introJs();
1259
1260 if(!newButtonId) {
1261 newButtonId = false;
1262 }
1263
1264 intro.setOption('tooltipPosition', 'top');
1265 intro.setOptions({
1266 showBullets: false,
1267 exitOnOverlayClick: false,
1268 skipLabel: 'Exit tour'
1269 });
1270
1271 if(type == 'design') {
1272 intro.setOptions({
1273 steps: [
1274 {
1275 intro: "Let's start the tour through Buttonizer. You can skip this at any moment."
1276 },
1277 {
1278 element: document.querySelector('.intro-styling'),
1279 intro: "Set the default colors of The Buttonizer. We recommend using the colors of your corporate identity.",
1280 position: 'top'
1281 },
1282 {
1283 element: document.querySelector('.intro-icon'),
1284 intro: "Select the main icon. This icon will appear when you have multiple floating action buttons on one page (So you can create a Floating Menu).<br><br>When you have PRO featues, you will be able to choose a custom image.",
1285 position: 'top'
1286 },
1287 {
1288 element: document.querySelector('.intro-label'),
1289 intro: "Optional: Add text If you want to have a label next to your button to explain the button action like 'Click here' or 'Contact options'.",
1290 position: 'top'
1291 },
1292 {
1293 element: document.querySelector('#tab_container_placing'),
1294 intro: "Click here to go to the position and animation page",
1295 position: 'right'
1296 },
1297 {
1298 element: document.querySelector('.intro-position'),
1299 intro: "Here you can change the placing of the Buttonizer. 5% means 5% of the screen. The default setting is bottom 5% and right 5%. It will place itself on the right corner of your screen (mobile & desktop).",
1300 position: 'top'
1301 },
1302 {
1303 element: document.querySelector('.intro-animaton'),
1304 intro: "The Button animation option is only relevant if you are going to add multiple floating action buttons on one page (create a floating menu). This option let's you choose how the different buttons will 'pop' up.",
1305 position: 'top'
1306 },
1307 {
1308 element: document.querySelector('.intro-attention'),
1309 intro: "If you want your floating action button to have extra attention from your website visitors you can add a attention animation. The button will make a specific 'move' each 10 seconds.",
1310 position: 'top'
1311 },
1312 {
1313 element: document.querySelector('.button.savebutton'),
1314 intro: "For now, we are finished here. Click the save button.",
1315 position: 'left'
1316 }
1317 ]});
1318 }else if(type == 'buttons') {
1319 intro.setOptions({
1320 steps: [
1321 {
1322 element: document.querySelector('#new-button'),
1323 intro: "Great! You are ready to make your first Floating Action Button. As an example we will make a Click-to-Call button. To start click on 'New Button'.",
1324 position: 'left'
1325 },
1326 {
1327 element: document.querySelector('#new-button'),
1328 intro: "Waiting on you for clicking the button at the right... It says '+ New button'",
1329 position: 'left'
1330 },
1331 {
1332 element: document.querySelector('#new-button'),
1333 intro: "Hello? Please click that button...",
1334 position: 'left'
1335 },
1336 {
1337 element: document.querySelector('#new-button'),
1338 intro: "Here, on the right... If you won't click it, I will click it >:-)",
1339 position: 'left'
1340 },
1341 {
1342 element: document.querySelector('#new-button'),
1343 intro: "Okay. Nothing to say.",
1344 position: 'bottom'
1345 },
1346 ]});
1347 }
1348 else if(type == 'edit-button') {
1349 intro.setOptions({
1350 steps: [
1351 {
1352 element: document.querySelector('#' + newButtonId + " .row-info"),
1353 intro: "This is the quick-button info bar.<br /><br />When you have multiple buttons, you can drag them to position them on the right place.",
1354 position: 'bottom',
1355 disableInteraction: true
1356 },
1357 {
1358 element: document.querySelector('#' + newButtonId + " .row-info .row-title"),
1359 intro: "This is the button title. Your webvisitors won't see this name, this is only visible here. We will change the name in 1 steps.",
1360 position: 'right',
1361 disableInteraction: true
1362 },
1363 {
1364 element: document.querySelector('#' + newButtonId + " .row-info .desktop-button"),
1365 intro: "This is a quick-button to enable the button on desktop. When it's blue it's enabled. When grey it's disabled for desktop.",
1366 position: 'left',
1367 disableInteraction: true
1368 },
1369 {
1370 element: document.querySelector('#' + newButtonId + " .row-info .mobile-button"),
1371 intro: "There is one for mobile too.",
1372 position: 'left',
1373 disableInteraction: true
1374 },
1375 {
1376 element: document.querySelector('#' + newButtonId + " .button_title"),
1377 intro: "Create a descent name for your Button like 'Call Button Sales department'. Your webvisitors won't see this name. Although it will appear on Google Analytics on your 'event tracking' section.",
1378 position: 'bottom'
1379 },
1380 {
1381 element: document.querySelector('#' + newButtonId + " .button-pdr"),
1382 intro: "Choose an appropriate icon or upload your own. Type 'phone' and select the phone icon to give it a phone icon.",
1383 position: 'bottom'
1384 },
1385 {
1386 element: document.querySelector('#' + newButtonId + " .button_textfield"),
1387 intro: "Optional - Add text If you want to have a label next to your button to explain the button action like 'Call our sales department'. This label will be shown next to the button.",
1388 position: 'bottom'
1389 },
1390 {
1391 element: document.querySelector('#' + newButtonId + " .button-action"),
1392 intro: "Choose the appropriate click action. When you want to add a click-to-call button select the option phone-number. Type in the phone-number you want your visitors to call when clicking on the button.",
1393 position: 'bottom'
1394 },
1395 {
1396 element: document.querySelector('#' + newButtonId + " #button_category"),
1397 intro: "Premium function - By default the button is shown on every page. If you want to show your button on selected pages you can add 'page categories'. You need a premium account if you want to do this.",
1398 position: 'bottom'
1399 },
1400 {
1401 element: document.querySelector('#' + newButtonId + " .show-mobile-btn"),
1402 intro: "Decide if your button is shown on mobile, desktop or both by selecting the show on mobile and desktop functions. If you don't select at least one of both the button won't show on your website. In the case of a call button we recommend only selecting the option 'show on mobile'. ",
1403 position: 'top'
1404 },
1405 {
1406 element: document.querySelector('#' + newButtonId + " .show-desktop-btn"),
1407 intro: "Here you can enable it on your desktop",
1408 position: 'bottom'
1409 },
1410 {
1411 element: document.querySelector('#' + newButtonId + " .must-save-button"),
1412 intro: "This is a quick save button. If your button has no changes to it, it'll say 'live'",
1413 position: 'left',
1414 disableInteraction: true
1415 },
1416 {
1417 intro: "<b>Congratulations!</b> Your first Floating Action button is ready to go live! Click on save and take a look at the result. Go to your website on your phone or desktop (if you've enabled it there too) and test your button.",
1418 },
1419 {
1420 intro: "Now it's time to get creative. Add another button on your website like a navigation button or a url to your contact page or maybe even opening Facebook Messenger. <b> It's all up to you </b> ",
1421 },
1422 {
1423 element: document.querySelector('h2 .savebutton'),
1424 intro: "Do you have a feature request, idea or do you need support? Feel free to contact us! Push the save button to finish the tour.",
1425 position: 'left',
1426 },
1427 ]});
1428 }
1429
1430 return intro;
1431 },
1432 stickyId: 0,
1433 sticky: function(type, message) {
1434 buttonizer.stickyId++;
1435
1436 var elemDiv = document.createElement('div');
1437 elemDiv.className = 'buttonizer-sticky '+ type +' sticky-'+ buttonizer.stickyId;
1438 elemDiv.innerHTML = message;
1439 document.body.appendChild(elemDiv);
1440
1441
1442 // document.body.innerHTML += '<div class="buttonizer-sticky '+ type +' sticky-'+ buttonizer.stickyId +'">'+ message +'</div>';
1443
1444 setTimeout(function() {
1445 var element = document.querySelector(".sticky-" + buttonizer.stickyId);
1446 var opacity = 1;
1447
1448 var fadeOut = setInterval(function() {
1449 opacity = opacity - 0.05;
1450 element.style.opacity = opacity;
1451
1452 if(opacity <= 0) {
1453 clearInterval(fadeOut);
1454 }
1455 }, 20);
1456 }, 4000);
1457 }
1458 };
1459
1460 function checkSelection()
1461 {
1462 var inputError = false;
1463 var elements = document.querySelectorAll(".socialSharingCheckbox");
1464 var warning = document.querySelectorAll(".warning_text");
1465 var selected = 0;
1466 for(var i = 0; i < elements.length; i++){
1467 console.log(elements);
1468 if(elements[i].checked){
1469 selected++;
1470 }
1471 }
1472 if(selected < 4){
1473 for(var d = 0; d < warning.length; d++){
1474 warning[d].setAttribute("hidden", "hidden");
1475 }
1476 }else if(selected > 3){
1477 for(var o = 0; o < warning.length; o++){
1478 warning[o].removeAttribute("hidden");
1479 elements.setAttribute("disabled", "disabled");
1480 }
1481
1482 }
1483
1484
1485 }
1486
1487 document.addEventListener('DOMContentLoaded', buttonizer.init, false);
1488
1489 window.onbeforeunload = function(){
1490 if(document.location.href.indexOf('page=Buttonizer') === -1) {
1491 return;
1492 }
1493 if(buttonizer.settings.hasChanges && !buttonizer.settings.clickedButton) {
1494 return 'You have unsaved data. Are you sure you want to leave?';
1495 }
1496 };
1497