1/** 2 * Javascript utilities 3 * 4 * @package QWERY 5 * @since QWERY 1.0 6 */ 7 8/* global jQuery, QWERY_STORAGE */ 9 10/* Global variables manipulations 11---------------------------------------------------------------- */ 12 13(function(){ 14 "use strict"; 15 16 var $window = jQuery( window ), 17 $document = jQuery( document ), 18 $adminbar = jQuery( '#wpadminbar' ), 19 $body = jQuery( 'body' ); 20 21 // Global variables storage 22 if (typeof QWERY_STORAGE == 'undefined') { 23 window.QWERY_STORAGE = {}; 24 } 25 26 // Get global variable 27 window.qwery_storage_get = function(var_name) { 28 return qwery_isset( QWERY_STORAGE[var_name] ) ? QWERY_STORAGE[var_name] : ''; 29 }; 30 31 // Set global variable 32 window.qwery_storage_set = function(var_name, value) { 33 QWERY_STORAGE[var_name] = value; 34 }; 35 36 // Inc/Dec global variable with specified value 37 window.qwery_storage_inc = function(var_name) { 38 var value = arguments[1] === undefined ? 1 : arguments[1]; 39 QWERY_STORAGE[var_name] += value; 40 }; 41 42 // Concatenate global variable with specified value 43 window.qwery_storage_concat = function(var_name, value) { 44 QWERY_STORAGE[var_name] += '' + value; 45 }; 46 47 // Get global array element 48 window.qwery_storage_get_array = function(var_name, key) { 49 return qwery_isset( QWERY_STORAGE[var_name][key] ) ? QWERY_STORAGE[var_name][key] : ''; 50 }; 51 52 // Set global array element 53 window.qwery_storage_set_array = function(var_name, key, value) { 54 if ( ! qwery_isset( QWERY_STORAGE[var_name] )) { 55 QWERY_STORAGE[var_name] = {}; 56 } 57 QWERY_STORAGE[var_name][key] = value; 58 }; 59 60 // Inc/Dec global array element with specified value 61 window.qwery_storage_inc_array = function(var_name, key) { 62 var value = arguments[2] === undefined ? 1 : arguments[2]; 63 QWERY_STORAGE[var_name][key] += value; 64 }; 65 66 // Concatenate global array element with specified value 67 window.qwery_storage_concat_array = function(var_name, key, value) { 68 QWERY_STORAGE[var_name][key] += '' + value; 69 }; 70 71 /* PHP-style functions 72 ---------------------------------------------------------------- */ 73 window.qwery_isset = function(obj) { 74 return typeof(obj) != 'undefined'; 75 }; 76 77 window.qwery_empty = function(obj) { 78 return typeof(obj) == 'undefined' || (typeof(obj) == 'object' && obj === null) || (typeof(obj) == 'array' && obj.length === 0) || (typeof(obj) == 'string' && qwery_alltrim( obj ) === '') || obj === 0; 79 }; 80 81 window.qwery_is_array = function(obj) { 82 return typeof(obj) == 'array'; 83 }; 84 85 window.qwery_is_object = function(obj) { 86 return typeof(obj) == 'object'; 87 }; 88 89 window.qwery_clone_object = function(obj) { 90 if (obj === null || typeof(obj) != 'object') { 91 return obj; 92 } 93 var temp = {}; 94 for (var key in obj) { 95 temp[key] = qwery_clone_object( obj[key] ); 96 } 97 return temp; 98 }; 99 100 window.qwery_merge_objects = function(obj1, obj2) { 101 for (var i in obj2) { 102 obj1[i] = obj2[i]; 103 } 104 return obj1; 105 }; 106 107 window.qwery_array_merge = function(a1, a2) { 108 for (var i in a2) { 109 a1[i] = a2[i]; 110 } 111 return a1; 112 }; 113 114 window.qwery_array_first_key = function(arr) { 115 var rez = null; 116 for (var i in arr) { 117 rez = i; 118 break; 119 } 120 return rez; 121 }; 122 123 window.qwery_array_first_value = function(arr) { 124 var rez = null; 125 for (var i in arr) { 126 rez = arr[i]; 127 break; 128 } 129 return rez; 130 }; 131 132 // Generates a storable representation of a value 133 window.qwery_serialize = function(mixed_val) { 134 var obj_to_array = arguments.length == 1 || argument[1] === true; 135 136 switch (typeof(mixed_val)) { 137 138 case "number": 139 if (isNaN( mixed_val ) || ! isFinite( mixed_val )) { 140 return false; 141 } else { 142 return (Math.floor( mixed_val ) == mixed_val ? "i" : "d") + ":" + mixed_val + ";"; 143 } 144 145 case "string": 146 return "s:" + mixed_val.length + ":\"" + mixed_val + "\";"; 147 148 case "boolean": 149 return "b:" + (mixed_val ? "1" : "0") + ";"; 150 151 case "object": 152 if (mixed_val == null) { 153 return "N;"; 154 } else if (mixed_val instanceof Array) { 155 var idxobj = { idx: -1 }; 156 var map = []; 157 for (var i = 0; i < mixed_val.length; i++) { 158 idxobj.idx++; 159 var ser = qwery_serialize( mixed_val[i] ); 160 if (ser) { 161 map.push( qwery_serialize( idxobj.idx ) + ser ); 162 } 163 } 164 return "a:" + mixed_val.length + ":{" + map.join( "" ) + "}"; 165 } else { 166 var class_name = qwery_get_class( mixed_val ); 167 if (class_name == undefined) { 168 return false;
169 } 170 var props = new Array(); 171 for (var prop in mixed_val) { 172 var ser = qwery_serialize( mixed_val[prop] ); 173 if (ser) { 174 props.push( qwery_serialize( prop ) + ser ); 175 } 176 } 177 if (obj_to_array) { 178 return "a:" + props.length + ":{" + props.join( "" ) + "}"; 179 } else { 180 return "O:" + class_name.length + ":\"" + class_name + "\":" + props.length + ":{" + props.join( "" ) + "}"; 181 } 182 } 183 184 case "undefined": 185 return "N;"; 186 } 187 return false; 188 }; 189 190 // Encode / Decode Unicode string to / from single-byte characters 191 ( function( $ ) { 192 var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 193 a256 = '', 194 r64 = [256], 195 r256 = [256], 196 i = 0; 197 198 var UTF8 = { 199 200 /** 201 * Encode multi-byte Unicode string into utf-8 multiple single-byte characters 202 * (BMP / basic multilingual plane only) 203 * 204 * Chars in range U+0080 - U+07FF are encoded in 2 chars, U+0800 - U+FFFF in 3 chars 205 * 206 * @param {String} strUni Unicode string to be encoded as UTF-8 207 * @returns {String} encoded string 208 */ 209 encode: function(strUni) { 210 // use regular expressions & String.replace callback function for better efficiency than procedural approaches 211 var strUtf = strUni 212 .replace( 213 /[\u0080-\u07ff]/g, // U+0080 - U+07FF => 2 bytes 110yyyyy, 10zzzzzz 214 function(c) { 215 var cc = c.charCodeAt(0); 216 return String.fromCharCode(0xc0 | cc >> 6, 0x80 | cc & 0x3f); 217 } 218 ) 219 .replace( 220 /[\u0800-\uffff]/g, // U+0800 - U+FFFF => 3 bytes 1110xxxx, 10yyyyyy, 10zzzzzz 221 function(c) { 222 var cc = c.charCodeAt(0); 223 return String.fromCharCode(0xe0 | cc >> 12, 0x80 | cc >> 6 & 0x3F, 0x80 | cc & 0x3f); 224 } 225 ); 226 return strUtf; 227 }, 228 229 /** 230 * Decode utf-8 encoded string back into multi-byte Unicode characters 231 * 232 * @param {String} strUtf UTF-8 string to be decoded back to Unicode 233 * @returns {String} decoded string 234 */ 235 decode: function(strUtf) { 236 // note: decode 3-byte chars first as decoded 2-byte strings could appear to be 3-byte char! 237 var strUni = strUtf 238 .replace( 239 /[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g, // 3-byte chars 240 function(c) { // (note parentheses for precence) 241 var cc = ((c.charCodeAt(0) & 0x0f) << 12) | ((c.charCodeAt(1) & 0x3f) << 6) | (c.charCodeAt(2) & 0x3f); 242 return String.fromCharCode(cc); 243 } 244 ) 245 .replace( 246 /[\u00c0-\u00df][\u0080-\u00bf]/g, // 2-byte chars 247 function(c) { // (note parentheses for precence) 248 var cc = (c.charCodeAt(0) & 0x1f) << 6 | c.charCodeAt(1) & 0x3f; 249 return String.fromCharCode(cc); 250 } 251 ); 252 return strUni; 253 } 254 }; 255 256 while( i < 256 ) { 257 var c = String.fromCharCode(i); 258 a256 += c; 259 r256[i] = i; 260 r64[i] = b64.indexOf(c); 261 ++i; 262 } 263 264 function code(s, discard, alpha, beta, w1, w2) { 265 s = String(s); 266 var buffer = 0, 267 i = 0, 268 length = s.length, 269 result = '', 270 bitsInBuffer = 0; 271 272 while (i < length) { 273 var c = s.charCodeAt(i); 274 c = c < 256 ? alpha[c] : -1; 275 276 buffer = (buffer << w1) + c; 277 bitsInBuffer += w1; 278 279 while (bitsInBuffer >= w2) { 280 bitsInBuffer -= w2; 281 var tmp = buffer >> bitsInBuffer; 282 result += beta.charAt(tmp); 283 buffer ^= tmp << bitsInBuffer; 284 } 285 ++i; 286 } 287 if ( ! discard && bitsInBuffer > 0) { 288 result += beta.charAt(buffer << (w2 - bitsInBuffer)); 289 } 290 return result; 291 } 292 293 var Plugin = $.qwery_encoder = function(dir, input, encode) { 294 return input ? Plugin[dir](input, encode) : dir ? null : this; 295 }; 296 297 Plugin.btoa = Plugin.encode = function(plain, utf8encode) { 298 plain = Plugin.raw === false || Plugin.utf8encode || utf8encode 299 ? UTF8.encode(plain) 300 : plain; 301 plain = code(plain, false, r256, b64, 8, 6); 302 return plain + '===='.slice((plain.length % 4) || 4); 303 }; 304 305 Plugin.atob = Plugin.decode = function(coded, utf8decode) { 306 coded = String(coded).split('='); 307 var i = coded.length; 308 do { 309 --i; 310 coded[i] = code(coded[i], true, r64, a256, 6, 8); 311 } while (i > 0); 312 coded = coded.join(''); 313 return Plugin.raw === false || Plugin.utf8decode || utf8decode 314 ? UTF8.decode(coded) 315 : coded; 316 }; 317 }(jQuery) ); 318 319 // Returns the name of the class of an object 320 window.qwery_get_class = function(obj) { 321 if (obj instanceof Object && ! (obj instanceof Array) && ! (obj instanceof Function) && obj.constructor) { 322 var arr = obj.constructor.toString().match( /function\s*(\w+)/ ); 323 if (arr && arr.length == 2) { 324 return arr[1]; 325 } 326 } 327 return false;
328 }; 329 330 331 /* Timing functions 332 ---------------------------------------------------------------- */ 333 window.qwery_debounce = function(func, wait) { 334 var timeout; 335 return function () { 336 var context = this, args = arguments; 337 var later = function later() { 338 timeout = null; 339 func.apply(context, args); 340 }; 341 var callNow = !timeout; 342 clearTimeout(timeout); 343 timeout = setTimeout(later, wait); 344 if (callNow) { 345 func.apply(context, args); 346 } 347 }; 348 }; 349 350 window.qwery_throttle = function(func, wait, debounce) { 351 var timeout; 352 return function () { 353 var context = this, args = arguments; 354 var throttler = function () { 355 timeout = null; 356 func.apply(context, args); 357 }; 358 if (debounce) clearTimeout(timeout); 359 if (debounce || !timeout) timeout = setTimeout(throttler, wait); 360 }; 361 }; 362 363 364 /* Mutation observers 365 ---------------------------------------------------------------- */ 366 var qwery_observers = {}; 367 368 // Create mutations observer 369 window.qwery_create_observer = function( id, obj, callback, args ) { 370 if ( typeof window.trx_addons_create_observer != 'undefined' ) { 371 return trx_addons_create_observer( id, obj, callback, args ); 372 } else if ( typeof window.MutationObserver !== 'undefined' && obj.length > 0 ) { 373 if ( typeof qwery_observers[ id ] == 'undefined' ) { 374 var defa = { 375 attributes: false, 376 childList: true, 377 subtree: true 378 }; 379 if ( args ) { 380 defa = qwery_object_merge( defa, args ); 381 } 382 qwery_observers[ id ] = { 383 observer: new MutationObserver( callback ), 384 obj: obj.get(0) 385 }; 386 qwery_observers[ id ].observer.observe( qwery_observers[ id ].obj, defa ); 387 } 388 return true; 389 } 390 return false; 391 }; 392 393 // Remove mutations observer 394 window.qwery_remove_observer = function( id ) { 395 if ( typeof window.trx_addons_remove_observer != 'undefined' ) { 396 return trx_addons_remove_observer( id ); 397 } else if ( typeof window.MutationObserver !== 'undefined' ) { 398 if ( typeof qwery_observers[ id ] !== 'undefined' ) { 399 qwery_observers[ id ].observer.disconnect( 400 qwery_observers[ id ].obj 401 ); 402 delete qwery_observers[ id ]; 403 } 404 return true; 405 } 406 return false; 407 }; 408 409 410 /* Wordpress-style functions 411 ---------------------------------------------------------------- */ 412 413 var filters = {}; 414
415 // Add filter's handler 416 window.qwery_add_filter = function( filter, callback, priority ) { 417 if ( typeof window.trx_addons_add_filter != 'undefined' ) { 418 trx_addons_add_filter( filter, callback, priority ); 419 } else if ( typeof wp != 'undefined' && typeof wp.hooks != 'undefined' ) { 420 wp.hooks.addFilter( filter, 'qwery', callback, priority == undefined ? 10 : priority ); 421 } else { 422 if ( ! filters[filter] ) filters[filter] = {}; 423 if ( ! filters[filter][priority] ) filters[filter][priority] = []; 424 filters[filter][priority].push( callback ); 425 } 426 }; 427 428 // Apply filter's handlers 429 window.qwery_apply_filters = function( filter, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ) { 430 if ( typeof window.trx_addons_apply_filters != 'undefined' ) { 431 arg1 = trx_addons_apply_filters( filter, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); 432 } else if ( typeof wp != 'undefined' && typeof wp.hooks != 'undefined' && typeof wp.hooks.applyFilters != 'undefined' ) { 433 arg1 = wp.hooks.applyFilters( filter, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); 434 } else if ( typeof filters[filter] == 'object' ) { 435 var keys = Object.keys(filters[filter]).sort(); 436 for (var i=0; i < keys.length; i++ ) { 437 for (var j=0; j < filters[filter][keys[i]].length; j++ ) { 438 if ( typeof filters[filter][keys[i]][j] == 'function' ) { 439 arg1 = filters[filter][keys[i]][j](arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); 440 } 441 } 442 } 443 } 444 return arg1; 445 }; 446 447 // Add action's handler 448 window.qwery_add_action = function( action, callback, priority ) { 449 if ( typeof window.trx_addons_add_action != 'undefined' ) { 450 trx_addons_add_action( action, callback, priority ); 451 } else if ( typeof wp != 'undefined' && typeof wp.hooks != 'undefined' ) { 452 wp.hooks.addAction( action, 'qwery', callback, priority == undefined ? 10 : priority ); 453 } else { 454 qwery_add_filter( action, callback, priority ); 455 } 456 }; 457 458 // Do action's handlers 459 window.qwery_do_action = function( action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ) { 460 if ( typeof window.trx_addons_do_action != 'undefined' ) { 461 trx_addons_do_action( action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); 462 } else if ( typeof wp != 'undefined' && typeof wp.hooks != 'undefined' && typeof wp.hooks.doActions != 'undefined' ) { 463 wp.hooks.doActions( action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); 464 } else { 465 qwery_apply_filters( action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); 466 } 467 }; 468 469 470 /* String functions 471 ---------------------------------------------------------------- */ 472 473 window.qwery_in_list = function(str, list) { 474 var delim = arguments[2] !== undefined ? arguments[2] : '|'; 475 var icase = arguments[3] !== undefined ? arguments[3] : true; 476 var retval = false; 477 if (icase) { 478 if (typeof(str) == 'string') { 479 str = str.toLowerCase(); 480 } 481 list = list.toLowerCase(); 482 } 483 var parts = list.split( delim ); 484 for (var i = 0; i < parts.length; i++) { 485 if (parts[i] == str) { 486 retval = true; 487 break; 488 } 489 } 490 return retval; 491 }; 492 493 window.qwery_alltrim = function(str) { 494 var dir = arguments[1] !== undefined ? arguments[1] : 'a'; 495 var rez = ''; 496 var i, start = 0, end = str.length - 1; 497 if (dir == 'a' || dir == 'l') { 498 for (i = 0; i < str.length; i++) { 499 if (str.substr( i, 1 ) != ' ') { 500 start = i; 501 break; 502 } 503 } 504 } 505 if (dir == 'a' || dir == 'r') { 506 for (i = str.length - 1; i >= 0; i--) { 507 if (str.substr( i, 1 ) != ' ') { 508 end = i; 509 break; 510 } 511 } 512 } 513 return str.substring( start, end + 1 ); 514 }; 515 516 window.qwery_ltrim = function(str) { 517 return qwery_alltrim( str, 'l' ); 518 }; 519 520 window.qwery_rtrim = function(str) { 521 return qwery_alltrim( str, 'r' ); 522 }; 523 524 window.qwery_padl = function(str, len) { 525 var ch = arguments[2] !== undefined ? arguments[2] : ' '; 526 var rez = str.substr( 0, len ); 527 if (rez.length < len) { 528 for (var i = 0; i < len - str.length; i++) { 529 rez += ch; 530 } 531 } 532 return rez; 533 }; 534 535 window.qwery_padr = function(str, len) { 536 var ch = arguments[2] !== undefined ? arguments[2] : ' '; 537 var rez = str.substr( 0, len ); 538 if (rez.length < len) { 539 for (var i = 0; i < len - str.length; i++) { 540 rez = ch + rez; 541 } 542 } 543 return rez; 544 }; 545 546 window.qwery_padc = function(str, len) { 547 var ch = arguments[2] !== undefined ? arguments[2] : ' '; 548 var rez = str.substr( 0, len ); 549 if (rez.length < len) { 550 for (var i = 0; i < Math.floor( (len - str.length) / 2 ); i++) { 551 rez = ch + rez + ch; 552 } 553 } 554 return rez + (rez.length < len ? ch : ''); 555 }; 556 557 window.qwery_replicate = function(str, num) { 558 var rez = ''; 559 for (var i = 0; i < num; i++) { 560 rez += str; 561 } 562 return rez; 563 }; 564 565 window.qwery_prepare_macros = function(str) { 566 return str 567 .replace( /\{\{/g, "<i>" ) 568 .replace( /\}\}/g, "</i>" ) 569 .replace( /\(\(/g, "<b>" ) 570 .replace( /\)\)/g, "</b>" ) 571 .replace( /\|\|/g, "<br>" ); 572 }; 573 574 575 /* Numbers functions 576 ---------------------------------------------------------------- */ 577 578 // Round number to specified precision.
579 // For example: num=1.12345, prec=2, rounded=1.12 580 // num=12345, prec=-2, rounded=12300 581 window.qwery_round_number = function(num) { 582 var precision = arguments[1] !== undefined ? arguments[1] : 0; 583 var p = Math.pow( 10, precision ); 584 return Math.round( num * p ) / p; 585 }; 586 587 // Clear number from any characters and append it with 0 to desired precision 588 // For example: num=test1.12dd, prec=3, cleared=1.120 589 window.qwery_clear_number = function(num) { 590 var precision = arguments[1] !== undefined ? arguments[1] : 0; 591 var defa = arguments[2] !== undefined ? arguments[2] : 0; 592 var res = ''; 593 var decimals = -1; 594 num = "" + num; 595 if (num == "") { 596 num = "" + defa; 597 } 598 for (var i = 0; i < num.length; i++) { 599 if (decimals == 0) { 600 break; 601 } else if (decimals > 0) { 602 decimals--; 603 } 604 var ch = num.substr( i,1 ); 605 if (ch == '.') { 606 if (precision > 0) { 607 res += ch; 608 } 609 decimals = precision; 610 } else if ((ch >= 0 && ch <= 9) || (ch == '-' && i == 0)) { 611 res += ch; 612 } 613 } 614 if (precision > 0 && decimals != 0) { 615 if (decimals == -1) { 616 res += '.'; 617 decimals = precision; 618 } 619 for (i = decimals; i > 0; i--) { 620 res += '0'; 621 } 622 } 623 return res; 624 }; 625 626 // Convert number from decimal to hex 627 window.qwery_dec2hex = function(n) { 628 return Number( n ).toString( 16 ); 629 }; 630 631 // Convert number from hex to decimal 632 window.qwery_hex2dec = function(hex) { 633 return parseInt( hex,16 ); 634 }; 635 636 637 /* Array manipulations 638 ---------------------------------------------------------------- */ 639 640 window.qwery_in_array = function(val, thearray) { 641 var rez = false; 642 for (var i = 0; i < thearray.length - 1; i++) { 643 if (thearray[i] == val) { 644 rez = true; 645 break; 646 } 647 } 648 return rez; 649 }; 650 651 window.qwery_sort_array = function(thearray) { 652 var caseSensitive = arguments[1] !== undefined ? arguments[1] : false; 653 var tmp = ''; 654 for (var x = 0; x < thearray.length - 1; x++) { 655 for (var y = (x + 1); y < thearray.length; y++) { 656 if (caseSensitive) { 657 if (thearray[x] > thearray[y]) { 658 tmp = thearray[x]; 659 thearray[x] = thearray[y]; 660 thearray[y] = tmp; 661 } 662 } else { 663 if (thearray[x].toLowerCase() > thearray[y].toLowerCase()) { 664 tmp = thearray[x]; 665 thearray[x] = thearray[y]; 666 thearray[y] = tmp; 667 } 668 } 669 } 670 } 671 return thearray; 672 }; 673 674 /* Date manipulations 675 ---------------------------------------------------------------- */ 676 677 // Return array[Year, Month, Day, Hours, Minutes, Seconds] 678 // from string: Year[-/.]Month[-/.]Day[T ]Hours:Minutes:Seconds 679 window.qwery_parse_date = function(dt) { 680 dt = dt.replace( /\//g, '-' ).replace( /\./g, '-' ).replace( /T/g, ' ' ).split( '+' )[0]; 681 var dt2 = dt.split( ' ' ); 682 var d = dt2[0].split( '-' ); 683 var t = dt2[1].split( ':' ); 684 d.push( t[0], t[1], t[2] ); 685 return d; 686 }; 687 688 // Return difference string between two dates 689 window.qwery_get_date_difference = function(dt1) { 690 var dt2 = arguments[1] !== undefined ? arguments[1] : ''; 691 var short_date = arguments[2] !== undefined ? arguments[2] : true; 692 var sec = arguments[3] !== undefined ? arguments[3] : false; 693 var a1 = qwery_parse_date( dt1 ); 694 dt1 = Date.UTC( a1[0], a1[1], a1[2], a1[3], a1[4], a1[5] ); 695 if (dt2 == '') { 696 dt2 = new Date(); 697 var a2 = [dt2.getFullYear(), dt2.getMonth() + 1, dt2.getDate(), dt2.getHours(), dt2.getMinutes(), dt2.getSeconds()]; 698 } else { 699 var a2 = qwery_parse_date( dt2 ); 700 } 701 dt2 = Date.UTC( a2[0], a2[1], a2[2], a2[3], a2[4], a2[5] ); 702 var diff = Math.round( (dt2 - dt1) / 1000 ); 703 var days = Math.floor( diff / (24 * 3600) ); 704 diff -= days * 24 * 3600; 705 var hours = Math.floor( diff / 3600 ); 706 diff -= hours * 3600; 707 var minutes = Math.floor( diff / 60 ); 708 diff -= minutes * 60; 709 var rez = ''; 710 if (days > 0) { 711 rez += (rez !== '' ? ' ' : '') + days + ' day' + (days > 1 ? 's' : ''); 712 } 713 if (( ! short_date || rez == '') && hours > 0) { 714 rez += (rez !== '' ? ' ' : '') + hours + ' hour' + (hours > 1 ? 's' : ''); 715 } 716 if (( ! short_date || rez == '') && minutes > 0) { 717 rez += (rez !== '' ? ' ' : '') + minutes + ' minute' + (minutes > 1 ? 's' : ''); 718 } 719 if (sec || rez == '') { 720 rez += rez !== '' || sec ? (' ' + diff + ' second' + (diff > 1 ? 's' : '')) : 'less then minute'; 721 } 722 return rez; 723 }; 724 725 /* Colors functions 726 ---------------------------------------------------------------- */ 727 728 /** 729 * Convert color from hex to the object with rgb components 730 * 731 * @param {string} hex Color in hex format (#RRGGBB) 732 * 733 * @return {object} Color in RGB format {r: red, g: green, b: blue} 734 */ 735 window.qwery_hex2rgb = function(hex) { 736 hex = parseInt( ((hex.indexOf( '#' ) > -1) ? hex.substring( 1 ) : hex), 16 ); 737 return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)}; 738 }; 739 740 741 /** 742 * Convert a color from hex to a CSS rgba function and add an alpha channel value 743 * 744 * @param {string} hex Color in hex format (#RRGGBB) 745 * @param {number} alpha Alpha channel value (0-1) 746 * 747 * @return {string} Color in CSS rgba format rgba(R,G,B,A) 748 */ 749 window.qwery_hex2rgba = function(hex, alpha) { 750 var rgb = qwery_hex2rgb( hex ); 751 return 'rgba(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ',' + alpha + ')'; 752 }; 753 754 /** 755 * 756 * @param {string} color Color in rgba format rgba(R,G,B,A) 757 * @param {bool} alpha If true, add alpha channel value to the result 758 * 759 * @return {string} Color in hex format (#RRGGBB) or (#RRGGBBAA) 760 */ 761 window.qwery_rgba2hex = function(color, alpha) { 762 var aRGB = color.match( /^rgba?\((\d{1,3}),(\d{1,3}),(\d{1,3})(,(\d{1,3}))?\)$/i ); 763 if ( ! aRGB) { 764 return color; 765 } 766 var rgb = ''; 767 for (var i = 1; i <= 3; i++) { 768 rgb += Math.round( aRGB[i] ).toString( 16 ).replace( /^(.)$/,'0$1' ); 769 } 770 if ( alpha ) { 771 rgb += Math.round( aRGB[5] * 255 ).toString( 16 ).replace( /^(.)$/,'0$1' ); 772 } 773 return '#' + rgb; 774 }; 775 776 /** 777 * Convert color from the rgb() or rgba() to hex format 778 * 779 * @param {object} color Color as a CSS function rgb() or rgba() 780 * @param {bool} alpha If true, add alpha channel value to the result. Default: false 781 * 782 * @return {string} Color in hex format (#RRGGBB[AA]) 783 */ 784 window.qwery_rgb2hex = function(color, alpha) { 785 var aRGB; 786 color = color.replace( /\s/g,"" ).toLowerCase(); 787 if (color == 'rgba(0,0,0,0)' || color == 'rgba(0%,0%,0%,0%)') { 788 color = 'transparent'; 789 } 790 if (color.indexOf( 'rgba(' ) == 0) { 791 aRGB = color.match( /^rgba\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i ); 792 } else { 793 aRGB = color.match( /^rgb\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i ); 794 } 795 796 if (aRGB) { 797 color = ''; 798 for (var i = 1; i <= 3; i++) { 799 color += Math.round( (aRGB[i][aRGB[i].length - 1] == "%" ? 2.55 : 1) * parseInt( aRGB[i] ) ).toString( 16 ).replace( /^(.)$/,'0$1' ); 800 } 801 if ( alpha && aRGB[4] !== undefined ) { 802 color += Math.round( aRGB[4] * 255 ).toString( 16 ).replace( /^(.)$/,'0$1' ); 803 } 804 } else {
805 color = color.replace( /^#?([\da-f])([\da-f])([\da-f])$/i, '$1$1$2$2$3$3' ); 806 } 807 return (color.substr( 0,1 ) != '#' ? '#' : '') + color; 808 }; 809 810 /** 811 * Return color in hex format from separate RGB components 812 * 813 * @param {number} r Red component (0-255) 814 * @param {number} g Green component (0-255) 815 * @param {number} b Blue component (0-255) 816 * 817 * @return {string} Color in hex format (#RRGGBB) 818 */ 819 window.qwery_components2hex = function(r,g,b) { 820 return '#' + 821 Number( r ).toString( 16 ).toUpperCase().replace( /^(.)$/,'0$1' ) + 822 Number( g ).toString( 16 ).toUpperCase().replace( /^(.)$/,'0$1' ) + 823 Number( b ).toString( 16 ).toUpperCase().replace( /^(.)$/,'0$1' ); 824 }; 825 826 window.qwery_rgb2components = function(color) { 827 color = qwery_rgb2hex( color ); 828 var matches = color.match( /^#?([\dabcdef]{2})([\dabcdef]{2})([\dabcdef]{2})$/i ); 829 if ( ! matches) { 830 return false; 831 } 832 for (var i = 1, rgb = new Array( 3 ); i <= 3; i++) { 833 rgb[i - 1] = parseInt( matches[i],16 ); 834 } 835 return rgb; 836 }; 837 838 window.qwery_hex2hsb = function(hex) { 839 var h = arguments[1] !== undefined ? arguments[1] : 0; 840 var s = arguments[2] !== undefined ? arguments[2] : 0; 841 var b = arguments[3] !== undefined ? arguments[3] : 0; 842 var hsb = qwery_rgb2hsb( qwery_hex2rgb( hex ) ); 843 hsb.h = Math.min( 359, Math.max( 0, hsb.h + h ) ); 844 hsb.s = Math.min( 100, Math.max( 0, hsb.s + s ) ); 845 hsb.b = Math.min( 100, Math.max( 0, hsb.b + b ) ); 846 return hsb; 847 }; 848 849 window.qwery_hsb2hex = function(hsb) { 850 var rgb = qwery_hsb2rgb( hsb ); 851 return qwery_components2hex( rgb.r, rgb.g, rgb.b ); 852 }; 853 854 window.qwery_rgb2hsb = function(rgb) { 855 var hsb = {}; 856 hsb.b = Math.max( Math.max( rgb.r,rgb.g ),rgb.b ); 857 hsb.s = (hsb.b <= 0) ? 0 : Math.round( 100 * (hsb.b - Math.min( Math.min( rgb.r,rgb.g ),rgb.b )) / hsb.b ); 858 hsb.b = Math.round( (hsb.b / 255) * 100 ); 859 if ((rgb.r == rgb.g) && (rgb.g == rgb.b)) { 860 hsb.h = 0; 861 } else if (rgb.r >= rgb.g && rgb.g >= rgb.b) { 862 hsb.h = 60 * (rgb.g - rgb.b) / (rgb.r - rgb.b); 863 } else if (rgb.g >= rgb.r && rgb.r >= rgb.b) { 864 hsb.h = 60 + 60 * (rgb.g - rgb.r) / (rgb.g - rgb.b); 865 } else if (rgb.g >= rgb.b && rgb.b >= rgb.r) { 866 hsb.h = 120 + 60 * (rgb.b - rgb.r) / (rgb.g - rgb.r); 867 } else if (rgb.b >= rgb.g && rgb.g >= rgb.r) { 868 hsb.h = 180 + 60 * (rgb.b - rgb.g) / (rgb.b - rgb.r); 869 } else if (rgb.b >= rgb.r && rgb.r >= rgb.g) { 870 hsb.h = 240 + 60 * (rgb.r - rgb.g) / (rgb.b - rgb.g); 871 } else if (rgb.r >= rgb.b && rgb.b >= rgb.g) { 872 hsb.h = 300 + 60 * (rgb.r - rgb.b) / (rgb.r - rgb.g); 873 } else { 874 hsb.h = 0; 875 } 876 hsb.h = Math.round( hsb.h ); 877 return hsb; 878 }; 879 880 window.qwery_hsb2rgb = function(hsb) { 881 var rgb = {}; 882 var h = Math.round( hsb.h ); 883 var s = Math.round( hsb.s * 255 / 100 ); 884 var v = Math.round( hsb.b * 255 / 100 ); 885 if (s == 0) { 886 rgb.r = rgb.g = rgb.b = v; 887 } else { 888 var t1 = v; 889 var t2 = (255 - s) * v / 255; 890 var t3 = (t1 - t2) * (h % 60) / 60; 891 if (h == 360) { 892 h = 0; 893 } 894 if (h < 60) { 895 rgb.r = t1; rgb.b = t2; rgb.g = t2 + t3; } else if (h < 120) { 896 rgb.g = t1; rgb.b = t2; rgb.r = t1 - t3; } else if (h < 180) { 897 rgb.g = t1; rgb.r = t2; rgb.b = t2 + t3; } else if (h < 240) { 898 rgb.b = t1; rgb.r = t2; rgb.g = t1 - t3; } else if (h < 300) { 899 rgb.b = t1; rgb.g = t2; rgb.r = t2 + t3; } else if (h < 360) { 900 rgb.r = t1; rgb.g = t2; rgb.b = t1 - t3; } else { 901 rgb.r = 0; rgb.g = 0; rgb.b = 0; } 902 } 903 return { r:Math.round( rgb.r ), g:Math.round( rgb.g ), b:Math.round( rgb.b ) }; 904 }; 905 906 window.qwery_color_picker = function(){ 907 var id = arguments[0] !== undefined ? arguments[0] : "iColorPicker" + Math.round( Math.random() * 1000 ); 908 var colors = arguments[1] !== undefined ? arguments[1] : 909 '#f00,#ff0,#0f0,#0ff,#00f,#f0f,#fff,#ebebeb,#e1e1e1,#d7d7d7,#cccccc,#c2c2c2,#b7b7b7,#acacac,#a0a0a0,#959595,' 910 + '#ee1d24,#fff100,#00a650,#00aeef,#2f3192,#ed008c,#898989,#7d7d7d,#707070,#626262,#555,#464646,#363636,#262626,#111,#000,' 911 + '#f7977a,#fbad82,#fdc68c,#fff799,#c6df9c,#a4d49d,#81ca9d,#7bcdc9,#6ccff7,#7ca6d8,#8293ca,#8881be,#a286bd,#bc8cbf,#f49bc1,#f5999d,' 912 + '#f16c4d,#f68e54,#fbaf5a,#fff467,#acd372,#7dc473,#39b778,#16bcb4,#00bff3,#438ccb,#5573b7,#5e5ca7,#855fa8,#a763a9,#ef6ea8,#f16d7e,' 913 + '#ee1d24,#f16522,#f7941d,#fff100,#8fc63d,#37b44a,#00a650,#00a99e,#00aeef,#0072bc,#0054a5,#2f3192,#652c91,#91278f,#ed008c,#ee105a,' 914 + '#9d0a0f,#a1410d,#a36209,#aba000,#588528,#197b30,#007236,#00736a,#0076a4,#004a80,#003370,#1d1363,#450e61,#62055f,#9e005c,#9d0039,' 915 + '#790000,#7b3000,#7c4900,#827a00,#3e6617,#045f20,#005824,#005951,#005b7e,#003562,#002056,#0c004b,#30004a,#4b0048,#7a0045,#7a0026'; 916 var colorsList = colors.split( ',' ); 917 var tbl = '<table class="colorPickerTable"><thead>'; 918 for (var i = 0; i < colorsList.length; i++) { 919 if (i % 16 == 0) { 920 tbl += (i > 0 ? '</tr>' : '') + '<tr>'; 921 } 922 tbl += '<td style="background-color:' + colorsList[i] + '"> </td>'; 923 } 924 tbl += '</tr></thead><tbody>' 925 + '<tr style="height:60px;">' 926 + '<td colspan="8" id="' + id + '_colorPreview" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">' 927 + '<input style="width:55px;color:#000;border:1px solid rgb(0, 0, 0);padding:5px;background-color:#fff;font:11px Arial, Helvetica, sans-serif;" maxlength="7" />' 928 + '<a href="#" id="' + id + '_moreColors" class="iColorPicker_moreColors"></a>' 929 + '</td>' 930 + '<td colspan="8" id="' + id + '_colorOriginal" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">' 931 + '<input style="width:55px;color:#000;border:1px solid rgb(0, 0, 0);padding:5px;background-color:#fff;font:11px Arial, Helvetica, sans-serif;" readonly="readonly" />' 932 + '</td>' 933 + '</tr></tbody></table>'; 934 935 jQuery( document.createElement( "div" ) ) 936 .attr( "id", id ) 937 .css( 'display','none' ) 938 .html( tbl ) 939 .appendTo( "body" ) 940 .addClass( "iColorPickerTable" ) 941 .on( 'mouseover', 'thead td', function(){ 942 var aaa = qwery_rgb2hex( jQuery( this ).css( 'background-color' ) ); 943 jQuery( '#' + id + '_colorPreview' ).css( 'background',aaa ); 944 jQuery( '#' + id + '_colorPreview input' ).val( aaa ); 945 } 946 ) 947 .on( 'keypress', '#' + id + '_colorPreview input', function(key){ 948 var aaa = jQuery( this ).val(); 949 if (aaa.length < 7 && ((key.which >= 48 && key.which <= 57) || (key.which >= 97 && key.which <= 102) || (key.which === 35 || aaa.length === 0))) { 950 aaa += String.fromCharCode( key.which ); 951 } else if (key.which == 8 && aaa.length > 0) { 952 aaa = aaa.substring( 0, aaa.length - 1 ); 953 } else if (key.which === 13 && (aaa.length === 4 || aaa.length === 7)) { 954 var fld = jQuery( '#' + id ).data( 'field' ); 955 var func = jQuery( '#' + id ).data( 'func' ); 956 if (func !== null && func != 'undefined') { 957 func( fld, aaa ); 958 } else { 959 fld.val( aaa ).css( 'backgroundColor', aaa ).trigger( 'change' ); 960 } 961 jQuery( '#' + id + '_Bg' ).fadeOut( 500 ); 962 jQuery( '#' + id ).fadeOut( 500 ); 963 964 } else { 965 key.preventDefault(); 966 return false;
967 } 968 if (aaa.substr( 0,1 ) === '#' && (aaa.length === 4 || aaa.length === 7)) { 969 jQuery( '#' + id + '_colorPreview' ).css( 'background',aaa ); 970 } 971 return true; 972 } 973 ) 974 .on( 'click', 'thead td', function(e){ 975 var fld = jQuery( '#' + id ).data( 'field' ); 976 var func = jQuery( '#' + id ).data( 'func' ); 977 var aaa = qwery_rgb2hex( jQuery( this ).css( 'background-color' ) ); 978 if (func !== null && func != 'undefined') { 979 func( fld, aaa ); 980 } else { 981 fld.val( aaa ).css( 'backgroundColor', aaa ).trigger( 'change' ); 982 } 983 jQuery( '#' + id + '_Bg' ).fadeOut( 500 ); 984 jQuery( '#' + id ).fadeOut( 500 ); 985 e.preventDefault(); 986 return false; 987 } 988 ) 989 .on( 'click', 'tbody .iColorPicker_moreColors', function(e){ 990 var thead = jQuery( this ).parents( 'table' ).find( 'thead' ); 991 var out = ''; 992 if (thead.hasClass( 'more_colors' )) { 993 for (var i = 0; i < colorsList.length; i++) { 994 if (i % 16 == 0) { 995 out += (i > 0 ? '</tr>' : '') + '<tr>'; 996 } 997 out += '<td style="background-color:' + colorsList[i] + '"> </td>'; 998 } 999 thead.removeClass( 'more_colors' ).empty().html( out + '</tr>' ); 1000 jQuery( '#' + id + '_colorPreview' ).attr( 'colspan', 8 ); 1001 jQuery( '#' + id + '_colorOriginal' ).attr( 'colspan', 8 ); 1002 } else { 1003 var rgb = [0,0,0], i = 0, j = -1; // Set j=-1 or j=0 - show 2 different colors layouts 1004 while (rgb[0] < 0xF || rgb[1] < 0xF || rgb[2] < 0xF) { 1005 if (i % 18 === 0) { 1006 out += (i > 0 ? '</tr>' : '') + '<tr>'; 1007 } 1008 i++; 1009 out += '<td style="background-color:' + qwery_components2hex( rgb[0] * 16 + rgb[0],rgb[1] * 16 + rgb[1],rgb[2] * 16 + rgb[2] ) + '"> </td>'; 1010 rgb[2] += 3; 1011 if (rgb[2] > 0xF) { 1012 rgb[1] += 3; 1013 if (rgb[1] > (j === 0 ? 6 : 0xF)) { 1014 rgb[0] += 3; 1015 if (rgb[0] > 0xF) { 1016 if (j === 0) { 1017 j = 1; 1018 rgb[0] = 0; 1019 rgb[1] = 9; 1020 rgb[2] = 0; 1021 } else { 1022 break; 1023 } 1024 } else { 1025 rgb[1] = (j < 1 ? 0 : 9); 1026 rgb[2] = 0; 1027 } 1028 } else { 1029 rgb[2] = 0; 1030 } 1031 } 1032 } 1033 thead.addClass( 'more_colors' ).empty().html( out + '<td style="background-color:#ffffff" colspan="8"> </td></tr>' ); 1034 jQuery( '#' + id + '_colorPreview' ).attr( 'colspan', 9 ); 1035 jQuery( '#' + id + '_colorOriginal' ).attr( 'colspan', 9 ); 1036 } 1037 jQuery( '#' + id + ' table.colorPickerTable thead td' ) 1038 .css( 1039 { 1040 'width':'12px', 1041 'height':'14px', 1042 'border':'1px solid #000', 1043 'cursor':'pointer' 1044 } 1045 ); 1046 e.preventDefault(); 1047 return false; 1048 } 1049 ); 1050 jQuery( document.createElement( "div" ) ) 1051 .attr( "id", id + "_Bg" ) 1052 .on( 'click', function(e) { 1053 jQuery( "#" + id + "_Bg" ).fadeOut( 500 ); 1054 jQuery( "#" + id ).fadeOut( 500 ); 1055 e.preventDefault(); 1056 return false; 1057 } 1058 ) 1059 .appendTo( "body" ); 1060 jQuery( '#' + id + ' table.colorPickerTable thead td' ) 1061 .css( 1062 { 1063 'width':'12px', 1064 'height':'14px', 1065 'border':'1px solid #000', 1066 'cursor':'pointer' 1067 } 1068 ); 1069 jQuery( '#' + id + ' table.colorPickerTable' ) 1070 .css( {'border-collapse':'collapse'} ); 1071 jQuery( '#' + id ) 1072 .css( 1073 { 1074 'border':'1px solid #ccc', 1075 'background':'#333', 1076 'padding':'5px', 1077 'color':'#fff' 1078 } 1079 ); 1080 jQuery( '#' + id + '_colorPreview' ) 1081 .css( {'height':'50px'} ); 1082 return id; 1083 }; 1084 1085 window.qwery_color_picker_show = function(id, fld, func) { 1086 if (id === null || id === '') { 1087 id = jQuery( '.iColorPickerTable' ).attr( 'id' ); 1088 } 1089 var eICP = fld.offset(); 1090 var w = jQuery( '#' + id ).width(); 1091 var h = jQuery( '#' + id ).height(); 1092 var l = eICP.left + w < $window.width() - 10 ? eICP.left : $window.width() - 10 - w; 1093 var t = eICP.top + fld.outerHeight() + h < $window.scrollTop() + $window.height() - 10 ? eICP.top + fld.outerHeight() : eICP.top - h - 13; 1094 jQuery( "#" + id ) 1095 .data( {field: fld, func: func} ) 1096 .css( 1097 { 1098 'top':t + "px", 1099 'left':l + "px", 1100 'position':'absolute', 1101 'z-index':999999 1102 } 1103 ) 1104 .fadeIn( 500 ); 1105 jQuery( "#" + id + "_Bg" ) 1106 .css( 1107 { 1108 'position':'fixed', 1109 'z-index':999998, 1110 'top':0, 1111 'left':0, 1112 'width':'100%', 1113 'height':'100%' 1114 } 1115 ) 1116 .fadeIn( 500 ); 1117 var def = fld.val().substr( 0, 1 ) == '#' ? fld.val() : qwery_rgb2hex( fld.css( 'backgroundColor' ) ); 1118 jQuery( '#' + id + '_colorPreview input,#' + id + '_colorOriginal input' ).val( def ); 1119 jQuery( '#' + id + '_colorPreview,#' + id + '_colorOriginal' ).css( 'background',def ); 1120 }; 1121 1122 /* CSS functions 1123 ---------------------------------------------------------------- */ 1124 1125 // Return font-family string from the font parameters 1126 window.qwery_get_load_fonts_family_string = function( name, family ) { 1127 var parts = [ name ]; 1128 if ( qwery_alltrim( family ) != '' ) { 1129 parts = parts.concat( family.split( ',' ) ); 1130 } 1131 for( var i = 0; i < parts.length; i++ ) { 1132 parts[ i ] = qwery_alltrim( parts[ i ] ); 1133 if ( parts[ i ].indexOf( '"' ) < 0 && parts[ i ].indexOf( ' ' ) >= 0 ) { 1134 parts[ i ] = '"' + parts[ i ] + '"'; 1135 } 1136 } 1137 return parts.join(','); 1138 }; 1139 1140 // Return class by prefix from classes string
1141 window.qwery_get_class_by_prefix = function(classes, prefix) { 1142 var rez = ''; 1143 if ( classes ) { 1144 classes = classes.split(' '); 1145 for (var i=0; i < classes.length; i++) { 1146 if (classes[i].indexOf(prefix) >= 0) { 1147 rez = classes[i].replace(/[\s]+/g, ''); // Remove \t\r\n and spaces from the new class 1148 break; 1149 } 1150 } 1151 } 1152 return rez; 1153 }; 1154 1155 // Replace class by prefix with new value 1156 window.qwery_chg_class_by_prefix = function(classes, prefix, new_value) { 1157 var chg = false; 1158 if ( ! classes ) classes = ''; 1159 classes = classes.replace(/[\s]+/g, ' ').split(' '); // Replace groups \t\r\n and spaces with the single space 1160 new_value = new_value.replace(/[\s]+/g, ''); // Remove \t\r\n and spaces from the new class 1161 if ( typeof prefix == 'string' ) { 1162 prefix = [prefix]; 1163 } 1164 for (var i=0; i < classes.length; i++) { 1165 for (var j = 0; j < prefix.length; j++ ) { 1166 if (classes[i].indexOf( prefix[j] ) >= 0) { 1167 classes[i] = new_value; 1168 chg = true; 1169 break; 1170 } 1171 } 1172 if ( chg ) break; 1173 } 1174 if ( ! chg && new_value ) { 1175 if (classes.length == 1 && classes[0] === '') 1176 classes[0] = new_value; 1177 else 1178 classes.push( new_value ); 1179 } 1180 return classes.join(' '); 1181 }; 1182 1183 // Get inline styles and add to the page styles 1184 window.qwery_import_inline_styles = function( response ) { 1185 if ( ! response ) { 1186 return; 1187 } 1188 var selectors = qwery_apply_filters( 'qwery_filter_spa_inline_css_selectors', [ 1189 'qwery-inline-styles-inline-css', 1190 'trx_addons-inline-styles-inline-css', 1191 'woocommerce-inline-inline-css', 1192// 'wpgdprc-front-css-inline-css', 1193 'elementor-frontend-inline-css' 1194 ] ); 1195 var p1, p2, inline_css, $inline_css_tag; 1196 for ( var i = 0; i < selectors.length; i++ ) { 1197 p1 = response.indexOf( selectors[i] ); 1198 if ( p1 > 0 ) { 1199 p1 = response.indexOf( '>', p1 ) + 1; 1200 p2 = response.indexOf( '</style>', p1 ), 1201 inline_css = response.substring( p1, p2 ), 1202 $inline_css_tag = jQuery( '#' + selectors[i] ); 1203 if ( $inline_css_tag.length === 0 ) { 1204 $body.append( '<style id="' + selectors[i] + '" type="text/css">' + inline_css + '</style>' ); 1205 } else { 1206 $inline_css_tag.append( inline_css ); 1207 } 1208 } 1209 } 1210 }; 1211 1212 1213 // Get tags 'link' from response and add its to the 'head' 1214 window.qwery_import_tags_link = function( response ) { 1215 // Get links to css from response 1216 var links = response ? response.match( /<link[^>]*rel=['"]stylesheet['"][^>]*id=['"]([^'"]+)['"][^>]*>/g ) : false; 1217 if ( links ) { 1218 // Prepend its to the HEAD (if not loaded in the current page) 1219 var $head = jQuery( 'head' ); 1220 for ( var i = 0; i < links.length; i++ ) { 1221 var matches = links[i].match( /<link[^>]*rel=['"]stylesheet['"][^>]*id=['"]([^'"]+)['"][^>]*>/ ); 1222 if ( matches && matches.length && matches.length > 1 && matches[1] ) { 1223 if ( jQuery( '#' + matches[1].replace('.', '\\.') ).length === 0 ) { 1224 $head.prepend( links[i] ); 1225 } 1226 } 1227 } 1228 } 1229 }; 1230 1231 1232 /* Cookies manipulations 1233 ---------------------------------------------------------------- */ 1234 1235 window.qwery_get_cookie = function(name) { 1236 var defa = arguments[1] !== undefined ? arguments[1] : null; 1237 var start = document.cookie.indexOf( name + '=' ); 1238 var len = start + name.length + 1; 1239 if (( ! start) && (name != document.cookie.substring( 0, name.length ))) { 1240 return defa; 1241 } 1242 if (start == -1) { 1243 return defa; 1244 } 1245 var end = document.cookie.indexOf( ';', len ); 1246 if (end == -1) { 1247 end = document.cookie.length; 1248 } 1249 return unescape( document.cookie.substring( len, end ) ); 1250 }; 1251 1252 window.qwery_set_cookie = function(name, value) { 1253 var expires = arguments[2] !== undefined ? arguments[2] : 0; // In ms ( sec * 1000 ). If 0 (by default) - store the value for the current session only 1254 var path = arguments[3] !== undefined ? arguments[3] : '/'; 1255 var domain = arguments[4] !== undefined ? arguments[4] : ''; 1256 var secure = arguments[5] !== undefined ? arguments[5] : ''; 1257 var samesite = arguments[6] !== undefined ? arguments[6] : 'strict'; // strict | lax | none 1258 var today = new Date(); 1259 today.setTime( today.getTime() ); 1260 var expires_date = new Date( today.getTime() + (expires * 1) ); 1261 document.cookie = encodeURIComponent(name) + '=' 1262 + encodeURIComponent( value ) 1263 + (expires ? ';expires=' + expires_date.toGMTString() : '') 1264 + (path ? ';path=' + path : '') 1265 + (domain ? ';domain=' + domain : '') 1266 + (secure ? ';secure' : '') 1267 + (samesite ? ';samesite=' + samesite : ''); 1268 }; 1269
1270 window.qwery_del_cookie = function(name) { 1271 var path = arguments[1] !== undefined ? arguments[1] : '/'; 1272 var domain = arguments[2] !== undefined ? arguments[2] : ''; 1273 var secure = arguments[3] !== undefined ? arguments[3] : ''; 1274 var samesite = arguments[4] !== undefined ? arguments[4] : 'strict'; // strict | lax | none 1275 if ( qwery_get_cookie( name ) ) { 1276 document.cookie = name + '=' 1277 + ';expires=Thu, 01-Jan-1970 00:00:01 GMT' 1278 + (path ? ';path=' + path : '') 1279 + (domain ? ';domain=' + domain : '') 1280 + (secure ? ';secure' : '') 1281 + (samesite ? ';samesite=' + samesite : ''); 1282 } 1283 }; 1284 1285 /* Local storage manipulations 1286 ---------------------------------------------------------------- */ 1287 1288 window.qwery_is_local_storage_exists = function() { 1289 try { 1290 return 'localStorage' in window && window['localStorage'] !== null; 1291 } catch (e) { 1292 return false; 1293 } 1294 }; 1295 1296 window.qwery_get_storage = function(name) { 1297 var defa = arguments[1] !== undefined ? arguments[1] : null; 1298 var val = null; 1299 if (qwery_is_local_storage_exists()) { 1300 val = window['localStorage'].getItem(name); 1301 if (val === null) val = defa; 1302 } else { 1303 val = qwery_get_cookie(name, defa); 1304 } 1305 return val; 1306 }; 1307 1308 window.qwery_set_storage = function(name, value) { 1309 if (qwery_is_local_storage_exists()) 1310 window['localStorage'].setItem(name, value); 1311 else 1312 qwery_set_cookie(name, value, 365 * 24 * 60 * 60 * 1000); // 1 year 1313 }; 1314 1315 window.qwery_del_storage = function(name) { 1316 if (qwery_is_local_storage_exists()) 1317 window['localStorage'].removeItem(name); 1318 else 1319 qwery_del_cookie(name); 1320 }; 1321 1322 window.qwery_clear_storage = function() { 1323 if (qwery_is_local_storage_exists()) 1324 window['localStorage'].clear(); 1325 }; 1326 1327 /* ListBox and ComboBox manipulations 1328 ---------------------------------------------------------------- */ 1329 1330 window.qwery_clear_listbox = function(box) { 1331 for (var i = box.options.length - 1; i >= 0; i--) { 1332 box.options[i] = null; 1333 } 1334 }; 1335 1336 window.qwery_add_listbox_item = function(box, val, text) { 1337 var item = new Option(); 1338 item.value = val; 1339 item.text = text; 1340 box.options.add( item ); 1341 }; 1342 1343 window.qwery_del_listbox_item_by_value = function(box, val) { 1344 for (var i = 0; i < box.options.length; i++) { 1345 if (box.options[i].value == val) { 1346 box.options[i] = null; 1347 break; 1348 } 1349 } 1350 }; 1351 1352 window.qwery_del_listbox_item_by_text = function(box, txt) { 1353 for (var i = 0; i < box.options.length; i++) { 1354 if (box.options[i].text == txt) { 1355 box.options[i] = null; 1356 break; 1357 } 1358 } 1359 }; 1360 1361 window.qwery_find_listbox_item_by_value = function(box, val) { 1362 var idx = -1; 1363 for (var i = 0; i < box.options.length; i++) { 1364 if (box.options[i].value == val) { 1365 idx = i; 1366 break; 1367 } 1368 } 1369 return idx; 1370 }; 1371 1372 window.qwery_find_listbox_item_by_text = function(box, txt) { 1373 var idx = -1; 1374 for (var i = 0; i < box.options.length; i++) { 1375 if (box.options[i].text == txt) { 1376 idx = i; 1377 break; 1378 } 1379 } 1380 return idx; 1381 }; 1382 1383 window.qwery_select_listbox_item_by_value = function(box, val) { 1384 for (var i = 0; i < box.options.length; i++) { 1385 box.options[i].selected = (val == box.options[i].value); 1386 } 1387 }; 1388 1389 window.qwery_select_listbox_item_by_text = function(box, txt) { 1390 for (var i = 0; i < box.options.length; i++) { 1391 box.options[i].selected = (txt == box.options[i].text); 1392 } 1393 }; 1394 1395 window.qwery_get_listbox_values = function(box) { 1396 var delim = arguments[1] !== undefined ? arguments[1] : ','; 1397 var str = ''; 1398 for (var i = 0; i < box.options.length; i++) { 1399 str += (str ? delim : '') + box.options[i].value; 1400 } 1401 return str; 1402 }; 1403 1404 window.qwery_get_listbox_texts = function(box) { 1405 var delim = arguments[1] !== undefined ? arguments[1] : ','; 1406 var str = ''; 1407 for (var i = 0; i < box.options.length; i++) { 1408 str += (str ? delim : '') + box.options[i].text; 1409 } 1410 return str; 1411 }; 1412 1413 window.qwery_sort_listbox = function(box) { 1414 var temp_opts = new Array(), 1415 temp = new Option(), 1416 i, x, y; 1417 for (i = 0; i < box.options.length; i++) { 1418 temp_opts[i] = box.options[i].clone(); 1419 } 1420 for (x = 0; x < temp_opts.length - 1; x++) { 1421 for (y = (x + 1); y < temp_opts.length; y++) { 1422 if (temp_opts[x].text > temp_opts[y].text) { 1423 temp = temp_opts[x]; 1424 temp_opts[x] = temp_opts[y]; 1425 temp_opts[y] = temp; 1426 } 1427 } 1428 } 1429 for (i = 0; i < box.options.length; i++) { 1430 box.options[i] = temp_opts[i].clone(); 1431 } 1432 }; 1433 1434 window.qwery_get_listbox_selected_index = function(box) { 1435 for (var i = 0; i < box.options.length; i++) { 1436 if (box.options[i].selected) { 1437 return i; 1438 } 1439 } 1440 return -1; 1441 }; 1442 1443 window.qwery_get_listbox_selected_value = function(box) { 1444 for (var i = 0; i < box.options.length; i++) { 1445 if (box.options[i].selected) { 1446 return box.options[i].value; 1447 } 1448 } 1449 return null; 1450 }; 1451 1452 window.qwery_get_listbox_selected_text = function(box) { 1453 for (var i = 0; i < box.options.length; i++) { 1454 if (box.options[i].selected) { 1455 return box.options[i].text; 1456 } 1457 } 1458 return null; 1459 }; 1460 1461 window.qwery_get_listbox_selected_option = function(box) { 1462 for (var i = 0; i < box.options.length; i++) { 1463 if (box.options[i].selected) { 1464 return box.options[i]; 1465 } 1466 } 1467 return null; 1468 }; 1469 1470 /* Radio buttons manipulations 1471 ---------------------------------------------------------------- */ 1472 1473 window.qwery_get_radio_value = function(radioGroupObj) { 1474 for (var i = 0; i < radioGroupObj.length; i++) { 1475 if (radioGroupObj[i].checked) { 1476 return radioGroupObj[i].value; 1477 } 1478 } 1479 return null; 1480 }; 1481 1482 window.qwery_set_radio_checked_by_num = function(radioGroupObj, num) { 1483 for (var i = 0; i < radioGroupObj.length; i++) { 1484 if (radioGroupObj[i].checked && i != num) { 1485 radioGroupObj[i].checked = false;
1486 } else if (i == num) { 1487 radioGroupObj[i].checked = true; 1488 } 1489 } 1490 }; 1491 1492 window.qwery_set_radio_checked_by_value = function(radioGroupObj, val) { 1493 for (var i = 0; i < radioGroupObj.length; i++) { 1494 if (radioGroupObj[i].checked && radioGroupObj[i].value != val) { 1495 radioGroupObj[i].checked = false; 1496 } else if (radioGroupObj[i].value == val) { 1497 radioGroupObj[i].checked = true; 1498 } 1499 } 1500 }; 1501 1502 /* Form manipulations 1503 ---------------------------------------------------------------- */ 1504 1505 /* 1506 // Usage example: 1507 var error = qwery_form_validate(jQuery(form_selector), { // -------- Options --------- 1508 error_message_show: true, // Display or not error message 1509 error_message_time: 5000, // Time to display error message 1510 error_message_class: 'message_box message_box_error', // Class, appended to error message block 1511 error_message_text: 'Global error text', // Global error message text (if don't write message in checked field) 1512 error_fields_class: 'error_field', // Class, appended to error fields 1513 exit_after_first_error: false, // Cancel validation and exit after first error 1514 rules: [ 1515 { 1516 field: 'author', // Checking field name 1517 min_length: { value: 1, message: 'The author name can\'t be empty' }, // Min character count (0 - don't check), message - if error occurs 1518 max_length: { value: 60, message: 'Too long author name'} // Max character count (0 - don't check), message - if error occurs 1519 }, 1520 { 1521 field: 'email', 1522 min_length: { value: 7, message: 'Too short (or empty) email address' }, 1523 max_length: { value: 60, message: 'Too long email address'}, 1524 mask: { value: '^([a-zA-Z0-9_\\-]+\\.)*[a-zA-Z0-9_\\-]+@[a-zA-Z0-9_\\-]+(\\.[a-zA-Z0-9_\\-]+)*\\.[a-zA-Z]{2,6}$', message: 'Invalid email address'} 1525 }, 1526 { 1527 field: 'comment', 1528 min_length: { value: 1, message: 'The comment text can\'t be empty' }, 1529 max_length: { value: 200, message: 'Too long comment'} 1530 }, 1531 { 1532 field: 'pwd1', 1533 min_length: { value: 5, message: 'The password can\'t be less then 5 characters' }, 1534 max_length: { value: 20, message: 'Too long password'} 1535 }, 1536 { 1537 field: 'pwd2', 1538 equal_to: { value: 'pwd1', message: 'The passwords in both fields must be equals' } 1539 } 1540 ] 1541 }); 1542 */ 1543 1544 window.qwery_form_validate = function(form, opt) { 1545 var error_msg = ''; 1546 form.find( ":input" ).each( 1547 function() { 1548 if (error_msg !== '' && opt.exit_after_first_error) { 1549 return; 1550 } 1551 for (var i = 0; i < opt.rules.length; i++) { 1552 if (jQuery( this ).attr( "name" ) == opt.rules[i].field) { 1553 var val = jQuery( this ).val(); 1554 var error = false; 1555 if (typeof(opt.rules[i].min_length) == 'object') { 1556 if (opt.rules[i].min_length.value > 0 && val.length < opt.rules[i].min_length.value) { 1557 if (error_msg == '') { 1558 jQuery( this ).get( 0 ).focus(); 1559 } 1560 error_msg += '<p class="error_item">' + (typeof(opt.rules[i].min_length.message) != 'undefined' ? opt.rules[i].min_length.message : opt.error_message_text ) + '</p>'; 1561 error = true; 1562 } 1563 } 1564 if (( ! error || ! opt.exit_after_first_error) && typeof(opt.rules[i].max_length) == 'object') { 1565 if (opt.rules[i].max_length.value > 0 && val.length > opt.rules[i].max_length.value) { 1566 if (error_msg == '') { 1567 jQuery( this ).get( 0 ).focus(); 1568 } 1569 error_msg += '<p class="error_item">' + (typeof(opt.rules[i].max_length.message) != 'undefined' ? opt.rules[i].max_length.message : opt.error_message_text ) + '</p>'; 1570 error = true; 1571 } 1572 } 1573 if (( ! error || ! opt.exit_after_first_error) && typeof(opt.rules[i].mask) == 'object') { 1574 if (opt.rules[i].mask.value !== '') { 1575 var regexp = new RegExp( opt.rules[i].mask.value ); 1576 if ( ! regexp.test( val )) { 1577 if (error_msg == '') { 1578 jQuery( this ).get( 0 ).focus(); 1579 } 1580 error_msg += '<p class="error_item">' + (typeof(opt.rules[i].mask.message) != 'undefined' ? opt.rules[i].mask.message : opt.error_message_text ) + '</p>'; 1581 error = true; 1582 } 1583 } 1584 } 1585 if (( ! error || ! opt.exit_after_first_error) && typeof(opt.rules[i].state) == 'object') { 1586 if (opt.rules[i].state.value == 'checked' && ! jQuery( this ).get( 0 ).
1586checked) { 1587 if (error_msg == '') { 1588 jQuery( this ).get( 0 ).focus(); 1589 } 1590 error_msg += '<p class="error_item">' + (typeof(opt.rules[i].state.message) != 'undefined' ? opt.rules[i].state.message : opt.error_message_text ) + '</p>'; 1591 error = true; 1592 } 1593 } 1594 if (( ! error || ! opt.exit_after_first_error) && typeof(opt.rules[i].equal_to) == 'object') { 1595 if (opt.rules[i].equal_to.value !== '' && val != jQuery( jQuery( this ).get( 0 ).form[opt.rules[i].equal_to.value] ).val()) { 1596 if (error_msg == '') { 1597 jQuery( this ).get( 0 ).focus(); 1598 } 1599 error_msg += '<p class="error_item">' + (typeof(opt.rules[i].equal_to.message) != 'undefined' ? opt.rules[i].equal_to.message : opt.error_message_text ) + '</p>'; 1600 error = true; 1601 } 1602 } 1603 if (opt.error_fields_class !== '') { 1604 jQuery( this ).toggleClass( opt.error_fields_class, error ); 1605 } 1606 } 1607 } 1608 } 1609 ); 1610 if (error_msg !== '' && opt.error_message_show) { 1611 var error_message_box = form.find( ".result" ); 1612 if (error_message_box.length == 0) { 1613 error_message_box = form.parent().find( ".result" ); 1614 } 1615 if (error_message_box.length == 0) { 1616 form.append( '<div class="result"></div>' ); 1617 error_message_box = form.find( ".result" ); 1618 } 1619 if (opt.error_message_class) { 1620 error_message_box.toggleClass( opt.error_message_class, true ); 1621 } 1622 error_message_box.html( error_msg ).fadeIn(); 1623 setTimeout( function() { error_message_box.fadeOut(); }, opt.error_message_time ); 1624 } 1625 return error_msg !== ''; 1626 }; 1627 1628 /* Document manipulations 1629 ---------------------------------------------------------------- */ 1630 1631 // Animated scroll to selected id 1632 window.trx_addons_document_animate_to_busy = false; 1633 window.qwery_document_animate_to = function(id) { 1634 var split_animation = true; 1635 var speed = arguments.length > 1 ? arguments[1] : -1; 1636 var callback = arguments.length > 2 ? arguments[2] : undefined; 1637 var oft = ! isNaN( id ) ? Number( id ) : 0, 1638 oft2 = -1; 1639 var obj = null; 1640 if (isNaN( id )) { 1641 if ( typeof id == 'object' ) { 1642 if ( id.length > 0 ) { 1643 obj = id; 1644 } else { 1645 return; 1646 } 1647 } else { 1648 if ( id.substring(0, 1) != '#' && id.substring(0, 1) != '.' ) { 1649 id = '#' + id; 1650 } 1651 obj = jQuery(id).eq(0); 1652 if ( obj.length === 0 ) { 1653 return; 1654 } 1655 } 1656 oft = split_animation ? obj.offset().top : Math.max( 0, obj.offset().top - qwery_fixed_rows_height() ); 1657 if ( split_animation ) { 1658 oft2 = Math.max( 0, oft - qwery_fixed_rows_height() ); 1659 } 1660 } 1661 if (speed < 0) { 1662 speed = Math.min( 1000, Math.max( 300, Math.round( Math.abs( ( oft2 < 0 ? oft : oft2 ) - $window.scrollTop() ) / $window.height() * 300 ) ) ); 1663 } 1664 if (oft2 >= 0) { 1665 setTimeout( function() { 1666 if (isNaN( id )) { 1667 oft = obj.offset().top; 1668 } 1669 oft2 = Math.max( 0, oft - qwery_fixed_rows_height() ); 1670 jQuery( 'body,html' ).stop( true ).animate( {scrollTop: oft2}, Math.floor( speed / 2 ), 'linear', function() { 1671 _window_scroll_top = $window.scrollTop(); 1672 window.trx_addons_document_animate_to_busy = false; 1673 if ( callback ) callback( id, speed ); 1674 } ); 1675 }, Math.floor( speed / 2 ) ); 1676 } else { 1677 oft2 = oft; 1678 } 1679 if ( speed > 0 ) { 1680 jQuery( 'body,html' ).stop( true ).animate( { scrollTop: oft2 }, speed, 'linear', function() { 1681 _window_scroll_top = $window.scrollTop(); 1682 window.trx_addons_document_animate_to_busy = false; 1683 if ( callback ) callback( id, speed ); 1684 } ); 1685 } else { 1686 jQuery( 'body,html' ).stop( true ).scrollTop( oft2 ); 1687 _window_scroll_top = $window.scrollTop(); 1688 window.trx_addons_document_animate_to_busy = false; 1689 if ( callback ) callback( id, speed ); 1690 } 1691 }; 1692 1693 // Detect window width, height and scroll 1694 var _window_width = $window.width(), 1695 _window_height = $window.height(), 1696 _window_scroll_top = $window.scrollTop(), 1697 _window_scroll_left = $window.scrollLeft(); 1698 $window.on( 'resize', function() { 1699 _window_width = $window.width(); 1700 _window_height = $window.height(); 1701 _window_scroll_top = $window.scrollTop(); 1702 _window_scroll_left = $window.scrollLeft(); 1703 } ); 1704 $window.on( 'scroll', function() { 1705 _window_scroll_top = $window.scrollTop(); 1706 _window_scroll_left = $window.scrollLeft(); 1707 } ); 1708 window.qwery_window_width = function( val ) { 1709 if ( val ) _window_width = val; 1710 return _window_width; 1711 }; 1712 window.qwery_window_height = function( val ) { 1713 if ( val ) _window_height = val; 1714 return _window_height; 1715 }; 1716 window.qwery_window_scroll_top = function() { 1717 return _window_scroll_top; 1718 }; 1719 window.qwery_window_scroll_left = function() { 1720 return _window_scroll_left; 1721 }; 1722 1723 // Detect document height 1724 var _document_height; 1725 var _document_height_first_run = true; 1726 var _update_document_height = function( e ) { 1727 if ( typeof window.trx_addons_document_height == 'undefined' ) { 1728 if ( _document_height_first_run && e && e.namespace == 'init_hidden_elements' ) { 1729 _document_height_first_run = false;
1730 return; 1731 } 1732 _document_height = $document.height(); 1733 } 1734 }; 1735 $document.on( 'action.init_hidden_elements action.got_ajax_response', // Maybe need for ' action.sc_layouts_row_fixed_on action.sc_layouts_row_fixed_off' 1736 _update_document_height 1737 ); 1738 $window.on( 'resize', _update_document_height ); 1739 window.qwery_document_height = function() { 1740 return typeof window.trx_addons_document_height != 'undefined' ? trx_addons_document_height() : _document_height; 1741 }; 1742 1743 // Detect adminbar height (if present and fixed) 1744 var _adminbar_height = 0; 1745 var _update_adminbar_height = function() { 1746 if ( typeof window.trx_addons_adminbar_height == 'undefined' ) { 1747 _adminbar_height = qwery_adminbar_height_calc(); 1748 document.querySelector('html').style.setProperty( '--fixed-rows-height', _adminbar_height + 'px' ); 1749 } 1750 }; 1751 $window.on( 'resize', _update_adminbar_height ); 1752 window.qwery_adminbar_height_calc = function() { 1753 return qwery_apply_filters( 'qwery_filter_adminbar_height', 1754 $adminbar.length === 0 1755 || $adminbar.css( 'display' ) == 'none' 1756 || $adminbar.css( 'position' ) == 'absolute' 1757 ? 0 1758 : $adminbar.height() 1759 ); 1760 }; 1761 window.qwery_adminbar_height = function() { 1762 return typeof window.trx_addons_adminbar_height != 'undefined' ? trx_addons_adminbar_height() : _adminbar_height; 1763 }; 1764 1765 // First run - set initial values of document and adminbar height 1766 $document.ready( function() { 1767 _update_document_height(); 1768 _update_adminbar_height(); 1769 } ); 1770 1771 // Detect fixed rows height 1772 window.qwery_fixed_rows_height = function() { 1773 var with_admin_bar = arguments.length > 0 ? arguments[0] : true, 1774 with_fixed_rows = arguments.length > 1 ? arguments[1] : true; 1775 return typeof trx_addons_fixed_rows_height != 'undefined' 1776 ? trx_addons_fixed_rows_height( with_admin_bar, with_fixed_rows ) 1777 : ( with_admin_bar ? qwery_adminbar_height() : 0 ); 1778 }; 1779 1780 // Change browser address without reload page 1781 window.qwery_document_set_location = function( curLoc, state ) { 1782 try { 1783 history.pushState( state ? state : { url: curLoc }, null, curLoc ); 1784 return; 1785 } catch ( e ) {} 1786 location.href = curLoc; 1787 }; 1788 1789 // Add/Change arguments to the url address 1790 window.qwery_add_to_url = function(loc, prm) { 1791 var ignore_empty = arguments[2] !== undefined ? arguments[2] : true; 1792 var q = loc.indexOf( '?' ); 1793 var attr = {}; 1794 if (q > 0) { 1795 var qq = loc.substr( q + 1 ).split( '&' ); 1796 var parts = ''; 1797 for (var i = 0; i < qq.length; i++) { 1798 var parts = qq[i].split( '=' ); 1799 attr[parts[0]] = parts.length > 1 ? parts[1] : ''; 1800 } 1801 } 1802 for (var p in prm) { 1803 attr[p] = prm[p]; 1804 } 1805 loc = (q > 0 ? loc.substr( 0, q ) : loc) + '?'; 1806 var i = 0; 1807 for (p in attr) { 1808 if (ignore_empty && attr[p] == '') { 1809 continue; 1810 } 1811 loc += (i++ > 0 ? '&' : '') + p + '=' + attr[p]; 1812 } 1813 return loc; 1814 }; 1815 1816 // Check if url is page-inner (local) link 1817 window.qwery_is_local_link = function(url) { 1818 var rez = url !== undefined; 1819 if (rez) { 1820 var url_pos = url.indexOf( '#' ); 1821 if (url_pos == 0 && url.length == 1) { 1822 rez = false; 1823 } else { 1824 if (url_pos < 0) { 1825 url_pos = url.length; 1826 } 1827 var loc = window.location.href; 1828 var loc_pos = loc.indexOf( '#' ); 1829 if (loc_pos > 0) { 1830 loc = loc.substring( 0, loc_pos ); 1831 } 1832 rez = url_pos == 0; 1833 if ( ! rez) { 1834 rez = loc == url.substring( 0, url_pos ); 1835 } 1836 } 1837 } 1838 return rez; 1839 }; 1840 1841 // Check if the specified path is url 1842 window.qwery_is_url = function( url ) { 1843 return url.indexOf( '//' ) === 0 || url.indexOf( '://' ) > 0; 1844 }; 1845 1846 // Parse the string with AJAX response from the server and return it as an object 1847 window.qwery_parse_ajax_response = function( response, error_msg = '' ) { 1848 var rez = {}; 1849 if ( response == '' || response == 0 ) { 1850 rez = { error: error_msg || QWERY_STORAGE['msg_ajax_error'] }; 1851 } else if ( typeof response == 'string' ) { 1852 try { 1853 rez = JSON.parse( response ); 1854 } catch (e) { 1855 rez = { error: error_msg || QWERY_STORAGE['msg_ajax_error'] }; 1856 console.log( response ); 1857 } 1858 } else { 1859 rez = response; 1860 } 1861 return rez; 1862 }; 1863 1864 1865 /* Browsers detection 1866 ---------------------------------------------------------------- */ 1867 1868 window.qwery_browser_is_mobile = function() { 1869 var check = false;
1870 (function(a){if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test( a ) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test( a.substr( 0,4 ) )) { 1871 check = true} 1872 })( navigator.userAgent || navigator.vendor || window.opera ); 1873 return check; 1874 }; 1875 1876 window.qwery_browser_is_ios = function( with_mac ) { 1877 return navigator.userAgent.match( /iPad|iPhone|iPod/i ) != null || ( with_mac && navigator.userAgent.match( /Macintosh/i ) != null ); 1878 }; 1879 1880 window.qwery_is_retina = function() { 1881 var mediaQuery = '(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx)'; 1882 return (window.devicePixelRatio > 1) || (window.matchMedia && window.matchMedia( mediaQuery ).matches); 1883 }; 1884 1885 /* File functions 1886 ---------------------------------------------------------------- */ 1887 1888 window.qwery_get_file_name = function(path) { 1889 path = path.replace( /\\/g, '/' ); 1890 var pos = path.lastIndexOf( '/' ); 1891 if (pos >= 0) { 1892 path = path.substr( pos + 1 ); 1893 } 1894 return path; 1895 }; 1896 1897 window.qwery_get_file_ext = function(path) { 1898 var pos = path.lastIndexOf( '.' ); 1899 path = pos >= 0 ? path.substr( pos + 1 ) : ''; 1900 return path; 1901 }; 1902 1903 /* Image functions 1904 ---------------------------------------------------------------- */ 1905 1906 // Return true, if all images in the specified container are loaded 1907 window.qwery_is_images_loaded = function(cont) { 1908 var complete = true; 1909 cont.find( 'img' ).each( 1910 function() { 1911 // If any of previous images is not loaded - skip rest 1912 if ( ! complete) { 1913 return; 1914 } 1915 var img = jQuery( this ).get( 0 ); 1916 if (typeof img.complete == 'boolean') { 1917 // See if "complete" property is available 1918 complete = img.complete; 1919 } else if (typeof img.naturalWidth == 'number' && typeof img.naturalHeight == 'number') { 1920 // See if "naturalWidth" and "naturalHeight" properties are available 1921 complete = ! (this.naturalWidth == 0 && this.naturalHeight == 0); 1922 } 1923 } 1924 ); 1925 return complete; 1926 }; 1927 1928 // Call function when all images in the specified container are loaded 1929 window.qwery_when_images_loaded = function(cont, callback, max_delay) { 1930 if (max_delay === undefined) { 1931 max_delay = 3000; 1932 } 1933 if (max_delay <= 0 || qwery_is_images_loaded( cont )) { 1934 callback(); 1935 } else { 1936 setTimeout( 1937 function(){ 1938 qwery_when_images_loaded( cont, callback, max_delay - 100 ); 1939 }, 100 1940 ); 1941 } 1942 }; 1943 1944 1945 1946 /* Dev shorthands 1947 ---------------------------------------------------------------- */ 1948 1949 window.dcl === undefined && ( window.dcl = function(s) { console.log(s); } ); 1950 window.dcs === undefined && ( window.dcs = function() { console.trace(); } ); 1951 window.dcts === undefined && ( window.dcts = function( name ) { console.time( name ? name : 'timer' ); } ); 1952 window.dctl === undefined && ( window.dctl = function( name ) { console.timeLog( name ? name : 'timer' ); } ); 1953 window.dcte === undefined && ( window.dcte = function( name ) { console.timeEnd( name ? name : 'timer' ); } ); 1954 1955})();
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.