| 1 |
|
| 2 |
var buttonizer = { |
| 3 |
settings: { |
| 4 |
wpButtonSaveKey: 'buttonizer_buttons', |
| 5 |
wpCategorySaveKey: 'buttonizer_page_categories', |
| 6 |
windowNumber: 0, |
| 7 |
hasChanges: false, |
| 8 |
clickedButton: false |
| 9 |
}, |
| 10 |
|
| 11 |
setTimouts: { |
| 12 |
a: function() { |
| 13 |
return setTimeout(function() { }, 0) |
| 14 |
}, |
| 15 |
b: function() { |
| 16 |
return setTimeout(function() { }, 0) |
| 17 |
}, |
| 18 |
}, |
| 19 |
|
| 20 |
init: function() { |
| 21 |
buttonizer.overwriteFavIcon(); |
| 22 |
buttonizer.faInit(); |
| 23 |
buttonizer.initButtons(); |
| 24 |
|
| 25 |
// WP color picker |
| 26 |
jQuery('#button_unpushed').wpColorPicker(); |
| 27 |
jQuery('#button_pushed').wpColorPicker(); |
| 28 |
jQuery('#icon_color').wpColorPicker(); |
| 29 |
|
| 30 |
jQuery(".savebutton").each(function() { |
| 31 |
jQuery(this).click(buttonizer.saveAnimation); |
| 32 |
}); |
| 33 |
|
| 34 |
jQuery("input, textarea, select").change(function() { |
| 35 |
buttonizer.settings.hasChanges = true; |
| 36 |
}); |
| 37 |
|
| 38 |
setTimeout(function() { |
| 39 |
// Init preview button |
| 40 |
jQuery('.button-preview').css({ |
| 41 |
'background-color': jQuery("#button_unpushed").val() |
| 42 |
}); |
| 43 |
|
| 44 |
jQuery(".button-preview").hover(function() { |
| 45 |
jQuery(this).css({ |
| 46 |
'background-color': jQuery("#button_pushed").val() |
| 47 |
}); |
| 48 |
}, function() { |
| 49 |
jQuery(this).css({ |
| 50 |
'background-color': jQuery("#button_unpushed").val() |
| 51 |
}); |
| 52 |
}); |
| 53 |
}, 500); |
| 54 |
|
| 55 |
jQuery(".vertical-tabs .icon-or-image").each(function() { |
| 56 |
buttonizer.iconImageHandler(jQuery(this)); |
| 57 |
}); |
| 58 |
|
| 59 |
// Remove the spam from other plugins |
| 60 |
setTimeout(function() { |
| 61 |
var foundOurContent = false; |
| 62 |
if(jQuery(".buttonizerWarning").length > 0) { |
| 63 |
foundOurContent = true; |
| 64 |
var buttonizerData = jQuery(".buttonizerWarning").html(); |
| 65 |
var buttonizerStyle = jQuery(".buttonizerWarning").attr('class'); |
| 66 |
} |
| 67 |
|
| 68 |
jQuery("#wordpress-plugin-message-spam").remove(); |
| 69 |
|
| 70 |
if(foundOurContent) { |
| 71 |
jQuery(".nav-tab-wrapper").after('<div class="'+ buttonizerStyle +'">'+ buttonizerData +'</div>'); |
| 72 |
} |
| 73 |
}, 1000); |
| 74 |
|
| 75 |
// Hash |
| 76 |
if(document.location.hash != "") { |
| 77 |
var tabKey = document.location.hash; |
| 78 |
buttonizer.tabNavigate(tabKey.replace("#tab_", "")); |
| 79 |
} |
| 80 |
|
| 81 |
jQuery(".buttonizer-click-to-pro").each(function() { |
| 82 |
jQuery(this).click(function(e) { |
| 83 |
e.preventDefault(); |
| 84 |
buttonizer.proInfoWindow(); |
| 85 |
}); |
| 86 |
}); |
| 87 |
|
| 88 |
buttonizer.loadPageCategorie(); |
| 89 |
|
| 90 |
if(!jQuery(".button-row").hasClass("is_category")) { |
| 91 |
buttonizer.addSortable(); |
| 92 |
} |
| 93 |
}, |
| 94 |
|
| 95 |
proInfoWindow: function() { |
| 96 |
buttonizer.createWindow({ |
| 97 |
title: 'You like Buttonizer?', |
| 98 |
text: '<p>Are you ready to try Buttonizer PRO?</p><p><b class="color-buttonizer">What do you get?</b></p>'+ |
| 99 |
|
| 100 |
'<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Show on opening hours</div>' + |
| 101 |
'<div class="color-buttonizer-orange buttonizer-pro-checklist"><i class="fa fa-check"></i> Show buttons on specific pages: Use page rules</div>' + |
| 102 |
'<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Unlimited page rules</div>' + |
| 103 |
'<div class="color-buttonizer-orange buttonizer-pro-checklist"><i class="fa fa-check"></i> Add custom image or button-icon</div>' + |
| 104 |
'<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Exit intend</div>' + |
| 105 |
'<div class="color-buttonizer-orange buttonizer-pro-checklist"><i class="fa fa-check"></i> Show on scroll</div>' + |
| 106 |
'<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Show on timeout</div>' + |
| 107 |
'<br />' + |
| 108 |
'<p class="color-buttonizer text-right"><b>Do you <span><i class="fa fa-heart"></i></span> these features?</b></p>', |
| 109 |
confirmText: 'Upgrade', |
| 110 |
onConfirm: function() { |
| 111 |
document.location.href = 'admin.php?page=Buttonizer-pricing'; |
| 112 |
} |
| 113 |
}); |
| 114 |
}, |
| 115 |
|
| 116 |
overwriteFavIcon: function() { |
| 117 |
(function() { |
| 118 |
var link = document.querySelector("link[rel*='icon']") || document.createElement('link'); |
| 119 |
link.type = 'image/x-icon'; |
| 120 |
link.rel = 'shortcut icon'; |
| 121 |
link.href = faviconUrl; |
| 122 |
document.getElementsByTagName('head')[0].appendChild(link); |
| 123 |
})(); |
| 124 |
}, |
| 125 |
|
| 126 |
tabNavigate: function(key) { |
| 127 |
jQuery(".vertical-tabs .tab-container").each(function() { |
| 128 |
if(jQuery(this).attr('id') == "tab_container_" + key) { |
| 129 |
jQuery(this).show(); |
| 130 |
}else{ |
| 131 |
jQuery(this).hide(); |
| 132 |
} |
| 133 |
}); |
| 134 |
|
| 135 |
jQuery(".vertical-tabs .tabs a").each(function() { |
| 136 |
if(jQuery(this).attr('id') == "tab_container_" + key) { |
| 137 |
jQuery(this).addClass('nav-tab-active'); |
| 138 |
}else{ |
| 139 |
jQuery(this).removeClass('nav-tab-active'); |
| 140 |
} |
| 141 |
}); |
| 142 |
|
| 143 |
// jQuery("type[name=_wp_http_referer]").val(); |
| 144 |
}, |
| 145 |
|
| 146 |
iconImageHandler: function(currentContainer) { |
| 147 |
var type = currentContainer.data("type"); |
| 148 |
|
| 149 |
// Chooser |
| 150 |
currentContainer.find(".placeholder-choose a").click(function() { |
| 151 |
if(type == 'image') { |
| 152 |
type = 'icon'; |
| 153 |
|
| 154 |
currentContainer.find(".image-placeholder").hide(); |
| 155 |
currentContainer.find(".icon-placeholder").show(); |
| 156 |
|
| 157 |
currentContainer.find("input").val(""); |
| 158 |
}else { |
| 159 |
type = 'image'; |
| 160 |
|
| 161 |
currentContainer.find(".image-placeholder").show(); |
| 162 |
currentContainer.find(".icon-placeholder").hide(); |
| 163 |
} |
| 164 |
}); |
| 165 |
|
| 166 |
// Insert image and icon type |
| 167 |
currentContainer.find(".image-uploader-button").click(function(e) { |
| 168 |
e.preventDefault(); |
| 169 |
|
| 170 |
var custom_uploader = wp.media({ |
| 171 |
title: 'Choose button icon', |
| 172 |
multiple: false |
| 173 |
}) |
| 174 |
.on('select', function() { |
| 175 |
var attachment = custom_uploader.state().get('selection').first().toJSON(); |
| 176 |
currentContainer.find('.button-preview img').attr( 'src', attachment.url).show(); |
| 177 |
currentContainer.find(".button-preview").show(); |
| 178 |
|
| 179 |
currentContainer.find('input').val(attachment.url); |
| 180 |
}) |
| 181 |
.open(); |
| 182 |
}); |
| 183 |
}, |
| 184 |
|
| 185 |
colorPaletHandler: function(colorPalet) { |
| 186 |
var buttonId = colorPalet.attr("data-btnid"); |
| 187 |
var customColors = false; |
| 188 |
var currentColors = { |
| 189 |
default: buttonizer.rgb2hex(colorPalet.find(".color.default").css('background-color')), |
| 190 |
pushed: buttonizer.rgb2hex(colorPalet.find(".color.pushed").css('background-color')), |
| 191 |
icon: buttonizer.rgb2hex(colorPalet.find(".color.icon").css('background-color')) |
| 192 |
}; |
| 193 |
|
| 194 |
jQuery("#btn_row_"+ buttonId +" .button-preview").css({ 'background-color': currentColors.default }); |
| 195 |
|
| 196 |
colorPalet.click(function() { |
| 197 |
var randomText = (buttonizer.settings.windowNumber + 1); |
| 198 |
|
| 199 |
buttonizer.createWindow({ |
| 200 |
title: 'Choose colors', |
| 201 |
text: |
| 202 |
'<p>Choose the colors here of your button. You can give every button different colors.</p>' + |
| 203 |
'<table width="100%" class="color-chooser-table">' + |
| 204 |
'<tr><td width="150">' + |
| 205 |
'<b>Button color</b>' + |
| 206 |
'</td><td>' + |
| 207 |
'<input type="text" class="colorpalet-initializer" value="'+ currentColors.default +'" id="color_default_'+ randomText +'" />' + |
| 208 |
'</td></tr>' + |
| 209 |
|
| 210 |
'<tr><td>' + |
| 211 |
'<b>Pushed/hover color</b>' + |
| 212 |
'</td><td>' + |
| 213 |
'<input type="text" class="colorpalet-initializer" value="'+ currentColors.pushed +'" id="color_pushed_'+ randomText +'" />' + |
| 214 |
'</td></tr>' + |
| 215 |
|
| 216 |
'<tr><td>' + |
| 217 |
'<b>Icon color</b>' + |
| 218 |
'</td><td>' + |
| 219 |
'<input type="text" class="colorpalet-initializer" value="'+ currentColors.icon +'" id="color_icon_'+ randomText +'" />' + |
| 220 |
'</td></tr>' + |
| 221 |
'</table>', |
| 222 |
|
| 223 |
confirmText: 'Choose', |
| 224 |
|
| 225 |
afterInit: function() { |
| 226 |
jQuery(".colorpalet-initializer").wpColorPicker(); |
| 227 |
}, |
| 228 |
|
| 229 |
onConfirm: function() { |
| 230 |
currentColors.default = jQuery("#color_default_" + randomText).val(); |
| 231 |
currentColors.pushed = jQuery("#color_pushed_" + randomText).val(); |
| 232 |
currentColors.icon = jQuery("#color_icon_" + randomText).val(); |
| 233 |
jQuery("#btn_row_"+ buttonId +" .button-preview").css({ 'background-color': currentColors.default }); |
| 234 |
customColors = true; |
| 235 |
|
| 236 |
jQuery("#reset_colors_" + buttonId).show(); |
| 237 |
updatePalet(); |
| 238 |
} |
| 239 |
}); |
| 240 |
}); |
| 241 |
|
| 242 |
jQuery("#reset_colors_" + buttonId).click(function() { |
| 243 |
buttonizer.createWindow({ |
| 244 |
title: 'Back to default colors', |
| 245 |
text: '<p>The button colors will reset to the choosen default button colors (from the general settings).</p>' + |
| 246 |
'<p>Are you sure you want to get the default colors for this button?</p>', |
| 247 |
|
| 248 |
canCancel: true, |
| 249 |
cancelText: 'Cancel', |
| 250 |
confirmText: '<i class="fa fa-thumbs-o-up"></i> Yes, I am', |
| 251 |
|
| 252 |
onConfirm: function() { |
| 253 |
customColors = false; |
| 254 |
currentColors.default = colorPalet.find(".color.default").attr("data-default"); |
| 255 |
currentColors.pushed = colorPalet.find(".color.pushed").attr("data-default"); |
| 256 |
currentColors.icon = colorPalet.find(".color.icon").attr("data-default"); |
| 257 |
updatePalet(); |
| 258 |
jQuery("#reset_colors_" + buttonId).hide(); |
| 259 |
jQuery("#btn_row_"+ buttonId +" .button-preview").css({ 'background-color': currentColors.default }); |
| 260 |
} |
| 261 |
}); |
| 262 |
}); |
| 263 |
|
| 264 |
function updatePalet() { |
| 265 |
colorPalet.find(".color.default").css({ 'background-color': currentColors.default}); |
| 266 |
colorPalet.find(".color.pushed").css({ 'background-color': currentColors.pushed}); |
| 267 |
colorPalet.find(".color.icon").css({ 'background-color': currentColors.icon}); |
| 268 |
|
| 269 |
colorPalet.find("input.custom").val(customColors ? '1' : '0').change(); |
| 270 |
colorPalet.find("input.default").val(currentColors.default); |
| 271 |
colorPalet.find("input.pushed").val(currentColors.pushed); |
| 272 |
colorPalet.find("input.icon").val(currentColors.icon); |
| 273 |
} |
| 274 |
}, |
| 275 |
|
| 276 |
rgb2hex: function(rgb) { |
| 277 |
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); |
| 278 |
function hex(x) { |
| 279 |
return ("0" + parseInt(x).toString(16)).slice(-2); |
| 280 |
} |
| 281 |
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); |
| 282 |
}, |
| 283 |
|
| 284 |
loadPageCategorie: function() { |
| 285 |
jQuery(".page-categorie-styling").each(function() { |
| 286 |
var maxLoaded = 10; |
| 287 |
var isLoaded = 10; |
| 288 |
var table = jQuery(this); |
| 289 |
jQuery(this).addClass("initialized") |
| 290 |
|
| 291 |
table.find("tr").each(function() { |
| 292 |
jQuery(this).click(function(e) { |
| 293 |
buttonizer.settings.hasChanges = true; |
| 294 |
if(jQuery(e.target).attr("type") != "checkbox") { |
| 295 |
jQuery(this).find("input").click(); |
| 296 |
} |
| 297 |
}); |
| 298 |
}); |
| 299 |
|
| 300 |
jQuery(".categories-load-more[data-id="+ jQuery(this).attr("data-id") +"]").click(function() { |
| 301 |
maxLoaded += 10; |
| 302 |
isLoaded = 0; |
| 303 |
|
| 304 |
table.find("tr").each(function() { |
| 305 |
isLoaded++; |
| 306 |
if(isLoaded <= maxLoaded) { |
| 307 |
jQuery(this).show(); |
| 308 |
}else{ |
| 309 |
return; |
| 310 |
} |
| 311 |
}); |
| 312 |
|
| 313 |
if(jQuery(".page-categorie-styling[data-id="+ jQuery(this).attr("data-id") +"] tr").length < maxLoaded) { |
| 314 |
jQuery(this).hide(); |
| 315 |
} |
| 316 |
}); |
| 317 |
}); |
| 318 |
}, |
| 319 |
|
| 320 |
addSortable: function() { |
| 321 |
var sortable = new Sortable(document.getElementById("button-rows"), { |
| 322 |
group: "button-rows", |
| 323 |
sort: true, |
| 324 |
animation: 150, |
| 325 |
scroll: true, |
| 326 |
scrollSensitivity: 30, |
| 327 |
scrollSpeed: 10, |
| 328 |
|
| 329 |
onSort: function (evt) { |
| 330 |
jQuery("#" + evt.clone.children[0].id + " .row-info").css({ |
| 331 |
opacity: .45, |
| 332 |
}).delay(500).animate({ |
| 333 |
opacity: 1, |
| 334 |
}, 500); |
| 335 |
} |
| 336 |
}); |
| 337 |
}, |
| 338 |
|
| 339 |
saveAnimation: function() { |
| 340 |
jQuery(".savebutton").each(function() { |
| 341 |
jQuery(this).html('<i class="fa fa-cog fa-spin"></i> <span>Saving</span>'); |
| 342 |
}); |
| 343 |
buttonizer.settings.clickedButton = true; |
| 344 |
jQuery('form#buttonizer').submit(); |
| 345 |
}, |
| 346 |
|
| 347 |
/* |
| 348 |
* Buttons |
| 349 |
*/ |
| 350 |
initButtons: function() { |
| 351 |
jQuery(".button-row .savebutton").each(function() { |
| 352 |
jQuery(this).click(buttonizer.saveAnimation); |
| 353 |
}); |
| 354 |
|
| 355 |
jQuery(".button-row").each(function() { |
| 356 |
if(jQuery(this).attr("button-id") == '-1') { |
| 357 |
return; |
| 358 |
} |
| 359 |
|
| 360 |
var rowObj = jQuery(this); |
| 361 |
var rowId = jQuery(this).attr("button-id"); |
| 362 |
var buttonTitle = rowObj.find(".row-info span .row-title"); |
| 363 |
var buttonEdit = rowObj.find(".row-info .pencil-edit"); |
| 364 |
var buttonTitleField = rowObj.find(".button_title"); |
| 365 |
var doubleClick = setTimeout(function() {}, 100); |
| 366 |
var isCategory = rowObj.hasClass('is_category'); |
| 367 |
var clicked = 0; |
| 368 |
|
| 369 |
buttonEdit.click(function(e) { |
| 370 |
e.preventDefault(); |
| 371 |
buttonTitle.dblclick(); |
| 372 |
}); |
| 373 |
|
| 374 |
buttonTitle.html(buttonTitleField.val()); |
| 375 |
|
| 376 |
rowObj.find(".row-info").click(function(e) { |
| 377 |
if( |
| 378 |
jQuery(e.target).hasClass('fa-desktop') || |
| 379 |
jQuery(e.target).hasClass('fa-mobile') || |
| 380 |
jQuery(e.target).hasClass('fa-pencil') || |
| 381 |
jQuery(e.target).hasClass('mobiledesktop') || |
| 382 |
jQuery(e.target).hasClass('is-live-button') || |
| 383 |
jQuery(e.target).hasClass('must-save-button') |
| 384 |
) { |
| 385 |
return; |
| 386 |
} |
| 387 |
|
| 388 |
clicked = 0; |
| 389 |
clearInterval(doubleClick); |
| 390 |
doubleClick = setTimeout(function() { |
| 391 |
if(clicked == 0) { |
| 392 |
if(rowObj.hasClass("opened")) { |
| 393 |
rowObj.removeClass("opened"); |
| 394 |
}else{ |
| 395 |
rowObj.addClass("opened"); |
| 396 |
} |
| 397 |
} |
| 398 |
clicked = 0; |
| 399 |
}, 100); |
| 400 |
}); |
| 401 |
|
| 402 |
buttonTitle.dblclick(function() { |
| 403 |
buttonizer.updateTitle(buttonTitle, buttonTitleField, false); |
| 404 |
|
| 405 |
clicked++; |
| 406 |
}); |
| 407 |
|
| 408 |
rowObj.find(".button_showonphone").change(function(e) { |
| 409 |
var isSelected = jQuery(this).is(":checked"); |
| 410 |
|
| 411 |
if(!isSelected) { |
| 412 |
jQuery("#btn_row_" + rowId + " .row-info .mobile-button").addClass("selected"); |
| 413 |
}else { |
| 414 |
jQuery("#btn_row_" + rowId + " .row-info .mobile-button").removeClass("selected"); |
| 415 |
} |
| 416 |
}); |
| 417 |
|
| 418 |
rowObj.find('.button_title').change(function() { |
| 419 |
newTitle = jQuery(this).val(); |
| 420 |
|
| 421 |
if(buttonizer.checkTitleDuplicate(newTitle, rowId)) { |
| 422 |
buttonizer.updateTitle(buttonTitle, buttonTitleField, true, newTitle); |
| 423 |
return; |
| 424 |
} |
| 425 |
|
| 426 |
buttonTitle.html(newTitle); |
| 427 |
}); |
| 428 |
|
| 429 |
rowObj.find(".button_showondesktop").change(function(e) { |
| 430 |
var isSelected = jQuery(this).is(":checked"); |
| 431 |
|
| 432 |
if(!isSelected) { |
| 433 |
jQuery("#btn_row_" + rowId + " .row-info .desktop-button").addClass("selected"); |
| 434 |
}else { |
| 435 |
jQuery("#btn_row_" + rowId + " .row-info .desktop-button").removeClass("selected"); |
| 436 |
} |
| 437 |
}); |
| 438 |
|
| 439 |
jQuery("#button_"+ rowId +"_icon").change(function(e) { |
| 440 |
rowObj.find(".button-icon").attr('class', "fa "+ jQuery(this).val() +" button-icon"); |
| 441 |
}); |
| 442 |
|
| 443 |
jQuery("#btn_row_" + rowId + " input").change(function() { |
| 444 |
jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide(); |
| 445 |
jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show(); |
| 446 |
}); |
| 447 |
|
| 448 |
if(isCategory) { |
| 449 |
var checked = false; |
| 450 |
rowObj.find(".select-all").click(function() { |
| 451 |
if(!checked) { |
| 452 |
checked = true; |
| 453 |
rowObj.find(".page-categorie-styling input[type=checkbox]").attr("checked", "checked"); |
| 454 |
}else{ |
| 455 |
checked = false; |
| 456 |
rowObj.find(".page-categorie-styling input[type=checkbox]").removeAttr("checked"); |
| 457 |
} |
| 458 |
}); |
| 459 |
}else{ |
| 460 |
// Image icon handler |
| 461 |
buttonizer.iconImageHandler(rowObj.find(".icon-or-image")); |
| 462 |
buttonizer.colorPaletHandler(rowObj.find(".button-color-palet")); |
| 463 |
} |
| 464 |
}); |
| 465 |
}, |
| 466 |
|
| 467 |
updateTitle: function(buttonTitle, buttonTitleField, isDuplicate, text) { |
| 468 |
if(!text) { |
| 469 |
var text = ''; |
| 470 |
} |
| 471 |
|
| 472 |
if(!isDuplicate) { |
| 473 |
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()); |
| 474 |
}else{ |
| 475 |
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); |
| 476 |
} |
| 477 |
|
| 478 |
if(!newTitle || newTitle == "") { |
| 479 |
if(isDuplicate) { |
| 480 |
buttonTitleField.val(buttonTitle.html()); |
| 481 |
} |
| 482 |
return; |
| 483 |
} |
| 484 |
|
| 485 |
if(buttonizer.checkTitleDuplicate(newTitle)) { |
| 486 |
buttonizer.updateTitle(buttonTitle, buttonTitleField, true, newTitle); |
| 487 |
return; |
| 488 |
} |
| 489 |
|
| 490 |
buttonTitle.html(newTitle); |
| 491 |
buttonTitleField.val(newTitle); |
| 492 |
}, |
| 493 |
|
| 494 |
checkTitleDuplicate: function(text, allowRowId) { |
| 495 |
isDuplicate = false; |
| 496 |
if(!allowRowId) { |
| 497 |
var allowRowId = -1; |
| 498 |
} |
| 499 |
|
| 500 |
jQuery(".button-row").each(function() { |
| 501 |
if(jQuery(this).find('.button_title').val() == text && jQuery(this).attr("button-id") != allowRowId) { |
| 502 |
isDuplicate = true; |
| 503 |
} |
| 504 |
}); |
| 505 |
|
| 506 |
return isDuplicate; |
| 507 |
}, |
| 508 |
|
| 509 |
removeRow: function(id) { |
| 510 |
var buttonName = jQuery("#btn_row_" +id + " .row-info span .row-title").html(); |
| 511 |
var wasCategory = jQuery("#btn_row_" + id).hasClass('is_category'); |
| 512 |
|
| 513 |
if(confirm("Are you sure you want to remove the row with the text: '"+ buttonName +"'?\n\nThis is not recoverable.")) { |
| 514 |
jQuery("#btn_row_" +id).remove(); |
| 515 |
|
| 516 |
if(jQuery(".button-row").length > 1) { |
| 517 |
jQuery(".buttonizer-no-buttons").hide(); |
| 518 |
}else{ |
| 519 |
jQuery(".buttonizer-no-buttons").show(); |
| 520 |
} |
| 521 |
} |
| 522 |
}, |
| 523 |
|
| 524 |
toggleMobile: function(id) { |
| 525 |
var isSelected = jQuery("#button_"+ id +"_show_on_phone").is(":checked"); |
| 526 |
|
| 527 |
if(!isSelected) { |
| 528 |
jQuery("#btn_row_" + id + " .row-info .mobile-button").removeClass("selected"); |
| 529 |
jQuery("#button_"+ id +"_show_on_phone").click(); |
| 530 |
}else { |
| 531 |
jQuery("#btn_row_" + id + " .row-info .mobile-button").addClass("selected"); |
| 532 |
jQuery("#button_"+ id +"_show_on_phone").click(); |
| 533 |
} |
| 534 |
|
| 535 |
jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide(); |
| 536 |
jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show(); |
| 537 |
}, |
| 538 |
|
| 539 |
toggleDesktop: function(id) { |
| 540 |
var isSelected = jQuery("#button_"+ id +"_show_on_desktop").is(":checked"); |
| 541 |
|
| 542 |
if(!isSelected) { |
| 543 |
jQuery("#btn_row_" + id + " .row-info .desktop-button").removeClass("selected"); |
| 544 |
jQuery("#button_"+ id +"_show_on_desktop").click(); |
| 545 |
}else { |
| 546 |
jQuery("#btn_row_" + id + " .row-info .desktop-button").addClass("selected"); |
| 547 |
jQuery("#button_"+ id +"_show_on_desktop").click(); |
| 548 |
} |
| 549 |
|
| 550 |
jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide(); |
| 551 |
jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show(); |
| 552 |
}, |
| 553 |
|
| 554 |
addRow: function() { |
| 555 |
if(jQuery("#new-button").hasClass('disabled')) { |
| 556 |
return; |
| 557 |
} |
| 558 |
buttonizer.settings.hasChanges = true; |
| 559 |
|
| 560 |
jQuery(".buttonizer-no-buttons").hide(); |
| 561 |
|
| 562 |
var isCategory = jQuery(".button-row[button-id=-1]").hasClass("is_category"); |
| 563 |
|
| 564 |
jQuery("#new-button").attr('disabled', 'disabled').addClass('disabled'); |
| 565 |
var defaultRow = jQuery(".button-row[button-id=-1]").html(); |
| 566 |
var numberOfButtons = jQuery(".button-row").length - (isCategory ? 1 : 0); |
| 567 |
|
| 568 |
numberOfButtons = Math.floor(Date.now() / 1000); |
| 569 |
numberOfButtons = numberOfButtons + "-" + Math.floor((Math.random() * 999) + 100); |
| 570 |
numberOfButtons = numberOfButtons.replace('-', ''); |
| 571 |
|
| 572 |
var newData = defaultRow.replace('/-1/g', numberOfButtons); |
| 573 |
newData = newData.replace('-1', numberOfButtons); |
| 574 |
|
| 575 |
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>' : '')); |
| 576 |
|
| 577 |
clearInterval(buttonizer.setTimouts.a); |
| 578 |
clearInterval(buttonizer.setTimouts.b); |
| 579 |
|
| 580 |
buttonizer.setTimouts.a = setTimeout(function() { |
| 581 |
jQuery(".button-row *").unbind("click"); |
| 582 |
jQuery(".button-row").removeClass("opened"); |
| 583 |
jQuery(".fontawesome-searcher-clicker").remove(); |
| 584 |
jQuery("#btn_row_"+ numberOfButtons +" .button_title").val("New button " + numberOfButtons); |
| 585 |
|
| 586 |
if(isCategory) { |
| 587 |
jQuery("#btn_row_"+ numberOfButtons +" input").each(function() { |
| 588 |
jQuery(this).attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"][]"); |
| 589 |
}); |
| 590 |
|
| 591 |
jQuery("#btn_row_"+ numberOfButtons + " select").attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"_type]"); |
| 592 |
} |
| 593 |
}, 100); |
| 594 |
|
| 595 |
|
| 596 |
buttonizer.setTimouts.b = setTimeout(function() { |
| 597 |
buttonizer.initButtons(); |
| 598 |
if(!isCategory) { |
| 599 |
buttonizer.updateRowInputNames(numberOfButtons); |
| 600 |
jQuery("#btn_row_"+ numberOfButtons).addClass('opened'); |
| 601 |
jQuery("#btn_row_"+ numberOfButtons + " input.button_title").focus(); |
| 602 |
}else{ |
| 603 |
console.log("Initialize new page category"); |
| 604 |
jQuery("#btn_row_"+ numberOfButtons + " #categoryIsUsed").val(numberOfButtons); |
| 605 |
jQuery("#btn_row_"+ numberOfButtons + " #categoryIsUsed").attr("name", buttonizer.settings.wpCategorySaveKey + '[categorieOrder][]'); |
| 606 |
jQuery("#btn_row_"+ numberOfButtons + " .delete-button").attr("href", "javascript:buttonizer.removeRow("+ numberOfButtons +")"); |
| 607 |
jQuery("#btn_row_"+ numberOfButtons + " .button_title").attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"_title]").val('New page category ' + (jQuery(".button-row").length - 1)); |
| 608 |
jQuery("#btn_row_"+ numberOfButtons + " .row-title").html("New page category " + (jQuery(".button-row").length - 1)); |
| 609 |
} |
| 610 |
buttonizer.faInit(); |
| 611 |
buttonizer.loadPageCategorie(); |
| 612 |
jQuery("#new-button").removeAttr('disabled').removeClass('disabled'); |
| 613 |
|
| 614 |
jQuery("#btn_row_"+ numberOfButtons + " .savebutton").show(); |
| 615 |
}, 400); |
| 616 |
}, |
| 617 |
|
| 618 |
updateRowInputNames: function(buttonId) { |
| 619 |
// Textfield |
| 620 |
jQuery("#btn_row_"+ buttonId + " .button_textfield") |
| 621 |
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_text]") |
| 622 |
.attr("id", "button_"+ buttonId +"_text").val(""); |
| 623 |
|
| 624 |
// Iconfield |
| 625 |
jQuery("#btn_row_"+ buttonId + " .icon-placeholder select").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_icon]"); |
| 626 |
|
| 627 |
// Iconfield |
| 628 |
jQuery("#btn_row_"+ buttonId + " .image-placeholder input").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_image]"); |
| 629 |
|
| 630 |
// Button title |
| 631 |
jQuery("#btn_row_"+ buttonId + " .button_title").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_title]"); |
| 632 |
|
| 633 |
// Button show on page category |
| 634 |
jQuery("#btn_row_"+ buttonId + " #button_category").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_pages]"); |
| 635 |
|
| 636 |
// Color palets |
| 637 |
jQuery("#btn_row_"+ buttonId + " input.custom").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_using_custom_colors]"); |
| 638 |
|
| 639 |
jQuery("#btn_row_"+ buttonId + " input.default").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_colors_button]"); |
| 640 |
jQuery("#btn_row_"+ buttonId + " input.pushed").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_colors_pushed]"); |
| 641 |
jQuery("#btn_row_"+ buttonId + " input.icon").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_colors_icon]"); |
| 642 |
|
| 643 |
// Show on phone |
| 644 |
jQuery("#btn_row_"+ buttonId + " .button_showonphone") |
| 645 |
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_phone]") |
| 646 |
.attr("id", "button_"+ buttonId +"_show_on_phone"); |
| 647 |
|
| 648 |
jQuery("label[for='button_"+ -1 +"_show_on_phone']").attr("for", "button_"+ buttonId +"_show_on_phone"); |
| 649 |
|
| 650 |
// Show on desktop |
| 651 |
jQuery("#btn_row_"+ buttonId + " .button_showondesktop") |
| 652 |
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_desktop]") |
| 653 |
.attr("id", "button_"+ buttonId +"_show_on_desktop"); |
| 654 |
|
| 655 |
jQuery("label[for='button_"+ -1 +"_show_on_desktop']").attr("for", "button_"+ buttonId +"_show_on_desktop"); |
| 656 |
|
| 657 |
// Url |
| 658 |
jQuery("#btn_row_"+ buttonId + " .button_isurl") |
| 659 |
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_url]") |
| 660 |
.attr("id", "button_"+ buttonId +"_url"); |
| 661 |
|
| 662 |
jQuery("label[for='button_"+ -1 +"_url']").attr("for", "button_"+ buttonId +"_url"); |
| 663 |
|
| 664 |
// Is phone buttonId |
| 665 |
jQuery("#btn_row_"+ buttonId + " .button_isphonenumber") |
| 666 |
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_is_phonenumber]") |
| 667 |
.attr("id", "button_"+ buttonId +"_is_phonenumber"); |
| 668 |
|
| 669 |
jQuery("label[for='button_"+ -1 +"_is_phonenumber']").attr("for", "button_"+ buttonId +"_is_phonenumber"); |
| 670 |
|
| 671 |
// New tab |
| 672 |
jQuery("#btn_row_"+ buttonId + " .button_isnewtab") |
| 673 |
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_url_newtab]") |
| 674 |
.attr("id", "button_"+ buttonId +"_url_newtab"); |
| 675 |
|
| 676 |
jQuery("label[for='button_"+ -1 +"_url_newtab']").attr("for", "button_"+ buttonId +"_url_newtab"); |
| 677 |
|
| 678 |
|
| 679 |
// Show only on opening hours |
| 680 |
jQuery("#btn_row_"+ buttonId + " .button_showwhenopened") |
| 681 |
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_when_opened]") |
| 682 |
.attr("id", "button_"+ buttonId +"_show_when_opened"); |
| 683 |
|
| 684 |
jQuery("label[for='button_"+ -1 +"_show_when_opened']").attr("for", "button_"+ buttonId +"_show_when_opened"); |
| 685 |
|
| 686 |
// Show only on opening hours |
| 687 |
jQuery("#btn_row_"+ buttonId + " .button_hidelabel") |
| 688 |
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_hide_label]") |
| 689 |
.attr("id", "button_"+ buttonId +"_hide_label"); |
| 690 |
|
| 691 |
jQuery("label[for='button_"+ -1 +"_hide_label']").attr("for", "button_"+ buttonId +"_hide_label"); |
| 692 |
|
| 693 |
/* |
| 694 |
* Link fixes |
| 695 |
*/ |
| 696 |
// Delete button link |
| 697 |
jQuery("#btn_row_"+ buttonId + " .delete-button").attr("href", "javascript:buttonizer.removeRow("+ buttonId +")"); |
| 698 |
|
| 699 |
// Show on mobile button link |
| 700 |
jQuery("#btn_row_"+ buttonId + " .mobiledesktop.mobile-button").attr("href", "javascript:buttonizer.toggleMobile("+ buttonId +")"); |
| 701 |
|
| 702 |
// Show on desktop button link |
| 703 |
jQuery("#btn_row_"+ buttonId + " .mobiledesktop.desktop-button").attr("href", "javascript:buttonizer.toggleDesktop("+ buttonId +")"); |
| 704 |
}, |
| 705 |
|
| 706 |
createWindow: function(data) { |
| 707 |
this.settings.windowNumber++; |
| 708 |
var currentWindow = this.settings.windowNumber; |
| 709 |
|
| 710 |
if(!data.title) { |
| 711 |
data.title = ''; |
| 712 |
} |
| 713 |
|
| 714 |
if(!data.text) { |
| 715 |
data.text = '<p>This dialog has not text.</p><p>Weird, isn\'t it?</p>'; |
| 716 |
} |
| 717 |
|
| 718 |
if(!data.confirmText) { |
| 719 |
data.confirmText = 'Close'; |
| 720 |
} |
| 721 |
|
| 722 |
if(!data.canCancel) { |
| 723 |
data.canCancel = false; |
| 724 |
} |
| 725 |
|
| 726 |
if(!data.cancelText) { |
| 727 |
data.cancelText = 'Cancel'; |
| 728 |
} |
| 729 |
|
| 730 |
if(!data.onConfirm) { |
| 731 |
data.onConfirm = function() {}; |
| 732 |
} |
| 733 |
|
| 734 |
if(!data.onClose) { |
| 735 |
data.onClose = function() {}; |
| 736 |
} |
| 737 |
|
| 738 |
if(!data.afterInit) { |
| 739 |
data.afterInit = function() {}; |
| 740 |
} |
| 741 |
|
| 742 |
var windowStyle = '<div class="fs-modal active" id="buttonizer-window-'+ currentWindow +'"><div class="fs-modal-dialog">'; |
| 743 |
|
| 744 |
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>'; |
| 745 |
|
| 746 |
windowStyle += '<div class="fs-modal-body"><div class="fs-modal-panel active">'; |
| 747 |
windowStyle += data.text; |
| 748 |
windowStyle += '</div></div>'; |
| 749 |
|
| 750 |
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>'; |
| 751 |
|
| 752 |
windowStyle += '</div></div>'; |
| 753 |
|
| 754 |
jQuery("body").append(windowStyle); |
| 755 |
|
| 756 |
jQuery(document).ready(data.afterInit); |
| 757 |
|
| 758 |
jQuery("#buttonizer-window-"+ currentWindow + " .fs-close, #buttonizer-window-"+ currentWindow + " button").click(function(e) { |
| 759 |
e.preventDefault(); |
| 760 |
jQuery("#buttonizer-window-"+ currentWindow).fadeOut(); |
| 761 |
|
| 762 |
if(jQuery(this).hasClass("confirm")) { |
| 763 |
data.onConfirm(); |
| 764 |
} |
| 765 |
|
| 766 |
data.onClose(); |
| 767 |
}) |
| 768 |
}, |
| 769 |
|
| 770 |
/* |
| 771 |
* Font awesome searcher |
| 772 |
*/ |
| 773 |
faSettings: { |
| 774 |
objects: 0, |
| 775 |
currentSelect: {}, |
| 776 |
currentObject: {}, |
| 777 |
isGenerated: false, |
| 778 |
isOpened: false |
| 779 |
}, |
| 780 |
faInit: function() { |
| 781 |
buttonizer.faSettings.isOpened = false; |
| 782 |
|
| 783 |
if(buttonizer.faSettings.isGenerated == false) { |
| 784 |
buttonizer.faSettings.isGenerated = true; |
| 785 |
fontAwesome = jQuery.map(fontAwesome, function(value, index) { |
| 786 |
return [index]; |
| 787 |
}); |
| 788 |
} |
| 789 |
|
| 790 |
jQuery("body").click(function(e){ |
| 791 |
if(!jQuery(e.target).closest('.fontawesome-searcher').length && !jQuery(e.target).closest('.fontawesome-searcher-clicker').length){ |
| 792 |
jQuery(".fontawesome-searcher").hide(); |
| 793 |
buttonizer.faSettings.isOpened = false; |
| 794 |
} |
| 795 |
}); |
| 796 |
|
| 797 |
var typeTimeOut = setTimeout(function() { buttonizer.faSearchWord(''); }, 300); |
| 798 |
|
| 799 |
var adminBody = jQuery("#wpbody"); |
| 800 |
|
| 801 |
jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").keyup(function() { |
| 802 |
clearInterval(typeTimeOut); |
| 803 |
|
| 804 |
typeTimeOut = setTimeout(function() { buttonizer.faSearchWord(jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").val()); }, 300); |
| 805 |
}); |
| 806 |
|
| 807 |
jQuery("select.fa-chooser").each(function() { |
| 808 |
buttonizer.faSettings.objects++; |
| 809 |
var obj = jQuery(this); |
| 810 |
|
| 811 |
obj.hide(); |
| 812 |
obj.parent().append("<a href=\"javascript:void(0)\" class=\"fontawesome-searcher-clicker\" id=\"fa-chooser_"+ buttonizer.faSettings.objects +"\">Icon: "+ obj.val() +" <i class=\"fa "+ obj.val() +"\"></i></a>"); |
| 813 |
|
| 814 |
var newObject = jQuery("#fa-chooser_" + buttonizer.faSettings.objects); |
| 815 |
newObject.click(function(e) { |
| 816 |
if(buttonizer.faSettings.isOpened == false || buttonizer.faSettings.currentSelect != obj) { |
| 817 |
jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").focus(); |
| 818 |
buttonizer.faSettings.isOpened = true; |
| 819 |
|
| 820 |
// Update process |
| 821 |
jQuery(".fontawesome-searcher").css({ |
| 822 |
"top": newObject.offset().top - 20 + newObject.height(), |
| 823 |
"left": newObject.offset().left - adminBody.offset().left, |
| 824 |
"width": newObject.width() |
| 825 |
}).show(); |
| 826 |
|
| 827 |
buttonizer.faSettings.currentSelect = obj; |
| 828 |
buttonizer.faSettings.currentObject = newObject; |
| 829 |
}else{ |
| 830 |
buttonizer.faSettings.isOpened = false; |
| 831 |
jQuery(".fontawesome-searcher").hide(); |
| 832 |
} |
| 833 |
|
| 834 |
e.preventDefault(); |
| 835 |
}); |
| 836 |
}); |
| 837 |
}, |
| 838 |
faSearchWord: function(word) { |
| 839 |
var foundMatches = []; |
| 840 |
|
| 841 |
for(var i = 0; i < fontAwesome.length; i++) { |
| 842 |
if(fontAwesome[i].indexOf(word) !== -1) { |
| 843 |
foundMatches.push(fontAwesome[i]); |
| 844 |
} |
| 845 |
}; |
| 846 |
|
| 847 |
if(foundMatches.length == 0) { |
| 848 |
jQuery(".fontawesome-searcher .no-matches-found").show(); |
| 849 |
jQuery(".fontawesome-searcher .fontawesome-searcher-icons").hide(); |
| 850 |
}else{ |
| 851 |
jQuery(".fontawesome-searcher .no-matches-found").hide(); |
| 852 |
jQuery(".fontawesome-searcher .fontawesome-searcher-icons").show(); |
| 853 |
|
| 854 |
var text = '<table><tr>'; |
| 855 |
for(var b = 0; b < foundMatches.length; b++) { |
| 856 |
if(b % 4 == 0) { |
| 857 |
text += "</tr><tr>"; |
| 858 |
} |
| 859 |
|
| 860 |
text += '<td><a href="javascript:buttonizer.faChooseIcon(\''+ foundMatches[b] +'\')"><i class="fa '+ foundMatches[b] +'"></i></a></td>'; |
| 861 |
}; |
| 862 |
|
| 863 |
text += '</tr>'; |
| 864 |
|
| 865 |
jQuery(".fontawesome-searcher .fontawesome-searcher-icons").html(text); |
| 866 |
} |
| 867 |
}, |
| 868 |
faChooseIcon: function(icon) { |
| 869 |
buttonizer.faSettings.currentSelect.val(icon).change(); |
| 870 |
buttonizer.faSettings.currentObject.html("Icon: "+ icon +" <i class=\"fa "+ icon +"\"></i>"); |
| 871 |
jQuery("#" + buttonizer.faSettings.currentObject.attr("id")).click(); |
| 872 |
} |
| 873 |
} |
| 874 |
|
| 875 |
document.addEventListener('DOMContentLoaded', buttonizer.init, false); |
| 876 |
|
| 877 |
window.onbeforeunload = function(){ |
| 878 |
if(buttonizer.settings.hasChanges && !buttonizer.settings.clickedButton) { |
| 879 |
return 'You have unsaved data. Are you sure you want to leave?'; |
| 880 |
} |
| 881 |
}; |
| 882 |
|