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

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

695 lines 28.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1
2 var buttonizer = {
3 settings: {
4 wpButtonSaveKey: 'buttonizer_buttons',
5 wpCategorySaveKey: 'buttonizer_page_categories',
6 windowNumber: 0,
7 hasChanges: false,
8 clickedButton: false
9 },
10
11 setTimouts: {
12 a: function() {
13 return setTimeout(function() { }, 0)
14 },
15 b: function() {
16 return setTimeout(function() { }, 0)
17 },
18 },
19
20 init: function() {
21 buttonizer.overwriteFavIcon();
22 buttonizer.faInit();
23 buttonizer.initButtons();
24
25 // WP color picker
26 jQuery('#button_unpushed').wpColorPicker();
27 jQuery('#button_pushed').wpColorPicker();
28 jQuery('#icon_color').wpColorPicker();
29
30 jQuery(".savebutton").each(function() {
31 jQuery(this).click(buttonizer.saveAnimation);
32 });
33
34 jQuery("input, textarea, select").change(function() {
35 buttonizer.settings.hasChanges = true;
36 });
37
38 var iconImage = jQuery.wpMediaUploader({
39 target : '.smartcat-uploader', // The class wrapping the textbox
40 uploaderTitle : 'Select or upload image', // The title of the media upload popup
41 uploaderButton : 'Set image', // the text of the button in the media upload popup
42 multiple : false, // Allow the user to select multiple images
43 buttonText : '<i class="fa fa-image"></i> <span>Upload image</span>', // The text of the upload button
44 buttonClass : '.smartcat-upload', // the class of the upload button
45 previewSize : '32px', // The preview image size
46 modal : false, // is the upload button within a bootstrap modal ?
47 buttonStyle : { // style the button
48
49 },
50 });
51
52 setTimeout(function() {
53 // Init preview button
54 jQuery('.button-preview').css({
55 'background-color': jQuery("#button_unpushed").val()
56 });
57
58 jQuery(".button-preview").hover(function() {
59 jQuery(this).css({
60 'background-color': jQuery("#button_pushed").val()
61 });
62 }, function() {
63 jQuery(this).css({
64 'background-color': jQuery("#button_unpushed").val()
65 });
66 });
67 }, 500);
68
69 // Remove the spam from other plugins
70 setTimeout(function() {
71 var foundOurContent = false;
72 if(jQuery(".buttonizerWarning").length > 0) {
73 foundOurContent = true;
74 var buttonizerData = jQuery(".buttonizerWarning").html();
75 var buttonizerStyle = jQuery(".buttonizerWarning").attr('class');
76 }
77
78 jQuery("#wordpress-plugin-message-spam").remove();
79
80 if(foundOurContent) {
81 jQuery(".nav-tab-wrapper").after('<div class="'+ buttonizerStyle +'">'+ buttonizerData +'</div>');
82 }
83 }, 1000);
84
85 jQuery(".icon-or-image").each(function() {
86 var type = jQuery(this).data("type");
87 var currentContainer = jQuery(this);
88
89 jQuery(this).find(".placeholder-choose a").click(function() {
90 if(type == 'image') {
91 type = 'icon';
92
93 currentContainer.find(".image-placeholder").hide();
94 currentContainer.find(".icon-placeholder").show();
95
96 currentContainer.find("input").val("");
97 }else {
98 type = 'image';
99
100 currentContainer.find(".image-placeholder").show();
101 currentContainer.find(".icon-placeholder").hide();
102 }
103 });
104 });
105
106 // Hash
107 if(document.location.hash != "") {
108 var tabKey = document.location.hash;
109 buttonizer.tabNavigate(tabKey.replace("#tab_", ""));
110 }
111
112 jQuery(".buttonizer-click-to-pro").each(function() {
113 jQuery(this).click(function(e) {
114 e.preventDefault();
115 buttonizer.proInfoWindow();
116 });
117 });
118
119 buttonizer.loadPageCategorie();
120 },
121
122 proInfoWindow: function() {
123 buttonizer.createWindow({
124 title: 'You like Buttonizer?',
125 text: '<p>Are you ready to try Buttonizer PRO?</p><p><b class="color-buttonizer">What do you get?</b></p>'+
126
127 '<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Show on opening hours</div>' +
128 '<div class="color-buttonizer-orange buttonizer-pro-checklist"><i class="fa fa-check"></i> Show buttons on specific pages: Use page rules</div>' +
129 '<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Unlimited page rules</div>' +
130 '<div class="color-buttonizer-orange buttonizer-pro-checklist"><i class="fa fa-check"></i> Add custom image or button-icon</div>' +
131 '<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Exit intend</div>' +
132 '<div class="color-buttonizer-orange buttonizer-pro-checklist"><i class="fa fa-check"></i> Show on scroll</div>' +
133 '<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Show on timeout</div>' +
134 '<br />' +
135 '<p class="color-buttonizer text-right"><b>Do you <span><i class="fa fa-heart"></i></span> these features?</b></p>',
136 closeText: 'Upgrade',
137 callback: function() {
138 document.location.href = 'admin.php?page=Buttonizer-pricing';
139 }
140 });
141 },
142
143 overwriteFavIcon: function() {
144 (function() {
145 var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
146 link.type = 'image/x-icon';
147 link.rel = 'shortcut icon';
148 link.href = faviconUrl;
149 document.getElementsByTagName('head')[0].appendChild(link);
150 })();
151 },
152
153 tabNavigate: function(key) {
154 jQuery(".vertical-tabs .tab-container").each(function() {
155 if(jQuery(this).attr('id') == "tab_container_" + key) {
156 jQuery(this).show();
157 }else{
158 jQuery(this).hide();
159 }
160 });
161
162 jQuery(".vertical-tabs .tabs a").each(function() {
163 if(jQuery(this).attr('id') == "tab_container_" + key) {
164 jQuery(this).addClass('nav-tab-active');
165 }else{
166 jQuery(this).removeClass('nav-tab-active');
167 }
168 });
169
170 // jQuery("type[name=_wp_http_referer]").val();
171 },
172
173 loadPageCategorie: function() {
174 jQuery(".page-categorie-styling").each(function() {
175 var maxLoaded = 10;
176 var isLoaded = 10;
177 var table = jQuery(this);
178 jQuery(this).addClass("initialized")
179
180 table.find("tr").each(function() {
181 jQuery(this).click(function(e) {
182 if(jQuery(e.target).attr("type") != "checkbox") {
183 jQuery(this).find("input").click();
184 }
185 });
186 });
187
188 jQuery(".categories-load-more[data-id="+ jQuery(this).attr("data-id") +"]").click(function() {
189 maxLoaded += 10;
190 isLoaded = 0;
191
192
193 table.find("tr").each(function() {
194 isLoaded++;
195 if(isLoaded <= maxLoaded) {
196 jQuery(this).show();
197 }else{
198 return;
199 }
200 });
201
202 if(jQuery(".page-categorie-styling[data-id="+ jQuery(this).attr("data-id") +"] tr").length < maxLoaded) {
203 jQuery(this).hide();
204 }
205 });
206 });
207 },
208
209 saveAnimation: function() {
210 jQuery(".savebutton").each(function() {
211 jQuery(this).html('<i class="fa fa-cog fa-spin"></i> <span>Saving</span>');
212 });
213 buttonizer.settings.clickedButton = true;
214 jQuery('form#buttonizer').submit();
215 },
216
217 /*
218 * Buttons
219 */
220 initButtons: function() {
221 jQuery(".button-row").each(function() {
222 var rowObj = jQuery(this);
223 var rowId = jQuery(this).attr("button-id")
224 var buttonTitle = rowObj.find(".row-info span .row-title");
225 var buttonEdit = rowObj.find(".row-info .pencil-edit");
226 var buttonTitleField = rowObj.find(".button_title");
227 var doubleClick = setTimeout(function() {}, 100);
228 var isCategory = rowObj.hasClass('is_category');
229 var clicked = 0;
230
231 buttonEdit.click(function(e) {
232 e.preventDefault();
233 buttonTitle.dblclick();
234 });
235
236 buttonTitle.html(buttonTitleField.val());
237
238 rowObj.find(".row-info").click(function(e) {
239
240 if(
241 jQuery(e.target).hasClass('fa-desktop') ||
242 jQuery(e.target).hasClass('fa-mobile') ||
243 jQuery(e.target).hasClass('fa-pencil') ||
244 jQuery(e.target).hasClass('mobiledesktop')
245 ) {
246 return;
247 }
248
249 clicked = 0;
250 clearInterval(doubleClick);
251 doubleClick = setTimeout(function() {
252 if(clicked == 0) {
253 if(rowObj.hasClass("opened")) {
254 rowObj.removeClass("opened");
255 }else{
256 rowObj.addClass("opened");
257 }
258 }
259 clicked = 0;
260 }, 100);
261 });
262
263 buttonTitle.dblclick(function() {
264 buttonizer.updateTitle(buttonTitle, buttonTitleField, false);
265
266 clicked++;
267 });
268
269 rowObj.find(".button_showonphone").change(function(e) {
270 var isSelected = jQuery(this).is(":checked");
271
272 if(!isSelected) {
273 jQuery("#btn_row_" + rowId + " .row-info .mobile-button").addClass("selected");
274 }else {
275 jQuery("#btn_row_" + rowId + " .row-info .mobile-button").removeClass("selected");
276 }
277 });
278
279 rowObj.find('.button_title').change(function() {
280 newTitle = jQuery(this).val();
281
282 if(buttonizer.checkTitleDuplicate(newTitle, rowId)) {
283 buttonizer.updateTitle(buttonTitle, buttonTitleField, true, newTitle);
284 return;
285 }
286
287 buttonTitle.html(newTitle);
288 });
289
290 rowObj.find(".button_showondesktop").change(function(e) {
291 var isSelected = jQuery(this).is(":checked");
292
293 if(!isSelected) {
294 jQuery("#btn_row_" + rowId + " .row-info .desktop-button").addClass("selected");
295 }else {
296 jQuery("#btn_row_" + rowId + " .row-info .desktop-button").removeClass("selected");
297 }
298 });
299
300 jQuery("#button_"+ rowId +"_icon").change(function(e) {
301 console.log("test");
302 rowObj.find(".button-icon").attr('class', "fa "+ jQuery(this).val() +" button-icon");
303 });
304
305 if(isCategory) {
306 var checked = false;
307 rowObj.find(".select-all").click(function() {
308 if(!checked) {
309 checked = true;
310 rowObj.find(".page-categorie-styling input[type=checkbox]").attr("checked", "checked");
311 }else{
312 checked = false;
313 rowObj.find(".page-categorie-styling input[type=checkbox]").removeAttr("checked");
314 }
315 });
316 }
317 });
318 },
319
320 updateTitle: function(buttonTitle, buttonTitleField, isDuplicate, text) {
321 if(!text) {
322 var text = '';
323 }
324
325 if(!isDuplicate) {
326 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());
327 }else{
328 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);
329 }
330
331 if(!newTitle || newTitle == "") {
332 if(isDuplicate) {
333 buttonTitleField.val(buttonTitle.html());
334 }
335 return;
336 }
337
338 if(buttonizer.checkTitleDuplicate(newTitle)) {
339 buttonizer.updateTitle(buttonTitle, buttonTitleField, true, newTitle);
340 return;
341 }
342
343 buttonTitle.html(newTitle);
344 buttonTitleField.val(newTitle);
345 },
346
347 checkTitleDuplicate: function(text, allowRowId) {
348 isDuplicate = false;
349 if(!allowRowId) {
350 var allowRowId = -1;
351 }
352
353 jQuery(".button-row").each(function() {
354 if(jQuery(this).find('.button_title').val() == text && jQuery(this).attr("button-id") != allowRowId) {
355 isDuplicate = true;
356 }
357 });
358
359 return isDuplicate;
360 },
361
362 removeRow: function(id) {
363 var buttonName = jQuery("#btn_row_" +id + " .row-info span .row-title").html();
364 var wasCategory = jQuery("#btn_row_" + id).hasClass('is_category');
365
366 if(confirm("Are you sure you want to remove the row with the text: '"+ buttonName +"'?\n\nThis is not recoverable.")) {
367 jQuery("#btn_row_" +id).remove();
368
369 if(jQuery(".button-row").length > 1) {
370 jQuery(".buttonizer-no-buttons").hide();
371 }else{
372 jQuery(".buttonizer-no-buttons").show();
373 }
374 }
375 },
376
377 toggleMobile: function(id) {
378 var isSelected = jQuery("#button_"+ id +"_show_on_phone").is(":checked");
379
380 if(!isSelected) {
381 jQuery("#btn_row_" + id + " .row-info .mobile-button").removeClass("selected");
382 jQuery("#button_"+ id +"_show_on_phone").click();
383 }else {
384 jQuery("#btn_row_" + id + " .row-info .mobile-button").addClass("selected");
385 jQuery("#button_"+ id +"_show_on_phone").click();
386 }
387 },
388
389 toggleDesktop: function(id) {
390 var isSelected = jQuery("#button_"+ id +"_show_on_desktop").is(":checked");
391
392 if(!isSelected) {
393 jQuery("#btn_row_" + id + " .row-info .desktop-button").removeClass("selected");
394 jQuery("#button_"+ id +"_show_on_desktop").click();
395 }else {
396 jQuery("#btn_row_" + id + " .row-info .desktop-button").addClass("selected");
397 jQuery("#button_"+ id +"_show_on_desktop").click();
398 }
399 },
400
401 addRow: function() {
402 if(jQuery("#new-button").hasClass('disabled')) {
403 return;
404 }
405 jQuery(".buttonizer-no-buttons").hide();
406
407 var isCategory = jQuery(".button-row[button-id=-1]").hasClass("is_category");
408
409 jQuery("#new-button").attr('disabled', 'disabled').addClass('disabled');
410 var defaultRow = jQuery(".button-row[button-id=-1]").html();
411 var numberOfButtons = jQuery(".button-row").length - (isCategory ? 1 : 0);
412
413 numberOfButtons = Math.floor(Date.now() / 1000);
414 numberOfButtons = numberOfButtons + "-" + Math.floor((Math.random() * 999) + 100);
415 numberOfButtons = numberOfButtons.replace('-', '');
416
417 var newData = defaultRow.replace('/-1/g', numberOfButtons);
418 newData = newData.replace('-1', numberOfButtons);
419
420 jQuery("#button-rows, #page-categories").append('<div class="button-row ' + (isCategory ? 'is_category' : '') + '" id="btn_row_'+ numberOfButtons +'" button-id="'+ numberOfButtons +'">' + newData + '</div>');
421
422 clearInterval(buttonizer.setTimouts.a);
423 clearInterval(buttonizer.setTimouts.b);
424
425 buttonizer.setTimouts.a = setTimeout(function() {
426 jQuery(".button-row *").unbind("click");
427 jQuery(".button-row").removeClass("opened");
428 jQuery(".fontawesome-searcher-clicker").remove();
429 jQuery("#btn_row_"+ numberOfButtons +" .button_title").val("New button " + numberOfButtons);
430
431 if(isCategory) {
432 jQuery("#btn_row_"+ numberOfButtons +" input").each(function() {
433 jQuery(this).attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"][]");
434 });
435
436 jQuery("#btn_row_"+ numberOfButtons + " select").attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"_type]");
437 }
438 }, 100);
439
440
441 buttonizer.setTimouts.b = setTimeout(function() {
442 buttonizer.initButtons();
443 if(!isCategory) {
444 buttonizer.updateRowInputNames(numberOfButtons);
445 jQuery("#btn_row_"+ numberOfButtons).addClass('opened');
446 jQuery("#btn_row_"+ numberOfButtons + " input.button_title").focus();
447 }else{
448 console.log("Initialize new page category");
449 jQuery("#btn_row_"+ numberOfButtons + " #categoryIsUsed").val(numberOfButtons);
450 jQuery("#btn_row_"+ numberOfButtons + " #categoryIsUsed").attr("name", buttonizer.settings.wpCategorySaveKey + '[categorieOrder][]');
451 jQuery("#btn_row_"+ numberOfButtons + " .delete-button").attr("href", "javascript:buttonizer.removeRow("+ numberOfButtons +")");
452 jQuery("#btn_row_"+ numberOfButtons + " .button_title").attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"_title]").val('New page category ' + (jQuery(".button-row").length - 1));
453 jQuery("#btn_row_"+ numberOfButtons + " .row-title").html("New page category " + (jQuery(".button-row").length - 1));
454 }
455 buttonizer.faInit();
456 buttonizer.loadPageCategorie();
457 jQuery("#new-button").removeAttr('disabled').removeClass('disabled');
458 }, 400);
459 },
460
461 updateRowInputNames: function(buttonId) {
462 // Textfield
463 jQuery("#btn_row_"+ buttonId + " .button_textfield")
464 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_text]")
465 .attr("id", "button_"+ buttonId +"_text").val("");
466
467 // Iconfield
468 jQuery("#btn_row_"+ buttonId + " .button_iconfield").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_icon]");
469
470 // Button title
471 jQuery("#btn_row_"+ buttonId + " .button_title").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_title]");
472
473 // Button show on page category
474 jQuery("#btn_row_"+ buttonId + " #button_category").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_pages]");
475
476 // Show on phone
477 jQuery("#btn_row_"+ buttonId + " .button_showonphone")
478 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_phone]")
479 .attr("id", "button_"+ buttonId +"_show_on_phone");
480
481 jQuery("label[for='button_"+ -1 +"_show_on_phone']").attr("for", "button_"+ buttonId +"_show_on_phone");
482
483 // Show on desktop
484 jQuery("#btn_row_"+ buttonId + " .button_showondesktop")
485 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_desktop]")
486 .attr("id", "button_"+ buttonId +"_show_on_desktop");
487
488 jQuery("label[for='button_"+ -1 +"_show_on_desktop']").attr("for", "button_"+ buttonId +"_show_on_desktop");
489
490 // Url
491 jQuery("#btn_row_"+ buttonId + " .button_isurl")
492 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_url]")
493 .attr("id", "button_"+ buttonId +"_url");
494
495 jQuery("label[for='button_"+ -1 +"_url']").attr("for", "button_"+ buttonId +"_url");
496
497 // Is phone buttonId
498 jQuery("#btn_row_"+ buttonId + " .button_isphonenumber")
499 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_is_phonenumber]")
500 .attr("id", "button_"+ buttonId +"_is_phonenumber");
501
502 jQuery("label[for='button_"+ -1 +"_is_phonenumber']").attr("for", "button_"+ buttonId +"_is_phonenumber");
503
504 // New tab
505 jQuery("#btn_row_"+ buttonId + " .button_isnewtab")
506 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_url_newtab]")
507 .attr("id", "button_"+ buttonId +"_url_newtab");
508
509 jQuery("label[for='button_"+ -1 +"_url_newtab']").attr("for", "button_"+ buttonId +"_url_newtab");
510
511
512 // Show only on opening hours
513 jQuery("#btn_row_"+ buttonId + " .button_showwhenopened")
514 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_when_opened]")
515 .attr("id", "button_"+ buttonId +"_show_when_opened");
516
517 jQuery("label[for='button_"+ -1 +"_show_when_opened']").attr("for", "button_"+ buttonId +"_show_when_opened");
518
519 // Show only on opening hours
520 jQuery("#btn_row_"+ buttonId + " .button_hidelabel")
521 .attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_hide_label]")
522 .attr("id", "button_"+ buttonId +"_hide_label");
523
524 jQuery("label[for='button_"+ -1 +"_hide_label']").attr("for", "button_"+ buttonId +"_hide_label");
525
526 /*
527 * Link fixes
528 */
529 // Delete button link
530 jQuery("#btn_row_"+ buttonId + " .delete-button").attr("href", "javascript:buttonizer.removeRow("+ buttonId +")");
531
532 // Show on mobile button link
533 jQuery("#btn_row_"+ buttonId + " .mobiledesktop.mobile-button").attr("href", "javascript:buttonizer.toggleMobile("+ buttonId +")");
534
535 // Show on desktop button link
536 jQuery("#btn_row_"+ buttonId + " .mobiledesktop.desktop-button").attr("href", "javascript:buttonizer.toggleDesktop("+ buttonId +")");
537 },
538
539 createWindow: function(data) {
540 this.settings.windowNumber++;
541 var currentWindow = this.settings.windowNumber;
542
543 if(!data.title) {
544 data.title = '';
545 }
546
547 if(!data.text) {
548 data.text = '<p>This dialog has not text.</p><p>Weird, isn\'t it?</p>';
549 }
550
551 if(!data.closeText) {
552 data.closeText = 'Close';
553 }
554
555 if(!data.callback) {
556 data.callback = function() {};
557 }
558
559 var windowStyle = '<div class="fs-modal active" id="buttonizer-window-'+ currentWindow +'"><div class="fs-modal-dialog">';
560
561 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>';
562
563 windowStyle += '<div class="fs-modal-body"><div class="fs-modal-panel active">';
564 windowStyle += data.text;
565 windowStyle += '</div></div>';
566
567 windowStyle += '<div class="fs-modal-footer"><button class="button button-primary" tabindex="3">'+ data.closeText +'</button></div>';
568
569 windowStyle += '</div></div>';
570
571 jQuery("body").append(windowStyle);
572
573 jQuery("#buttonizer-window-"+ currentWindow + " .fs-close, #buttonizer-window-"+ currentWindow + " button").click(function(e) {
574 e.preventDefault();
575 jQuery("#buttonizer-window-"+ currentWindow).fadeOut();
576
577 if(!jQuery(this).hasClass("fs-close")) {
578 data.callback();
579 }
580 })
581 },
582
583 /*
584 * Font awesome searcher
585 */
586 faSettings: {
587 objects: 0,
588 currentSelect: {},
589 currentObject: {},
590 isGenerated: false,
591 isOpened: false
592 },
593 faInit: function() {
594 buttonizer.faSettings.isOpened = false;
595
596 if(buttonizer.faSettings.isGenerated == false) {
597 buttonizer.faSettings.isGenerated = true;
598 fontAwesome = jQuery.map(fontAwesome, function(value, index) {
599 return [index];
600 });
601 }
602
603 jQuery("body").click(function(e){
604 if(!jQuery(e.target).closest('.fontawesome-searcher').length && !jQuery(e.target).closest('.fontawesome-searcher-clicker').length){
605 jQuery(".fontawesome-searcher").hide();
606 buttonizer.faSettings.isOpened = false;
607 }
608 });
609
610 var typeTimeOut = setTimeout(function() { buttonizer.faSearchWord(''); }, 300);
611
612 var adminBody = jQuery("#wpbody");
613
614 jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").keyup(function() {
615 clearInterval(typeTimeOut);
616
617 typeTimeOut = setTimeout(function() { buttonizer.faSearchWord(jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").val()); }, 300);
618 });
619
620 jQuery("select.fa-chooser").each(function() {
621 buttonizer.faSettings.objects++;
622 var obj = jQuery(this);
623
624 obj.hide();
625 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>");
626
627 var newObject = jQuery("#fa-chooser_" + buttonizer.faSettings.objects);
628 newObject.click(function(e) {
629 if(buttonizer.faSettings.isOpened == false || buttonizer.faSettings.currentSelect != obj) {
630 jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").focus();
631 buttonizer.faSettings.isOpened = true;
632
633 // Update process
634 jQuery(".fontawesome-searcher").css({
635 "top": newObject.offset().top - 20 + newObject.height(),
636 "left": newObject.offset().left - adminBody.offset().left,
637 "width": newObject.width()
638 }).show();
639
640 buttonizer.faSettings.currentSelect = obj;
641 buttonizer.faSettings.currentObject = newObject;
642 }else{
643 buttonizer.faSettings.isOpened = false;
644 jQuery(".fontawesome-searcher").hide();
645 }
646
647 e.preventDefault();
648 });
649 });
650 },
651 faSearchWord: function(word) {
652 var foundMatches = [];
653
654 for(var i = 0; i < fontAwesome.length; i++) {
655 if(fontAwesome[i].indexOf(word) !== -1) {
656 foundMatches.push(fontAwesome[i]);
657 }
658 };
659
660 if(foundMatches.length == 0) {
661 jQuery(".fontawesome-searcher .no-matches-found").show();
662 jQuery(".fontawesome-searcher .fontawesome-searcher-icons").hide();
663 }else{
664 jQuery(".fontawesome-searcher .no-matches-found").hide();
665 jQuery(".fontawesome-searcher .fontawesome-searcher-icons").show();
666
667 var text = '<table><tr>';
668 for(var b = 0; b < foundMatches.length; b++) {
669 if(b % 4 == 0) {
670 text += "</tr><tr>";
671 }
672
673 text += '<td><a href="javascript:buttonizer.faChooseIcon(\''+ foundMatches[b] +'\')"><i class="fa '+ foundMatches[b] +'"></i></a></td>';
674 };
675
676 text += '</tr>';
677
678 jQuery(".fontawesome-searcher .fontawesome-searcher-icons").html(text);
679 }
680 },
681 faChooseIcon: function(icon) {
682 buttonizer.faSettings.currentSelect.val(icon).change();
683 buttonizer.faSettings.currentObject.html("Icon: "+ icon +" &nbsp; <i class=\"fa "+ icon +"\"></i>");
684 jQuery("#" + buttonizer.faSettings.currentObject.attr("id")).click();
685 }
686 }
687
688 document.addEventListener('DOMContentLoaded', buttonizer.init, false);
689
690 window.onbeforeunload = function(){
691 if(buttonizer.settings.hasChanges && !buttonizer.settings.clickedButton) {
692 return 'You have unsaved data. Are you sure you want to leave?';
693 }
694 };
695