1jQuery( document ).ready( function ( $ ) { 2 3 /** 4 * add jQuery functions 5 */ 6 $.fn.extend({ 7 8 /** 9 * center elements on screen 10 * @param {string} position // relative, absolute or fixed (default) 11 */ 12 eeCenter: function(position = 'fixed') { 13 position = typeof position !== 'undefined' && position !== '' ? position : 'fixed'; 14 let window_height = $(window).height(), 15 window_width = $(window).width(), 16 container_height = this.outerHeight(), 17 container_width = this.outerWidth(), 18 element_top = 0, 19 element_left = 0; 20 // top 21 if(container_height < window_height) { 22 element_top = (( window_height / 2 ) - container_height ) / 2; 23 element_top = position === 'fixed' 24 ? element_top + window_height / 8 25 : element_top + $(window).scrollTop; 26 } else if (container_height !== window_height) { 27 element_top= $(window).scrollTop 28 } 29 30 // left 31 if (container_width < window_width) { 32 element_left = ( window_width - container_width ) / 2; 33 element_left = position === 'fixed' 34 ? element_left 35 : element_left + $(window).scrollLeft; 36 } else if (container_width !== window_width) { 37 element_left = $(window).scrollLeft; 38 } 39 40 this.css({ 41 'position': position, 42 'top': Math.max(1, element_top) + 'px', 43 'left': Math.max(0, element_left) + 'px', 44 'transform': 'unset', 45 'margin': 0 46 }); 47 return this; 48 }, 49 50 51 /** 52 * Shortcut for adding a window overlay quickly if none exists in the dom 53 * 54 * @param {int} opacity allows the setting of the opacity value for the overlay via client. opacity[0] = webkit opacity, opacity[1] = value for alpha(opacity=). 55 * @return {object} 56 */ 57 eeAddOverlay : function( opacity ) { 58 opacity = typeof opacity === 'undefined' || opacity > 1 ? 0.5 : opacity; 59 const overlay = '<div id="ee-overlay"></div>'; 60 $(overlay).appendTo('body').css({ 61 'position' : 'fixed', 62 'top' : 0, 63 'left' : 0, 64 'width' : '100%', 65 'height' : '100%', 66 'background' : '#000', 67 'opacity' : opacity, 68 'filter' : 'alpha(opacity=' + ( opacity * 100 ) + ')', 69 'z-index' : 10000 70 }); 71 return this; 72 }, 73 74 75 76 77 /** 78 * Shortcut for removing a window overlay quickly if none exists in the dom (will destroy) 79 * @return {object} 80 */ 81 eeRemoveOverlay : function() { 82 $('#ee-overlay').remove(); 83 return this; 84 }, 85 86 87 /** 88 * adds a scrollTo action for jQuery 89 * @return {object} 90 */ 91 eeScrollTo : function( speed ) { 92 const selector = this; 93 speed = typeof(speed) === 'undefined' ? 2000 : speed; 94 $("html,body").animate({ 95 scrollTop: selector.offset().top - 80 96 }, speed); 97 return this; 98 }, 99 100 101 /** 102 * return the correct value for a form input regardless of it's type 103 */ 104 eeInputValue : function () { 105 const inputType = this.prop('type'); 106 if ( inputType === 'checkbox' || inputType === 'radio' ) { 107 return this.prop('checked'); 108 } else { 109 return this.val(); 110 } 111 }, 112 113 114 /** 115 * return an object of URL params 116 */ 117 eeGetParams : function () { 118 const urlParams = {}; 119 let url = this.attr('href'); 120 url = typeof url !== 'undefined' && url !== '' ? url : location.href; 121 url = url.substring( url.indexOf( '?' ) + 1 ).split( '#' ); 122 urlParams.hash = typeof url[1] !== 'undefined' && url[1] !== '' ? url[1] : ''; 123 const qs = url[0].split('&'); 124 for( let i = 0; i < qs.length; i++ ) { 125 qs[ i ] = qs[ i ].split( '=' ); 126 urlParams[ qs[ i ][0] ] = decodeURIComponent( qs[ i ][1] ); 127 } 128 return urlParams; 129 }, 130 131 132 /** 133 * Set element visibility to hidden 134 * 135 */ 136 eeInvisible: function() { 137 return this.each( function() { 138 $(this).css("visibility", "hidden"); 139 }); 140 }, 141 142 143 /** 144 * Set element visibility to visible 145 * 146 */ 147 eeVisible: function() { 148 return this.each( function() { 149 $(this).css("visibility", "visible"); 150 }); 151 }, 152 153 154 155 /** 156 * This helper method simply removes any matching items from a js array.
157 * @param {array} arr js array to remove items from 158 * @param {string} ind value of what element is being removed 159 * @return {array} new array with removed items 160 */ 161 removeFromArray: function( arr, ind ) { 162 return arr.filter( function(i) { 163 return i !== ind; 164 }); 165 } 166 167 168 }); 169 170 171 const existing_message = $('#message'); 172 $('.show-if-js').css({ 'display' : 'inline-block' }); 173 $('.hide-if-no-js').removeClass( 'hide-if-no-js' ); 174 175 176 window.do_before_admin_page_ajax = function do_before_admin_page_ajax() { 177 // stop any message alerts that are in progress 178 $(existing_message).stop().hide(); 179 // spinny things pacify the masses 180 $("#espresso-ajax-loading").eeCenter("fixed").show(); 181 }; 182 183 184 185 window.show_admin_page_ajax_msg = function show_admin_page_ajax_msg( response, beforeWhat, removeExisting, doScroll ) { 186 removeExisting = typeof removeExisting !== false; 187 doScroll = typeof doScroll === 'undefined' ? true : doScroll; 188 const messages = $('#ajax-notices-container'); 189 // if there is no existing message... 190 if ( removeExisting === true ) { 191 messages.html(''); 192 } 193 // make sure there is at least ONE notification to display 194 if ( 195 ( typeof response !== 'object' ) || 196 ! ( // or NOT the following 197 ( typeof response.success !== 'undefined' && response.success !== '' && response.success !== false ) || 198 ( typeof response.attention !== 'undefined' && response.attention !== '' && response.attention !== false ) || 199 ( typeof response.errors !== 'undefined' && response.errors !== '' && response.errors !== false ) 200 ) 201 ) { 202 console.log( JSON.stringify( 'show_admin_page_ajax_msg response: ', null, 4 ) ); 203 console.log( response ); 204 return; 205 } 206 207 $( '#espresso-ajax-loading' ).fadeOut( 'fast' ); 208 let msg = ''; 209 // no existing errors? 210 if ( typeof(response.errors) !== 'undefined' && response.errors !== '' && response.errors !== false ) { 211 msg = msg + '<div class="ee-admin-notification ee-status-outline ee-status-bg--error hidden"><p>' + response.errors + '</p></div>'; 212 } 213 // attention notice? 214 if ( typeof(response.attention) !== 'undefined' && response.attention !== '' && response.attention !== false ) { 215 msg = msg + '<div class="ee-admin-notification ee-status-outline ee-status-bg--attention hidden"><p>' + response.attention + '</p></div>'; 216 } 217 // success ? 218 if ( typeof(response.success) !== 'undefined' && response.success !== '' && response.success !== false ) { 219 msg = msg + '<div class="ee-admin-notification ee-status-outline ee-status-bg--success hidden ee-fade-away"><p>' + response.success + '</p></div>'; 220 } 221 messages.html( msg ); 222 const new_messages = messages; 223 messages.remove(); 224 beforeWhat = typeof beforeWhat !== 'undefined' && beforeWhat !== '' ? beforeWhat : '.nav-tab-wrapper'; 225 // set message content 226 if ( doScroll ) { 227 $( 'body, html' ).animate( { scrollTop : 0 }, 'normal', function() { 228 $( beforeWhat ).before( new_messages ); 229 } ); 230 } else { 231 $( beforeWhat ).before( new_messages ); 232 } 233 // and display it 234 new_messages.find('.ee-admin-notification').each( function() { 235 $( this ).removeAttr( 'style' ).removeClass( 'hidden' ).show(); 236 // but sometimes not too long 237 if ( $( this ).hasClass( 'ee-fade-away' ) ) { 238 $( this ).delay( 8000 ).fadeOut(); 239 } 240 } ); 241 242 }; 243 244 245 function display_espresso_notices() { 246 $('.espresso-notices').slideDown(); 247 $('.espresso-notices.fade-away').delay(10000).slideUp(); 248 } 249 display_espresso_notices(); 250 251 252 253 function display_espresso_ajax_notices( message, type ) { 254 type = typeof type !== 'undefined' && type !== '' ? type : 'error'; 255 const notice_id = '#espresso-ajax-notices-' + type; 256 $( notice_id + ' .espresso-notices-msg' ).text( message ); 257 $( '#espresso-ajax-notices' ).eeCenter('fixed'); 258 $( notice_id ).slideDown('fast'); 259 $('.espresso-ajax-notices.fade-away').delay(10000).slideUp('fast'); 260 } 261 262 263 //close btn for notifications 264 $('.close-espresso-notice').on( 'click', function(e){ 265 $(this).parent().hide(); 266 e.preventDefault(); 267 e.stopPropagation(); 268 }); 269 270 271 272 // submit form 273 $('.submit-this-form').click(function(e) { 274 e.preventDefault(); 275 e.stopPropagation(); 276 $(this).closest('form').submit(); 277 return false;
278 }); 279 280 281 282 // generic click event for displaying and giving focus to an element and hiding control 283 $('.display-the-hidden').on( 'click', function(e) { 284 // get target element from "this" (the control element's) "rel" attribute 285 const item_to_display = $(this).attr("rel"); 286 // alert( 'item_to_display = ' + item_to_display ); 287 // hide the control element 288 $(this).fadeOut(50).hide(); 289 // display the target's div container - use slideToggle or removeClass 290 $('#'+item_to_display+'-dv').slideToggle(250, function() { 291 // display the target div's hide link 292 $('#hide-'+item_to_display).css('display', 'flex').fadeIn(50); 293 // if hiding/showing a form input, then id of the form input must = item_to_display 294 $('#'+item_to_display).focus(); // add focus to the target 295 }); 296 e.preventDefault(); 297 e.stopPropagation(); 298 return false; 299 }); 300 301 302 303 // generic click event for re-hiding an element and displaying its display control 304 $('.hide-the-displayed').on( 'click', function(e) { 305 // get target element from "this" (the control element's) "rel" attribute 306 const item_to_hide = $(this).attr("rel"); 307 // hide the control element 308 $(this).fadeOut(50).hide(); 309 // hide the target's div container - use slideToggle or addClass 310 $('#'+item_to_hide+'-dv').slideToggle(250, function() { 311 // display the control element that toggles display of this element 312 $('#display-'+item_to_hide).css('display', 'flex').fadeIn(50); 313 }); 314 e.preventDefault(); 315 e.stopPropagation(); 316 return false; 317 }); 318 319 320 321 // generic click event for resetting a form input - can be coupled with the "hide_the_displayed" function above 322 $('.cancel').click(function(e) { 323 // get target element from "this" (the control element's) "rel" attribute 324 const item_to_cancel = $(this).attr("rel"); 325 // set target element's value to an empty string 326 $('#'+item_to_cancel).val(''); 327 e.preventDefault(); 328 e.stopPropagation(); 329 }); 330 331 332 333 /** 334 * when a Country select dropdown changes, find its corresponding state select dropdown 335 * and hide all option groups that do not correspond to the selected country 336 */ 337 $( '.ee-country-select-js' ).change( 338 function () { 339 let country_select_id = $(this).attr('id'), 340 selected_country = $(this).find("option:selected").text(), 341 state_select_id = '', 342 $state_select = null, 343 selected_state = null, 344 valid_option = false; 345 346 // console.log( ' ' ); 347 // console.log( 'COUNTRY SELECTION CHANGED' ); 348 // console.log( 'country_select_id: ' + country_select_id ); 349 // console.log( 'selected_country: ' + selected_country ); 350 // console.log( 'state_select_id: ' + state_select_id ); 351 // console.log( 'country_select_id.indexOf( country ): ' + ~country_select_id.indexOf( 'country' ) ); 352 353 // is this country question a system question ? 354 if ( ~country_select_id.indexOf( 'country' ) ) { 355 // good, then just swap 'country' for 'state' to get the corresponding state select id 356 state_select_id = country_select_id.replace( 'country', 'state' ); 357 } else { 358 // no ??? dang... now we have to try and find the corresponding state question. 359 let $state_div = $(this).parent().next('.ee-state-select-js-input-dv'); 360 if ( ! $state_div.length ) { 361 // console.log( 'State Select div not found after Country Select div' ); 362 $state_div = $(this).parent().prev( '.ee-state-select-js-input-dv' ); 363 } 364 if ( ! $state_div.length ) { 365 console.log( 366 'Can not find corresponding State select for Country select with id: ' 367 + country_select_id + '. Ideally the State question should be immediately after the Country question.' 368 ); 369 } 370 $state_select = $state_div.find('.ee-state-select-js'); 371 if ( $state_select === null || ! $state_select.length ) { 372 console.log( 373 'Invalid "country_select_id"! Can not find corresponding State select for Country select with id: ' 374 + country_select_id 375 ); 376 return; 377 } 378 state_select_id = $state_select.attr( 'id' ); 379 } 380 if ( ( $state_select === null || ! $state_select.length ) && state_select_id !== '' ) { 381 $state_select = $( '#' + state_select_id ); 382 } 383 // console.log('state_select_id: ' + state_select_id, false); 384 385 if ( $state_select.length ) { 386 // console.log('FOUND STATE SELECTOR'); 387 // grab the currently selected state (if there is one) 388 selected_state = $state_select.find( ":selected" ).text(); 389 // console.log( 'selected_state: ' + selected_state ); 390 // display and enable all optgroups 391 $( 'optgroup', $state_select ) 392 .show() 393 .children('option') 394 .prop('disabled', false) 395 .show(); 396 // if a valid country is selected 397 if ( selected_country !== '' ) { 398 // console.log('Hide unselected countries'); 399 // hide all unselected optgroups and disable their options 400 $( 'optgroup:not([label="' + selected_country + '"])', $state_select ) 401 .hide() 402 .children('option') 403 .prop('selected', false) 404 .prop('disabled', true) 405 .hide(); 406 // then enable all options for selected country, but don't select anything 407 $('optgroup[label="' + selected_country + '"]', $state_select) 408 .show() 409 .children('option') 410 .prop('disabled', false) 411 .show(); 412 // if a valid corresponding state select exists 413 if ( selected_state.length ) { 414 // loop through all of its optgroups 415 $state_select.find( 'optgroup' ).each( 416 function () { 417 // if this is the selected optgroup 418 if ( $(this).attr('label') === selected_country ) { 419 // then make sure its options are enabled 420 $(this).show().children('option').prop('disabled', false); 421 // and it contains the selected option 422 if ( $(this).text().indexOf(selected_state) !== -1 ) { 423 // then loop through each of its options 424 $(this).find('option').each( 425 function () { 426 // console.log('option text: ' + $(this).text() ); 427 // was this option match the previously selected state ? 428 if ($(this).text() === selected_state) { 429 valid_option = true; 430 // make sure it's set as the selected option 431 $(this).prop('selected', true); 432 $state_select.change(); 433 } else { 434 $(this).prop('selected', false); 435 } 436 } 437 ); 438 } 439 } 440 } 441 ); 442 } 443 // console.log( 'valid_option: ' + valid_option );
444 // if the previously selected state is not valid 445 if ( valid_option ) { 446 // console.log('VALID OPTION'); 447 // previously selected state IS valid 448 // so make sure the empty placeholder is unselected 449 $state_select 450 .find('optgroup[label=""]') 451 .hide() 452 .find('option[value=""]') 453 .prop('selected', false) 454 .prop('disabled', true); 455 456 } else { 457 // console.log('INVALID OPTION'); 458 // then find the empty placeholder and select it 459 $state_select 460 .find('optgroup[label=""]') 461 .show() 462 .find('option[value=""]') 463 .prop('disabled', false) 464 .prop('selected', true) 465 .val(''); 466 467 } 468 } else { 469 // console.log( 'NO COUNTRY SELECTED' ); 470 // display any hidden optgroups and re-enable options 471 $state_select.find( 'optgroup' ).each( 472 function () { 473 // console.log( 'optgroup: ' + $(this).val() ); 474 $(this).show().children('option').prop('disabled', false); 475 } 476 ); 477 } 478 } 479 } 480 ); 481 482 483 484 485 /** 486 * @function rgb2hex 487 * converts hex format to a rgb color 488 * @see http://jsfiddle.net/Mottie/xcqpF/1/light/ 489 * 490 * @param {string} rgb 491 * @return string 492 */ 493 window.eeRgbToHex = function (rgb) { 494 // console_log('rgb', rgb, false); 495 let hex = ''; 496 const rgb_parts = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i); 497 if (rgb_parts && rgb_parts.length === 4) { 498 hex = "#" + ("0" + parseInt(rgb_parts[1], 10).toString(16)).slice(-2); 499 hex += ("0" + parseInt(rgb_parts[2], 10).toString(16)).slice(-2); 500 hex += ("0" + parseInt(rgb_parts[3], 10).toString(16)).slice(-2); 501 } 502 hex = hex !== '' ? hex : rgb; 503 // console_log('hex', hex, false); 504 return hex; 505 }; 506 507 508 509 /** 510 * @function getParentBackgroundColor 511 * recursively walks up the DOM looking for the first element with 512 * some sort of color set for the background, then returns that value 513 * 514 * @param {object} domElement 515 * @return string 516 */ 517 window.eeGetParentBackgroundColor = function (domElement) { 518 // set default color of white with full opacity 519 let BackgroundColor = 'rgba(255,255,255,1)'; 520 const $parent = domElement.parent(); 521 // if no BG color is found by the time we get to the "<html>" tag, then just return the default; 522 if ($parent.length && $parent.prop('tagName') !== 'HTML') { 523 // console_log('$parent', $parent.prop('tagName') + ' #' + $parent.attr('id'), true); 524 BackgroundColor = $parent.css('backgroundColor'); 525 // console_log('BackgroundColor', BackgroundColor, false); 526 if ( 527 typeof BackgroundColor === 'undefined' 528 || BackgroundColor === 'transparent' 529 || BackgroundColor === 'inherit' 530 || BackgroundColor === 'rgba(0, 0, 0, 0)' 531 || BackgroundColor === '' 532 ) { 533 return eeGetParentBackgroundColor($parent); 534 } 535 } 536 return BackgroundColor; 537 }; 538 539 540 // display a "you need to enable cookies" message if cookies are disabled in the browser settings 541 if (! navigator.cookieEnabled) { 542 $('#ee-cookies-not-set-msg').removeClass('hidden'); 543 } 544 545 546 window.espressoAnnounceToScreenReader = function (text) { 547 const $ariaLive = $('#espresso-aria-live-region'); 548 const announcement = text.trim(); 549 if (! $ariaLive.length || announcement === '') { 550 return; 551 } 552 // clear first to improve announcement reliability 553 $ariaLive.text(''); 554 setTimeout(function () { 555 $ariaLive.text(announcement); 556 }, 50); 557 } 558}); 559 560 561 562//functions available to window 563 564 565 566/**
567 * Function : dump() 568 * Arguments: The data - array,hash(associative array),object 569 * The level - OPTIONAL 570 * Returns : The textual representation of the array. 571 * This function was inspired by the print_r function of PHP. 572 * This will accept some data as the argument and return a 573 * text that will be a more readable version of the 574 * array/hash/object that is given. 575 * Docs: http://www.openjs.com/scripts/others/dump_function_php_print_r.php 576 */ 577function dump(arr,level) { 578 let dumped_text = ""; 579 if ( ! level ) { 580 level = 0; 581 } 582 583 //The padding given at the beginning of the line. 584 let level_padding = ""; 585 for(let j=0; j<level+1; j++) { 586 level_padding += " "; 587 } 588 //Array/Hashes/Objects 589 if( typeof(arr) === 'object' ) { 590 for(const item in arr) { 591 if ( typeof item !== 'undefined' && arr.hasOwnProperty( item ) ) { 592 const value = arr[item]; 593 //If it is an array 594 if( typeof(value) === 'object' ) { 595 dumped_text += level_padding + "'" + item + "' ...\n"; 596 dumped_text += dump(value,level+1); 597 } else { 598 dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n"; 599 } 600 } 601 } 602 } else { //Stings/Chars/Numbers etc. 603 dumped_text = "===>"+arr+"<===("+typeof(arr)+")"; 604 } 605 return dumped_text; 606} 607 608/** 609 * @function console_log 610 * print to the browser console 611 * @param {string} item_name 612 * @param {*} value 613 * @param {boolean} spacer 614 */ 615window.console_log = function( item_name, value, spacer ) { 616 if ( typeof value === 'object' ) { 617 console_log_object( item_name, value, 0 ); 618 } else { 619 if ( spacer === true ) { 620 console.log( ' ' ); 621 } 622 if ( typeof item_name !== 'undefined' && typeof value !== 'undefined' && value !== '' ) { 623 console.log( item_name + ' = ' + value ); 624 } else if ( typeof item_name !== 'undefined' ) { 625 console.log( item_name ); 626 } 627 } 628}; 629 630/** 631 * @function console_log_object 632 * print object to the browser console 633 * @param {string} obj_name 634 * @param {object} obj 635 * @param {number} depth 636 */ 637window.console_log_object = function( obj_name, obj, depth ) { 638 depth = typeof depth !== 'undefined' ? depth : 0; 639 let spacer = ''; 640 for (let i = 0; i < depth; i++ ) { 641 spacer = spacer + ' '; 642 } 643 if ( typeof obj === 'object' ) { 644 if ( !depth ) { 645 console.log( ' ' ); 646 } 647 if ( typeof obj_name !== 'undefined' ) { 648 console.log( spacer + 'OBJ: ' + obj_name + ' : ' ); 649 } else { 650 console.log( spacer + 'OBJ : ' ); 651 } 652 jQuery.each( 653 obj, function ( index, value ) { 654 if ( typeof value === 'object' && depth < 3 ) { 655 depth++; 656 console_log_object( index, value, depth ); 657 } else { 658 console.log( spacer + index + ' = ' + value ); 659 } 660 depth = 0; 661 } 662 ); 663 } else { 664 console_log( spacer + obj_name, obj, true ); 665 } 666}; 667 668 669/** 670 * @function object_exists 671 * returns true if object exists and displays console error if it does not 672 * @param {object} $object 673 * @param {string} object_name 674 * @param log_error 675 * @return boolean 676 */ 677function object_exists($object, object_name, log_error = true) { 678 if ($object.length) { 679 return true; 680 } 681 if (log_error) { 682 console_log('ERROR: object not found', object_name, false); 683 } 684 return false; 685}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.