1(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 ) { 13 position = typeof position !== 'undefined' && position !== '' ? position : 'fixed'; 14 var element_top = (( $( window ).height() / 2 ) - this.outerHeight() ) / 2; 15 element_top = position === 'fixed' ? element_top + $( window ).height() / 8 : element_top + $( window ).scrollTop; 16 element_top = Math.max( 0, element_top ); 17 var element_left = ( $( window ).width() - this.outerWidth() ) / 2; 18 element_left = position === 'fixed' ? element_left : element_left + $( window ).scrollLeft; 19 element_left = Math.max( 0, element_left ); 20 this.css({ 'position' : position, 'top' : element_top + 'px', 'left' : element_left + 'px' , 'margin' : 0 }); 21 return this; 22 }, 23 24 25 /** 26 * Shortcut for adding a window overlay quickly if none exists in the dom 27 * 28 * @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=). 29 * @return {jQuery} 30 */ 31 eeAddOverlay : function( opacity ) { 32 opacity = typeof opacity === 'undefined' || opacity > 1 ? 0.5 : opacity; 33 var overlay = '<div id="ee-overlay"></div>'; 34 $(overlay).appendTo('body').css({ 35 'position' : 'fixed', 36 'top' : 0, 37 'left' : 0, 38 'width' : '100%', 39 'height' : '100%', 40 'background' : '#000', 41 'opacity' : opacity, 42 'filter' : 'alpha(opacity=' + ( opacity * 100 ) + ')', 43 'z-index' : 10000 44 }); 45 return this; 46 }, 47 48 49 50 51 /** 52 * Shortcut for removing a window overlay quickly if none exists in the dom (will destroy) 53 * @return {jQuery} 54 */ 55 eeRemoveOverlay : function() { 56 $('#ee-overlay').remove(); 57 return this; 58 }, 59 60 61 /** 62 * adds a scrollTo action for jQuery 63 * @return {jQuery} 64 */ 65 eeScrollTo : function( speed ) { 66 var selector = this; 67 speed = typeof(speed) === 'undefined' ? 2000 : speed; 68 $("html,body").animate({ 69 scrollTop: selector.offset().top - 80 70 }, speed); 71 return this; 72 }, 73 74 75 /** 76 * return the correct value for a form input regardless of it's type 77 */ 78 eeInputValue : function () { 79 var inputType = this.prop('type'); 80 if ( inputType === 'checkbox' || inputType === 'radio' ) { 81 return this.prop('checked'); 82 } else { 83 return this.val(); 84 } 85 }, 86 87 88 /** 89 * return an object of URL params 90 */ 91 eeGetParams : function () { 92 var urlParams = {}; 93 var url = this.attr('href'); 94 url = typeof url !== 'undefined' && url !== '' ? url : location.href; 95 url = url.substring( url.indexOf( '?' ) + 1 ).split( '#' ); 96 urlParams.hash = typeof url[1] !== 'undefined' && url[1] !== '' ? url[1] : ''; 97 var qs = url[0].split( '&' ); 98 for( var i = 0; i < qs.length; i++ ) { 99 qs[ i ] = qs[ i ].split( '=' ); 100 urlParams[ qs[ i ][0] ] = decodeURIComponent( qs[ i ][1] ); 101 } 102 return urlParams; 103 }, 104 105 106 /** 107 * Set element visibility to hidden 108 * 109 */ 110 eeInvisible: function() { 111 return this.each( function() { 112 $(this).css("visibility", "hidden"); 113 }); 114 }, 115 116 117 /** 118 * Set element visibility to visible 119 * 120 */ 121 eeVisible: function() { 122 return this.each( function() { 123 $(this).css("visibility", "visible"); 124 }); 125 }, 126 127 128 129 /** 130 * This helper method simply removes any matching items from a js array. 131 * @param {array} arr js array to remove items from 132 * @param {string} ind value of what element is being removed 133 * @return {array} new array with removed items 134 */ 135 removeFromArray: function( arr, ind ) { 136 return arr.filter( function(i) { 137 return i !== ind; 138 }); 139 } 140 141 142 }); 143 144}( jQuery )); 145 146 147jQuery(document).ready(function($) { 148 149 var existing_message = $('#message'); 150 $('.show-if-js').css({ 'display' : 'inline-block' }); 151 $('.hide-if-no-js').removeClass( 'hide-if-no-js' ); 152 153 154 window.do_before_admin_page_ajax = function do_before_admin_page_ajax() { 155 // stop any message alerts that are in progress 156 $(existing_message).stop().hide(); 157 // spinny things pacify the masses 158 $('#espresso-ajax-loading').eeCenter().show(); 159 }; 160 161 162
163 window.show_admin_page_ajax_msg = function show_admin_page_ajax_msg( response, beforeWhat, closeModal ) { 164 console.log( response ); 165 $('#espresso-ajax-loading').fadeOut('fast'); 166 if (( typeof(response.success) !== 'undefined' && response.success !== '' ) || ( typeof(response.errors) !== 'undefined' && response.errors !== '' )) { 167// if ( closeModal === undefined ) { 168// closeModal = false; 169// } 170 var fadeaway = true; 171 var msg = ''; 172 // if there is no existing message... 173 if ( $(existing_message).length === 0 ) { 174 //create one and add it to the DOM 175 $('.nav-tab-wrapper').before( '<div id="message" class="updated hidden"></div>' ); 176 } 177 // success ? 178 if ( typeof(response.success) !== 'undefined' && response.success !== '' && response.success !== false ) { 179 msg = '<p>' + response.success + '</p>'; 180 } 181 // no existing errors? 182 if ( typeof(response.errors) !== 'undefined' && response.errors !== '' && response.errors !== false ) { 183 msg = '<p>' + response.errors + '</p>'; 184 $(existing_message).removeClass('updated').addClass('error'); 185 fadeaway = false; 186 } 187 // set message content 188 $(existing_message).html(msg); 189 // change location in the DOM if so desired 190 if ( typeof(beforeWhat) !== 'undefined' && beforeWhat !== '' ) { 191 var moved_message = $(existing_message); 192 $(existing_message).remove(); 193 $( beforeWhat ).before( moved_message ); 194 } 195 // and display it 196 if ( fadeaway === true ) { 197 $(existing_message).removeAttr('style').removeClass('hidden').show().delay(8000).fadeOut(); 198 } else { 199 $(existing_message).removeAttr('style').removeClass('hidden').show(); 200 } 201 } 202 }; 203 204 205 function display_espresso_notices() { 206 $('#espresso-notices').eeCenter(); 207 $('.espresso-notices').slideDown(); 208 $('.espresso-notices.fade-away').delay(10000).slideUp(); 209 } 210 display_espresso_notices(); 211 212 213 214 function display_espresso_ajax_notices( message, type ) { 215 type = typeof type !== 'undefined' && type !== '' ? type : 'error'; 216 var notice_id = '#espresso-ajax-notices-' + type; 217 $( notice_id + ' .espresso-notices-msg' ).text( message ); 218 $( '#espresso-ajax-notices' ).eeCenter(); 219 $( notice_id ).slideDown('fast'); 220 $('.espresso-ajax-notices.fade-away').delay(10000).slideUp('fast'); 221 } 222 223 224 //close btn for notifications 225 $('.close-espresso-notice').on( 'click', function(e){ 226 $(this).parent().hide(); 227 e.preventDefault(); 228 e.stopPropagation(); 229 }); 230 231 232 233 // submit form 234 $('.submit-this-form').click(function(e) { 235 e.preventDefault(); 236 e.stopPropagation(); 237 $(this).closest('form').submit(); 238 return false; 239 }); 240 241 242 243 // generic click event for displaying and giving focus to an element and hiding control 244 $('.display-the-hidden').on( 'click', function(e) { 245 // get target element from "this" (the control element's) "rel" attribute 246 var item_to_display = $(this).attr("rel"); 247 //alert( 'item_to_display = ' + item_to_display ); 248 // hide the control element 249 $(this).fadeOut(50).hide(); 250 // display the target's div container - use slideToggle or removeClass 251 $('#'+item_to_display+'-dv').slideToggle(250, function() { 252 // display the target div's hide link 253 $('#hide-'+item_to_display).show().fadeIn(50); 254 // if hiding/showing a form input, then id of the form input must = item_to_display 255 $('#'+item_to_display).focus();
255 // add focus to the target 256 }); 257 e.preventDefault(); 258 e.stopPropagation(); 259 return false; 260 }); 261 262 263 264 // generic click event for re-hiding an element and displaying it's display control 265 $('.hide-the-displayed').on( 'click', function(e) { 266 // get target element from "this" (the control element's) "rel" attribute 267 var item_to_hide = $(this).attr("rel"); 268 // hide the control element 269 $(this).fadeOut(50).hide(); 270 // hide the target's div container - use slideToggle or addClass 271 $('#'+item_to_hide+'-dv').slideToggle(250, function() { 272 // display the control element that toggles display of this element 273 $('#display-'+item_to_hide).show().fadeIn(50); 274 }); 275 e.preventDefault(); 276 e.stopPropagation(); 277 return false; 278 }); 279 280 281 282 // generic click event for resetting a form input - can be coupled with the "hide_the_displayed" function above 283 $('.cancel').click(function() { 284 // get target element from "this" (the control element's) "rel" attribute 285 var item_to_cancel = $(this).attr("rel"); 286 // set target element's value to an empty string 287 $('#'+item_to_cancel).val(''); 288 e.preventDefault(); 289 e.stopPropagation(); 290 }); 291 292 293 294 295 296 297}); 298 299 300 301//functions available to window 302 303 304 305/** 306 * Function : dump() 307 * Arguments: The data - array,hash(associative array),object 308 * The level - OPTIONAL 309 * Returns : The textual representation of the array. 310 * This function was inspired by the print_r function of PHP. 311 * This will accept some data as the argument and return a 312 * text that will be a more readable version of the 313 * array/hash/object that is given. 314 * Docs: http://www.openjs.com/scripts/others/dump_function_php_print_r.php 315 */ 316function dump(arr,level) { 317 var dumped_text = ""; 318 if ( ! level ) { 319 level = 0; 320 } 321 322 //The padding given at the beginning of the line. 323 var level_padding = ""; 324 for(var j=0;j<level+1;j++) { 325 level_padding += " "; 326 } 327 //Array/Hashes/Objects 328 if( typeof(arr) === 'object' ) { 329 for(var item in arr) { 330 if ( typeof item !== 'undefined' && arr.hasOwnProperty( item ) ) { 331 var value = arr[item]; 332 //If it is an array 333 if( typeof(value) === 'object' ) { 334 dumped_text += level_padding + "'" + item + "' ...\n"; 335 dumped_text += dump(value,level+1); 336 } else { 337 dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n"; 338 } 339 } 340 } 341 } else { //Stings/Chars/Numbers etc. 342 dumped_text = "===>"+arr+"<===("+typeof(arr)+")"; 343 } 344 return dumped_text; 345} 346 347 348//function getFunctionName() { 349// var myName = arguments.callee.toString(); 350// myName = myName.substr('function '.length); 351// myName = myName.substr(0, myName.indexOf('(')); 352// return myName; 353//}
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.