| 1 |
|
| 2 |
var maxAdmin; |
| 3 |
|
| 4 |
|
| 5 |
jQuery(document).ready(function($) { |
| 6 |
|
| 7 |
maxAdmin = function () |
| 8 |
{ |
| 9 |
// $ = jquery; |
| 10 |
return this; |
| 11 |
} |
| 12 |
maxAdmin.prototype = { |
| 13 |
//initialized: false, |
| 14 |
colorUpdateTime: true, |
| 15 |
fields: null, |
| 16 |
button_id: null, |
| 17 |
form_updated: false, |
| 18 |
tabs: null, |
| 19 |
|
| 20 |
|
| 21 |
}; // MaxAdmin |
| 22 |
|
| 23 |
maxAdmin.prototype.init = function () { |
| 24 |
|
| 25 |
this.button_id = $('input[name="button_id"]').val(); |
| 26 |
// Prevents the output button from being clickable (also in admin list view ) |
| 27 |
$(document).on('click', ".maxbutton-preview", function(e) { e.preventDefault(); }); |
| 28 |
$(document).on('click', '.output .preview-toggle', $.proxy(this.toggle_preview, this)); |
| 29 |
|
| 30 |
// overview input paging |
| 31 |
$('#maxbuttons .input-paging').on('change', $.proxy(this.do_paging, this)); |
| 32 |
|
| 33 |
$('.manual-toggle').on('click', $.proxy(this.toggleManual, this)); |
| 34 |
$('.manual-entry').draggable({ |
| 35 |
cancel: 'p, li', |
| 36 |
}); |
| 37 |
|
| 38 |
$(document).on('submit', 'form.mb_ajax_save', $.proxy(this.formAjaxSave, this)); |
| 39 |
|
| 40 |
// copy / delete / trash action buttons via ajax |
| 41 |
$(document).on('click', '[data-buttonaction]', $.proxy(this.button_action, this )); |
| 42 |
|
| 43 |
// conditionals |
| 44 |
$(document).on('reInitConditionals', $.proxy(this.initConditionials, this)); |
| 45 |
this.initConditionials(); // conditional options |
| 46 |
// range inputs |
| 47 |
|
| 48 |
$(document).on('change, input', 'input[type="range"]', $.proxy(this.updateRange, this )); |
| 49 |
this.updateRange(null); |
| 50 |
|
| 51 |
/* |
| 52 |
**** |
| 53 |
### After this only init for button main edit screen |
| 54 |
**** |
| 55 |
|
| 56 |
*/ |
| 57 |
if ($('#new-button-form').length == 0) |
| 58 |
return; |
| 59 |
|
| 60 |
|
| 61 |
if (this.button_id > 0) { |
| 62 |
$("#maxbuttons .mb-message").show(); |
| 63 |
} |
| 64 |
|
| 65 |
this.initResponsive(); // responsive edit interface |
| 66 |
|
| 67 |
$("#maxbuttons .output").draggable({ |
| 68 |
cancel: '.nodrag', |
| 69 |
}); |
| 70 |
|
| 71 |
$('#maxbuttons .color-field').wpColorPicker( |
| 72 |
{ |
| 73 |
width: 300, |
| 74 |
|
| 75 |
change: $.proxy( _.throttle(function(event, ui) { |
| 76 |
event.preventDefault(); |
| 77 |
var color = ui.color.toString(); |
| 78 |
this.update_color(event,ui, color); |
| 79 |
}, 200), this), |
| 80 |
|
| 81 |
} |
| 82 |
); |
| 83 |
|
| 84 |
/* Copy Color Interface */ |
| 85 |
$('.input.mbcolor .arrows').on('click', $.proxy(this.copyColor, this) ); |
| 86 |
|
| 87 |
$('#radius_toggle').on('click', $.proxy(this.toggleRadiusLock,this)); |
| 88 |
|
| 89 |
if ( typeof buttonFieldMap != 'undefined') |
| 90 |
this.fields = $.parseJSON(buttonFieldMap); |
| 91 |
|
| 92 |
// bind to all inputs, except for color-field or items with different handler. |
| 93 |
$('input').not('.color-field').on('keyup change', $.proxy(this.update_preview,this)); |
| 94 |
$('input.color-field').on('focus', $.proxy(this.select_field, this)); |
| 95 |
|
| 96 |
$('select').on('change', $.proxy(this.update_preview, this)); |
| 97 |
|
| 98 |
$(window).on('beforeunload', $.proxy(function () { if (this.form_updated) return maxcol_wp.leave_page; }, this)); |
| 99 |
$(document).on('keyup', 'input', function (e) { |
| 100 |
|
| 101 |
if (e.keyCode && e.keyCode == 13) |
| 102 |
{ |
| 103 |
$(":input")[$(":input").index(document.activeElement) + 1].focus(); |
| 104 |
return false; |
| 105 |
} |
| 106 |
}); |
| 107 |
|
| 108 |
$(".button-save").click( $.proxy(function() { |
| 109 |
this.saveIndicator(false); // prevent alert when saving. |
| 110 |
$("#new-button-form").submit(); |
| 111 |
return false; |
| 112 |
}, this) ); |
| 113 |
|
| 114 |
// Expand shortcode tabs for more examples. |
| 115 |
$('.shortcode-expand').on('click', this.toggleShortcode); |
| 116 |
|
| 117 |
}; // INIT |
| 118 |
|
| 119 |
|
| 120 |
maxAdmin.prototype.repaint_preview = function () |
| 121 |
{ |
| 122 |
$('.mb_tab input[type="text"]').trigger('change'); |
| 123 |
$('.mb_tab input[type="number"]').trigger('change'); |
| 124 |
$('.mb_tab select').trigger('change'); |
| 125 |
$('.mb_tab input[type="hidden"]').trigger('change'); |
| 126 |
$('.mb_tab input[type="radio"]:checked').trigger('change'); |
| 127 |
$('.mb_tab input[type="checkbox"]:checked').trigger('change'); |
| 128 |
|
| 129 |
//$(document).trigger('colorUpdate', ['#text_color', $('#text_color').val() ]); |
| 130 |
//$(document).trigger('colorUpdate', ['#text_color_hover', $('#text_color_hover').val() ]); |
| 131 |
|
| 132 |
} |
| 133 |
|
| 134 |
maxAdmin.prototype.update_preview = function(e) |
| 135 |
{ |
| 136 |
e.preventDefault(); |
| 137 |
this.saveIndicator(true); |
| 138 |
var target = $(e.target); |
| 139 |
|
| 140 |
// migration to data field |
| 141 |
var field = $(target).data('field'); |
| 142 |
if (typeof field == 'undefined') |
| 143 |
var id = $(target).attr('id'); // this should change to be ready for the option to have two the same fields on multi locations. |
| 144 |
else |
| 145 |
var id = field; |
| 146 |
|
| 147 |
var data = this.fields[id]; |
| 148 |
|
| 149 |
if (typeof data == 'undefined') |
| 150 |
return; // field doesn't have updates |
| 151 |
|
| 152 |
if (typeof data.css != 'undefined') |
| 153 |
{ |
| 154 |
value = target.val(); |
| 155 |
|
| 156 |
if (typeof data.css_unit != 'undefined' && value.indexOf(data.css_unit) == -1) |
| 157 |
value += data.css_unit; |
| 158 |
|
| 159 |
// a target that is checkbox but not checked should unset (empty) value. |
| 160 |
if (target.is(':checkbox') && ! target.is(':checked') ) |
| 161 |
value = ''; |
| 162 |
|
| 163 |
this.putCSS(data, value); |
| 164 |
} |
| 165 |
if (typeof data.attr != 'undefined') |
| 166 |
{ |
| 167 |
$('.output .result').find('a').attr(data.attr, target.val()); |
| 168 |
} |
| 169 |
if (typeof data.func != 'undefined') |
| 170 |
{ |
| 171 |
|
| 172 |
eval('this.'+ data.func + '(target)'); |
| 173 |
} |
| 174 |
}; |
| 175 |
|
| 176 |
maxAdmin.prototype.select_field = function(e) |
| 177 |
{ |
| 178 |
$(e.target).select(); |
| 179 |
} |
| 180 |
|
| 181 |
maxAdmin.prototype.button_action = function(e) |
| 182 |
{ |
| 183 |
e.preventDefault(); |
| 184 |
var action = $(e.target).data('buttonaction'); |
| 185 |
|
| 186 |
this.form_updated = false; |
| 187 |
|
| 188 |
var button_id = $(e.target).data('buttonid'); |
| 189 |
var nonce = $('input[name="' + action + '_nonce"]').val(); |
| 190 |
|
| 191 |
var url = mb_ajax.ajaxurl; |
| 192 |
var data = |
| 193 |
{ |
| 194 |
action: 'mb_button_action', |
| 195 |
button_action: action, |
| 196 |
button_id: button_id, |
| 197 |
nonce: nonce, |
| 198 |
|
| 199 |
}; |
| 200 |
|
| 201 |
$.post({ |
| 202 |
url: url, |
| 203 |
data: data, |
| 204 |
success: function (data) { |
| 205 |
response = JSON.parse(data); |
| 206 |
|
| 207 |
if (typeof response.redirection != 'undefined') |
| 208 |
{ |
| 209 |
window.location = response.redirection; |
| 210 |
} |
| 211 |
}, |
| 212 |
error: function () { |
| 213 |
console.log('error in button action' + action); |
| 214 |
}, |
| 215 |
}); |
| 216 |
} |
| 217 |
|
| 218 |
/* Check the copy modal and display a warning if the button has been changes */ |
| 219 |
maxAdmin.prototype.checkCopyModal = function(modal) |
| 220 |
{ |
| 221 |
if (this.form_updated) |
| 222 |
{ |
| 223 |
modal.currentModal.find('.mb-message').show(); |
| 224 |
|
| 225 |
} |
| 226 |
else |
| 227 |
$(modal.currentModal).find('.mb-message').hide(); |
| 228 |
} |
| 229 |
|
| 230 |
maxAdmin.prototype.toggle_preview = function (e) |
| 231 |
{ |
| 232 |
if ( $('.output .inner').is(':hidden') ) |
| 233 |
{ |
| 234 |
$('.output .inner').show(); |
| 235 |
$('.output').css('height', 'auto'); |
| 236 |
$('.preview .preview-toggle').removeClass('dashicons-arrow-down').addClass('dashicons-arrow-up'); |
| 237 |
} |
| 238 |
else |
| 239 |
{ |
| 240 |
$('.output .inner').hide(); |
| 241 |
$('.output').css('height', 'auto'); |
| 242 |
$('.preview .preview-toggle').removeClass('dashicons-arrow-up').addClass('dashicons-arrow-down'); |
| 243 |
} |
| 244 |
}; |
| 245 |
|
| 246 |
|
| 247 |
maxAdmin.prototype.putCSS = function(data,value,state) |
| 248 |
{ |
| 249 |
state = state || 'both'; |
| 250 |
|
| 251 |
var element = '.maxbutton'; |
| 252 |
if (state == 'hover') |
| 253 |
element = 'a.hover '; |
| 254 |
else if(state == 'normal') |
| 255 |
element = 'a.normal '; |
| 256 |
|
| 257 |
if (typeof data.csspart != 'undefined') |
| 258 |
{ |
| 259 |
var parts = data.csspart.split(","); |
| 260 |
for(i=0; i < parts.length; i++) |
| 261 |
{ |
| 262 |
var cpart = parts[i]; |
| 263 |
var fullpart = element + " ." + cpart; |
| 264 |
$('.output .result').find(fullpart).css(data.css, value); |
| 265 |
} |
| 266 |
} |
| 267 |
else |
| 268 |
$('.output .result').find(element).css(data.css, value); |
| 269 |
} |
| 270 |
|
| 271 |
maxAdmin.prototype.update_color = function(event, ui, color) |
| 272 |
{ |
| 273 |
event.preventDefault(); |
| 274 |
this.saveIndicator(true); |
| 275 |
|
| 276 |
var target = $(event.target); |
| 277 |
//var color = target.val(); |
| 278 |
|
| 279 |
if (color.indexOf('#') === -1) |
| 280 |
color = '#' + color; |
| 281 |
|
| 282 |
var id = target.attr('id'); |
| 283 |
$('#' + id).val(color); // otherwise field value is running 1 click behind. |
| 284 |
|
| 285 |
|
| 286 |
if(id.indexOf('box_shadow') !== -1) |
| 287 |
{ |
| 288 |
this.updateBoxShadow(target); |
| 289 |
} |
| 290 |
else if(id.indexOf('text_shadow') !== -1) |
| 291 |
{ |
| 292 |
this.updateTextShadow(target); |
| 293 |
} |
| 294 |
else if (id.indexOf('gradient') !== -1) |
| 295 |
{ |
| 296 |
if (id.indexOf('hover') == -1) |
| 297 |
this.updateGradient(); |
| 298 |
else |
| 299 |
this.updateGradient(true); |
| 300 |
} |
| 301 |
else if (id == 'button_preview') |
| 302 |
{ |
| 303 |
$(".output .result").css('backgroundColor', color); |
| 304 |
} |
| 305 |
else // simple update |
| 306 |
{ |
| 307 |
|
| 308 |
if (id.indexOf('hover') == -1) |
| 309 |
{ |
| 310 |
state = 'normal'; |
| 311 |
} |
| 312 |
else |
| 313 |
{ |
| 314 |
state = 'hover'; |
| 315 |
} |
| 316 |
|
| 317 |
var data = this.fields[id]; |
| 318 |
|
| 319 |
this.putCSS(data, color, state); |
| 320 |
return; |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
}; |
| 325 |
|
| 326 |
maxAdmin.prototype.copyColor = function (e) |
| 327 |
{ |
| 328 |
e.preventDefault(); |
| 329 |
e.stopPropagation(); // stop the color picker from closing itself. |
| 330 |
|
| 331 |
var target = $(e.target); |
| 332 |
var bindto = $(e.target).parents('[data-bind]'); |
| 333 |
var fieldId = '#' + bindto.data('id'); // Field which is used |
| 334 |
var bindId = '#' + bindto.data('bind'); // Field is bound to. |
| 335 |
|
| 336 |
// check which arrow was pressed |
| 337 |
if (target.hasClass('arrow-right')) |
| 338 |
var arrow_click = 'right'; |
| 339 |
else |
| 340 |
var arrow_click = 'left'; |
| 341 |
|
| 342 |
// check on which side the interface is. If arrows are on right side, it's the left side (...) |
| 343 |
if (bindto.hasClass('right') ) |
| 344 |
var if_side = 'left'; |
| 345 |
else |
| 346 |
var if_side = 'right'; |
| 347 |
|
| 348 |
/* Decide which color to replace. If interface is left - then right click is copy to other element, but if interface is right, right is overwrite current element. |
| 349 |
Left : right click - copy, left replace. |
| 350 |
Right : right click - replace, left copy. |
| 351 |
*/ |
| 352 |
if (if_side == 'left') |
| 353 |
{ |
| 354 |
if (arrow_click == 'right') |
| 355 |
copy = true; |
| 356 |
else |
| 357 |
copy = false; |
| 358 |
} |
| 359 |
else if (if_side == 'right') |
| 360 |
{ |
| 361 |
if (arrow_click == 'right') |
| 362 |
copy = false; |
| 363 |
else |
| 364 |
copy = true; |
| 365 |
} |
| 366 |
|
| 367 |
if ( copy ) |
| 368 |
{ |
| 369 |
$(bindId).val( $(fieldId).val() ); |
| 370 |
$(bindId).trigger('change'); |
| 371 |
$(bindId).wpColorPicker('color', $(fieldId).val()); |
| 372 |
} |
| 373 |
else |
| 374 |
{ |
| 375 |
$(fieldId).val( $(bindId).val() ); |
| 376 |
$(fieldId).trigger('change'); |
| 377 |
$(fieldId).wpColorPicker('color', $(bindId).val()); |
| 378 |
} |
| 379 |
|
| 380 |
} |
| 381 |
|
| 382 |
maxAdmin.prototype.updateGradient = function(hover) |
| 383 |
{ |
| 384 |
hover = hover || false; |
| 385 |
|
| 386 |
var hovtarget = ''; |
| 387 |
if (hover) |
| 388 |
hovtarget = "_hover"; |
| 389 |
|
| 390 |
var stop = parseInt($('#gradient_stop').val()); |
| 391 |
|
| 392 |
if (isNaN(stop) ) |
| 393 |
stop = 45; |
| 394 |
|
| 395 |
var gradients_on = $('#use_gradient').prop('checked'); |
| 396 |
|
| 397 |
var start = this.hexToRgb($('#gradient_start_color' + hovtarget).val()); |
| 398 |
var end = this.hexToRgb($('#gradient_end_color' + hovtarget).val()); |
| 399 |
var startop = parseInt($('#gradient_start_opacity' + hovtarget).val()); |
| 400 |
var endop = parseInt($('#gradient_end_opacity' + hovtarget).val()); |
| 401 |
|
| 402 |
if (! gradients_on) |
| 403 |
{ |
| 404 |
end = start; |
| 405 |
endop = startop; |
| 406 |
} |
| 407 |
|
| 408 |
if(isNaN(startop)) startop = 100; |
| 409 |
if(isNaN(endop)) endop = 100; |
| 410 |
|
| 411 |
if (!hover) |
| 412 |
var button = $('.output .result').find('a.normal'); |
| 413 |
else |
| 414 |
var button = $('.output .result').find('a.hover'); |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
button.css("background", "linear-gradient( rgba(" + start + "," + (startop/100) + ") " + stop + "%," + " rgba(" + end + "," + (endop/100) + ") )"); |
| 420 |
button.css("background", "-moz-linear-gradient( rgba(" + start + "," + (startop/100) + ") " + stop + "%," + " rgba(" + end + "," + (endop/100) + ") )"); |
| 421 |
button.css("background", "-o-linear-gradient( rgba(" + start + "," + (startop/100) + ") " + stop + "%," + " rgba(" + end + "," + (endop/100) + ") )"); |
| 422 |
button.css("background", "-webkit-gradient(linear, left top, left bottom, color-stop(" +stop+ "%, rgba(" + start + "," + (startop/100) + ")), color-stop(1, rgba(" + end + "," + (endop/100) + ") ));"); |
| 423 |
|
| 424 |
|
| 425 |
} |
| 426 |
|
| 427 |
maxAdmin.prototype.hexToRgb = function(hex) { |
| 428 |
|
| 429 |
hex = hex.replace('#',''); |
| 430 |
var bigint = parseInt(hex, 16); |
| 431 |
var r = (bigint >> 16) & 255; |
| 432 |
var g = (bigint >> 8) & 255; |
| 433 |
var b = bigint & 255; |
| 434 |
|
| 435 |
return r + "," + g + "," + b; |
| 436 |
} |
| 437 |
|
| 438 |
maxAdmin.prototype.updateBoxShadow = function (target) |
| 439 |
{ |
| 440 |
target = target || null; |
| 441 |
|
| 442 |
var left = $("#box_shadow_offset_left").val(); |
| 443 |
var top = $("#box_shadow_offset_top").val(); |
| 444 |
var width = $("#box_shadow_width").val(); |
| 445 |
var spread = $('#box_shadow_spread').val(); |
| 446 |
|
| 447 |
var color = $("#box_shadow_color").val(); |
| 448 |
var hovcolor = $("#box_shadow_color_hover").val(); |
| 449 |
|
| 450 |
$('.output .result').find('a.normal').css("boxShadow",left + 'px ' + top + 'px ' + width + 'px ' + spread + 'px ' + color); |
| 451 |
$('.output .result').find('a.hover').css("boxShadow",left + 'px ' + top + 'px ' + width + 'px ' + spread + 'px ' + hovcolor); |
| 452 |
} |
| 453 |
|
| 454 |
maxAdmin.prototype.updateTextShadow = function(target,hover) |
| 455 |
{ |
| 456 |
hover = hover || false; |
| 457 |
|
| 458 |
var left = $("#text_shadow_offset_left").val(); |
| 459 |
var top = $("#text_shadow_offset_top").val(); |
| 460 |
var width = $("#text_shadow_width").val(); |
| 461 |
|
| 462 |
var color = $("#text_shadow_color").val(); |
| 463 |
var hovcolor = $("#text_shadow_color_hover").val(); |
| 464 |
|
| 465 |
var id = $(target).attr('id'); |
| 466 |
var data = this.fields[id]; |
| 467 |
|
| 468 |
data.css = 'textShadow'; |
| 469 |
|
| 470 |
var value = left + 'px ' + top + 'px ' + width + 'px ' + color; |
| 471 |
this.putCSS(data, value, 'normal'); |
| 472 |
|
| 473 |
value = left + 'px ' + top + 'px ' + width + 'px ' + hovcolor; |
| 474 |
this.putCSS(data, value, 'hover'); |
| 475 |
|
| 476 |
} |
| 477 |
|
| 478 |
maxAdmin.prototype.updateAnchorText = function (target) |
| 479 |
{ |
| 480 |
var preview_text = $('.output .result').find('a .mb-text'); |
| 481 |
|
| 482 |
// This can happen when the text is removed, button is saved, so the preview doesn't load the text element. |
| 483 |
if (preview_text.length === 0) |
| 484 |
{ |
| 485 |
$('.output .result').find('a').append('<span class="mb-text"></span>'); |
| 486 |
$('.output .result').find('a .mb-text').css({'display':'block','line-height':'1em','box-sizing':'border-box'}); |
| 487 |
|
| 488 |
this.repaint_preview(); |
| 489 |
} |
| 490 |
$('.output .result').find('a .mb-text').text(target.val()); |
| 491 |
} |
| 492 |
|
| 493 |
maxAdmin.prototype.updateGradientOpacity = function(target) |
| 494 |
{ |
| 495 |
this.updateGradient(true); |
| 496 |
this.updateGradient(false); |
| 497 |
} |
| 498 |
|
| 499 |
maxAdmin.prototype.updateDimension = function (target) |
| 500 |
{ |
| 501 |
var dimension = $(target).val(); |
| 502 |
var id = $(target).attr('id'); |
| 503 |
var data = this.fields[id]; |
| 504 |
if (dimension > 0) |
| 505 |
this.putCSS(data, dimension); |
| 506 |
else |
| 507 |
this.putCSS(data, 'auto'); |
| 508 |
} |
| 509 |
|
| 510 |
maxAdmin.prototype.updateRadius = function(target) |
| 511 |
{ |
| 512 |
var value = target.val(); |
| 513 |
var fields = ['radius_bottom_left', 'radius_bottom_right', 'radius_top_left', 'radius_top_right']; |
| 514 |
|
| 515 |
if ( $('#radius_toggle').data('lock') == 'lock') |
| 516 |
{ |
| 517 |
for(i=0; i < fields.length; i++) |
| 518 |
{ |
| 519 |
var id = fields[i]; |
| 520 |
$('#' + id).val(value); |
| 521 |
var data = this.fields[id]; |
| 522 |
this.putCSS(data,value + 'px'); |
| 523 |
|
| 524 |
} |
| 525 |
|
| 526 |
} |
| 527 |
} |
| 528 |
|
| 529 |
maxAdmin.prototype.toggleRadiusLock = function (event) |
| 530 |
{ |
| 531 |
var target = $(event.target); |
| 532 |
var lock = $(target).data('lock'); |
| 533 |
if (lock == 'lock') |
| 534 |
{ |
| 535 |
$(target).removeClass('dashicons-lock').addClass('dashicons-unlock'); |
| 536 |
$(target).data('lock', 'unlock'); |
| 537 |
} |
| 538 |
else if (lock == 'unlock') |
| 539 |
{ |
| 540 |
$(target).removeClass('dashicons-unlock').addClass('dashicons-lock'); |
| 541 |
$(target).data('lock', 'lock'); |
| 542 |
} |
| 543 |
|
| 544 |
} |
| 545 |
|
| 546 |
|
| 547 |
maxAdmin.prototype.initResponsive = function() |
| 548 |
{ |
| 549 |
|
| 550 |
window.maxFoundry.maxadmin.responsive = new mbResponsive($); |
| 551 |
window.maxFoundry.maxadmin.responsive.init(this); |
| 552 |
|
| 553 |
} |
| 554 |
|
| 555 |
|
| 556 |
maxAdmin.prototype.do_paging = function(e) |
| 557 |
{ |
| 558 |
var page = parseInt($(e.target).val()); |
| 559 |
|
| 560 |
if (page <= parseInt($(e.target).attr('max')) ) |
| 561 |
{ |
| 562 |
var url = $(e.target).data("url"); |
| 563 |
window.location = url + "&paged=" + page; |
| 564 |
|
| 565 |
} |
| 566 |
} |
| 567 |
|
| 568 |
|
| 569 |
maxAdmin.prototype.toggleShortcode = function (e) |
| 570 |
{ |
| 571 |
if ($('.shortcode-expand').hasClass('closed')) |
| 572 |
{ |
| 573 |
$(' .mb-message.shortcode .expanded').css('display','inline-block'); |
| 574 |
$('.shortcode-expand span').removeClass('dashicons-arrow-down').addClass('dashicons-arrow-up'); |
| 575 |
$('.shortcode-expand').removeClass('closed').addClass('open'); |
| 576 |
} |
| 577 |
else |
| 578 |
{ |
| 579 |
$(' .mb-message.shortcode .expanded').css('display','none'); |
| 580 |
$('.shortcode-expand span').addClass('dashicons-arrow-down').removeClass('dashicons-arrow-up'); |
| 581 |
$('.shortcode-expand').addClass('closed').removeClass('open'); |
| 582 |
} |
| 583 |
|
| 584 |
} |
| 585 |
|
| 586 |
maxAdmin.prototype.toggleManual = function (e) |
| 587 |
{ |
| 588 |
e.preventDefault(); |
| 589 |
var $target = $(e.target); |
| 590 |
|
| 591 |
var subject = $target.data("target"); |
| 592 |
var $newWindow = $('.manual-entry[data-manual="' + subject + '"]'); |
| 593 |
|
| 594 |
if ($newWindow.is(':visible')) |
| 595 |
{ |
| 596 |
$newWindow.hide(); |
| 597 |
return true; |
| 598 |
} |
| 599 |
|
| 600 |
var offset = $('[data-options="' + subject + '"]').position() ; |
| 601 |
// top + height to position under manual link. |
| 602 |
var top = offset.top + $target.height(); |
| 603 |
|
| 604 |
$newWindow.css('top', top); |
| 605 |
$newWindow.css('right',15); |
| 606 |
$newWindow.css('left', 'auto'); |
| 607 |
|
| 608 |
$newWindow.show(); |
| 609 |
} |
| 610 |
|
| 611 |
maxAdmin.prototype.initConditionials = function () |
| 612 |
{ |
| 613 |
var mAP = this; |
| 614 |
$('[data-show]').each(function () { |
| 615 |
var condition = $(this).data('show'); |
| 616 |
var target = condition.target; |
| 617 |
var values = condition.values; |
| 618 |
var self = this; |
| 619 |
|
| 620 |
$(document).on('change','[name="' + target + '"]', {child: this, values: values}, $.proxy(mAP.updateConditional, mAP) ); |
| 621 |
|
| 622 |
if ( $('[name="' + target + '"]').length > 1) // trigger change to test condition |
| 623 |
{ |
| 624 |
$('[name="' + target + '"]:checked').trigger('change', ['conditional']); // radio / checkbox button |
| 625 |
} |
| 626 |
else { |
| 627 |
$('[name="' + target + '"]').trigger('change', ['conditional']); |
| 628 |
} |
| 629 |
}); |
| 630 |
|
| 631 |
// problem here is fields having same target, will add the same event over and over // |
| 632 |
// the target, input array, have a lot of input fields, which all receive the events. this is the issue. |
| 633 |
|
| 634 |
var updatelist = []; |
| 635 |
|
| 636 |
$('[data-has]').each(function () { |
| 637 |
var condition = $(this).data('has'); |
| 638 |
var target = condition.target; |
| 639 |
var values = condition.values; |
| 640 |
|
| 641 |
$('[name="' + target + '"]').on('change', {target: target, child: this, values: values}, $.proxy(mAP.updateHasConditional, mAP) ); |
| 642 |
|
| 643 |
var targetdecl = '[name="' + target + '"]'; |
| 644 |
if (! $.inArray(targetdecl, updatelist)); |
| 645 |
updatelist.push(targetdecl); |
| 646 |
}); |
| 647 |
|
| 648 |
if (updatelist.length > 0) |
| 649 |
{ |
| 650 |
// the issue will a lot of event checking still exist.. |
| 651 |
$(updatelist.toString()).first().trigger('change', ['conditional']); |
| 652 |
} |
| 653 |
|
| 654 |
} |
| 655 |
|
| 656 |
maxAdmin.prototype.updateConditional = function (event) |
| 657 |
{ |
| 658 |
var data = event.data; |
| 659 |
var cond_values = data.values; |
| 660 |
var cond_child = data.child; |
| 661 |
|
| 662 |
var target = $(event.currentTarget); |
| 663 |
var value = $(target).val(); |
| 664 |
|
| 665 |
// if type = checkbox: cond_value checked means it has to be 'checked' to show. Otherwise 'unchecked' go hide. |
| 666 |
if (target.attr('type') === 'checkbox') |
| 667 |
{ |
| 668 |
|
| 669 |
var checked = $(target).prop('checked'); |
| 670 |
|
| 671 |
if (cond_values == 'checked' && checked) |
| 672 |
value = 'checked'; |
| 673 |
else if (cond_values == 'unchecked' && !checked) |
| 674 |
value = 'unchecked'; |
| 675 |
else |
| 676 |
value = 0; |
| 677 |
} |
| 678 |
|
| 679 |
if (cond_values.indexOf(value) >= 0) |
| 680 |
{ |
| 681 |
|
| 682 |
$(cond_child).fadeIn('fast'); |
| 683 |
$(cond_child).find('input, select').trigger('change'); |
| 684 |
} |
| 685 |
else |
| 686 |
{ |
| 687 |
$(cond_child).fadeOut('fast'); |
| 688 |
$(cond_child).find('input, select').trigger('change'); |
| 689 |
} |
| 690 |
} |
| 691 |
|
| 692 |
maxAdmin.prototype.updateHasConditional = function(event) |
| 693 |
{ |
| 694 |
var mAP = this; |
| 695 |
var data = event.data; |
| 696 |
|
| 697 |
var cond_values = data.values; |
| 698 |
var cond_child = data.child; |
| 699 |
|
| 700 |
var target = data.target; |
| 701 |
|
| 702 |
var hascond = false; |
| 703 |
|
| 704 |
/** The issue here is to change this calls, to searches directly for value form cond_values ( mostly 1-3 options ) and not run the entire DOM each time. |
| 705 |
*/ |
| 706 |
var filter = []; |
| 707 |
$(cond_values).each(function (el) |
| 708 |
{ |
| 709 |
|
| 710 |
filter.push( '[value=' + this + ']'); |
| 711 |
} ); |
| 712 |
|
| 713 |
if ($('[name="' + target + '"]').filter( filter.toString() ).length > 0) |
| 714 |
{ |
| 715 |
hascond = true; |
| 716 |
} |
| 717 |
else { |
| 718 |
hascond = false |
| 719 |
} |
| 720 |
|
| 721 |
if (hascond) |
| 722 |
{ |
| 723 |
$(cond_child).fadeIn('fast'); |
| 724 |
} |
| 725 |
else |
| 726 |
{ |
| 727 |
$(cond_child).fadeOut('fast'); |
| 728 |
} |
| 729 |
|
| 730 |
} |
| 731 |
|
| 732 |
maxAdmin.prototype.updateRange = function (event) |
| 733 |
{ |
| 734 |
if (typeof event == 'undefined' || event === null ) |
| 735 |
{ |
| 736 |
var targets = $('input[type="range"]'); |
| 737 |
} |
| 738 |
else |
| 739 |
{ |
| 740 |
var targets = [event.target]; |
| 741 |
} |
| 742 |
|
| 743 |
$(targets).each(function () { |
| 744 |
var value = $(this).val(); |
| 745 |
$(this).parents('.input').find('.range_value output').val(value + '%'); |
| 746 |
|
| 747 |
}); |
| 748 |
|
| 749 |
} |
| 750 |
|
| 751 |
maxAdmin.prototype.saveIndicator = function(toggle) |
| 752 |
{ |
| 753 |
if (toggle) |
| 754 |
this.form_updated = true; |
| 755 |
else |
| 756 |
this.form_updated = false; |
| 757 |
} |
| 758 |
|
| 759 |
// General AJAX form save |
| 760 |
maxAdmin.prototype.formAjaxSave = function (e) |
| 761 |
{ |
| 762 |
e.preventDefault(); |
| 763 |
var url = mb_ajax.ajaxurl; |
| 764 |
var form = $(e.target); |
| 765 |
|
| 766 |
var data = form.serialize(); |
| 767 |
|
| 768 |
|
| 769 |
$.ajax({ |
| 770 |
type: "POST", |
| 771 |
url: url, |
| 772 |
data: data, |
| 773 |
|
| 774 |
}).done($.proxy(this.saveDone, this)); |
| 775 |
} |
| 776 |
|
| 777 |
/* |
| 778 |
maxAdmin.prototype.buttonSubmit = function (e) |
| 779 |
{ |
| 780 |
|
| 781 |
e.preventDefault(); |
| 782 |
$('[data-form]').prop('disabled', true); |
| 783 |
var formName = $(e.target).data('form'); |
| 784 |
$('#' + formName).submit(); |
| 785 |
|
| 786 |
} |
| 787 |
*/ |
| 788 |
|
| 789 |
maxAdmin.prototype.saveDone = function (res) |
| 790 |
{ |
| 791 |
$('[data-form]').prop('disabled', false); |
| 792 |
|
| 793 |
var json = $.parseJSON(res); |
| 794 |
|
| 795 |
var result = json.result; |
| 796 |
var title = json.title; |
| 797 |
|
| 798 |
|
| 799 |
var collection_id = json.data.id; |
| 800 |
|
| 801 |
if (typeof json.data.new_nonce !== 'undefined') |
| 802 |
{ |
| 803 |
var nonce = json.data.new_nonce; |
| 804 |
$('input[name="nonce"]').val(json.data.new_nonce); |
| 805 |
} |
| 806 |
|
| 807 |
if (result) |
| 808 |
{ |
| 809 |
// if collection is new - add collection_id to the field |
| 810 |
$('input[name="collection_id"]').val(collection_id); |
| 811 |
|
| 812 |
// replace the location to the correct collection |
| 813 |
var href = window.location.href; |
| 814 |
if (href.indexOf('collection_id') === -1) |
| 815 |
window.history.replaceState({}, '', href + '&collection_id=' + collection_id); |
| 816 |
|
| 817 |
// trigger other updates if needed |
| 818 |
$(document).trigger('mbFormSaved'); |
| 819 |
|
| 820 |
// update previous selection to current state; |
| 821 |
var order = $('input[name="sorted"]').val(); |
| 822 |
$('input[name="previous_selection"]').val(order); |
| 823 |
|
| 824 |
// in case the interface needs to be reloaded. |
| 825 |
if (json.data.reload) |
| 826 |
{ |
| 827 |
document.location.reload(true); |
| 828 |
} |
| 829 |
|
| 830 |
} |
| 831 |
if (! result) |
| 832 |
{ |
| 833 |
$modal = window.maxFoundry.maxmodal; |
| 834 |
$modal.newModal('collection_error'); |
| 835 |
$modal.setTitle(title); |
| 836 |
$modal.setContent(json.body); |
| 837 |
|
| 838 |
$modal.setControls('<button class="modal_close button-primary">' + json.close_text + '</button>'); |
| 839 |
$modal.show(); |
| 840 |
|
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
|
| 845 |
}); /* END OF JQUERY */ |
| 846 |
|