| 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 |
buttonizer.addSortable(); |
| 121 |
}, |
| 122 |
|
| 123 |
proInfoWindow: function() { |
| 124 |
buttonizer.createWindow({ |
| 125 |
title: 'You like Buttonizer?', |
| 126 |
text: '<p>Are you ready to try Buttonizer PRO?</p><p><b class="color-buttonizer">What do you get?</b></p>'+ |
| 127 |
|
| 128 |
'<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Show on opening hours</div>' + |
| 129 |
'<div class="color-buttonizer-orange buttonizer-pro-checklist"><i class="fa fa-check"></i> Show buttons on specific pages: Use page rules</div>' + |
| 130 |
'<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Unlimited page rules</div>' + |
| 131 |
'<div class="color-buttonizer-orange buttonizer-pro-checklist"><i class="fa fa-check"></i> Add custom image or button-icon</div>' + |
| 132 |
'<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Exit intend</div>' + |
| 133 |
'<div class="color-buttonizer-orange buttonizer-pro-checklist"><i class="fa fa-check"></i> Show on scroll</div>' + |
| 134 |
'<div class="color-buttonizer-blue buttonizer-pro-checklist"><i class="fa fa-check"></i> Show on timeout</div>' + |
| 135 |
'<br />' + |
| 136 |
'<p class="color-buttonizer text-right"><b>Do you <span><i class="fa fa-heart"></i></span> these features?</b></p>', |
| 137 |
closeText: 'Upgrade', |
| 138 |
callback: function() { |
| 139 |
document.location.href = 'admin.php?page=Buttonizer-pricing'; |
| 140 |
} |
| 141 |
}); |
| 142 |
}, |
| 143 |
|
| 144 |
overwriteFavIcon: function() { |
| 145 |
(function() { |
| 146 |
var link = document.querySelector("link[rel*='icon']") || document.createElement('link'); |
| 147 |
link.type = 'image/x-icon'; |
| 148 |
link.rel = 'shortcut icon'; |
| 149 |
link.href = faviconUrl; |
| 150 |
document.getElementsByTagName('head')[0].appendChild(link); |
| 151 |
})(); |
| 152 |
}, |
| 153 |
|
| 154 |
tabNavigate: function(key) { |
| 155 |
jQuery(".vertical-tabs .tab-container").each(function() { |
| 156 |
if(jQuery(this).attr('id') == "tab_container_" + key) { |
| 157 |
jQuery(this).show(); |
| 158 |
}else{ |
| 159 |
jQuery(this).hide(); |
| 160 |
} |
| 161 |
}); |
| 162 |
|
| 163 |
jQuery(".vertical-tabs .tabs a").each(function() { |
| 164 |
if(jQuery(this).attr('id') == "tab_container_" + key) { |
| 165 |
jQuery(this).addClass('nav-tab-active'); |
| 166 |
}else{ |
| 167 |
jQuery(this).removeClass('nav-tab-active'); |
| 168 |
} |
| 169 |
}); |
| 170 |
|
| 171 |
// jQuery("type[name=_wp_http_referer]").val(); |
| 172 |
}, |
| 173 |
|
| 174 |
loadPageCategorie: function() { |
| 175 |
jQuery(".page-categorie-styling").each(function() { |
| 176 |
var maxLoaded = 10; |
| 177 |
var isLoaded = 10; |
| 178 |
var table = jQuery(this); |
| 179 |
jQuery(this).addClass("initialized") |
| 180 |
|
| 181 |
table.find("tr").each(function() { |
| 182 |
jQuery(this).click(function(e) { |
| 183 |
if(jQuery(e.target).attr("type") != "checkbox") { |
| 184 |
jQuery(this).find("input").click(); |
| 185 |
} |
| 186 |
}); |
| 187 |
}); |
| 188 |
|
| 189 |
jQuery(".categories-load-more[data-id="+ jQuery(this).attr("data-id") +"]").click(function() { |
| 190 |
maxLoaded += 10; |
| 191 |
isLoaded = 0; |
| 192 |
|
| 193 |
|
| 194 |
table.find("tr").each(function() { |
| 195 |
isLoaded++; |
| 196 |
if(isLoaded <= maxLoaded) { |
| 197 |
jQuery(this).show(); |
| 198 |
}else{ |
| 199 |
return; |
| 200 |
} |
| 201 |
}); |
| 202 |
|
| 203 |
if(jQuery(".page-categorie-styling[data-id="+ jQuery(this).attr("data-id") +"] tr").length < maxLoaded) { |
| 204 |
jQuery(this).hide(); |
| 205 |
} |
| 206 |
}); |
| 207 |
}); |
| 208 |
}, |
| 209 |
|
| 210 |
addSortable: function() { |
| 211 |
var sortable = new Sortable(document.getElementById("button-rows"), { |
| 212 |
group: "button-rows", |
| 213 |
sort: true, |
| 214 |
animation: 150, |
| 215 |
scroll: true, |
| 216 |
scrollSensitivity: 30, |
| 217 |
scrollSpeed: 10, |
| 218 |
|
| 219 |
onSort: function (evt) { |
| 220 |
jQuery("#" + evt.clone.children[0].id + " .row-info").css({ |
| 221 |
opacity: .45, |
| 222 |
}).delay(500).animate({ |
| 223 |
opacity: 1, |
| 224 |
}, 500); |
| 225 |
} |
| 226 |
}); |
| 227 |
}, |
| 228 |
|
| 229 |
saveAnimation: function() { |
| 230 |
jQuery(".savebutton").each(function() { |
| 231 |
jQuery(this).html('<i class="fa fa-cog fa-spin"></i> <span>Saving</span>'); |
| 232 |
}); |
| 233 |
buttonizer.settings.clickedButton = true; |
| 234 |
jQuery('form#buttonizer').submit(); |
| 235 |
}, |
| 236 |
|
| 237 |
/* |
| 238 |
* Buttons |
| 239 |
*/ |
| 240 |
initButtons: function() { |
| 241 |
jQuery(".button-row .savebutton").each(function() { |
| 242 |
jQuery(this).click(buttonizer.saveAnimation); |
| 243 |
}); |
| 244 |
|
| 245 |
jQuery(".button-row").each(function() { |
| 246 |
var rowObj = jQuery(this); |
| 247 |
var rowId = jQuery(this).attr("button-id") |
| 248 |
var buttonTitle = rowObj.find(".row-info span .row-title"); |
| 249 |
var buttonEdit = rowObj.find(".row-info .pencil-edit"); |
| 250 |
var buttonTitleField = rowObj.find(".button_title"); |
| 251 |
var doubleClick = setTimeout(function() {}, 100); |
| 252 |
var isCategory = rowObj.hasClass('is_category'); |
| 253 |
var clicked = 0; |
| 254 |
|
| 255 |
buttonEdit.click(function(e) { |
| 256 |
e.preventDefault(); |
| 257 |
buttonTitle.dblclick(); |
| 258 |
}); |
| 259 |
|
| 260 |
buttonTitle.html(buttonTitleField.val()); |
| 261 |
|
| 262 |
rowObj.find(".row-info").click(function(e) { |
| 263 |
|
| 264 |
if( |
| 265 |
jQuery(e.target).hasClass('fa-desktop') || |
| 266 |
jQuery(e.target).hasClass('fa-mobile') || |
| 267 |
jQuery(e.target).hasClass('fa-pencil') || |
| 268 |
jQuery(e.target).hasClass('mobiledesktop') || |
| 269 |
jQuery(e.target).hasClass('is-live-button') || |
| 270 |
jQuery(e.target).hasClass('must-save-button') |
| 271 |
) { |
| 272 |
return; |
| 273 |
} |
| 274 |
|
| 275 |
clicked = 0; |
| 276 |
clearInterval(doubleClick); |
| 277 |
doubleClick = setTimeout(function() { |
| 278 |
if(clicked == 0) { |
| 279 |
if(rowObj.hasClass("opened")) { |
| 280 |
rowObj.removeClass("opened"); |
| 281 |
}else{ |
| 282 |
rowObj.addClass("opened"); |
| 283 |
} |
| 284 |
} |
| 285 |
clicked = 0; |
| 286 |
}, 100); |
| 287 |
}); |
| 288 |
|
| 289 |
buttonTitle.dblclick(function() { |
| 290 |
buttonizer.updateTitle(buttonTitle, buttonTitleField, false); |
| 291 |
|
| 292 |
clicked++; |
| 293 |
}); |
| 294 |
|
| 295 |
rowObj.find(".button_showonphone").change(function(e) { |
| 296 |
var isSelected = jQuery(this).is(":checked"); |
| 297 |
|
| 298 |
if(!isSelected) { |
| 299 |
jQuery("#btn_row_" + rowId + " .row-info .mobile-button").addClass("selected"); |
| 300 |
}else { |
| 301 |
jQuery("#btn_row_" + rowId + " .row-info .mobile-button").removeClass("selected"); |
| 302 |
} |
| 303 |
}); |
| 304 |
|
| 305 |
rowObj.find('.button_title').change(function() { |
| 306 |
newTitle = jQuery(this).val(); |
| 307 |
|
| 308 |
if(buttonizer.checkTitleDuplicate(newTitle, rowId)) { |
| 309 |
buttonizer.updateTitle(buttonTitle, buttonTitleField, true, newTitle); |
| 310 |
return; |
| 311 |
} |
| 312 |
|
| 313 |
buttonTitle.html(newTitle); |
| 314 |
}); |
| 315 |
|
| 316 |
rowObj.find(".button_showondesktop").change(function(e) { |
| 317 |
var isSelected = jQuery(this).is(":checked"); |
| 318 |
|
| 319 |
if(!isSelected) { |
| 320 |
jQuery("#btn_row_" + rowId + " .row-info .desktop-button").addClass("selected"); |
| 321 |
}else { |
| 322 |
jQuery("#btn_row_" + rowId + " .row-info .desktop-button").removeClass("selected"); |
| 323 |
} |
| 324 |
}); |
| 325 |
|
| 326 |
jQuery("#button_"+ rowId +"_icon").change(function(e) { |
| 327 |
console.log("test"); |
| 328 |
rowObj.find(".button-icon").attr('class', "fa "+ jQuery(this).val() +" button-icon"); |
| 329 |
}); |
| 330 |
|
| 331 |
jQuery("#btn_row_" + rowId + " input").change(function() { |
| 332 |
jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide(); |
| 333 |
jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show(); |
| 334 |
}); |
| 335 |
|
| 336 |
if(isCategory) { |
| 337 |
var checked = false; |
| 338 |
rowObj.find(".select-all").click(function() { |
| 339 |
if(!checked) { |
| 340 |
checked = true; |
| 341 |
rowObj.find(".page-categorie-styling input[type=checkbox]").attr("checked", "checked"); |
| 342 |
}else{ |
| 343 |
checked = false; |
| 344 |
rowObj.find(".page-categorie-styling input[type=checkbox]").removeAttr("checked"); |
| 345 |
} |
| 346 |
}); |
| 347 |
} |
| 348 |
}); |
| 349 |
}, |
| 350 |
|
| 351 |
updateTitle: function(buttonTitle, buttonTitleField, isDuplicate, text) { |
| 352 |
if(!text) { |
| 353 |
var text = ''; |
| 354 |
} |
| 355 |
|
| 356 |
if(!isDuplicate) { |
| 357 |
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()); |
| 358 |
}else{ |
| 359 |
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); |
| 360 |
} |
| 361 |
|
| 362 |
if(!newTitle || newTitle == "") { |
| 363 |
if(isDuplicate) { |
| 364 |
buttonTitleField.val(buttonTitle.html()); |
| 365 |
} |
| 366 |
return; |
| 367 |
} |
| 368 |
|
| 369 |
if(buttonizer.checkTitleDuplicate(newTitle)) { |
| 370 |
buttonizer.updateTitle(buttonTitle, buttonTitleField, true, newTitle); |
| 371 |
return; |
| 372 |
} |
| 373 |
|
| 374 |
buttonTitle.html(newTitle); |
| 375 |
buttonTitleField.val(newTitle); |
| 376 |
}, |
| 377 |
|
| 378 |
checkTitleDuplicate: function(text, allowRowId) { |
| 379 |
isDuplicate = false; |
| 380 |
if(!allowRowId) { |
| 381 |
var allowRowId = -1; |
| 382 |
} |
| 383 |
|
| 384 |
jQuery(".button-row").each(function() { |
| 385 |
if(jQuery(this).find('.button_title').val() == text && jQuery(this).attr("button-id") != allowRowId) { |
| 386 |
isDuplicate = true; |
| 387 |
} |
| 388 |
}); |
| 389 |
|
| 390 |
return isDuplicate; |
| 391 |
}, |
| 392 |
|
| 393 |
removeRow: function(id) { |
| 394 |
var buttonName = jQuery("#btn_row_" +id + " .row-info span .row-title").html(); |
| 395 |
var wasCategory = jQuery("#btn_row_" + id).hasClass('is_category'); |
| 396 |
|
| 397 |
if(confirm("Are you sure you want to remove the row with the text: '"+ buttonName +"'?\n\nThis is not recoverable.")) { |
| 398 |
jQuery("#btn_row_" +id).remove(); |
| 399 |
|
| 400 |
if(jQuery(".button-row").length > 1) { |
| 401 |
jQuery(".buttonizer-no-buttons").hide(); |
| 402 |
}else{ |
| 403 |
jQuery(".buttonizer-no-buttons").show(); |
| 404 |
} |
| 405 |
} |
| 406 |
}, |
| 407 |
|
| 408 |
toggleMobile: function(id) { |
| 409 |
var isSelected = jQuery("#button_"+ id +"_show_on_phone").is(":checked"); |
| 410 |
|
| 411 |
if(!isSelected) { |
| 412 |
jQuery("#btn_row_" + id + " .row-info .mobile-button").removeClass("selected"); |
| 413 |
jQuery("#button_"+ id +"_show_on_phone").click(); |
| 414 |
}else { |
| 415 |
jQuery("#btn_row_" + id + " .row-info .mobile-button").addClass("selected"); |
| 416 |
jQuery("#button_"+ id +"_show_on_phone").click(); |
| 417 |
} |
| 418 |
|
| 419 |
jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide(); |
| 420 |
jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show(); |
| 421 |
}, |
| 422 |
|
| 423 |
toggleDesktop: function(id) { |
| 424 |
var isSelected = jQuery("#button_"+ id +"_show_on_desktop").is(":checked"); |
| 425 |
|
| 426 |
if(!isSelected) { |
| 427 |
jQuery("#btn_row_" + id + " .row-info .desktop-button").removeClass("selected"); |
| 428 |
jQuery("#button_"+ id +"_show_on_desktop").click(); |
| 429 |
}else { |
| 430 |
jQuery("#btn_row_" + id + " .row-info .desktop-button").addClass("selected"); |
| 431 |
jQuery("#button_"+ id +"_show_on_desktop").click(); |
| 432 |
} |
| 433 |
|
| 434 |
jQuery("#btn_row_" + rowId + " .row-info .is-live-button").hide(); |
| 435 |
jQuery("#btn_row_" + rowId + " .row-info .must-save-button").show(); |
| 436 |
}, |
| 437 |
|
| 438 |
addRow: function() { |
| 439 |
if(jQuery("#new-button").hasClass('disabled')) { |
| 440 |
return; |
| 441 |
} |
| 442 |
jQuery(".buttonizer-no-buttons").hide(); |
| 443 |
|
| 444 |
var isCategory = jQuery(".button-row[button-id=-1]").hasClass("is_category"); |
| 445 |
|
| 446 |
jQuery("#new-button").attr('disabled', 'disabled').addClass('disabled'); |
| 447 |
var defaultRow = jQuery(".button-row[button-id=-1]").html(); |
| 448 |
var numberOfButtons = jQuery(".button-row").length - (isCategory ? 1 : 0); |
| 449 |
|
| 450 |
numberOfButtons = Math.floor(Date.now() / 1000); |
| 451 |
numberOfButtons = numberOfButtons + "-" + Math.floor((Math.random() * 999) + 100); |
| 452 |
numberOfButtons = numberOfButtons.replace('-', ''); |
| 453 |
|
| 454 |
var newData = defaultRow.replace('/-1/g', numberOfButtons); |
| 455 |
newData = newData.replace('-1', numberOfButtons); |
| 456 |
|
| 457 |
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>' : '')); |
| 458 |
|
| 459 |
clearInterval(buttonizer.setTimouts.a); |
| 460 |
clearInterval(buttonizer.setTimouts.b); |
| 461 |
|
| 462 |
buttonizer.setTimouts.a = setTimeout(function() { |
| 463 |
jQuery(".button-row *").unbind("click"); |
| 464 |
jQuery(".button-row").removeClass("opened"); |
| 465 |
jQuery(".fontawesome-searcher-clicker").remove(); |
| 466 |
jQuery("#btn_row_"+ numberOfButtons +" .button_title").val("New button " + numberOfButtons); |
| 467 |
|
| 468 |
if(isCategory) { |
| 469 |
jQuery("#btn_row_"+ numberOfButtons +" input").each(function() { |
| 470 |
jQuery(this).attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"][]"); |
| 471 |
}); |
| 472 |
|
| 473 |
jQuery("#btn_row_"+ numberOfButtons + " select").attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"_type]"); |
| 474 |
} |
| 475 |
}, 100); |
| 476 |
|
| 477 |
|
| 478 |
buttonizer.setTimouts.b = setTimeout(function() { |
| 479 |
buttonizer.initButtons(); |
| 480 |
if(!isCategory) { |
| 481 |
buttonizer.updateRowInputNames(numberOfButtons); |
| 482 |
jQuery("#btn_row_"+ numberOfButtons).addClass('opened'); |
| 483 |
jQuery("#btn_row_"+ numberOfButtons + " input.button_title").focus(); |
| 484 |
}else{ |
| 485 |
console.log("Initialize new page category"); |
| 486 |
jQuery("#btn_row_"+ numberOfButtons + " #categoryIsUsed").val(numberOfButtons); |
| 487 |
jQuery("#btn_row_"+ numberOfButtons + " #categoryIsUsed").attr("name", buttonizer.settings.wpCategorySaveKey + '[categorieOrder][]'); |
| 488 |
jQuery("#btn_row_"+ numberOfButtons + " .delete-button").attr("href", "javascript:buttonizer.removeRow("+ numberOfButtons +")"); |
| 489 |
jQuery("#btn_row_"+ numberOfButtons + " .button_title").attr("name", buttonizer.settings.wpCategorySaveKey + "[category_"+ numberOfButtons +"_title]").val('New page category ' + (jQuery(".button-row").length - 1)); |
| 490 |
jQuery("#btn_row_"+ numberOfButtons + " .row-title").html("New page category " + (jQuery(".button-row").length - 1)); |
| 491 |
} |
| 492 |
buttonizer.faInit(); |
| 493 |
buttonizer.loadPageCategorie(); |
| 494 |
jQuery("#new-button").removeAttr('disabled').removeClass('disabled'); |
| 495 |
|
| 496 |
jQuery("#btn_row_"+ numberOfButtons + " .savebutton").show(); |
| 497 |
}, 400); |
| 498 |
}, |
| 499 |
|
| 500 |
updateRowInputNames: function(buttonId) { |
| 501 |
// Textfield |
| 502 |
jQuery("#btn_row_"+ buttonId + " .button_textfield") |
| 503 |
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_text]") |
| 504 |
.attr("id", "button_"+ buttonId +"_text").val(""); |
| 505 |
|
| 506 |
// Iconfield |
| 507 |
jQuery("#btn_row_"+ buttonId + " .button_iconfield").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_icon]"); |
| 508 |
|
| 509 |
// Button title |
| 510 |
jQuery("#btn_row_"+ buttonId + " .button_title").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_title]"); |
| 511 |
|
| 512 |
// Button show on page category |
| 513 |
jQuery("#btn_row_"+ buttonId + " #button_category").attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_pages]"); |
| 514 |
|
| 515 |
// Show on phone |
| 516 |
jQuery("#btn_row_"+ buttonId + " .button_showonphone") |
| 517 |
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_phone]") |
| 518 |
.attr("id", "button_"+ buttonId +"_show_on_phone"); |
| 519 |
|
| 520 |
jQuery("label[for='button_"+ -1 +"_show_on_phone']").attr("for", "button_"+ buttonId +"_show_on_phone"); |
| 521 |
|
| 522 |
// Show on desktop |
| 523 |
jQuery("#btn_row_"+ buttonId + " .button_showondesktop") |
| 524 |
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_on_desktop]") |
| 525 |
.attr("id", "button_"+ buttonId +"_show_on_desktop"); |
| 526 |
|
| 527 |
jQuery("label[for='button_"+ -1 +"_show_on_desktop']").attr("for", "button_"+ buttonId +"_show_on_desktop"); |
| 528 |
|
| 529 |
// Url |
| 530 |
jQuery("#btn_row_"+ buttonId + " .button_isurl") |
| 531 |
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_url]") |
| 532 |
.attr("id", "button_"+ buttonId +"_url"); |
| 533 |
|
| 534 |
jQuery("label[for='button_"+ -1 +"_url']").attr("for", "button_"+ buttonId +"_url"); |
| 535 |
|
| 536 |
// Is phone buttonId |
| 537 |
jQuery("#btn_row_"+ buttonId + " .button_isphonenumber") |
| 538 |
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_is_phonenumber]") |
| 539 |
.attr("id", "button_"+ buttonId +"_is_phonenumber"); |
| 540 |
|
| 541 |
jQuery("label[for='button_"+ -1 +"_is_phonenumber']").attr("for", "button_"+ buttonId +"_is_phonenumber"); |
| 542 |
|
| 543 |
// New tab |
| 544 |
jQuery("#btn_row_"+ buttonId + " .button_isnewtab") |
| 545 |
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_url_newtab]") |
| 546 |
.attr("id", "button_"+ buttonId +"_url_newtab"); |
| 547 |
|
| 548 |
jQuery("label[for='button_"+ -1 +"_url_newtab']").attr("for", "button_"+ buttonId +"_url_newtab"); |
| 549 |
|
| 550 |
|
| 551 |
// Show only on opening hours |
| 552 |
jQuery("#btn_row_"+ buttonId + " .button_showwhenopened") |
| 553 |
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_show_when_opened]") |
| 554 |
.attr("id", "button_"+ buttonId +"_show_when_opened"); |
| 555 |
|
| 556 |
jQuery("label[for='button_"+ -1 +"_show_when_opened']").attr("for", "button_"+ buttonId +"_show_when_opened"); |
| 557 |
|
| 558 |
// Show only on opening hours |
| 559 |
jQuery("#btn_row_"+ buttonId + " .button_hidelabel") |
| 560 |
.attr("name", buttonizer.settings.wpButtonSaveKey + "[button_"+ buttonId +"_hide_label]") |
| 561 |
.attr("id", "button_"+ buttonId +"_hide_label"); |
| 562 |
|
| 563 |
jQuery("label[for='button_"+ -1 +"_hide_label']").attr("for", "button_"+ buttonId +"_hide_label"); |
| 564 |
|
| 565 |
/* |
| 566 |
* Link fixes |
| 567 |
*/ |
| 568 |
// Delete button link |
| 569 |
jQuery("#btn_row_"+ buttonId + " .delete-button").attr("href", "javascript:buttonizer.removeRow("+ buttonId +")"); |
| 570 |
|
| 571 |
// Show on mobile button link |
| 572 |
jQuery("#btn_row_"+ buttonId + " .mobiledesktop.mobile-button").attr("href", "javascript:buttonizer.toggleMobile("+ buttonId +")"); |
| 573 |
|
| 574 |
// Show on desktop button link |
| 575 |
jQuery("#btn_row_"+ buttonId + " .mobiledesktop.desktop-button").attr("href", "javascript:buttonizer.toggleDesktop("+ buttonId +")"); |
| 576 |
}, |
| 577 |
|
| 578 |
createWindow: function(data) { |
| 579 |
this.settings.windowNumber++; |
| 580 |
var currentWindow = this.settings.windowNumber; |
| 581 |
|
| 582 |
if(!data.title) { |
| 583 |
data.title = ''; |
| 584 |
} |
| 585 |
|
| 586 |
if(!data.text) { |
| 587 |
data.text = '<p>This dialog has not text.</p><p>Weird, isn\'t it?</p>'; |
| 588 |
} |
| 589 |
|
| 590 |
if(!data.closeText) { |
| 591 |
data.closeText = 'Close'; |
| 592 |
} |
| 593 |
|
| 594 |
if(!data.callback) { |
| 595 |
data.callback = function() {}; |
| 596 |
} |
| 597 |
|
| 598 |
var windowStyle = '<div class="fs-modal active" id="buttonizer-window-'+ currentWindow +'"><div class="fs-modal-dialog">'; |
| 599 |
|
| 600 |
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>'; |
| 601 |
|
| 602 |
windowStyle += '<div class="fs-modal-body"><div class="fs-modal-panel active">'; |
| 603 |
windowStyle += data.text; |
| 604 |
windowStyle += '</div></div>'; |
| 605 |
|
| 606 |
windowStyle += '<div class="fs-modal-footer"><button class="button button-primary" tabindex="3">'+ data.closeText +'</button></div>'; |
| 607 |
|
| 608 |
windowStyle += '</div></div>'; |
| 609 |
|
| 610 |
jQuery("body").append(windowStyle); |
| 611 |
|
| 612 |
jQuery("#buttonizer-window-"+ currentWindow + " .fs-close, #buttonizer-window-"+ currentWindow + " button").click(function(e) { |
| 613 |
e.preventDefault(); |
| 614 |
jQuery("#buttonizer-window-"+ currentWindow).fadeOut(); |
| 615 |
|
| 616 |
if(!jQuery(this).hasClass("fs-close")) { |
| 617 |
data.callback(); |
| 618 |
} |
| 619 |
}) |
| 620 |
}, |
| 621 |
|
| 622 |
/* |
| 623 |
* Font awesome searcher |
| 624 |
*/ |
| 625 |
faSettings: { |
| 626 |
objects: 0, |
| 627 |
currentSelect: {}, |
| 628 |
currentObject: {}, |
| 629 |
isGenerated: false, |
| 630 |
isOpened: false |
| 631 |
}, |
| 632 |
faInit: function() { |
| 633 |
buttonizer.faSettings.isOpened = false; |
| 634 |
|
| 635 |
if(buttonizer.faSettings.isGenerated == false) { |
| 636 |
buttonizer.faSettings.isGenerated = true; |
| 637 |
fontAwesome = jQuery.map(fontAwesome, function(value, index) { |
| 638 |
return [index]; |
| 639 |
}); |
| 640 |
} |
| 641 |
|
| 642 |
jQuery("body").click(function(e){ |
| 643 |
if(!jQuery(e.target).closest('.fontawesome-searcher').length && !jQuery(e.target).closest('.fontawesome-searcher-clicker').length){ |
| 644 |
jQuery(".fontawesome-searcher").hide(); |
| 645 |
buttonizer.faSettings.isOpened = false; |
| 646 |
} |
| 647 |
}); |
| 648 |
|
| 649 |
var typeTimeOut = setTimeout(function() { buttonizer.faSearchWord(''); }, 300); |
| 650 |
|
| 651 |
var adminBody = jQuery("#wpbody"); |
| 652 |
|
| 653 |
jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").keyup(function() { |
| 654 |
clearInterval(typeTimeOut); |
| 655 |
|
| 656 |
typeTimeOut = setTimeout(function() { buttonizer.faSearchWord(jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").val()); }, 300); |
| 657 |
}); |
| 658 |
|
| 659 |
jQuery("select.fa-chooser").each(function() { |
| 660 |
buttonizer.faSettings.objects++; |
| 661 |
var obj = jQuery(this); |
| 662 |
|
| 663 |
obj.hide(); |
| 664 |
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>"); |
| 665 |
|
| 666 |
var newObject = jQuery("#fa-chooser_" + buttonizer.faSettings.objects); |
| 667 |
newObject.click(function(e) { |
| 668 |
if(buttonizer.faSettings.isOpened == false || buttonizer.faSettings.currentSelect != obj) { |
| 669 |
jQuery(".fontawesome-searcher .fontawesome-searcher-searchbar input").focus(); |
| 670 |
buttonizer.faSettings.isOpened = true; |
| 671 |
|
| 672 |
// Update process |
| 673 |
jQuery(".fontawesome-searcher").css({ |
| 674 |
"top": newObject.offset().top - 20 + newObject.height(), |
| 675 |
"left": newObject.offset().left - adminBody.offset().left, |
| 676 |
"width": newObject.width() |
| 677 |
}).show(); |
| 678 |
|
| 679 |
buttonizer.faSettings.currentSelect = obj; |
| 680 |
buttonizer.faSettings.currentObject = newObject; |
| 681 |
}else{ |
| 682 |
buttonizer.faSettings.isOpened = false; |
| 683 |
jQuery(".fontawesome-searcher").hide(); |
| 684 |
} |
| 685 |
|
| 686 |
e.preventDefault(); |
| 687 |
}); |
| 688 |
}); |
| 689 |
}, |
| 690 |
faSearchWord: function(word) { |
| 691 |
var foundMatches = []; |
| 692 |
|
| 693 |
for(var i = 0; i < fontAwesome.length; i++) { |
| 694 |
if(fontAwesome[i].indexOf(word) !== -1) { |
| 695 |
foundMatches.push(fontAwesome[i]); |
| 696 |
} |
| 697 |
}; |
| 698 |
|
| 699 |
if(foundMatches.length == 0) { |
| 700 |
jQuery(".fontawesome-searcher .no-matches-found").show(); |
| 701 |
jQuery(".fontawesome-searcher .fontawesome-searcher-icons").hide(); |
| 702 |
}else{ |
| 703 |
jQuery(".fontawesome-searcher .no-matches-found").hide(); |
| 704 |
jQuery(".fontawesome-searcher .fontawesome-searcher-icons").show(); |
| 705 |
|
| 706 |
var text = '<table><tr>'; |
| 707 |
for(var b = 0; b < foundMatches.length; b++) { |
| 708 |
if(b % 4 == 0) { |
| 709 |
text += "</tr><tr>"; |
| 710 |
} |
| 711 |
|
| 712 |
text += '<td><a href="javascript:buttonizer.faChooseIcon(\''+ foundMatches[b] +'\')"><i class="fa '+ foundMatches[b] +'"></i></a></td>'; |
| 713 |
}; |
| 714 |
|
| 715 |
text += '</tr>'; |
| 716 |
|
| 717 |
jQuery(".fontawesome-searcher .fontawesome-searcher-icons").html(text); |
| 718 |
} |
| 719 |
}, |
| 720 |
faChooseIcon: function(icon) { |
| 721 |
buttonizer.faSettings.currentSelect.val(icon).change(); |
| 722 |
buttonizer.faSettings.currentObject.html("Icon: "+ icon +" <i class=\"fa "+ icon +"\"></i>"); |
| 723 |
jQuery("#" + buttonizer.faSettings.currentObject.attr("id")).click(); |
| 724 |
} |
| 725 |
} |
| 726 |
|
| 727 |
document.addEventListener('DOMContentLoaded', buttonizer.init, false); |
| 728 |
|
| 729 |
window.onbeforeunload = function(){ |
| 730 |
if(buttonizer.settings.hasChanges && !buttonizer.settings.clickedButton) { |
| 731 |
return 'You have unsaved data. Are you sure you want to leave?'; |
| 732 |
} |
| 733 |
}; |
| 734 |
|