1/** 2 * AxiomThemes Framework: global variables storage 3 * 4 * @package axiom 5 * @since axiom 1.0 6 */ 7 8 9/* Global variables manipulations 10---------------------------------------------------------------- */ 11 12// Global variables storage 13if (typeof AXIOM_GLOBALS == 'undefined') var AXIOM_GLOBALS = {}; 14 15// Get global variable 16function axiom_get_global(var_name) { 17 return axiom_isset(AXIOM_GLOBALS[var_name]) ? AXIOM_GLOBALS[var_name] : ''; 18} 19 20// Set global variable 21function axiom_set_global(var_name, value) { 22 AXIOM_GLOBALS[var_name] = value; 23} 24 25// Inc/Dec global variable with specified value 26function axiom_inc_global(var_name) { 27 var value = arguments[1]==undefined ? 1 : arguments[1]; 28 AXIOM_GLOBALS[var_name] += value; 29} 30 31// Concatenate global variable with specified value 32function axiom_concat_global(var_name, value) { 33 AXIOM_GLOBALS[var_name] += ''+value; 34} 35 36// Get global array element 37function axiom_get_global_array(var_name, key) { 38 return axiom_isset(AXIOM_GLOBALS[var_name][key]) ? AXIOM_GLOBALS[var_name][key] : ''; 39} 40 41// Set global array element 42function axiom_set_global_array(var_name, key, value) { 43 if (!axiom_isset(AXIOM_GLOBALS[var_name])) AXIOM_GLOBALS[var_name] = {}; 44 AXIOM_GLOBALS[var_name][key] = value; 45} 46 47// Inc/Dec global array element with specified value 48function axiom_inc_global_array(var_name, key) { 49 var value = arguments[2]==undefined ? 1 : arguments[2]; 50 AXIOM_GLOBALS[var_name][key] += value; 51} 52 53// Concatenate global array element with specified value 54function axiom_concat_global_array(var_name, key, value) { 55 AXIOM_GLOBALS[var_name][key] += ''+value; 56} 57 58 59 60/* PHP-style functions 61---------------------------------------------------------------- */ 62function axiom_isset(obj) { 63 return obj != undefined; 64} 65 66function axiom_empty(obj) { 67 return obj == undefined || (typeof(obj)=='object' && obj == null) || (typeof(obj)=='array' && obj.length == 0) || (typeof(obj)=='string' && axiom_alltrim(obj)==''); 68} 69 70function axiom_is_array(obj) { 71 "use strict"; 72 return typeof(obj)=='array'; 73} 74 75function axiom_is_object(obj) { 76 "use strict"; 77 return typeof(obj)=='object'; 78} 79 80function axiom_in_array(val, thearray) { 81 "use strict"; 82 var rez = false; 83 for (var i=0; i<thearray.length-1; i++) { 84 if (thearray[i] == val) { 85 rez = true; 86 break; 87 } 88 } 89 return rez; 90} 91 92function axiom_clone_object(obj) { 93 if (obj == null || typeof(obj) != 'object') { 94 return obj; 95 } 96 var temp = {}; 97 for (var key in obj) { 98 temp[key] = axiom_clone_object(obj[key]); 99 } 100 return temp; 101} 102 103 104 105/* String functions 106---------------------------------------------------------------- */ 107 108function axiom_in_list(str, list) { 109 "use strict"; 110 var delim = arguments[2] ? arguments[2] : '|'; 111 var icase = arguments[3] ? arguments[3] : true; 112 var retval = false; 113 if (icase) { 114 str = str.toLowerCase(); 115 list = list.toLowerCase(); 116 } 117 var parts = list.split(delim); 118 for (var i=0; i<parts.length; i++) { 119 if (parts[i]==str) { 120 retval=true; 121 break; 122 } 123 } 124 return retval; 125} 126 127function axiom_alltrim(str) { 128 "use strict"; 129 var dir = arguments[1] ? arguments[1] : 'a'; 130 var rez = ''; 131 var i, start = 0, end = str.length-1; 132 if (dir=='a' || dir=='l') { 133 for (i=0; i<str.length; i++) { 134 if (str.substr(i,1)!=' ') { 135 start = i; 136 break; 137 } 138 } 139 } 140 if (dir=='a' || dir=='r') { 141 for (i=str.length-1; i>=0; i--) { 142 if (str.substr(i,1)!=' ') { 143 end = i; 144 break; 145 } 146 } 147 } 148 return str.substring(start, end+1); 149} 150 151function axiom_ltrim(str) { 152 "use strict"; 153 return axiom_alltrim(str, 'l'); 154} 155 156function axiom_rtrim(str) { 157 "use strict"; 158 return axiom_alltrim(str, 'r'); 159} 160 161function axiom_padl(str, len) { 162 "use strict"; 163 var ch = arguments[2] ? arguments[2] : ' '; 164 var rez = str.substr(0,len); 165 if (rez.length < len) { 166 for (var i=0; i<len-str.length; i++) 167 rez += ch; 168 } 169 return rez; 170} 171 172function axiom_padr(str, len) { 173 "use strict"; 174 var ch = arguments[2] ? arguments[2] : ' '; 175 var rez = str.substr(0,len); 176 if (rez.length < len) { 177 for (var i=0; i<len-str.length; i++) 178 rez = ch + rez; 179 } 180 return rez; 181} 182 183function axiom_padc(str, len) { 184 "use strict"; 185 var ch = arguments[2] ? arguments[2] : ' '; 186 var rez = str.substr(0,len); 187 if (rez.length < len) { 188 for (var i=0; i<Math.floor((len-str.length)/2); i++) 189 rez = ch + rez + ch; 190 } 191 return rez+(rez.length<len ? ch : ''); 192} 193 194function axiom_replicate(str, num) { 195 "use strict"; 196 var rez = ''; 197 for (var i=0; i<num; i++) { 198 rez += str; 199 } 200 return rez; 201} 202 203 204 205/* Numbers functions 206---------------------------------------------------------------- */ 207 208// Round number to specified precision.
209// For example: num=1.12345, prec=2, rounded=1.12 210// num=12345, prec=-2, rounded=12300 211function axiom_round_number(num) { 212 "use strict"; 213 var precision = arguments[1] ? arguments[1] : 0; 214 var p = Math.pow(10, precision); 215 return Math.round(num*p)/p; 216} 217 218// Clear number from any characters and append it with 0 to desired precision 219// For example: num=test1.12dd, prec=3, cleared=1.120 220function axiom_clear_number(num) { 221 "use strict"; 222 var precision = arguments[1] ? arguments[1] : 0; 223 var defa = arguments[2] ? arguments[2] : 0; 224 var res = ''; 225 var decimals = -1; 226 num = ""+num; 227 if (num=="") num=""+defa; 228 for (var i=0; i<num.length; i++) { 229 if (decimals==0) break; 230 else if (decimals>0) decimals--; 231 var ch = num.substr(i,1); 232 if (ch=='.') { 233 if (precision>0) { 234 res += ch; 235 } 236 decimals = precision; 237 } else if ((ch>=0 && ch<=9) || (ch=='-' && i==0)) 238 res+=ch; 239 } 240 if (precision>0 && decimals!=0) { 241 if (decimals==-1) { 242 res += '.'; 243 decimals = precision; 244 } 245 for (i=decimals; i>0; i--) 246 res +='0'; 247 } 248 //if (isNaN(res)) res = clearNumber(defa, precision, defa); 249 return res; 250} 251 252// Convert number from decimal to hex 253function axiom_dec2hex(n) { 254 "use strict"; 255 return Number(n).toString(16); 256} 257 258// Convert number from hex to decimal 259function axiom_hex2dec(hex) { 260 "use strict"; 261 return parseInt(hex,16); 262} 263 264 265 266/* Array manipulations 267---------------------------------------------------------------- */ 268 269function axiom_sort_array(thearray) { 270 "use strict"; 271 var caseSensitive = arguments[1] ? arguments[1] : false; 272 for (var x=0; x<thearray.length-1; x++) { 273 for (var y=(x+1); y<thearray.length; y++) { 274 if (caseSensitive) { 275 if (thearray[x] > thearray[y]) { 276 tmp = thearray[x]; 277 thearray[x] = thearray[y]; 278 thearray[y] = tmp; 279 } 280 } else { 281 if (thearray[x].toLowerCase() > thearray[y].toLowerCase()) { 282 tmp = thearray[x]; 283 thearray[x] = thearray[y]; 284 thearray[y] = tmp; 285 } 286 } 287 } 288 } 289 return thearray; 290} 291 292 293 294/* Date manipulations 295---------------------------------------------------------------- */ 296 297// Return array[Year, Month, Day, Hours, Minutes, Seconds] 298// from string: Year[-/.]Month[-/.]Day[T ]Hours:Minutes:Seconds 299function axiom_parse_date(dt) { 300 "use strict"; 301 dt = dt.replace(/\//g, '-').replace(/\./g, '-').replace(/T/g, ' ').split('+')[0]; 302 var dt2 = dt.split(' '); 303 var d = dt2[0].split('-'); 304 var t = dt2[1].split(':'); 305 d.push(t[0], t[1], t[2]); 306 return d; 307} 308 309// Return difference string between two dates 310function axiom_get_date_difference(dt1) { 311 "use strict"; 312 var dt2 = arguments[1]!==undefined ? arguments[1] : ''; 313 var short_date = arguments[2]!==undefined ? arguments[2] : true; 314 var sec = arguments[3]!==undefined ? arguments[3] : false; 315 var a1 = axiom_parse_date(dt1); 316 dt1 = Date.UTC(a1[0], a1[1], a1[2], a1[3], a1[4], a1[5]); 317 if (dt2 == '') { 318 dt2 = new Date(); 319 var a2 = [dt2.getFullYear(), dt2.getMonth()+1, dt2.getDate(), dt2.getHours(), dt2.getMinutes(), dt2.getSeconds()]; 320 } else 321 var a2 = axiom_parse_date(dt2); 322 dt2 = Date.UTC(a2[0], a2[1], a2[2], a2[3], a2[4], a2[5]); 323 var diff = Math.round((dt2 - dt1)/1000); 324 var days = Math.floor(diff / (24*3600)); 325 diff -= days * 24 * 3600; 326 var hours = Math.floor(diff / 3600); 327 diff -= hours * 3600; 328 var minutes = Math.floor(diff / 60); 329 diff -= minutes * 60; 330 rez = ''; 331 if (days > 0) 332 rez += (rez!='' ? ' ' : '') + days + ' day' + (days > 1 ? 's' : ''); 333 if ((!short_date || rez=='') && hours > 0) 334 rez += (rez!='' ? ' ' : '') + hours + ' hour' + (hours > 1 ? 's' : ''); 335 if ((!short_date || rez=='') && minutes > 0) 336 rez += (rez!='' ? ' ' : '') + minutes + ' minute' + (minutes > 1 ? 's' : ''); 337 if (sec || rez=='') 338 rez += rez!='' || sec ? (' ' + diff + ' second' + (diff > 1 ? 's' : '')) : 'less then minute'; 339 return rez; 340} 341 342 343 344/* Colors functions 345---------------------------------------------------------------- */ 346 347function axiom_hex2rgb(hex) { 348 hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16); 349 return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)}; 350} 351 352function axiom_rgb2hex(color) { 353 "use strict"; 354 var aRGB; 355 color = color.replace(/\s/g,"").toLowerCase(); 356 if (color=='rgba(0,0,0,0)' || color=='rgba(0%,0%,0%,0%)') 357 color = 'transparent'; 358 if (color.indexOf('rgba(')==0) 359 aRGB = color.match(/^rgba\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i); 360 else 361 aRGB = color.match(/^rgb\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i); 362 363 if(aRGB) { 364 color = ''; 365 for (var i=1; i<=3; i++) 366 color += Math.round((aRGB[i][aRGB[i].length-1]=="%"?2.55:1)*parseInt(aRGB[i])).toString(16).replace(/^(.)$/,'0$1'); 367 } else 368 color = color.replace(/^#?([\da-f])([\da-f])([\da-f])$/i, '$1$1$2$2$3$3'); 369 return (color.substr(0,1)!='#' ? '#' : '') + color; 370} 371 372function axiom_components2hex(r,g,b) { 373 "use strict"; 374 return '#'+ 375 Number(r).toString(16).toUpperCase().replace(/^(.)$/,'0$1') + 376 Number(g).toString(16).toUpperCase().replace(/^(.)$/,'0$1') + 377 Number(b).toString(16).toUpperCase().replace(/^(.)$/,'0$1'); 378} 379 380function axiom_rgb2components(color) { 381 "use strict"; 382 color = axiom_rgb2hex(color); 383 var matches = color.match(/^#?([\dabcdef]{2})([\dabcdef]{2})([\dabcdef]{2})$/i); 384 if (!matches) return false;
385 for (var i=1, rgb = new Array(3); i<=3; i++) 386 rgb[i-1] = parseInt(matches[i],16); 387 return rgb; 388} 389 390function axiom_hex2hsb(hex) { 391 "use strict"; 392 return axiom_rgb2hsb(axiom_hex2rgb(hex)); 393} 394 395function axiom_hsb2hex(hsb) { 396 var rgb = axiom_hsb2rgb(hsb); 397 return axiom_components2hex(rgb.r, rgb.g, rgb.b); 398} 399 400function axiom_rgb2hsb(rgb) { 401 "use strict"; 402 var hsb = {}; 403 hsb.b = Math.max(Math.max(rgb.r,rgb.g),rgb.b); 404 hsb.s = (hsb.b <= 0) ? 0 : Math.round(100*(hsb.b - Math.min(Math.min(rgb.r,rgb.g),rgb.b))/hsb.b); 405 hsb.b = Math.round((hsb.b /255)*100); 406 if ((rgb.r==rgb.g) && (rgb.g==rgb.b)) hsb.h = 0; 407 else if (rgb.r>=rgb.g && rgb.g>=rgb.b) hsb.h = 60*(rgb.g-rgb.b)/(rgb.r-rgb.b); 408 else if (rgb.g>=rgb.r && rgb.r>=rgb.b) hsb.h = 60 + 60*(rgb.g-rgb.r)/(rgb.g-rgb.b); 409 else if (rgb.g>=rgb.b && rgb.b>=rgb.r) hsb.h = 120 + 60*(rgb.b-rgb.r)/(rgb.g-rgb.r); 410 else if (rgb.b>=rgb.g && rgb.g>=rgb.r) hsb.h = 180 + 60*(rgb.b-rgb.g)/(rgb.b-rgb.r); 411 else if (rgb.b>=rgb.r && rgb.r>=rgb.g) hsb.h = 240 + 60*(rgb.r-rgb.g)/(rgb.b-rgb.g); 412 else if (rgb.r>=rgb.b && rgb.b>=rgb.g) hsb.h = 300 + 60*(rgb.r-rgb.b)/(rgb.r-rgb.g); 413 else hsb.h = 0; 414 hsb.h = Math.round(hsb.h); 415 return hsb; 416} 417 418function axiom_hsb2rgb(hsb) { 419 var rgb = {}; 420 var h = Math.round(hsb.h); 421 var s = Math.round(hsb.s*255/100); 422 var v = Math.round(hsb.b*255/100); 423 if (s == 0) { 424 rgb.r = rgb.g = rgb.b = v; 425 } else { 426 var t1 = v; 427 var t2 = (255-s)*v/255; 428 var t3 = (t1-t2)*(h%60)/60; 429 if (h==360) h = 0; 430 if (h<60) { rgb.r=t1; rgb.b=t2; rgb.g=t2+t3; } 431 else if (h<120) { rgb.g=t1; rgb.b=t2; rgb.r=t1-t3; } 432 else if (h<180) { rgb.g=t1; rgb.r=t2; rgb.b=t2+t3; } 433 else if (h<240) { rgb.b=t1; rgb.r=t2; rgb.g=t1-t3; } 434 else if (h<300) { rgb.b=t1; rgb.g=t2; rgb.r=t2+t3; } 435 else if (h<360) { rgb.r=t1; rgb.g=t2; rgb.b=t1-t3; } 436 else { rgb.r=0; rgb.g=0; rgb.b=0; } 437 } 438 return { r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b) }; 439} 440 441function axiom_color_picker(){ 442 "use strict"; 443 var id = arguments[0] ? arguments[0] : "iColorPicker"+Math.round(Math.random()*1000); 444 var colors = arguments[1] ? arguments[1] : 445 '#f00,#ff0,#0f0,#0ff,#00f,#f0f,#fff,#ebebeb,#e1e1e1,#d7d7d7,#cccccc,#c2c2c2,#b7b7b7,#acacac,#a0a0a0,#959595,' 446 +'#ee1d24,#fff100,#00a650,#00aeef,#2f3192,#ed008c,#898989,#7d7d7d,#707070,#626262,#555,#464646,#363636,#262626,#111,#000,' 447 +'#f7977a,#fbad82,#fdc68c,#fff799,#c6df9c,#a4d49d,#81ca9d,#7bcdc9,#6ccff7,#7ca6d8,#8293ca,#8881be,#a286bd,#bc8cbf,#f49bc1,#f5999d,' 448 +'#f16c4d,#f68e54,#fbaf5a,#fff467,#acd372,#7dc473,#39b778,#16bcb4,#00bff3,#438ccb,#5573b7,#5e5ca7,#855fa8,#a763a9,#ef6ea8,#f16d7e,' 449 +'#ee1d24,#f16522,#f7941d,#fff100,#8fc63d,#37b44a,#00a650,#00a99e,#00aeef,#0072bc,#0054a5,#2f3192,#652c91,#91278f,#ed008c,#ee105a,' 450 +'#9d0a0f,#a1410d,#a36209,#aba000,#588528,#197b30,#007236,#00736a,#0076a4,#004a80,#003370,#1d1363,#450e61,#62055f,#9e005c,#9d0039,' 451 +'#790000,#7b3000,#7c4900,#827a00,#3e6617,#045f20,#005824,#005951,#005b7e,#003562,#002056,#0c004b,#30004a,#4b0048,#7a0045,#7a0026'; 452 var colorsList = colors.split(','); 453 var tbl = '<table class="colorPickerTable"><thead>'; 454 for (var i=0; i<colorsList.length; i++) { 455 if (i%16==0) tbl += (i>0 ? '</tr>' : '') + '<tr>'; 456 tbl += '<td style="background-color:'+colorsList[i]+'"> </td>'; 457 } 458 tbl += '</tr></thead><tbody>' 459 + '<tr style="height:60px;">' 460 + '<td colspan="8" id="'+id+'_colorPreview" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">' 461 + '<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" />' 462 + '<a href="#" id="'+id+'_moreColors" class="iColorPicker_moreColors"></a>' 463 + '</td>' 464 + '<td colspan="8" id="'+id+'_colorOriginal" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">' 465 + '<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" />' 466 + '</td>' 467 + '</tr></tbody></table>'; 468 //tbl += '<style>#iColorPicker input{margin:2px}</style>'; 469 470 jQuery(document.createElement("div")) 471 .attr("id", id) 472 .css('display','none') 473 .html(tbl) 474 .appendTo("body") 475 .addClass("iColorPickerTable") 476 .on('mouseover', 'thead td', function(){ 477 "use strict"; 478 var aaa = axiom_rgb2hex(jQuery(this).css('background-color')); 479 jQuery('#'+id+'_colorPreview').css('background',aaa); 480 jQuery('#'+id+'_colorPreview input').val(aaa); 481 }) 482 .on('keypress', '#'+id+'_colorPreview input', function(key){ 483 "use strict"; 484 var aaa = jQuery(this).val()
485 if (aaa.length<7 && ((key.which>=48 && key.which<=57) || (key.which>=97 && key.which<=102) || (key.which===35 || aaa.length===0))) { 486 aaa += String.fromCharCode(key.which); 487 } else if (key.which == 8 && aaa.length>0) { 488 aaa = aaa.substring(0, aaa.length-1); 489 } else if (key.which===13 && (aaa.length===4 || aaa.length===7)) { 490 var fld = jQuery('#'+id).data('field'); 491 var func = jQuery('#'+id).data('func'); 492 if (func!=null && func!='undefined') { 493 func(fld, aaa); 494 } else { 495 fld.val(aaa).css('backgroundColor', aaa).trigger('change'); 496 } 497 jQuery('#'+id+'_Bg').fadeOut(500); 498 jQuery('#'+id).fadeOut(500); 499 500 } else { 501 key.preventDefault(); 502 return false; 503 } 504 if (aaa.substr(0,1)==='#' && (aaa.length===4 || aaa.length===7)) { 505 jQuery('#'+id+'_colorPreview').css('background',aaa); 506 } 507 }) 508 .on('click', 'thead td', function(e){ 509 "use strict"; 510 var fld = jQuery('#'+id).data('field'); 511 var func = jQuery('#'+id).data('func'); 512 var aaa = axiom_rgb2hex(jQuery(this).css('background-color')); 513 if (func!=null && func!='undefined') { 514 func(fld, aaa); 515 } else { 516 fld.val(aaa).css('backgroundColor', aaa).trigger('change'); 517 } 518 jQuery('#'+id+'_Bg').fadeOut(500); 519 jQuery('#'+id).fadeOut(500); 520 e.preventDefault(); 521 return false; 522 }) 523 .on('click', 'tbody .iColorPicker_moreColors', function(e){ 524 "use strict"; 525 var thead = jQuery(this).parents('table').find('thead'); 526 var out = ''; 527 if (thead.hasClass('more_colors')) { 528 for (var i=0; i<colorsList.length; i++) { 529 if (i%16==0) out += (i>0 ? '</tr>' : '') + '<tr>'; 530 out += '<td style="background-color:'+colorsList[i]+'"> </td>'; 531 } 532 thead.removeClass('more_colors').empty().html(out+'</tr>'); 533 jQuery('#'+id+'_colorPreview').attr('colspan', 8); 534 jQuery('#'+id+'_colorOriginal').attr('colspan', 8); 535 } else { 536 var rgb=[0,0,0], i=0, j=-1; // Set j=-1 or j=0 - show 2 different colors layouts 537 while (rgb[0]<0xF || rgb[1]<0xF || rgb[2]<0xF) { 538 if (i%18==0) out += (i>0 ? '</tr>' : '') + '<tr>'; 539 i++; 540 out += '<td style="background-color:'+axiom_components2hex(rgb[0]*16+rgb[0],rgb[1]*16+rgb[1],rgb[2]*16+rgb[2])+'"> </td>'; 541 rgb[2]+=3; 542 if (rgb[2]>0xF) { 543 rgb[1]+=3; 544 if (rgb[1]>(j===0 ? 6 : 0xF)) { 545 rgb[0]+=3; 546 if (rgb[0]>0xF) { 547 if (j===0) { 548 j=1; 549 rgb[0]=0; 550 rgb[1]=9; 551 rgb[2]=0; 552 } else { 553 break; 554 } 555 } else { 556 rgb[1]=(j < 1 ? 0 : 9); 557 rgb[2]=0; 558 } 559 } else { 560 rgb[2]=0; 561 } 562 } 563 } 564 thead.addClass('more_colors').empty().html(out+'<td style="background-color:#ffffff" colspan="8"> </td></tr>'); 565 jQuery('#'+id+'_colorPreview').attr('colspan', 9); 566 jQuery('#'+id+'_colorOriginal').attr('colspan', 9); 567 } 568 jQuery('#'+id+' table.colorPickerTable thead td') 569 .css({ 570 'width':'12px', 571 'height':'14px', 572 'border':'1px solid #000', 573 'cursor':'pointer' 574 }); 575 e.preventDefault(); 576 return false; 577 }); 578 jQuery(document.createElement("div")) 579 .attr("id", id+"_Bg") 580 .click(function(e) { 581 "use strict"; 582 jQuery("#"+id+"_Bg").fadeOut(500); 583 jQuery("#"+id).fadeOut(500); 584 e.preventDefault(); 585 return false; 586 }) 587 .appendTo("body"); 588 jQuery('#'+id+' table.colorPickerTable thead td') 589 .css({ 590 'width':'12px', 591 'height':'14px', 592 'border':'1px solid #000', 593 'cursor':'pointer' 594 }); 595 jQuery('#'+id+' table.colorPickerTable') 596 .css({'border-collapse':'collapse'}); 597 jQuery('#'+id) 598 .css({ 599 'border':'1px solid #ccc', 600 'background':'#333', 601 'padding':'5px', 602 'color':'#fff', 603 'z-index':999999 604 }); 605 jQuery('#'+id+'_colorPreview') 606 .css({'height':'50px'}); 607 return id; 608} 609 610function axiom_color_picker_show(id, fld, func) { 611 "use strict"; 612 if (id===null || id==='') { 613 id = jQuery('.iColorPickerTable').attr('id'); 614 } 615 var eICP = fld.offset(); 616 var w = jQuery('#'+id).width(); 617 var h = jQuery('#'+id).height(); 618 var l = eICP.left + w < jQuery(window).width()-10 ? eICP.left : jQuery(window).width()-10 - w; 619 var t = eICP.top + fld.outerHeight() + h < jQuery(document).scrollTop() + jQuery(window).height()-10 ? eICP.top + fld.outerHeight() : eICP.top - h - 13; 620 jQuery("#"+id) 621 .data({field: fld, func: func}) 622 .css({ 623 'top':t+"px", 624 'left':l+"px", 625 'position':'absolute', 626 'z-index':100001 627 }) 628 .fadeIn(500); 629 jQuery("#"+id+"_Bg") 630 .css({ 631 'position':'fixed', 632 'z-index':100000, 633 'top':0, 634 'left':0, 635 'width':'100%', 636 'height':'100%' 637 }) 638 .fadeIn(500); 639 var def = fld.val().substr(0, 1)=='#' ? fld.val() : axiom_rgb2hex(fld.css('backgroundColor')); 640 jQuery('#'+id+'_colorPreview input,#'+id+'_colorOriginal input').val(def); 641 jQuery('#'+id+'_colorPreview,#'+id+'_colorOriginal').css('background',def); 642} 643 644 645 646/* Cookies manipulations 647---------------------------------------------------------------- */ 648 649function axiom_get_cookie(name) { 650 "use strict";
651 var defa = arguments[1]!=undefined ? arguments[1] : null; 652 var start = document.cookie.indexOf(name + '='); 653 var len = start + name.length + 1; 654 if ((!start) && (name != document.cookie.substring(0, name.length))) { 655 return defa; 656 } 657 if (start == -1) 658 return defa; 659 var end = document.cookie.indexOf(';', len); 660 if (end == -1) 661 end = document.cookie.length; 662 return unescape(document.cookie.substring(len, end)); 663} 664 665 666function axiom_set_cookie(name, value, expires, path, domain, secure) { 667 "use strict"; 668 var expires = arguments[2]!=undefined ? arguments[2] : 0; 669 var path = arguments[3]!=undefined ? arguments[3] : '/'; 670 var domain = arguments[4]!=undefined ? arguments[4] : ''; 671 var secure = arguments[5]!=undefined ? arguments[5] : ''; 672 var today = new Date(); 673 today.setTime(today.getTime()); 674 if (expires) { 675 expires = expires * 1000 * 60 * 60 * 24; 676 } 677 var expires_date = new Date(today.getTime() + (expires)); 678 document.cookie = name + '=' 679 + escape(value) 680 + ((expires) ? ';expires=' + expires_date.toGMTString() : '') 681 + ((path) ? ';path=' + path : '') 682 + ((domain) ? ';domain=' + domain : '') 683 + ((secure) ? ';secure' : ''); 684} 685 686 687function axiom_del_cookie(name, path, domain) { 688 "use strict";
689 var path = arguments[1]!=undefined ? arguments[1] : '/'; 690 var domain = arguments[2]!=undefined ? arguments[2] : ''; 691 if (axiom_get_cookie(name)) 692 document.cookie = name + '=' + ((path) ? ';path=' + path : '') 693 + ((domain) ? ';domain=' + domain : '') 694 + ';expires=Thu, 01-Jan-1970 00:00:01 GMT'; 695} 696 697 698 699/* ListBox and ComboBox manipulations 700---------------------------------------------------------------- */ 701 702function axiom_clear_listbox(box) { 703 "use strict"; 704 for (var i=box.options.length-1; i>=0; i--) 705 box.options[i] = null; 706} 707 708function axiom_add_listbox_item(box, val, text) { 709 "use strict"; 710 var item = new Option(); 711 item.value = val; 712 item.text = text; 713 box.options.add(item); 714} 715 716function axiom_del_listbox_item_by_value(box, val) { 717 "use strict"; 718 for (var i=0; i<box.options.length; i++) { 719 if (box.options[i].value == val) { 720 box.options[i] = null; 721 break; 722 } 723 } 724} 725 726function axiom_del_listbox_item_by_text(box, txt) { 727 "use strict"; 728 for (var i=0; i<box.options.length; i++) { 729 if (box.options[i].text == txt) { 730 box.options[i] = null; 731 break; 732 } 733 } 734} 735 736function axiom_find_listbox_item_by_value(box, val) { 737 "use strict"; 738 var idx = -1; 739 for (var i=0; i<box.options.length; i++) { 740 if (box.options[i].value == val) { 741 idx = i; 742 break; 743 } 744 } 745 return idx; 746} 747 748function axiom_find_listbox_item_by_text(box, txt) { 749 "use strict"; 750 var idx = -1; 751 for (var i=0; i<box.options.length; i++) { 752 if (box.options[i].text == txt) { 753 idx = i; 754 break; 755 } 756 } 757 return idx; 758} 759 760function axiom_select_listbox_item_by_value(box, val) { 761 "use strict"; 762 for (var i = 0; i < box.options.length; i++) { 763 box.options[i].selected = (val == box.options[i].value); 764 } 765} 766 767function axiom_select_listbox_item_by_text(box, txt) { 768 "use strict"; 769 for (var i = 0; i < box.options.length; i++) { 770 box.options[i].selected = (txt == box.options[i].text); 771 } 772} 773 774function axiom_get_listbox_values(box) { 775 "use strict"; 776 var delim = arguments[1] ? arguments[1] : ','; 777 var str = ''; 778 for (var i=0; i<box.options.length; i++) { 779 str += (str ? delim : '') + box.options[i].value; 780 } 781 return str; 782} 783 784function axiom_get_listbox_texts(box) { 785 "use strict"; 786 var delim = arguments[1] ? arguments[1] : ','; 787 var str = ''; 788 for (var i=0; i<box.options.length; i++) { 789 str += (str ? delim : '') + box.options[i].text; 790 } 791 return str; 792} 793 794function axiom_sort_listbox(box) { 795 "use strict"; 796 var temp_opts = new Array(); 797 var temp = new Option(); 798 for(var i=0; i<box.options.length; i++) { 799 temp_opts[i] = box.options[i].clone(); 800 } 801 for(var x=0; x<temp_opts.length-1; x++) { 802 for(var y=(x+1); y<temp_opts.length; y++) { 803 if(temp_opts[x].text > temp_opts[y].text) { 804 temp = temp_opts[x]; 805 temp_opts[x] = temp_opts[y]; 806 temp_opts[y] = temp; 807 } 808 } 809 } 810 for(var i=0; i<box.options.length; i++) { 811 box.options[i] = temp_opts[i].clone(); 812 } 813} 814 815function axiom_get_listbox_selected_index(box) { 816 "use strict"; 817 for (var i = 0; i < box.options.length; i++) { 818 if (box.options[i].selected) 819 return i; 820 } 821 return -1; 822} 823 824function axiom_get_listbox_selected_value(box) { 825 "use strict"; 826 for (var i = 0; i < box.options.length; i++) { 827 if (box.options[i].selected) { 828 return box.options[i].value; 829 } 830 } 831 return null; 832} 833 834function axiom_get_listbox_selected_text(box) { 835 "use strict"; 836 for (var i = 0; i < box.options.length; i++) { 837 if (box.options[i].selected) { 838 return box.options[i].text; 839 } 840 } 841 return null; 842} 843 844function axiom_get_listbox_selected_option(box) { 845 "use strict"; 846 for (var i = 0; i < box.options.length; i++) { 847 if (box.options[i].selected) { 848 return box.options[i]; 849 } 850 } 851 return null; 852} 853 854 855 856/* Radio buttons manipulations 857---------------------------------------------------------------- */ 858 859function axiom_get_radio_value(radioGroupObj) { 860 "use strict"; 861 for (var i=0; i < radioGroupObj.length; i++) 862 if (radioGroupObj[i].checked) return radioGroupObj[i].value; 863 return null; 864} 865 866function axiom_set_radio_checked_by_num(radioGroupObj, num) { 867 "use strict"; 868 for (var i=0; i < radioGroupObj.length; i++) 869 if (radioGroupObj[i].checked && i!=num) radioGroupObj[i].checked=false; 870 else if (i==num) radioGroupObj[i].checked=true; 871} 872 873function axiom_set_radio_checked_by_value(radioGroupObj, val) { 874 "use strict"; 875 for (var i=0; i < radioGroupObj.length; i++) 876 if (radioGroupObj[i].checked && radioGroupObj[i].value!=val) radioGroupObj[i].checked=false; 877 else if (radioGroupObj[i].value==val) radioGroupObj[i].checked=true; 878} 879 880 881 882/* Form manipulations 883---------------------------------------------------------------- */ 884
885/* 886// Usage example: 887var error = axiom_form_validate(jQuery(form_selector), { // -------- Options --------- 888 error_message_show: true, // Display or not error message 889 error_message_time: 5000, // Time to display error message 890 error_message_class: 'sc_infobox sc_infobox_style_error', // Class, appended to error message block 891 error_message_text: 'Global error text', // Global error message text (if don't write message in checked field) 892 error_fields_class: 'error_fields_class', // Class, appended to error fields 893 exit_after_first_error: false, // Cancel validation and exit after first error 894 rules: [ 895 { 896 field: 'author', // Checking field name 897 min_length: { value: 1, message: 'The author name can\'t be empty' }, // Min character count (0 - don't check), message - if error occurs 898 max_length: { value: 60, message: 'Too long author name'} // Max character count (0 - don't check), message - if error occurs 899 }, 900 { 901 field: 'email', 902 min_length: { value: 7, message: 'Too short (or empty) email address' }, 903 max_length: { value: 60, message: 'Too long email address'}, 904 mask: { value: '^([a-z0-9_\\-]+\\.)*[a-z0-9_\\-]+@[a-z0-9_\\-]+(\\.[a-z0-9_\\-]+)*\\.[a-z]{2,6}$', message: 'Invalid email address'} 905 }, 906 { 907 field: 'comment', 908 min_length: { value: 1, message: 'The comment text can\'t be empty' }, 909 max_length: { value: 200, message: 'Too long comment'} 910 }, 911 { 912 field: 'pwd1', 913 min_length: { value: 5, message: 'The password can\'t be less then 5 characters' }, 914 max_length: { value: 20, message: 'Too long password'} 915 }, 916 { 917 field: 'pwd2', 918 equal_to: { value: 'pwd1', message: 'The passwords in both fields must be equals' } 919 } 920 ] 921}); 922*/ 923 924function axiom_form_validate(form, opt) { 925 "use strict"; 926 var error_msg = ''; 927 form.find(":input").each(function() { 928 "use strict"; 929 if (error_msg!='' && opt.exit_after_first_error) return; 930 for (var i = 0; i < opt.rules.length; i++) { 931 if (jQuery(this).attr("name") == opt.rules[i].field) { 932 var val = jQuery(this).val(); 933 var error = false; 934 if (typeof(opt.rules[i].min_length) == 'object') { 935 if (opt.rules[i].min_length.value > 0 && val.length < opt.rules[i].min_length.value) { 936 if (error_msg=='') jQuery(this).get(0).focus(); 937 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>' 938 error = true; 939 } 940 } 941 if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].max_length) == 'object') { 942 if (opt.rules[i].max_length.value > 0 && val.length > opt.rules[i].max_length.value) { 943 if (error_msg=='') jQuery(this).get(0).focus(); 944 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>' 945 error = true; 946 } 947 } 948 if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].mask) == 'object') { 949 if (opt.rules[i].mask.value != '') { 950 var regexp = new RegExp(opt.rules[i].mask.value); 951 if (!regexp.test(val)) { 952 if (error_msg=='') jQuery(this).get(0).focus(); 953 error_msg += '<p class="error_item">' + (typeof(opt.rules[i].mask.message)!='undefined' ? opt.rules[i].mask.message : opt.error_message_text ) + '</p>' 954 error = true; 955 } 956 } 957 } 958 if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].equal_to) == 'object') { 959 if (opt.rules[i].equal_to.value != '' && val!=jQuery(jQuery(this).get(0).form[opt.rules[i].equal_to.value]).val()) { 960 if (error_msg=='') jQuery(this).get(0).focus(); 961 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>' 962 error = true; 963 } 964 } 965 if (opt.error_fields_class != '') jQuery(this).toggleClass(opt.error_fields_class, error); 966 } 967 } 968 }); 969 if (error_msg!='' && opt.error_message_show) { 970 var error_message_box = form.find(".result"); 971 if (error_message_box.length == 0) error_message_box = form.parent().find(".result"); 972 if (error_message_box.length == 0) { 973 form.append('<div class="result"></div>'); 974 error_message_box = form.find(".result"); 975 } 976 if (opt.error_message_class) error_message_box.toggleClass(opt.error_message_class, true); 977 error_message_box.html(error_msg).fadeIn(); 978 setTimeout(function() { error_message_box.fadeOut(); }, opt.error_message_time); 979 } 980 return error_msg!=''; 981} 982 983 984 985/* Document manipulations 986---------------------------------------------------------------- */ 987 988// Animated scroll to selected id 989function axiom_document_animate_to(id) { 990 if (id.indexOf('#')==-1) id = '#' + id; 991 var obj = jQuery(id).eq(0); 992 if (obj.length == 0) return; 993 var oft = jQuery(id).offset().top; 994 var st = jQuery(window).scrollTop(); 995 var speed = Math.min(1600, Math.max(400, Math.round(Math.abs(oft-st) / jQuery(window).height() * 100))); 996 jQuery('body,html').animate( {scrollTop: oft - jQuery('#wpadminbar').height() - jQuery('header.fixedTopMenu .topWrap').height()}, speed, 'swing'); 997} 998 999// Change browser address without reload page 1000function axiom_document_set_location(curLoc){ 1001 try { 1002 history.pushState(null, null, curLoc); 1003 return; 1004 } catch(e) {}
1005 location.href = curLoc; 1006} 1007 1008// Add hidden elements init functions after tab, accordion, toggles activate 1009function axiom_add_hidden_elements_handler(key, handler) { 1010 axiom_set_global_array('init_hidden_elements', key, handler); 1011} 1012 1013// Init hidden elements after tab, accordion, toggles activate 1014function axiom_init_hidden_elements(cont) { 1015 if (AXIOM_GLOBALS['init_hidden_elements']) { 1016 for (key in AXIOM_GLOBALS['init_hidden_elements']) { 1017 AXIOM_GLOBALS['init_hidden_elements'][key](cont); 1018 } 1019 } 1020} 1021 1022 1023 1024/* Browsers detection 1025---------------------------------------------------------------- */ 1026 1027function axiom_browser_is_mobile() { 1028 var check = false; 1029 (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)))check = true})(navigator.userAgent||navigator.vendor||window.opera); 1030 return check; 1031} 1032function axiom_browser_is_ios() { 1033 return navigator.userAgent.match(/iPad|iPhone|iPod/i) != null; 1034} 1035 1036 1037 1038/* File functions 1039---------------------------------------------------------------- */ 1040 1041function axiom_get_file_name(path) { 1042 path = path.replace(/\\/g, '/'); 1043 var pos = path.lastIndexOf('/'); 1044 if (pos >= 0) 1045 path = path.substr(pos+1); 1046 return path; 1047} 1048 1049function axiom_get_file_ext(path) { 1050 var pos = path.lastIndexOf('.'); 1051 path = pos >= 0 ? path.substr(pos+1) : ''; 1052 return path; 1053} 1054 1055 1056 1057/* Image functions 1058---------------------------------------------------------------- */ 1059 1060// Return true, if all images in the specified container are loaded 1061function axiom_check_images_complete(cont) { 1062 var complete = true; 1063 cont.find('img').each(function() { 1064 if (!complete) return; 1065 if (!jQuery(this).get(0).complete) complete = false; 1066 }); 1067 return complete; 1068}
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.