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