| 1 |
var pagelayer_fontHtmlArray = {}; |
| 2 |
|
| 3 |
(function($) { |
| 4 |
var api = wp.customize; |
| 5 |
|
| 6 |
api.bind( 'ready', function() { |
| 7 |
|
| 8 |
var controls = api.settings.controls; |
| 9 |
|
| 10 |
for(var control in controls){ |
| 11 |
if( !('show_filter' in controls[control]) ){ |
| 12 |
continue; |
| 13 |
} |
| 14 |
|
| 15 |
var filter = controls[control]['show_filter']; |
| 16 |
for(var showParam in filter){ |
| 17 |
var except = showParam.substr(0, 1) == '!' ? true : false; |
| 18 |
showParam = except ? showParam.substr(1) : showParam; |
| 19 |
|
| 20 |
// Show and Hide Controls |
| 21 |
api( showParam, function( setting ){ |
| 22 |
api.control( control, function( _control ) { |
| 23 |
var visibility = function() { |
| 24 |
var _filter = _control.params['show_filter']; |
| 25 |
for(var _showParam in _filter){ |
| 26 |
var reqval = _filter[_showParam]; |
| 27 |
var val = setting.get(); |
| 28 |
|
| 29 |
var toShow = false; |
| 30 |
|
| 31 |
if(typeof reqval == 'string' && reqval == val){ |
| 32 |
toShow = true; |
| 33 |
} |
| 34 |
|
| 35 |
// Its an array and a value is found, then dont show |
| 36 |
if(typeof reqval != 'string' && reqval.indexOf(val) > -1){ |
| 37 |
toShow = true; |
| 38 |
} |
| 39 |
|
| 40 |
if(except && !toShow || !except && toShow ){ |
| 41 |
_control.container.show(); |
| 42 |
return |
| 43 |
} |
| 44 |
|
| 45 |
_control.container.hide(); |
| 46 |
} |
| 47 |
|
| 48 |
}; |
| 49 |
|
| 50 |
visibility(); |
| 51 |
setting.bind( visibility ); |
| 52 |
}); |
| 53 |
}); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
// Expand pagelayer setting handler |
| 58 |
api.section('pagelayer_global_fonts_sec', function( section ){ |
| 59 |
section.expanded.bind(function( isExpanding ){ |
| 60 |
|
| 61 |
// Set default value |
| 62 |
section.container.find('select[data-font-key]').each(function(){ |
| 63 |
var ref = jQuery(this), |
| 64 |
name = ref.attr('data-font-key'), |
| 65 |
value = ref.attr('data-default-value'); |
| 66 |
|
| 67 |
ref.html(pagelayer_fontHtmlArray[name]).val(value); |
| 68 |
ref.removeAttr('data-font-key'); |
| 69 |
}); |
| 70 |
}); |
| 71 |
}); |
| 72 |
|
| 73 |
|
| 74 |
}); |
| 75 |
|
| 76 |
})(jQuery); |
| 77 |
|
| 78 |
/** |
| 79 |
* Initialization trigger. |
| 80 |
*/ |
| 81 |
jQuery(document).ready( function(){ |
| 82 |
|
| 83 |
// Create color setting |
| 84 |
pagelayer_alpha_color_control_init(); |
| 85 |
|
| 86 |
var option = function(val, lang){ |
| 87 |
var lang = lang || 'Default'; |
| 88 |
return '<option value="'+val+'">'+lang+'</option>'; |
| 89 |
} |
| 90 |
|
| 91 |
// Create font setting list |
| 92 |
for(var sk in pagelayer_global_font_settings){ |
| 93 |
var sval = pagelayer_global_font_settings[sk]; |
| 94 |
if('choices' in sval){ |
| 95 |
var fontHtml = ''; |
| 96 |
for( var value in sval['choices'] ) { |
| 97 |
|
| 98 |
if(typeof sval['choices'][value] !== 'object'){ |
| 99 |
fontHtml += option(value, sval['choices'][value]); |
| 100 |
continue; |
| 101 |
} |
| 102 |
|
| 103 |
if(value != 'default'){ |
| 104 |
fontHtml += '<optgroup label="'+value+'">'; |
| 105 |
} |
| 106 |
|
| 107 |
for (x in sval['choices'][value]){ |
| 108 |
fontHtml += option((jQuery.isNumeric(x) ? sval['choices'][value][x] : x), sval['choices'][value][x]); |
| 109 |
} |
| 110 |
|
| 111 |
// Close the optgroup if it was opened |
| 112 |
if(value !== 'default'){ |
| 113 |
fontHtml += '</optgroup>'; |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
pagelayer_fontHtmlArray[sk] = fontHtml; |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
// Show hide typography |
| 122 |
jQuery(document).on('click.pagelayer-typo-icon', function (e){ |
| 123 |
var target = jQuery(e.target); |
| 124 |
var isTypo = target.closest('.pagelayer-control-typo'); |
| 125 |
var isIcon = target.closest('.pagelayer-control-typo-icon'); |
| 126 |
var typoHolder = isIcon.closest('.pagelayer-control-typo-holder'); |
| 127 |
|
| 128 |
if(isTypo.length > 0){ |
| 129 |
return; |
| 130 |
} |
| 131 |
|
| 132 |
if(isIcon.length > 0){ |
| 133 |
|
| 134 |
// Set default value |
| 135 |
typoHolder.find('select[data-font-key]').each(function(){ |
| 136 |
var ref = jQuery(this), |
| 137 |
name = ref.attr('data-font-key'), |
| 138 |
value = ref.attr('data-default-value'); |
| 139 |
|
| 140 |
ref.html(pagelayer_fontHtmlArray[name]).val(value); |
| 141 |
ref.removeAttr('data-font-key'); |
| 142 |
}); |
| 143 |
|
| 144 |
var globalInput = typoHolder.find('.pagelayer-global-font-input'); |
| 145 |
|
| 146 |
if(!pagelayer_empty(globalInput)){ |
| 147 |
// Show the global values if is not customize |
| 148 |
typoHolder.find('.pagelayer-control-typo-fields').attr('pagelayer-set-global', 1); |
| 149 |
typoHolder.find('select, input').each(function(){ |
| 150 |
var sEle = jQuery(this); |
| 151 |
var val = sEle.val(); |
| 152 |
|
| 153 |
if(pagelayer_empty(val)){ |
| 154 |
return true; |
| 155 |
} |
| 156 |
|
| 157 |
sEle.closest('.pagelayer-control-typo-fields').removeAttr('pagelayer-set-global'); |
| 158 |
}); |
| 159 |
|
| 160 |
typoHolder.find('[pagelayer-set-global="1"] .pagelayer-typo-global-default').trigger('click'); |
| 161 |
} |
| 162 |
|
| 163 |
typoHolder.find('.pagelayer-control-typo').slideToggle(100); |
| 164 |
return; |
| 165 |
} |
| 166 |
|
| 167 |
jQuery('.pagelayer-control-typo').slideUp(100); |
| 168 |
}); |
| 169 |
|
| 170 |
// Show hide global color option |
| 171 |
jQuery(document).on('click.pagelayer-global-color-icon', function (e){ |
| 172 |
var target = jQuery(e.target); |
| 173 |
var isGcolor = target.closest('.pagelayer-global-color-list'); |
| 174 |
var isGIcon = target.closest('.pagelayer-control-global-color-icon'); |
| 175 |
|
| 176 |
if(isGcolor.length > 0){ |
| 177 |
return; |
| 178 |
} |
| 179 |
|
| 180 |
if(isGIcon.length > 0){ |
| 181 |
var listEle = isGIcon.closest('li').find('.pagelayer-global-color-list'); |
| 182 |
jQuery('.pagelayer-global-color-list').not(listEle).slideUp(100); |
| 183 |
listEle.slideToggle(100); |
| 184 |
return; |
| 185 |
} |
| 186 |
|
| 187 |
jQuery('.pagelayer-global-color-list').slideUp(100); |
| 188 |
}); |
| 189 |
|
| 190 |
// Hide global color option |
| 191 |
jQuery(document).on('focus', '.wp-color-result', function(e){ |
| 192 |
jQuery('.pagelayer-global-color-list').slideUp(100); |
| 193 |
}); |
| 194 |
|
| 195 |
// Show hide global fonts option |
| 196 |
jQuery('#customize-theme-controls').on('click.pagelayer-global-typo-icon', function (e){ |
| 197 |
var target = jQuery(e.target); |
| 198 |
var isGcolor = target.closest('.pagelayer-global-font-list'); |
| 199 |
var isGIcon = target.closest('.pagelayer-control-global-typo-icon'); |
| 200 |
var typoHolder = isGIcon.closest('.pagelayer-control-typo-holder'); |
| 201 |
|
| 202 |
if(isGcolor.length > 0){ |
| 203 |
return; |
| 204 |
} |
| 205 |
|
| 206 |
if(isGIcon.length > 0){ |
| 207 |
typoHolder.find('.pagelayer-global-font-list').slideToggle(100); |
| 208 |
return; |
| 209 |
} |
| 210 |
|
| 211 |
jQuery('.pagelayer-global-font-list').slideUp(100); |
| 212 |
}); |
| 213 |
|
| 214 |
// Device handler |
| 215 |
jQuery('#customize-theme-controls').on('click', '.pagelayer-devices button', function(e){ |
| 216 |
|
| 217 |
e.stopPropagation(); |
| 218 |
|
| 219 |
var device = jQuery(this).data('device'); |
| 220 |
var devices = {'desktop' : 'tablet', 'tablet' : 'mobile', 'mobile' : 'desktop'}; |
| 221 |
jQuery('.devices-wrapper .devices [data-device="'+devices[device]+'"]').click(); |
| 222 |
}); |
| 223 |
|
| 224 |
// Add attr to detect device |
| 225 |
jQuery('#customize-theme-controls').attr('data-device-detector', 'desktop'); |
| 226 |
|
| 227 |
// Device handler |
| 228 |
jQuery('.devices-wrapper .devices button[data-device]').on('click', function(e){ |
| 229 |
|
| 230 |
e.stopPropagation(); |
| 231 |
|
| 232 |
var device = jQuery(this).data('device'); |
| 233 |
|
| 234 |
jQuery('.pagelayer-devices .active-device').removeClass('active-device'); |
| 235 |
jQuery('.pagelayer-devices [data-device="'+device+'"]').addClass('active-device'); |
| 236 |
|
| 237 |
jQuery('[data-device-detector]').attr('data-device-detector', device); |
| 238 |
|
| 239 |
}); |
| 240 |
|
| 241 |
// Units handler |
| 242 |
jQuery('.pagelayer-units').each(function(){ |
| 243 |
var units = jQuery(this); |
| 244 |
var uList = units.find('[data-unit]'); |
| 245 |
var input = units.find('.pagelayer-unit-input'); |
| 246 |
var uActive = units.find('[data-unit="'+input.val()+'"]'); |
| 247 |
|
| 248 |
units.find('[data-unit]').on('click', function(){ |
| 249 |
var uEle = jQuery(this); |
| 250 |
uList.removeClass('active'); |
| 251 |
uEle.addClass('active'); |
| 252 |
input.val(uEle.data('unit')).trigger('input'); |
| 253 |
}); |
| 254 |
|
| 255 |
if(uActive.length > 0){ |
| 256 |
uActive.click(); |
| 257 |
return; |
| 258 |
} |
| 259 |
|
| 260 |
//uList.first().click(); |
| 261 |
|
| 262 |
}); |
| 263 |
|
| 264 |
// Accordion Tab handlers |
| 265 |
jQuery('.pagelayer-accordion-tab').on('click', function(){ |
| 266 |
var toggle = jQuery(this); |
| 267 |
var allToggle = toggle.closest('ul').find('.pagelayer-accordion-tab').not(toggle); |
| 268 |
|
| 269 |
allToggle.nextUntil('.pagelayer-accordion-tab').slideUp(); |
| 270 |
allToggle.removeClass('pagelayer-active-accordion-tab') |
| 271 |
toggle.nextUntil('.pagelayer-accordion-tab').slideToggle(); |
| 272 |
|
| 273 |
toggle.toggleClass('pagelayer-active-accordion-tab'); |
| 274 |
|
| 275 |
var dash = toggle.find('.pagelayer-customize-heading .dashicons'); |
| 276 |
var allDash = toggle.closest('ul').find('.pagelayer-accordion-tab .pagelayer-customize-heading .dashicons'); |
| 277 |
|
| 278 |
allDash.addClass('dashicons-arrow-right-alt2'); |
| 279 |
allDash.removeClass('dashicons-arrow-down-alt2'); |
| 280 |
|
| 281 |
if(toggle.hasClass('pagelayer-active-accordion-tab')){ |
| 282 |
dash.addClass('dashicons-arrow-down-alt2'); |
| 283 |
dash.removeClass('dashicons-arrow-right-alt2'); |
| 284 |
} |
| 285 |
|
| 286 |
}); |
| 287 |
|
| 288 |
// Close all accordion tabs |
| 289 |
jQuery('.pagelayer-accordion-tab').nextUntil('.pagelayer-accordion-tab').hide(); |
| 290 |
|
| 291 |
// Link padding control field handler |
| 292 |
jQuery('.pagelayer-control-padding').each(function(){ |
| 293 |
pagelayer_control_padding_handler(jQuery(this)); |
| 294 |
}); |
| 295 |
|
| 296 |
// Link Global Color Palette |
| 297 |
jQuery('.pagelayer-global-setting-color .dashicons').click(function(){ |
| 298 |
jQuery('#accordion-section-pagelayer_global_colors_sec .accordion-section-title').click(); |
| 299 |
}); |
| 300 |
|
| 301 |
// Link Global Font Palette |
| 302 |
jQuery('.pagelayer-global-setting-font .dashicons-admin-generic').click(function(){ |
| 303 |
jQuery('#accordion-section-pagelayer_global_fonts_sec .accordion-section-title').click(); |
| 304 |
}); |
| 305 |
|
| 306 |
// Color Palette Custom Control |
| 307 |
pagelayer_color_palette_control_handler(); |
| 308 |
|
| 309 |
// Color Palette Custom Control |
| 310 |
pagelayer_font_palette_control_handler(); |
| 311 |
|
| 312 |
// Global color list handler |
| 313 |
pagelayer_global_color_list_handler(); |
| 314 |
|
| 315 |
// Global font list handler |
| 316 |
pagelayer_global_font_list_handler(); |
| 317 |
|
| 318 |
// Slider handler |
| 319 |
pagelayer_control_slider_handler(); |
| 320 |
|
| 321 |
}); |
| 322 |
|
| 323 |
// Global font list handler |
| 324 |
function pagelayer_global_font_list_handler(){ |
| 325 |
|
| 326 |
var font_list = ''; |
| 327 |
|
| 328 |
// Create global font list |
| 329 |
for(var font in pagelayer_global_fonts){ |
| 330 |
font_list += '<div class="pagelayer-global-font-list-item" data-global-id="'+font+'">'+ |
| 331 |
'<span class="pagelayer-global-font-title">'+ pagelayer_global_fonts[font]['title'] +'</span>'+ |
| 332 |
'</div>'; |
| 333 |
} |
| 334 |
|
| 335 |
jQuery('.customize-control-pagelayer-typo-control .pagelayer-control-typo-holder').each(function(){ |
| 336 |
var fHolder = jQuery(this); |
| 337 |
var fList = fHolder.find('.pagelayer-global-font-list'); |
| 338 |
|
| 339 |
if(fList.length < 1){ |
| 340 |
return; |
| 341 |
} |
| 342 |
|
| 343 |
// Add list of font list |
| 344 |
fList.append(font_list); |
| 345 |
|
| 346 |
var globalInput = fHolder.find('.pagelayer-global-font-input'); |
| 347 |
var selectfont = globalInput.data('key'); |
| 348 |
|
| 349 |
// Restore global value |
| 350 |
fHolder.find('.pagelayer-typo-global-default').on('click', function(e){ |
| 351 |
e.preventDefault(); |
| 352 |
e.stopPropagation(); |
| 353 |
|
| 354 |
var sEle = jQuery(this); |
| 355 |
var fieldHolder = sEle.closest('.pagelayer-control-typo-fields'); |
| 356 |
var globalID = globalInput.val(); |
| 357 |
|
| 358 |
if(pagelayer_empty(globalID) || pagelayer_empty(pagelayer_global_fonts[globalID])){ |
| 359 |
return; |
| 360 |
} |
| 361 |
|
| 362 |
var allInput = fieldHolder.find('select, input'); |
| 363 |
var name = allInput.first().attr('name'); |
| 364 |
var setFonts = pagelayer_global_fonts[globalID]['value']; |
| 365 |
|
| 366 |
// Set default |
| 367 |
var modes = {desktop: '', tablet: '_tablet', mobile: '_mobile'}; |
| 368 |
var val = ''; |
| 369 |
|
| 370 |
fieldHolder.attr('pagelayer-set-global', 1); |
| 371 |
allInput.val(val).trigger('change'); |
| 372 |
|
| 373 |
if(name in setFonts){ |
| 374 |
val = setFonts[name]; |
| 375 |
} |
| 376 |
|
| 377 |
if(typeof val == 'object'){ |
| 378 |
|
| 379 |
for(var mode in modes){ |
| 380 |
var _val = ''; |
| 381 |
if(mode in val){ |
| 382 |
_val = val[mode]; |
| 383 |
} |
| 384 |
|
| 385 |
fieldHolder.find('[name="'+name+modes[mode]+'"]').val(_val); |
| 386 |
} |
| 387 |
|
| 388 |
return; |
| 389 |
} |
| 390 |
|
| 391 |
allInput.val(val); |
| 392 |
}); |
| 393 |
|
| 394 |
if(fList.find('[data-global-id="'+selectfont+'"]').length > 0){ |
| 395 |
fList.find('[data-global-id="'+selectfont+'"]').addClass('pagelayer-global-selected'); |
| 396 |
|
| 397 |
// Set active |
| 398 |
fHolder.find('.pagelayer-control-global-typo-icon').addClass('pagelayer-active-global'); |
| 399 |
} |
| 400 |
|
| 401 |
// On change any field we need to handle for the global |
| 402 |
fHolder.find('select, input').on('input', function(){ |
| 403 |
var sEle = jQuery(this); |
| 404 |
var fieldHolder = sEle.closest('.pagelayer-control-typo-fields'); |
| 405 |
|
| 406 |
if(fieldHolder.attr('pagelayer-set-global') == '1'){ |
| 407 |
fieldHolder.removeAttr('pagelayer-set-global'); |
| 408 |
fieldHolder.find('select, input').trigger('change'); |
| 409 |
} |
| 410 |
}); |
| 411 |
|
| 412 |
}); |
| 413 |
|
| 414 |
jQuery('#customize-theme-controls').on('click', '.pagelayer-global-font-list-item', function(){ |
| 415 |
var listItem = jQuery(this); |
| 416 |
var globalID = listItem.data('global-id'); |
| 417 |
var listHolder = listItem.closest('.pagelayer-global-font-list'); |
| 418 |
var holder = listItem.closest('.pagelayer-control-typo-holder'); |
| 419 |
var allInputs = holder.find('select, input'); |
| 420 |
|
| 421 |
// Remove global font |
| 422 |
if(listItem.hasClass('pagelayer-global-selected')){ |
| 423 |
listItem.removeClass('pagelayer-global-selected'); |
| 424 |
holder.find('.pagelayer-control-global-typo-icon').removeClass('pagelayer-active-global'); |
| 425 |
holder.find('.pagelayer-global-font-input').val(''); |
| 426 |
holder.removeClass('pagelayer-global-on'); |
| 427 |
allInputs.trigger('input'); |
| 428 |
allInputs.closest('.pagelayer-control-typo-fields').removeAttr('pagelayer-set-global'); |
| 429 |
listHolder.hide(); |
| 430 |
return; |
| 431 |
} |
| 432 |
|
| 433 |
// Remove previous selecttion |
| 434 |
listHolder.find('.pagelayer-global-selected').removeClass('pagelayer-global-selected') |
| 435 |
listHolder.hide(); |
| 436 |
|
| 437 |
listItem.addClass('pagelayer-global-selected'); |
| 438 |
|
| 439 |
var key = holder.find( '.pagelayer-global-font-input' ).attr( 'data-customize-setting-link' ); |
| 440 |
|
| 441 |
// Empty all the typo |
| 442 |
allInputs.val('').trigger('input'); |
| 443 |
allInputs.closest('.pagelayer-control-typo-fields').attr('pagelayer-set-global', 1); |
| 444 |
holder.addClass('pagelayer-global-on'); |
| 445 |
|
| 446 |
// Set the actual option value to empty string. |
| 447 |
wp.customize( key, function( obj ) { |
| 448 |
obj.set(globalID); |
| 449 |
}); |
| 450 |
|
| 451 |
// Apply all global values |
| 452 |
holder.find('.pagelayer-typo-global-default').click(); |
| 453 |
holder.find('.pagelayer-control-global-typo-icon').addClass('pagelayer-active-global'); |
| 454 |
}); |
| 455 |
} |
| 456 |
|
| 457 |
// Global color list handler |
| 458 |
function pagelayer_global_color_list_handler(){ |
| 459 |
|
| 460 |
jQuery(document).on('click', '.pagelayer-global-color-list-item', function(e, skip_update){ |
| 461 |
|
| 462 |
skip_update = skip_update || false; |
| 463 |
|
| 464 |
var listItem = jQuery(this); |
| 465 |
var globalID = listItem.data('global-id'); |
| 466 |
var listHolder = listItem.closest('.pagelayer-global-color-list'); |
| 467 |
|
| 468 |
// Remove previous selecttion |
| 469 |
listHolder.find('.pagelayer-global-selected').removeClass('pagelayer-global-selected'); |
| 470 |
listItem.addClass('pagelayer-global-selected'); |
| 471 |
listHolder.hide(); |
| 472 |
|
| 473 |
var input = listItem.closest('li').find( '.pagelayer-alpha-color-control' ) |
| 474 |
var code = '$'+globalID; |
| 475 |
var color = pagelayer_global_colors[globalID]['value']; |
| 476 |
|
| 477 |
input.unbind('change.pagelayer_global input.pagelayer_global color_change.pagelayer_global'); |
| 478 |
|
| 479 |
if(!skip_update){ |
| 480 |
var key = input.attr( 'data-customize-setting-link' ); |
| 481 |
|
| 482 |
// Set the actual option value to empty string. |
| 483 |
wp.customize( key, function( obj ) { |
| 484 |
obj.set(code); |
| 485 |
}); |
| 486 |
} |
| 487 |
|
| 488 |
// Set the actual option value to empty string. |
| 489 |
input.val( color ); |
| 490 |
input.closest('.wp-picker-container').find('.wp-color-result').css({'background-color': color}); |
| 491 |
|
| 492 |
input.on('change.pagelayer_global input.pagelayer_global color_change.pagelayer_global', function(){ |
| 493 |
var colorCode = jQuery(this).val(); |
| 494 |
if(jQuery.trim(colorCode) == color){ |
| 495 |
return; |
| 496 |
} |
| 497 |
listItem.closest('li').find('.pagelayer-control-global-color-icon').removeClass('pagelayer-active-global'); |
| 498 |
listHolder.find('.pagelayer-global-selected').removeClass('pagelayer-global-selected'); |
| 499 |
}); |
| 500 |
|
| 501 |
listItem.closest('li').find('.pagelayer-control-global-color-icon').addClass('pagelayer-active-global'); |
| 502 |
}); |
| 503 |
|
| 504 |
jQuery('.pagelayer-global-color-list-item.pagelayer-global-selected').trigger('click', [true]); |
| 505 |
} |
| 506 |
|
| 507 |
var pagelayer_global_colors_timmer = {}; |
| 508 |
// Color palette Custom Control |
| 509 |
function pagelayer_color_palette_control_handler(){ |
| 510 |
|
| 511 |
var global_palette = jQuery('#customize-control-pagelayer_global_colors'); |
| 512 |
|
| 513 |
// Get the values from the repeater input fields and add to our hidden field |
| 514 |
var pagelayerGetAllInputs = function() { |
| 515 |
|
| 516 |
var pagelayer_colors_palette = {}; |
| 517 |
|
| 518 |
global_palette.find('.pagelayer-alpha-color-control').each(function(){ |
| 519 |
var cEle = jQuery(this); |
| 520 |
var id = cEle.data('id'); |
| 521 |
|
| 522 |
pagelayer_colors_palette[id] = { |
| 523 |
'title' : cEle.closest('.pagelayer-color-holder').find('.pagelayer-color-title').text(), |
| 524 |
'value' : cEle.val(), |
| 525 |
} |
| 526 |
}); |
| 527 |
|
| 528 |
var inputValues = JSON.stringify(pagelayer_colors_palette); |
| 529 |
|
| 530 |
// Add all the values from our repeater fields to the hidden field (which is the one that actually gets saved) |
| 531 |
global_palette.find('.pagelayer-color-palette-data').val(inputValues).trigger('change'); |
| 532 |
} |
| 533 |
|
| 534 |
// Append a new row to our list of elements |
| 535 |
var pagelayer_add_row = function(ele, val = ''){ |
| 536 |
|
| 537 |
var id = pagelayer_generate_randstr(6); |
| 538 |
var name = ele.find('.pagelayer-color-holder').length - 3; |
| 539 |
|
| 540 |
var newRow = jQuery('<div class="pagelayer-color-holder"><span class="pagelayer-color-title" contenteditable="true">Color #'+name+'</span><span class="pagelayer-color-controls">'+val+'</span><span class="customize-control-color-repeater-delete"><span class="dashicons dashicons-no-alt"></span></span><input class="pagelayer-alpha-color-control" type="text" data-show-opacity="true" data-palette="true" data-default-color="'+val+'" data-id="'+id+'" data-title="New Color"/></div>'); |
| 541 |
|
| 542 |
ele.find('.pagelayer-color-holder:last').after(newRow); |
| 543 |
pagelayer_alpha_color_control_init(); |
| 544 |
|
| 545 |
// Update global variable |
| 546 |
ele.find('.pagelayer-alpha-color-control').trigger('color_change'); |
| 547 |
} |
| 548 |
|
| 549 |
jQuery(document).on('color_change change', '#customize-control-pagelayer_global_colors .pagelayer-alpha-color-control, #customize-control-pagelayer_global_colors .pagelayer-color-title', function(){ |
| 550 |
|
| 551 |
var cEle = jQuery(this); |
| 552 |
|
| 553 |
clearTimeout(pagelayer_global_colors_timmer); |
| 554 |
pagelayer_global_colors_timmer = setTimeout(function(){ |
| 555 |
cEle.closest('.pagelayer-color-holder').find('.pagelayer-color-controls').html(cEle.val()); |
| 556 |
pagelayerGetAllInputs(); |
| 557 |
}, 300); |
| 558 |
|
| 559 |
}); |
| 560 |
|
| 561 |
jQuery(document).on('input', '#customize-control-pagelayer_global_colors .pagelayer-color-title', function(){ |
| 562 |
clearTimeout(pagelayer_global_colors_timmer); |
| 563 |
pagelayer_global_colors_timmer = setTimeout(function(){ |
| 564 |
pagelayerGetAllInputs(); |
| 565 |
}, 500); |
| 566 |
}); |
| 567 |
|
| 568 |
// Add new item |
| 569 |
jQuery('.customize-control-color-repeater-add').click(function(event) { |
| 570 |
event.preventDefault(); |
| 571 |
pagelayer_add_row(jQuery(this).parent()); |
| 572 |
}); |
| 573 |
|
| 574 |
// Remove item starting from it's parent element |
| 575 |
jQuery(document).on('click', '.pagelayer-color-holder .customize-control-color-repeater-delete .dashicons', function(event) { |
| 576 |
event.preventDefault(); |
| 577 |
var numItems = jQuery(this).closest('.pagelayer-color-holder').remove(); |
| 578 |
pagelayerGetAllInputs(); |
| 579 |
}); |
| 580 |
} |
| 581 |
|
| 582 |
// Font palette Custom Control |
| 583 |
function pagelayer_font_palette_control_handler(){ |
| 584 |
|
| 585 |
var global_palette = jQuery('#customize-control-pagelayer_global_fonts'); |
| 586 |
|
| 587 |
// Get the values from the repeater input fields and add to our hidden field |
| 588 |
var pagelayerGetAllInputs = function() { |
| 589 |
|
| 590 |
var pagelayer_colors_palette = {}; |
| 591 |
global_palette.find('.pagelayer-font-holder').each(function(){ |
| 592 |
var cEle = jQuery(this); |
| 593 |
var id = cEle.data('id'); |
| 594 |
var data = {}; |
| 595 |
|
| 596 |
var array = cEle.find('input, textarea, select').serializeArray(); |
| 597 |
jQuery.each(array, function () { |
| 598 |
|
| 599 |
if(this.value == ''){ |
| 600 |
return; |
| 601 |
} |
| 602 |
|
| 603 |
var name = this.name; |
| 604 |
var value = this.value; |
| 605 |
|
| 606 |
// Is multi array |
| 607 |
if(name.indexOf("[") > -1){ |
| 608 |
|
| 609 |
var nameArray = name.replaceAll(']', '').split('\['), |
| 610 |
base = nameArray.shift(), |
| 611 |
last = nameArray.pop(); |
| 612 |
|
| 613 |
if(typeof data[base] != 'object'){ |
| 614 |
data[base] = {}; |
| 615 |
} |
| 616 |
|
| 617 |
// Set base object as refrence |
| 618 |
var _val = data[base]; |
| 619 |
|
| 620 |
for(key in nameArray){ |
| 621 |
|
| 622 |
if(typeof _val[nameArray[key]] != 'object'){ |
| 623 |
_val[nameArray[key]] = {}; |
| 624 |
} |
| 625 |
|
| 626 |
// Change the refrence of object |
| 627 |
_val = _val[nameArray[key]]; |
| 628 |
} |
| 629 |
|
| 630 |
_val[last] = value; |
| 631 |
return; |
| 632 |
} |
| 633 |
|
| 634 |
data[name] = value; |
| 635 |
}); |
| 636 |
|
| 637 |
pagelayer_colors_palette[id] = { |
| 638 |
'title' : cEle.children('.pagelayer-font-title').text(), |
| 639 |
'value' : data, |
| 640 |
} |
| 641 |
}); |
| 642 |
|
| 643 |
var inputValues = JSON.stringify(pagelayer_colors_palette); |
| 644 |
|
| 645 |
// Add all the values from our repeater fields to the hidden field (which is the one that actually gets saved) |
| 646 |
global_palette.find('.pagelayer-font-palette-data').val(inputValues).trigger('change'); |
| 647 |
} |
| 648 |
|
| 649 |
// Append a new row to our list of elements |
| 650 |
var pagelayer_add_row = function(ele, val = ''){ |
| 651 |
|
| 652 |
var id = pagelayer_generate_randstr(6); |
| 653 |
var name = ele.find('.pagelayer-font-holder').length - 3; |
| 654 |
var fontHtml = ''; |
| 655 |
|
| 656 |
var option = function(val, lang){ |
| 657 |
var selected = '';//(val != prop.c['val']) ? '' : 'selected="selected"'; |
| 658 |
var lang = lang || 'Default'; |
| 659 |
return '<option value="'+val+'" '+selected+'>'+lang+'</option>'; |
| 660 |
} |
| 661 |
|
| 662 |
fontHtml += '<div class="pagelayer-font-holder" data-id="'+id+'"><span class="pagelayer-font-title" contenteditable="true">New Font #'+ name +'</span><span class="customize-control-font-repeater-delete"><span class="dashicons dashicons-no-alt"></span></span><div class="pagelayer-control-typo-holder"><span class="pagelayer-control-typo-icon dashicons dashicons-edit"></span><div class="pagelayer-control-typo">'; |
| 663 |
|
| 664 |
for(var sk in pagelayer_global_font_settings){ |
| 665 |
var sval = pagelayer_global_font_settings[sk]; |
| 666 |
|
| 667 |
fontHtml += '<div class="pagelayer-control-typo-fields">'+ |
| 668 |
'<label class="pagelayer-control-typo-fields-label">'+sval['label']; |
| 669 |
|
| 670 |
if('responsive' in sval){ |
| 671 |
fontHtml += '<span class="pagelayer-devices">'+ |
| 672 |
'<button type="button" class="active-device" aria-pressed="true" data-device="desktop">'+ |
| 673 |
'<i class="dashicons dashicons-desktop"></i>'+ |
| 674 |
'</button>'+ |
| 675 |
'<button type="button"aria-pressed="false" data-device="tablet">'+ |
| 676 |
'<i class="dashicons dashicons-tablet"></i>'+ |
| 677 |
'</button>'+ |
| 678 |
'<button type="button" aria-pressed="false" data-device="mobile">'+ |
| 679 |
'<i class="dashicons dashicons-smartphone"></i>'+ |
| 680 |
'</button>'+ |
| 681 |
'</span>'; |
| 682 |
} |
| 683 |
|
| 684 |
fontHtml += '</label>'; |
| 685 |
|
| 686 |
if('choices' in sval){ |
| 687 |
fontHtml += '<select name="'+ sk +'">'; |
| 688 |
for( var value in sval['choices'] ) { |
| 689 |
if(typeof sval['choices'][value] !== 'object'){ |
| 690 |
fontHtml += option(value, sval['choices'][value]); |
| 691 |
continue; |
| 692 |
} |
| 693 |
|
| 694 |
if(value != 'default'){ |
| 695 |
fontHtml += '<optgroup label="'+value+'">'; |
| 696 |
} |
| 697 |
|
| 698 |
for (x in sval['choices'][value]){ |
| 699 |
fontHtml += option((jQuery.isNumeric(x) ? sval['choices'][value][x] : x), sval['choices'][value][x]); |
| 700 |
} |
| 701 |
|
| 702 |
} |
| 703 |
fontHtml += '</select>'; |
| 704 |
}else{ |
| 705 |
fontHtml += '<input type="number" name="'+ sk +'">'; |
| 706 |
} |
| 707 |
fontHtml += '</div>'; |
| 708 |
} |
| 709 |
|
| 710 |
fontHtml += '</div></div></div>'; |
| 711 |
|
| 712 |
ele.find('.customize-control-font-repeater-add').before(fontHtml); |
| 713 |
} |
| 714 |
|
| 715 |
jQuery(document).on('input', '#customize-control-pagelayer_global_fonts input, #customize-control-pagelayer_global_fonts textarea, #customize-control-pagelayer_global_fonts select', function(){ |
| 716 |
|
| 717 |
clearTimeout(pagelayer_global_colors_timmer); |
| 718 |
pagelayer_global_colors_timmer = setTimeout(function(){ |
| 719 |
pagelayerGetAllInputs(); |
| 720 |
}, 300); |
| 721 |
}); |
| 722 |
|
| 723 |
jQuery(document).on('input', '#customize-control-pagelayer_global_fonts .pagelayer-font-title', function(){ |
| 724 |
clearTimeout(pagelayer_global_colors_timmer); |
| 725 |
pagelayer_global_colors_timmer = setTimeout(function(){ |
| 726 |
pagelayerGetAllInputs(); |
| 727 |
}, 500); |
| 728 |
}); |
| 729 |
|
| 730 |
// Add new item |
| 731 |
jQuery('.customize-control-font-repeater-add').click(function(event) { |
| 732 |
event.preventDefault(); |
| 733 |
pagelayer_add_row(jQuery(this).parent()); |
| 734 |
pagelayerGetAllInputs(); |
| 735 |
}); |
| 736 |
|
| 737 |
// Remove item starting from it's parent element |
| 738 |
jQuery('#customize-theme-controls').on('click', '.pagelayer-font-holder .customize-control-font-repeater-delete .dashicons', function(event) { |
| 739 |
event.preventDefault(); |
| 740 |
var numItems = jQuery(this).closest('.pagelayer-font-holder').remove(); |
| 741 |
pagelayerGetAllInputs(); |
| 742 |
}); |
| 743 |
} |
| 744 |
|
| 745 |
// Padding handler |
| 746 |
function pagelayer_control_padding_handler(jEle){ |
| 747 |
|
| 748 |
var linked = jEle.find('.dashicons-admin-links'); |
| 749 |
var inputs = jEle.find('.pagelayer-padding-input'); |
| 750 |
var is_same = true; |
| 751 |
var first_val = jEle.find('.pagelayer-padding-input').first().val(); |
| 752 |
|
| 753 |
jEle.find('.pagelayer-padding-input').each(function(){ |
| 754 |
if(jQuery(this).val() == first_val){ |
| 755 |
return; |
| 756 |
} |
| 757 |
is_same = false; |
| 758 |
return false; |
| 759 |
}); |
| 760 |
|
| 761 |
|
| 762 |
if(is_same){ |
| 763 |
linked.addClass('pagelayer-padding-linked'); |
| 764 |
} |
| 765 |
|
| 766 |
linked.on('click', function (e){ |
| 767 |
jQuery(this).toggleClass('pagelayer-padding-linked'); |
| 768 |
}); |
| 769 |
|
| 770 |
inputs.on('change', function(){ |
| 771 |
|
| 772 |
// Are the values linked |
| 773 |
if(! linked.hasClass('pagelayer-padding-linked')){ |
| 774 |
return; |
| 775 |
} |
| 776 |
|
| 777 |
var val = jQuery(this).val(); |
| 778 |
inputs.each(function(){ |
| 779 |
jQuery(this).val(val); |
| 780 |
jQuery(this).trigger('input'); |
| 781 |
}); |
| 782 |
}); |
| 783 |
|
| 784 |
} |
| 785 |
|
| 786 |
/** |
| 787 |
* Alpha Color Picker JS |
| 788 |
* |
| 789 |
* This file includes several helper functions and the core control JS. |
| 790 |
*/ |
| 791 |
function pagelayer_alpha_color_control_init(){ |
| 792 |
|
| 793 |
var timeOut = 0; |
| 794 |
|
| 795 |
// Loop over each control and transform it into our color picker. |
| 796 |
jQuery( '.pagelayer-alpha-color-control' ).each( function() { |
| 797 |
// Scope the vars. |
| 798 |
var $control, startingColor, paletteInput, showOpacity, defaultColor, palette, |
| 799 |
colorPickerOptions, $container, $alphaSlider, alphaVal, sliderOptions; |
| 800 |
|
| 801 |
// Store the control instance. |
| 802 |
$control = jQuery( this ); |
| 803 |
|
| 804 |
if($control.closest('.wp-picker-holder').length > 0){ |
| 805 |
return; |
| 806 |
} |
| 807 |
|
| 808 |
setTimeout(function(){ |
| 809 |
// Get a clean starting value for the option. |
| 810 |
startingColor = $control.val().replace( /\s+/g, '' ); |
| 811 |
|
| 812 |
// Get some data off the control. |
| 813 |
paletteInput = $control.attr( 'data-palette' ); |
| 814 |
showOpacity = $control.attr( 'data-show-opacity' ); |
| 815 |
defaultColor = $control.attr( 'data-default-color' ); |
| 816 |
|
| 817 |
// Process the palette. |
| 818 |
if ( paletteInput.indexOf( '|' ) !== -1 ) { |
| 819 |
palette = paletteInput.split( '|' ); |
| 820 |
} else if ( 'false' == paletteInput ) { |
| 821 |
palette = false; |
| 822 |
} else { |
| 823 |
palette = true; |
| 824 |
} |
| 825 |
|
| 826 |
// Set up the options that we'll pass to wpColorPicker(). |
| 827 |
colorPickerOptions = { |
| 828 |
change: function( event, ui ) { |
| 829 |
var key, value, alpha, $transparency; |
| 830 |
|
| 831 |
key = $control.attr( 'data-customize-setting-link' ); |
| 832 |
value = $control.wpColorPicker( 'color' ); |
| 833 |
|
| 834 |
// Set the opacity value on the slider handle when the default color button is clicked. |
| 835 |
if ( defaultColor == value ) { |
| 836 |
alpha = pagelayer_get_alpha_value_from_color( value ); |
| 837 |
$alphaSlider.find( '.ui-slider-handle' ).text( alpha ); |
| 838 |
} |
| 839 |
|
| 840 |
// Send ajax request to wp.customize to trigger the Save action. |
| 841 |
wp.customize( key, function( obj ) { |
| 842 |
obj.set( value ); |
| 843 |
}); |
| 844 |
|
| 845 |
$transparency = $container.find( '.transparency' ); |
| 846 |
|
| 847 |
// Always show the background color of the opacity slider at 100% opacity. |
| 848 |
$transparency.css( 'background-color', ui.color.toString( 'no-alpha' ) ); |
| 849 |
$control.trigger('color_change'); |
| 850 |
}, |
| 851 |
palettes: palette // Use the passed in palette. |
| 852 |
}; |
| 853 |
|
| 854 |
// Create the colorpicker. |
| 855 |
$control.wpColorPicker( colorPickerOptions ); |
| 856 |
|
| 857 |
$container = $control.parents( '.wp-picker-container:first' ); |
| 858 |
|
| 859 |
// Insert our opacity slider. |
| 860 |
jQuery( '<div class="alpha-color-picker-container">' + |
| 861 |
'<div class="min-click-zone click-zone"></div>' + |
| 862 |
'<div class="max-click-zone click-zone"></div>' + |
| 863 |
'<div class="alpha-slider"></div>' + |
| 864 |
'<div class="transparency"></div>' + |
| 865 |
'</div>' ).appendTo( $container.find( '.wp-picker-holder' ) ); |
| 866 |
|
| 867 |
$alphaSlider = $container.find( '.alpha-slider' ); |
| 868 |
|
| 869 |
// If starting value is in format RGBa, grab the alpha channel. |
| 870 |
alphaVal = pagelayer_get_alpha_value_from_color( startingColor ); |
| 871 |
|
| 872 |
// Set up jQuery UI slider() options. |
| 873 |
sliderOptions = { |
| 874 |
create: function( event, ui ) { |
| 875 |
var value = jQuery( this ).slider( 'value' ); |
| 876 |
|
| 877 |
// Set up initial values. |
| 878 |
jQuery( this ).find( '.ui-slider-handle' ).text( value ); |
| 879 |
jQuery( this ).siblings( '.transparency ').css( 'background-color', startingColor ); |
| 880 |
}, |
| 881 |
value: alphaVal, |
| 882 |
range: 'max', |
| 883 |
step: 1, |
| 884 |
min: 0, |
| 885 |
max: 100, |
| 886 |
animate: 300 |
| 887 |
}; |
| 888 |
|
| 889 |
// Initialize jQuery UI slider with our options. |
| 890 |
$alphaSlider.slider( sliderOptions ); |
| 891 |
|
| 892 |
// Maybe show the opacity on the handle. |
| 893 |
if( 'true' == showOpacity ){ |
| 894 |
$alphaSlider.find( '.ui-slider-handle' ).addClass( 'show-opacity' ); |
| 895 |
} |
| 896 |
|
| 897 |
// Move input box inside the picker holder |
| 898 |
$control.closest('.wp-picker-input-wrap').each(function () { |
| 899 |
jQuery(this).next('.wp-picker-holder').prepend(jQuery(this)); |
| 900 |
}); |
| 901 |
|
| 902 |
// Bind event handlers for the click zones. |
| 903 |
$container.find( '.min-click-zone' ).on( 'click', function() { |
| 904 |
pagelayer_update_alpha_value_on_color_control( 0, $control, $alphaSlider, true ); |
| 905 |
}); |
| 906 |
|
| 907 |
$container.find( '.max-click-zone' ).on( 'click', function() { |
| 908 |
pagelayer_update_alpha_value_on_color_control( 100, $control, $alphaSlider, true ); |
| 909 |
}); |
| 910 |
|
| 911 |
// Bind event handler for clicking on a palette color. |
| 912 |
$container.find( '.iris-palette' ).on( 'click', function() { |
| 913 |
var color, alpha; |
| 914 |
|
| 915 |
color = jQuery( this ).css( 'background-color' ); |
| 916 |
alpha = pagelayer_get_alpha_value_from_color( color ); |
| 917 |
|
| 918 |
pagelayer_update_alpha_value_on_alpha_slider( alpha, $alphaSlider ); |
| 919 |
|
| 920 |
// Sometimes Iris doesn't set a perfect background-color on the palette, |
| 921 |
// for example rgba(20, 80, 100, 0.3) becomes rgba(20, 80, 100, 0.298039). |
| 922 |
// To compensante for this we round the opacity value on RGBa colors here |
| 923 |
// and save it a second time to the color picker object. |
| 924 |
if ( alpha != 100 ) { |
| 925 |
color = color.replace( /[^,]+(?=\))/, ( alpha / 100 ).toFixed( 2 ) ); |
| 926 |
} |
| 927 |
|
| 928 |
$control.wpColorPicker( 'color', color ); |
| 929 |
}); |
| 930 |
|
| 931 |
// Bind event handler for clicking on the 'Clear' button. |
| 932 |
$container.find( '.button.wp-picker-clear' ).on( 'click', function() { |
| 933 |
var key = $control.attr( 'data-customize-setting-link' ); |
| 934 |
|
| 935 |
// The #fff color is delibrate here. This sets the color picker to white instead of the |
| 936 |
// defult black, which puts the color picker in a better place to visually represent empty. |
| 937 |
$control.wpColorPicker( 'color', '' ); |
| 938 |
|
| 939 |
// Set the actual option value to empty string. |
| 940 |
wp.customize( key, function( obj ) { |
| 941 |
obj.set( '' ); |
| 942 |
}); |
| 943 |
|
| 944 |
pagelayer_update_alpha_value_on_alpha_slider( 100, $alphaSlider ); |
| 945 |
}); |
| 946 |
|
| 947 |
// Bind event handler for clicking on the 'Default' button. |
| 948 |
$container.find( '.button.wp-picker-default' ).on( 'click', function() { |
| 949 |
var alpha = pagelayer_get_alpha_value_from_color( defaultColor ); |
| 950 |
|
| 951 |
pagelayer_update_alpha_value_on_alpha_slider( alpha, $alphaSlider ); |
| 952 |
}); |
| 953 |
|
| 954 |
// Bind event handler for typing or pasting into the input. |
| 955 |
$control.on( 'input', function() { |
| 956 |
var value = jQuery( this ).val(); |
| 957 |
var alpha = pagelayer_get_alpha_value_from_color( value ); |
| 958 |
|
| 959 |
pagelayer_update_alpha_value_on_alpha_slider( alpha, $alphaSlider ); |
| 960 |
}); |
| 961 |
|
| 962 |
// Update all the things when the slider is interacted with. |
| 963 |
$alphaSlider.slider().on( 'slide', function( event, ui ) { |
| 964 |
var alpha = parseFloat( ui.value ) / 100.0; |
| 965 |
|
| 966 |
pagelayer_update_alpha_value_on_color_control( alpha, $control, $alphaSlider, false ); |
| 967 |
|
| 968 |
// Change value shown on slider handle. |
| 969 |
jQuery( this ).find( '.ui-slider-handle' ).text( ui.value ); |
| 970 |
}); |
| 971 |
}, timeOut); |
| 972 |
|
| 973 |
timeOut += 20; |
| 974 |
}); |
| 975 |
} |
| 976 |
|
| 977 |
/** |
| 978 |
* Override the stock color.js toString() method to add support for |
| 979 |
* outputting RGBa or Hex. |
| 980 |
*/ |
| 981 |
Color.prototype.toString = function( flag ) { |
| 982 |
|
| 983 |
// If our no-alpha flag has been passed in, output RGBa value with 100% opacity. |
| 984 |
// This is used to set the background color on the opacity slider during color changes. |
| 985 |
if ( 'no-alpha' == flag ) { |
| 986 |
return this.toCSS( 'rgba', '1' ).replace( /\s+/g, '' ); |
| 987 |
} |
| 988 |
|
| 989 |
// If we have a proper opacity value, output RGBa. |
| 990 |
if ( 1 > this._alpha ) { |
| 991 |
return this.toCSS( 'rgba', this._alpha ).replace( /\s+/g, '' ); |
| 992 |
} |
| 993 |
|
| 994 |
// Proceed with stock color.js hex output. |
| 995 |
var hex = parseInt( this._color, 10 ).toString( 16 ); |
| 996 |
if ( this.error ) { return ''; } |
| 997 |
if ( hex.length < 6 ) { |
| 998 |
for ( var i = 6 - hex.length - 1; i >= 0; i-- ) { |
| 999 |
hex = '0' + hex; |
| 1000 |
} |
| 1001 |
} |
| 1002 |
|
| 1003 |
return '#' + hex; |
| 1004 |
}; |
| 1005 |
|
| 1006 |
/** |
| 1007 |
* Given an RGBa, RGB, or hex color value, return the alpha channel value. |
| 1008 |
*/ |
| 1009 |
function pagelayer_get_alpha_value_from_color( value ) { |
| 1010 |
var alphaVal; |
| 1011 |
|
| 1012 |
// Remove all spaces from the passed in value to help our RGBa regex. |
| 1013 |
value = value.replace( / /g, '' ); |
| 1014 |
|
| 1015 |
if ( value.match( /rgba\(\d+\,\d+\,\d+\,([^\)]+)\)/ ) ) { |
| 1016 |
alphaVal = parseFloat( value.match( /rgba\(\d+\,\d+\,\d+\,([^\)]+)\)/ )[1] ).toFixed(2) * 100; |
| 1017 |
alphaVal = parseInt( alphaVal ); |
| 1018 |
} else { |
| 1019 |
alphaVal = 100; |
| 1020 |
} |
| 1021 |
|
| 1022 |
return alphaVal; |
| 1023 |
} |
| 1024 |
|
| 1025 |
/** |
| 1026 |
* Force update the alpha value of the color picker object and maybe the alpha slider. |
| 1027 |
*/ |
| 1028 |
function pagelayer_update_alpha_value_on_color_control( alpha, $control, $alphaSlider, update_slider ) { |
| 1029 |
var iris, colorPicker, color; |
| 1030 |
|
| 1031 |
iris = $control.data( 'a8cIris' ); |
| 1032 |
colorPicker = $control.data( 'wpWpColorPicker' ); |
| 1033 |
|
| 1034 |
// Set the alpha value on the Iris object. |
| 1035 |
iris._color._alpha = alpha; |
| 1036 |
|
| 1037 |
// Store the new color value. |
| 1038 |
color = iris._color.toString(); |
| 1039 |
|
| 1040 |
// Set the value of the input. |
| 1041 |
$control.val( color ).trigger('color_change'); |
| 1042 |
|
| 1043 |
// Update the background color of the color picker. |
| 1044 |
colorPicker.toggler.css({ |
| 1045 |
'background-color': color |
| 1046 |
}); |
| 1047 |
|
| 1048 |
// Maybe update the alpha slider itself. |
| 1049 |
if ( update_slider ) { |
| 1050 |
pagelayer_update_alpha_value_on_alpha_slider( alpha, $alphaSlider ); |
| 1051 |
} |
| 1052 |
|
| 1053 |
// Update the color value of the color picker object. |
| 1054 |
$control.wpColorPicker( 'color', color ); |
| 1055 |
} |
| 1056 |
|
| 1057 |
/** |
| 1058 |
* Update the slider handle position and label. |
| 1059 |
*/ |
| 1060 |
function pagelayer_update_alpha_value_on_alpha_slider( alpha, $alphaSlider ){ |
| 1061 |
$alphaSlider.slider( 'value', alpha ); |
| 1062 |
$alphaSlider.find( '.ui-slider-handle' ).text( alpha.toString() ); |
| 1063 |
} |
| 1064 |
|
| 1065 |
/** |
| 1066 |
* Generates random string. |
| 1067 |
*/ |
| 1068 |
|
| 1069 |
// Generates a random string of "n" characters |
| 1070 |
function pagelayer_generate_randstr(n, special){ |
| 1071 |
var text = ''; |
| 1072 |
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
| 1073 |
|
| 1074 |
special = special || 0; |
| 1075 |
if(special){ |
| 1076 |
possible = possible + '&#$%@'; |
| 1077 |
} |
| 1078 |
|
| 1079 |
for(var i=0; i < n; i++){ |
| 1080 |
text += possible.charAt(Math.floor(Math.random() * possible.length)); |
| 1081 |
} |
| 1082 |
|
| 1083 |
return text; |
| 1084 |
}; |
| 1085 |
|
| 1086 |
|
| 1087 |
// PHP equivalent empty() |
| 1088 |
function pagelayer_empty(mixed_var) { |
| 1089 |
|
| 1090 |
var undef, key, i, len; |
| 1091 |
var emptyValues = [undef, null, false, 0, '', '0']; |
| 1092 |
|
| 1093 |
for (i = 0, len = emptyValues.length; i < len; i++) { |
| 1094 |
if (mixed_var === emptyValues[i]) { |
| 1095 |
return true; |
| 1096 |
} |
| 1097 |
} |
| 1098 |
|
| 1099 |
if (typeof mixed_var === 'object') { |
| 1100 |
for (key in mixed_var) { |
| 1101 |
// TODO: should we check for own properties only? |
| 1102 |
//if (mixed_var.hasOwnProperty(key)) { |
| 1103 |
return false; |
| 1104 |
//} |
| 1105 |
} |
| 1106 |
return true; |
| 1107 |
} |
| 1108 |
|
| 1109 |
return false; |
| 1110 |
}; |
| 1111 |
|
| 1112 |
// Slider handler |
| 1113 |
function pagelayer_control_slider_handler(){ |
| 1114 |
|
| 1115 |
// Change the value of the input field as the slider is moved |
| 1116 |
jQuery('.pagelayer-slider').on('input', function(event, ui) { |
| 1117 |
var sliderValue = jQuery(this).val(); |
| 1118 |
jQuery(this).parent().find('.customize-control-slider-value').val(sliderValue).trigger('input'); |
| 1119 |
}); |
| 1120 |
|
| 1121 |
// Update slider if the input field loses focus as it's most likely changed |
| 1122 |
jQuery('.customize-control-slider-value').on('change', function() { |
| 1123 |
var resetValue = jQuery(this).val(); |
| 1124 |
var slider = jQuery(this).parent().find('.pagelayer-slider'); |
| 1125 |
var sliderMinValue = parseInt(slider.attr('min')); |
| 1126 |
var sliderMaxValue = parseInt(slider.attr('max')); |
| 1127 |
|
| 1128 |
// Make sure our manual input value doesn't exceed the minimum & maxmium values |
| 1129 |
if(resetValue < sliderMinValue) { |
| 1130 |
resetValue = sliderMinValue; |
| 1131 |
jQuery(this).val(resetValue).trigger('input'); |
| 1132 |
} |
| 1133 |
if(resetValue > sliderMaxValue) { |
| 1134 |
resetValue = sliderMaxValue; |
| 1135 |
jQuery(this).val(resetValue).trigger('input'); |
| 1136 |
} |
| 1137 |
slider.val(resetValue); |
| 1138 |
}); |
| 1139 |
} |