var buttonizer = {
settings: {
wpButtonSaveKey: 'buttonizer_buttons',
wpCategorySaveKey: 'buttonizer_page_categories',
windowNumber: 0,
hasChanges: false,
clickedButton: false
},
setTimouts: {
a: function() {
return setTimeout(function() { }, 0)
},
b: function() {
return setTimeout(function() { }, 0)
},
},
init: function() {
buttonizer.overwriteFavIcon();
buttonizer.faInit();
buttonizer.initButtons();
// WP color picker
jQuery('#button_unpushed').wpColorPicker();
jQuery('#button_pushed').wpColorPicker();
jQuery('#icon_color').wpColorPicker();
jQuery(".savebutton").each(function() {
jQuery(this).click(buttonizer.saveAnimation);
});
jQuery("input, textarea, select").change(function() {
buttonizer.settings.hasChanges = true;
});
setTimeout(function() {
// Init preview button
jQuery('.button-preview').css({
'background-color': jQuery("#button_unpushed").val()
});
jQuery(".button-preview").hover(function() {
jQuery(this).css({
'background-color': jQuery("#button_pushed").val()
});
}, function() {
jQuery(this).css({
'background-color': jQuery("#button_unpushed").val()
});
});
}, 500);
jQuery(".vertical-tabs .icon-or-image").each(function() {
buttonizer.iconImageHandler(jQuery(this));
});
// Remove the spam from other plugins
setTimeout(function() {
var foundOurContent = false;
if(jQuery(".buttonizerWarning").length > 0) {
foundOurContent = true;
var buttonizerData = jQuery(".buttonizerWarning").html();
var buttonizerStyle = jQuery(".buttonizerWarning").attr('class');
}
jQuery("#wordpress-plugin-message-spam").remove();
if(foundOurContent) {
jQuery(".nav-tab-wrapper").after('
'+ buttonizerData +'
');
}
}, 1000);
// Hash
if(document.location.hash != "") {
var tabKey = document.location.hash;
buttonizer.tabNavigate(tabKey.replace("#tab_", ""));
}
jQuery(".buttonizer-click-to-pro").each(function() {
jQuery(this).click(function(e) {
e.preventDefault();
buttonizer.proInfoWindow();
});
});
buttonizer.loadPageCategorie();
if(!jQuery(".button-row").hasClass("is_category")) {
buttonizer.addSortable();
}
},
proInfoWindow: function() {
buttonizer.createWindow({
title: 'You like Buttonizer?',
text: 'Are you ready to try Buttonizer PRO?
What do you get?
'+
' Show on opening hours
' +
' Show buttons on specific pages: Use page rules
' +
' Unlimited page rules
' +
' Add custom image or button-icon
' +
' Exit intend
' +
' Show on scroll
' +
' Show on timeout
' +
'
' +
'Do you these features?
',
confirmText: 'Upgrade',
onConfirm: function() {
document.location.href = 'admin.php?page=Buttonizer-pricing';
}
});
},
overwriteFavIcon: function() {
(function() {
var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
link.href = faviconUrl;
document.getElementsByTagName('head')[0].appendChild(link);
})();
},
tabNavigate: function(key) {
jQuery(".vertical-tabs .tab-container").each(function() {
if(jQuery(this).attr('id') == "tab_container_" + key) {
jQuery(this).show();
}else{
jQuery(this).hide();
}
});
jQuery(".vertical-tabs .tabs a").each(function() {
if(jQuery(this).attr('id') == "tab_container_" + key) {
jQuery(this).addClass('nav-tab-active');
}else{
jQuery(this).removeClass('nav-tab-active');
}
});
// jQuery("type[name=_wp_http_referer]").val();
},
iconImageHandler: function(currentContainer) {
var type = currentContainer.data("type");
// Chooser
currentContainer.find(".placeholder-choose a").click(function() {
if(type == 'image') {
type = 'icon';
currentContainer.find(".image-placeholder").hide();
currentContainer.find(".icon-placeholder").show();
currentContainer.find("input").val("");
}else {
type = 'image';
currentContainer.find(".image-placeholder").show();
currentContainer.find(".icon-placeholder").hide();
}
});
// Insert image and icon type
currentContainer.find(".image-uploader-button").click(function(e) {
e.preventDefault();
var custom_uploader = wp.media({
title: 'Choose button icon',
multiple: false
})
.on('select', function() {
var attachment = custom_uploader.state().get('selection').first().toJSON();
currentContainer.find('.button-preview img').attr( 'src', attachment.url).show();
currentContainer.find(".button-preview").show();
currentContainer.find('input').val(attachment.url);
})
.open();
});
},
colorPaletHandler: function(colorPalet) {
var buttonId = colorPalet.attr("data-btnid");
var customColors = false;
var currentColors = {
default: buttonizer.rgb2hex(colorPalet.find(".color.default").css('background-color')),
pushed: buttonizer.rgb2hex(colorPalet.find(".color.pushed").css('background-color')),
icon: buttonizer.rgb2hex(colorPalet.find(".color.icon").css('background-color'))
};
jQuery("#btn_row_"+ buttonId +" .button-preview").css({ 'background-color': currentColors.default });
colorPalet.click(function() {
var randomText = (buttonizer.settings.windowNumber + 1);
buttonizer.createWindow({
title: 'Choose colors',
text:
'Choose the colors here of your button. You can give every button different colors.
' +
'',
confirmText: 'Choose',
afterInit: function() {
jQuery(".colorpalet-initializer").wpColorPicker();
},
onConfirm: function() {
currentColors.default = jQuery("#color_default_" + randomText).val();
currentColors.pushed = jQuery("#color_pushed_" + randomText).val();
currentColors.icon = jQuery("#color_icon_" + randomText).val();
jQuery("#btn_row_"+ buttonId +" .button-preview").css({ 'background-color': currentColors.default });
customColors = true;
jQuery("#reset_colors_" + buttonId).show();
updatePalet();
}
});
});
jQuery("#reset_colors_" + buttonId).click(function() {
buttonizer.createWindow({
title: 'Back to default colors',
text: 'The button colors will reset to the choosen default button colors (from the general settings).
' +
'Are you sure you want to get the default colors for this button?
',
canCancel: true,
cancelText: 'Cancel',
confirmText: ' Yes, I am',
onConfirm: function() {
customColors = false;
currentColors.default = colorPalet.find(".color.default").attr("data-default");
currentColors.pushed = colorPalet.find(".color.pushed").attr("data-default");
currentColors.icon = colorPalet.find(".color.icon").attr("data-default");
updatePalet();
jQuery("#reset_colors_" + buttonId).hide();
jQuery("#btn_row_"+ buttonId +" .button-preview").css({ 'background-color': currentColors.default });
}
});
});
function updatePalet() {
colorPalet.find(".color.default").css({ 'background-color': currentColors.default});
colorPalet.find(".color.pushed").css({ 'background-color': currentColors.pushed});
colorPalet.find(".color.icon").css({ 'background-color': currentColors.icon});
colorPalet.find("input.custom").val(customColors ? '1' : '0').change();
colorPalet.find("input.default").val(currentColors.default);
colorPalet.find("input.pushed").val(currentColors.pushed);
colorPalet.find("input.icon").val(currentColors.icon);
}
},
rgb2hex: function(rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
function hex(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
}
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
},
loadPageCategorie: function() {
jQuery(".page-categorie-styling").each(function() {
var maxLoaded = 10;
var isLoaded = 10;
var table = jQuery(this);
jQuery(this).addClass("initialized")
table.find("tr").each(function() {
jQuery(this).click(function(e) {
buttonizer.settings.hasChanges = true;
if(jQuery(e.target).attr("type") != "checkbox") {
jQuery(this).find("input").click();
}
});
});
jQuery(".categories-load-more[data-id="+ jQuery(this).attr("data-id") +"]").click(function() {
maxLoaded += 10;
isLoaded = 0;
table.find("tr").each(function() {
isLoaded++;
if(isLoaded <= maxLoaded) {
jQuery(this).show();
}else{
return;
}
});
if(jQuery(".page-categorie-styling[data-id="+ jQuery(this).attr("data-id") +"] tr").length < maxLoaded) {
jQuery(this).hide();
}
});
});
},
addSortable: function() {
var sortable = new Sortable(document.getElementById("button-rows"), {
group: "button-rows",
sort: true,
animation: 150,
scroll: true,
scrollSensitivity: 30,
scrollSpeed: 10,
onSort: function (evt) {
jQuery("#" + evt.clone.children[0].id + " .row-info").css({
opacity: .45,
}).delay(500).animate({
opacity: 1,
}, 500);
}
});
},
saveAnimation: function() {
jQuery(".savebutton").each(function() {
jQuery(this).html(' Saving');
});
buttonizer.settings.clickedButton = true;
jQuery('form#buttonizer').submit();
},
/*
* Buttons
*/
initButtons: function() {
jQuery(".button-row .savebutton").each(function() {
jQuery(this).click(buttonizer.saveAnimation);
});
jQuery(".button-row").each(function() {
if(jQuery(this).attr("button-id") == '-1') {
return;
}
var rowObj = jQuery(this);
var rowId = jQuery(this).attr("button-id");
var buttonTitle = rowObj.find(".row-info span .row-title");
var buttonEdit = rowObj.find(".row-info .pencil-edit");
var buttonTitleField = rowObj.find(".button_title");
var doubleClick = setTimeout(function() {}, 100);
var isCategory = rowObj.hasClass('is_category');
var clicked = 0;
buttonEdit.click(function(e) {
e.preventDefault();
buttonTitle.dblclick();
});
buttonTitle.html(buttonTitleField.val());
rowObj.find(".row-info").click(function(e) {
if(
jQuery(e.target).hasClass('fa-desktop') ||
jQuery(e.target).hasClass('fa-mobile') ||
jQuery(e.target).hasClass('fa-pencil') ||
jQuery(e.target).hasClass('mobiledesktop') ||
jQuery(e.target).hasClass('is-live-button') ||
jQuery(e.target).hasClass('must-save-button')
) {
return;
}
clicked = 0;
clearInterval(doubleClick);
doubleClick = setTimeout(function() {
if(clicked == 0) {
if(rowObj.hasClass("opened")) {
rowObj.removeClass("opened");
}else{
rowObj.addClass("opened");
}
}
clicked = 0;
}, 100);
});
buttonTitle.dblclick(function() {
buttonizer.updateTitle(buttonTitle, buttonTitleField, false);
clicked++;
});
rowObj.find(".button_showonphone").change(function(e) {
var isSelected = jQuery(this).is(":checked");
if(!isSelected) {
jQuery("#btn_row_" + rowId + " .row-info .mobile-button").addClass("selected");
}else {
jQuery("#btn_row_" + rowId + " .row-info .mobile-button").removeClass("selected");
}
});
rowObj.find('.button_title').change(function() {
newTitle = jQuery(this).val();
if(buttonizer.checkTitleDuplicate(newTitle, rowId)) {
buttonizer.updateTitle(buttonTitle, buttonTitleField, true, newTitle);
return;
}
buttonTitle.html(newTitle);
});
rowObj.find(".button_showondesktop").change(function(e) {
var isSelected = jQuery(this).is(":checked");
if(!isSelected) {
jQuery("#btn_row_" + rowId + " .row-info .desktop-button").addClass("selected");
}else {
jQuery("#btn_row_" + rowId + " .row-info .desktop-button").removeClass("selected");
}
});
jQuery("#button_"+ rowId +"_icon").change(function(e) {
rowObj.find(".button-icon").attr('class', "fa "+ jQuery(this).val() +" button-icon");
});
jQuery("#btn_row_" + rowId + " input").change(function() {
jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide();
jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show();
});
if(isCategory) {
var checked = false;
rowObj.find(".select-all").click(function() {
if(!checked) {
checked = true;
rowObj.find(".page-categorie-styling input[type=checkbox]").attr("checked", "checked");
}else{
checked = false;
rowObj.find(".page-categorie-styling input[type=checkbox]").removeAttr("checked");
}
});
}else{
// Image icon handler
buttonizer.iconImageHandler(rowObj.find(".icon-or-image"));
buttonizer.colorPaletHandler(rowObj.find(".button-color-palet"));
}
});
},
updateTitle: function(buttonTitle, buttonTitleField, isDuplicate, text) {
if(!text) {
var text = '';
}
if(!isDuplicate) {
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());
}else{
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);
}
if(!newTitle || newTitle == "") {
if(isDuplicate) {
buttonTitleField.val(buttonTitle.html());
}
return;
}
if(buttonizer.checkTitleDuplicate(newTitle)) {
buttonizer.updateTitle(buttonTitle, buttonTitleField, true, newTitle);
return;
}
buttonTitle.html(newTitle);
buttonTitleField.val(newTitle);
},
checkTitleDuplicate: function(text, allowRowId) {
isDuplicate = false;
if(!allowRowId) {
var allowRowId = -1;
}
jQuery(".button-row").each(function() {
if(jQuery(this).find('.button_title').val() == text && jQuery(this).attr("button-id") != allowRowId) {
isDuplicate = true;
}
});
return isDuplicate;
},
removeRow: function(id) {
var buttonName = jQuery("#btn_row_" +id + " .row-info span .row-title").html();
var wasCategory = jQuery("#btn_row_" + id).hasClass('is_category');
if(confirm("Are you sure you want to remove the row with the text: '"+ buttonName +"'?\n\nThis is not recoverable.")) {
jQuery("#btn_row_" +id).remove();
if(jQuery(".button-row").length > 1) {
jQuery(".buttonizer-no-buttons").hide();
}else{
jQuery(".buttonizer-no-buttons").show();
}
}
},
toggleMobile: function(id) {
var isSelected = jQuery("#button_"+ id +"_show_on_phone").is(":checked");
if(!isSelected) {
jQuery("#btn_row_" + id + " .row-info .mobile-button").removeClass("selected");
jQuery("#button_"+ id +"_show_on_phone").click();
}else {
jQuery("#btn_row_" + id + " .row-info .mobile-button").addClass("selected");
jQuery("#button_"+ id +"_show_on_phone").click();
}
jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide();
jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show();
},
toggleDesktop: function(id) {
var isSelected = jQuery("#button_"+ id +"_show_on_desktop").is(":checked");
if(!isSelected) {
jQuery("#btn_row_" + id + " .row-info .desktop-button").removeClass("selected");
jQuery("#button_"+ id +"_show_on_desktop").click();
}else {
jQuery("#btn_row_" + id + " .row-info .desktop-button").addClass("selected");
jQuery("#button_"+ id +"_show_on_desktop").click();
}
jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide();
jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show();
},
addRow: function() {
if(jQuery("#new-button").hasClass('disabled')) {
return;
}
buttonizer.settings.hasChanges = true;
jQuery(".buttonizer-no-buttons").hide();
var isCategory = jQuery(".button-row[button-id=-1]").hasClass("is_category");
jQuery("#new-button").attr('disabled', 'disabled').addClass('disabled');
var defaultRow = jQuery(".button-row[button-id=-1]").html();
var numberOfButtons = jQuery(".button-row").length - (isCategory ? 1 : 0);
numberOfButtons = Math.floor(Date.now() / 1000);
numberOfButtons = numberOfButtons + "-" + Math.floor((Math.random() * 999) + 100);
numberOfButtons = numberOfButtons.replace('-', '');
var newData = defaultRow.replace('/-1/g', numberOfButtons);
newData = newData.replace('-1', numberOfButtons);
jQuery("#button-rows, #page-categories").append((!isCategory ? '' : '') + '' + newData + '
' + (!isCategory ? '' : ''));
clearInterval(buttonizer.setTimouts.a);
clearInterval(buttonizer.setTimouts.b);
buttonizer.setTimouts.a = setTimeout(function() {
jQuery(".button-row *").unbind("click");
jQuery(".button-row").removeClass("opened");
jQuery(".fontawesome-searcher-clicker").remove();
jQuery("#btn_row_"+ numberOfButtons +" .button_title").val("New button " + numberOfButtons);
if(isCategory) {
jQuery("#btn_row_"+ numberOfButtons +" input").each(function() {
jQuery(this).attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"][]");
});
jQuery("#btn_row_"+ numberOfButtons + " select").attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"_type]");
}
}, 100);
buttonizer.setTimouts.b = setTimeout(function() {
buttonizer.initButtons();
if(!isCategory) {
buttonizer.updateRowInputNames(numberOfButtons);
jQuery("#btn_row_"+ numberOfButtons).addClass('opened');
jQuery("#btn_row_"+ numberOfButtons + " input.button_title").focus();
}else{
console.log("Initialize new page category");
jQuery("#btn_row_"+ numberOfButtons + " #categoryIsUsed").val(numberOfButtons);
jQuery("#btn_row_"+ numberOfButtons + " #categoryIsUsed").attr("name", buttonizer.settings.wpCategorySaveKey + '[categorieOrder][]');
jQuery("#btn_row_"+ numberOfButtons + " .delete-button").attr("href", "javascript:buttonizer.removeRow("+ numberOfButtons +")");
jQuery("#btn_row_"+ numberOfButtons + " .button_title").attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"_title]").val('New page category ' + (jQuery(".button-row").length - 1));
jQuery("#btn_row_"+ numberOfButtons + " .row-title").html("New page category " + (jQuery(".button-row").length - 1));
}
buttonizer.faInit();
buttonizer.loadPageCategorie();
jQuery("#new-button").removeAttr('disabled').removeClass('disabled');
jQuery("#btn_row_"+ numberOfButtons + " .savebutton").show();
}, 400);
},
updateRowInputNames: function(buttonId) {
// Textfield
jQuery("#btn_row_"+ buttonId + " .button_textfield")
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_text]")
.attr("id", "button_"+ buttonId +"_text").val("");
// Iconfield
jQuery("#btn_row_"+ buttonId + " .icon-placeholder select").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_icon]");
// Iconfield
jQuery("#btn_row_"+ buttonId + " .image-placeholder input").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_image]");
// Button title
jQuery("#btn_row_"+ buttonId + " .button_title").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_title]");
// Button show on page category
jQuery("#btn_row_"+ buttonId + " #button_category").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_pages]");
// Color palets
jQuery("#btn_row_"+ buttonId + " input.custom").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_using_custom_colors]");
jQuery("#btn_row_"+ buttonId + " input.default").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_colors_button]");
jQuery("#btn_row_"+ buttonId + " input.pushed").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_colors_pushed]");
jQuery("#btn_row_"+ buttonId + " input.icon").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_colors_icon]");
// Show on phone
jQuery("#btn_row_"+ buttonId + " .button_showonphone")
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_phone]")
.attr("id", "button_"+ buttonId +"_show_on_phone");
jQuery("label[for='button_"+ -1 +"_show_on_phone']").attr("for", "button_"+ buttonId +"_show_on_phone");
// Show on desktop
jQuery("#btn_row_"+ buttonId + " .button_showondesktop")
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_desktop]")
.attr("id", "button_"+ buttonId +"_show_on_desktop");
jQuery("label[for='button_"+ -1 +"_show_on_desktop']").attr("for", "button_"+ buttonId +"_show_on_desktop");
// Url
jQuery("#btn_row_"+ buttonId + " .button_isurl")
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_url]")
.attr("id", "button_"+ buttonId +"_url");
jQuery("label[for='button_"+ -1 +"_url']").attr("for", "button_"+ buttonId +"_url");
// Is phone buttonId
jQuery("#btn_row_"+ buttonId + " .button_isphonenumber")
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_is_phonenumber]")
.attr("id", "button_"+ buttonId +"_is_phonenumber");
jQuery("label[for='button_"+ -1 +"_is_phonenumber']").attr("for", "button_"+ buttonId +"_is_phonenumber");
// New tab
jQuery("#btn_row_"+ buttonId + " .button_isnewtab")
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_url_newtab]")
.attr("id", "button_"+ buttonId +"_url_newtab");
jQuery("label[for='button_"+ -1 +"_url_newtab']").attr("for", "button_"+ buttonId +"_url_newtab");
// Show only on opening hours
jQuery("#btn_row_"+ buttonId + " .button_showwhenopened")
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_when_opened]")
.attr("id", "button_"+ buttonId +"_show_when_opened");
jQuery("label[for='button_"+ -1 +"_show_when_opened']").attr("for", "button_"+ buttonId +"_show_when_opened");
// Show only on opening hours
jQuery("#btn_row_"+ buttonId + " .button_hidelabel")
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_hide_label]")
.attr("id", "button_"+ buttonId +"_hide_label");
jQuery("label[for='button_"+ -1 +"_hide_label']").attr("for", "button_"+ buttonId +"_hide_label");
/*
* Link fixes
*/
// Delete button link
jQuery("#btn_row_"+ buttonId + " .delete-button").attr("href", "javascript:buttonizer.removeRow("+ buttonId +")");
// Show on mobile button link
jQuery("#btn_row_"+ buttonId + " .mobiledesktop.mobile-button").attr("href", "javascript:buttonizer.toggleMobile("+ buttonId +")");
// Show on desktop button link
jQuery("#btn_row_"+ buttonId + " .mobiledesktop.desktop-button").attr("href", "javascript:buttonizer.toggleDesktop("+ buttonId +")");
},
createWindow: function(data) {
this.settings.windowNumber++;
var currentWindow = this.settings.windowNumber;
if(!data.title) {
data.title = '';
}
if(!data.text) {
data.text = 'This dialog has not text.
Weird, isn\'t it?
';
}
if(!data.confirmText) {
data.confirmText = 'Close';
}
if(!data.canCancel) {
data.canCancel = false;
}
if(!data.cancelText) {
data.cancelText = 'Cancel';
}
if(!data.onConfirm) {
data.onConfirm = function() {};
}
if(!data.onClose) {
data.onClose = function() {};
}
if(!data.afterInit) {
data.afterInit = function() {};
}
var windowStyle = '';
jQuery("body").append(windowStyle);
jQuery(document).ready(data.afterInit);
jQuery("#buttonizer-window-"+ currentWindow + " .fs-close, #buttonizer-window-"+ currentWindow + " button").click(function(e) {
e.preventDefault();
jQuery("#buttonizer-window-"+ currentWindow).fadeOut();
if(jQuery(this).hasClass("confirm")) {
data.onConfirm();
}
data.onClose();
})
},
/*
* Font awesome searcher
*/
faSettings: {
objects: 0,
currentSelect: {},
currentObject: {},
isGenerated: false,
isOpened: false
},
faInit: function() {
buttonizer.faSettings.isOpened = false;
if(buttonizer.faSettings.isGenerated == false) {
buttonizer.faSettings.isGenerated = true;
fontAwesome = jQuery.map(fontAwesome, function(value, index) {
return [index];
});
}
jQuery("body").click(function(e){
if(!jQuery(e.target).closest('.fontawesome-searcher').length && !jQuery(e.target).closest('.fontawesome-searcher-clicker').length){
jQuery(".fontawesome-searcher").hide();
buttonizer.faSettings.isOpened = false;
}
});
var typeTimeOut = setTimeout(function() { buttonizer.faSearchWord(''); }, 300);
var adminBody = jQuery("#wpbody");
jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").keyup(function() {
clearInterval(typeTimeOut);
typeTimeOut = setTimeout(function() { buttonizer.faSearchWord(jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").val()); }, 300);
});
jQuery("select.fa-chooser").each(function() {
buttonizer.faSettings.objects++;
var obj = jQuery(this);
obj.hide();
obj.parent().append("Icon: "+ obj.val() +" ");
var newObject = jQuery("#fa-chooser_" + buttonizer.faSettings.objects);
newObject.click(function(e) {
if(buttonizer.faSettings.isOpened == false || buttonizer.faSettings.currentSelect != obj) {
jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").focus();
buttonizer.faSettings.isOpened = true;
// Update process
jQuery(".fontawesome-searcher").css({
"top": newObject.offset().top - 20 + newObject.height(),
"left": newObject.offset().left - adminBody.offset().left,
"width": newObject.width()
}).show();
buttonizer.faSettings.currentSelect = obj;
buttonizer.faSettings.currentObject = newObject;
}else{
buttonizer.faSettings.isOpened = false;
jQuery(".fontawesome-searcher").hide();
}
e.preventDefault();
});
});
},
faSearchWord: function(word) {
var foundMatches = [];
for(var i = 0; i < fontAwesome.length; i++) {
if(fontAwesome[i].indexOf(word) !== -1) {
foundMatches.push(fontAwesome[i]);
}
};
if(foundMatches.length == 0) {
jQuery(".fontawesome-searcher .no-matches-found").show();
jQuery(".fontawesome-searcher .fontawesome-searcher-icons").hide();
}else{
jQuery(".fontawesome-searcher .no-matches-found").hide();
jQuery(".fontawesome-searcher .fontawesome-searcher-icons").show();
var text = '';
for(var b = 0; b < foundMatches.length; b++) {
if(b % 4 == 0) {
text += "
";
}
text += ' | ';
};
text += '
';
jQuery(".fontawesome-searcher .fontawesome-searcher-icons").html(text);
}
},
faChooseIcon: function(icon) {
buttonizer.faSettings.currentSelect.val(icon).change();
buttonizer.faSettings.currentObject.html("Icon: "+ icon +" ");
jQuery("#" + buttonizer.faSettings.currentObject.attr("id")).click();
}
}
document.addEventListener('DOMContentLoaded', buttonizer.init, false);
window.onbeforeunload = function(){
if(buttonizer.settings.hasChanges && !buttonizer.settings.clickedButton) {
return 'You have unsaved data. Are you sure you want to leave?';
}
};