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

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