window.widget_manager = null; $(document).ready( function () { window.widget_manager = new WidgetManager( window.widget_names ); if ( window.widget_roots && window.widget_roots.length > 0 ) { for ( var i in window.widget_roots ) { init_widgets( window.widget_roots[i] ); } } else { init_widgets( document.body ); } $( window ).unload( function () { window.widget_manager.stopAll(); } ); } ); function widget_save_redir( url ) { var n = window.widget_manager.stopAll(); var t = n > 0 ? 2500 : 1; setTimeout( function () { location.href = url; }, t ); } function init_widgets( context ) { var x = $( context ).get(0); x && window.widget_manager.startWidgets( x ); } function WidgetManager( widget_names ) { this.widgetNames = widget_names; this.currentWidgets = {}; this.allWidgets = {}; } WidgetManager.prototype.widgets = function ( name ) { return this.allWidgets[name]; } WidgetManager.prototype.add = function ( name, w ) { this.allWidgets[name] = this.allWidgets[name] || []; this.allWidgets[name].push( w ); } WidgetManager.prototype.find_all = function ( f, ws ) { ws = ws || ['editinplace','editatonce']; var rt = []; for ( var i in ws ) { var a = this.allWidgets[ws[i]] || []; for ( var j in a ) { if ( f( a[j] ) ) { rt.push( a[j] ); } } } return rt; } WidgetManager.prototype.find = function ( f, ws ) { ws = ws || ['editinplace','editatonce']; for ( var i in ws ) { var a = this.allWidgets[ws[i]] || []; for ( var j in a ) { if ( f( a[j] ) ) { return a[j]; } } } return null; } WidgetManager.prototype.current = function ( name ) { return this.currentWidgets[name]; } WidgetManager.prototype.stopAll = function () { var count = 0; for ( var name in this.currentWidgets ) { var w = this.currentWidgets[name]; if ( w ) { if ( w.widgetBlur( name, null ) ) { count += 1; } } } return count; } WidgetManager.prototype.stop = function ( name ) { var w = this.currentWidgets[name]; w && w.widgetBlur( name, null ); } WidgetManager.prototype.widgetFocus = function ( name, obj ) { for ( i in this.currentWidgets ) { var w = this.currentWidgets[i]; w.widgetBlur && w.widgetBlur( name, obj ); } this.currentWidgets[name] = obj; } WidgetManager.prototype.startWidgets = function ( root ) { var stack = [root]; var names = this.widgetNames; var names_do = {}; for ( var i in names ) { names_do['do_' + names[i]] = names[i]; } while ( stack.length > 0 ) { var e = stack.pop(); if ( e.className && e.className.match( /do_[a-z_]+/ ) ) { var clsss = e.className.match( /do_[a-z_]+/g ); for ( var i = 0; i < clsss.length; i++ ) { var w = names_do[clsss[i]]; if ( w ) { eval("init_" + w + "( e )"); } } } if ( e.childNodes ) { for ( var i = 0 ; i < e.childNodes.length ; i++ ) { if ( e.childNodes[i].nodeType != 3 ) { stack.unshift( e.childNodes[i] ); } } } } var ends = ['editinplace','editatonce']; for ( var i in ends ) { if ( jQuery.inArray( names, ends[i] ) ) { eval( 'end_' + ends[i] + '()' ); } } } function validate_field2id ( name ) { name = name.replace( /\./g, "_" ); return 'required_fields_li_' + name; } function validate_cmpfield ( l ) { return function ( x ) { return jQuery.inArray( l, x.options.ajax.field ); } } function validate_goto ( i ) { var e = window.widget_manager.find( validate_cmpfield( [i] ) ); if ( e ) { var p = jQuery.getPosition( e.container ); scroll( 0, p.y - 100 ); } } function validate_update () { if ( jQuery.isEmptyObject( window.required_fields ) ) { $( "#required_fields_main" ).hide(); $( "#required_fields_other" ).show(); return; } $( "#required_fields_main" ).show(); $( "#required_fields_other" ).hide(); var fs = window.required_fields; var ul = $( "#required_fields_list" ).get( 0 ); ul.innerHTML = ''; var bind_click = function ( li, i ) { var fu = function ( x ) { return x.options.ajax.field == i; }; var e = window.widget_manager.find( fu ); if ( e && e.options ) { var c = e.options.callback; c = c || function () {}; var fc = function ( d ) { delete( window.required_fields[i] ); validate_update(); c && c( d ); } e.options.callback = fc; $( li ).bind( "click", function () { validate_goto( i ); return false; } ); } }; var gs = jQuery.objKeys( fs ); var fu = validate_cmpfield( gs ); var ws = window.widget_manager.find_all( fu ); for ( var i in ws ) { ws[i].addRequiredClass(); } for ( var i in fs ) { var li = document.createElement( "li" ); var an = document.createElement( "a" ); li.id = validate_field2id( i ); li.className = "required_field_title"; an.href='#'; $( an ).html( fs[i] ); $( li ).append( an ); $( ul ).append( li ); bind_click( an, i ); } } function apply_options( docs, o ) { for ( var i in docs ) { var d = docs[i]; var ds = d[0].split('.'); if ( ds.length > 1 ) { o[ds[0]][ds[1]] = o[ds[0]][ds[1]] || d[1]; } else { o[d[0]] = o[d[0]] || d[1]; } } return o; } function identity ( x ) { return x; } jQuery.fn.opacity = function ( v ) { this.css('opacity', v ); if ( jQuery.browser.msie ) { this.css('filter', 'alpha(opacity=' + v * 100 + ')'); } } jQuery.extend( { objKeys: function ( obj ) { var ret = []; for ( var i in obj ) { ret.push( i ); } return ret; }, label: function ( path, def ) { var names = path.split('.'); var tmp = window.labels; while ( names.length > 0 && tmp ) { tmp = tmp[names.shift()]; } return tmp || def; }, createCookie: function ( name, value, days ) { if ( days ) { var date = new Date(); date.setTime( date.getTime() + ( days * 24 * 60 * 60 * 1000 ) ); var expires = "; expires=" + date.toGMTString(); } else { var expires = ""; } document.cookie = name + "=" + value+expires + "; path=/"; }, readCookie: function ( name ) { var nameEQ = name + "="; var ca = document.cookie.split( ';' ); for ( var i = 0 ; i < ca.length ; i++ ) { var c = ca[i]; while ( c.charAt(0) == ' ' ) { c = c.substring( 1, c.length ); } if ( c.indexOf( nameEQ ) == 0 ) { return c.substring( nameEQ.length, c.length ); } } return null; }, eraseCookie: function( name ) { jQuery.createCookie( name, "", -1 ); }, log: function () { if ( window.console && window.console.log && window.console.assert ) { window.console.log( arguments ); } }, warn: function( where , what ) { if ( !what ) { what = "You cannot edit this now."; } alert( where + ': ' + what ); jQuery.log( arguments ); }, error: function ( msg , url , line ) { alert( msg + " @ " + url + " @ " + line ); return false; }, xparam: function ( params ) { var res = []; for ( var i in params ) { if ( params[i].constructor == Array ) { for ( var j = 0 ; j < params[i].length ; j++ ) { res.push( i + '[' + j + ']=' + encodeURIComponent( params[i][j] ) ); } } else if ( params[i].constructor == Object ) { for ( var j in params[i] ) { res.push( i + '[' + j + ']=' + encodeURIComponent( params[i][j] ) ); } } else { res.push( i + '=' + encodeURIComponent( params[i] ) ); } } return res.join( '&' ); }, windowSize: function () { var p = { w: 0, h: 0 }; var e = document.documentElement; var b = document.body; if ( typeof( window.innerWidth ) == 'number' ) { p.w = window.innerWidth; p.h = window.innerHeight; } else if( e && ( e.clientWidth || e.clientHeight ) ) { p.w = e.clientWidth; p.h = e.clientHeight; } else if( b && ( b.clientWidth || b.clientHeight ) ) { p.w = b.clientWidth; p.h = b.clientHeight; } return p; }, mousePosition: function ( ev ) { ev = ev || window.event; var x = 0, y = 0; if ( ev.pageX || ev.pageY ) { x = ev.pageX; y = ev.pageY; } else if ( ev.clientX || ev.clientY ) { x = ev.clientX + document.body.scrollLeft; y = ev.clientY + jQuery.pageScrollTop(); //document.body.scrollTop; } return { "x": x, "y": y }; }, mouseInWindow: function ( e ) { var ret = {}; if ( !e ) { var e = window.event; } if ( e.clientX || e.clientY ) { ret.x = e.clientX - Math.max( 0 , document.body.scrollLeft ); ret.y = e.clientY - Math.max( 0 , document.body.scrollTop ); // document.body.scrollTop*/ + document.documentElement.scrollTop; } return ret; }, assocMergeInto: function ( r , a ) { if ( a ) { for( var i in a ) { r[i] = a[i]; } } return r; }, assocMerge: function ( a , b ) { return jQuery.assocMergeInto( jQuery.assocMergeInto( {}, a ), b ); }, dateFormat: function ( format , date ) { format = format.replace( /\%Y/ , date.getFullYear() ); format = format.replace( /\%m/ , date.getMonth() + 1 ); format = format.replace( /\%d/ , date.getDate() ); format = format.replace( /\%H/ , date.getHours() ); format = format.replace( /\%M/ , date.getMinutes() ); return format; }, parseDateTime: function ( s ) { var x = s.split( ' ' ); date = x[0].split( '-' ); time = x[1].split( ':' ); return new Date( date[0] , date[1] - 1 , date[2] , time[0] , time[1] , time[2] ); }, addToQuery: function ( url , data ) { return url + ( url.match( /\?/ ) ? '&' : '?' ) + data; }, attrOptions: function ( e , name ) { var a = e.getAttribute( name ) || ''; a = a.replace( /,\s*$/ , '' ); eval( "var tmp = {" + a + "}" ); return tmp; }, pageScrollTop: function () { var pos = jQuery.getScroll(); return pos.y; }, getScroll: function () { var p = {x: 0, y: 0}; var e = document.documentElement; var b = document.body; if ( e && ( e.scrollLeft || e.scrollTop ) ) { p.x = e.scrollLeft; p.y = e.scrollTop; } else if ( b && ( b.scrollLeft || b.scrollTop ) ) { p.x = b.scrollLeft; p.y = b.scrollTop; } else if ( window.pageXOffset || window.pageYOffset ) { p.x = window.pageXOffset; p.y = window.pageYOffset; } else if( window.scrollX || window.scrollY ) { p.x = window.scrollX; p.y = window.scrollY; } return p; }, getPosition: function ( obj, ignoreRelative ) { ignoreRelative = ignoreRelative || false; var curleft = curtop = 0; if ( false && jQuery.browser.msie ) { var childImg = false; for ( var i in obj.childNodes ) { childImg = childImg || obj.childNodes[i].tagName == 'IMG'; } if ( childImg ) { curleft -= obj.offsetLeft; } } while ( obj ) { if ( !ignoreRelative || jQuery( obj ).css('position') != "relative" ) { curleft += obj.offsetLeft; curtop += obj.offsetTop; } obj = obj.offsetParent; } return { x: curleft, y: curtop }; }, getSize : function(e) { var w = jQuery.css(e,'width'); var h = jQuery.css(e,'height'); var wb = 0; var hb = 0; es = e.style; if ( jQuery(e).css('display') != 'none' ) { wb = e.offsetWidth; hb = e.offsetHeight; } else { oldVisibility = es.visibility; oldPosition = es.position; es.visibility = 'hidden'; es.display = 'block'; es.position = 'absolute'; wb = e.offsetWidth; hb = e.offsetHeight; es.display = 'none'; es.position = oldPosition; es.visibility = oldVisibility; } return { w:w, h:h, wb:wb, hb:hb }; }, elemInWindow: function ( o ) { var oLeft = o.offsetLeft; var oTop = o.offsetTop; while( o.offsetParent != null ) { oParent = o.offsetParent; // Get parent object reference oLeft += oParent.offsetLeft; // Add parent left position oTop += oParent.offsetTop; // Add parent top position o = oParent; } return { l: oLeft , t: oTop }; }, inArray: function (a, value) { var i; for ( i=0 ; i < a.length ; i++) { if ( a[i] === value ) { return true; } } return false; }, validateForm: function ( frm , alrt ) { if ( document.getElementById( frm ) ) { var f = document.getElementById( frm ); } else if ( document.forms[ frm ] ) { var f = document.forms[ frm ]; } else { f = frm; } if ( alrt != 'null' ) { alrt = 'All fields are required'; } var isValid = true; var vFormElems = new Array(); for ( i = 0 ; i < f.elements.length ; i++ ) { elem = f.elements[i]; vCode = ( elem['alt'] ) ? elem['alt'] : elem.getAttribute('alt'); if ( !( typeof vCode == 'undefined' || vCode == null || vCode == "" ) ) { if ( jQuery.inArray( vFormElems, elem.name ) ) { break; } else { v = jQuery.getValue( f.elements[elem.name] ); if ( vCode == 'required' && v.length < 1 ) { isValid = false; } vFormElems[i] = elem.name; } } } if (!isValid) { alert( alrt ); } return isValid }, getValue: function ( ffield , def ) { v = ''; t = ffield.type; if( !t ) { t = ffield[0].type; } if( t == 'checkbox' ) { if( ffield.length ) { for( gv_i=0 ; gv_i < ffield.length ; gv_i++ ) { if ( ffield[gv_i].checked ) { v = ffield[gv_i].value; } } } else { if ( ffield.checked ) { v = ffield.value; } } } else if ( t == 'file' ) v = ffield.value; else if ( t == 'hidden' ) v = ffield.value; else if ( t == 'password' ) v = ffield.value; else if ( t == 'radio' ) { if ( ffield.length ) { for ( gv_i=0 ; gv_i < ffield.length ; gv_i++) { if ( ffield[gv_i].checked ) v = ffield[gv_i].value; } } else { if ( ffield.checked ) v = ffield.value; } } else if (t == 'select-multiple' ) v = ffield.options[ffield.selectedIndex].value; else if (t == 'select-one' ) v = ffield.options[ffield.selectedIndex].value; else if (t == 'text' ) v = ffield.value; else if (t == 'textarea' ) v = ffield.value; if (def != null && v == '') { return def; } return v; }, byId: function ( id , doc ) { if ( typeof id == "string" || id instanceof String ) { if ( !doc ) { doc = document; } return doc.getElementById ( id ); } return id; }, textContent: function ( node ) { var _result = ""; if (node == null) { return _result; } for (var i = 0; i < node.childNodes.length; i++) { switch (node.childNodes[i].nodeType) { case 1: // ELEMENT_NODE case 5: // ENTITY_REFERENCE_NODE _result += jQuery.textContent(node.childNodes[i]); break; case 3: // TEXT_NODE case 2: // ATTRIBUTE_NODE case 4: // CDATA_SECTION_NODE _result += node.childNodes[i].nodeValue; break; default: break; } } return _result; }, isEmailAddress: function ( v ) { mailvalid = true; if ( v.indexOf ( '@' ) < 1 ) { mailvalid = false; } else if ( v.lastIndexOf ( '.' ) < v.indexOf ( '@' ) ) { isvalid = false; } aapje = v.indexOf( '@' ); puntje = v.indexOf( '.' ); if ( puntje - aapje == 1 ) { mailvalid = false; } return mailvalid; }, isSizeSmaller: function ( v , size ) { if ( v.length < size ) { return true; } else { return false; } }, isSizeGreater: function ( v , size ) { if ( v.length > size ) { return true; } else { return false; } }, showHide: function (str) { a = str.split(','); for ( var i = 0 ; i < a.length ; i++ ) { s = a[i]; c = s.charAt(0); v = 'block'; if (c == '-') { v = 'none'; s = s.substr( 1 , s.length-1); } else if ( c == '+') { s = s.substr( 1 , s.length - 1 ); } if ( $( "#" + s ) ) { $("#" + s).css( 'display', v ); } } }, hideAllBut: function ( a, b ) { if ( jQuery.isObject( a ) ) { for ( var p in a ) { $( "#" + a[p] ).hide(); } } else if ( jQuery.isArray(a) ) { for ( i = 0 ; i < a.length ; i++ ) { $( "#" + a[i] ).hide(); } } else if ( jQuery.isString( a ) ) { var d = document.getElementsByTagName( 'div' ); for( i = 0 ; i < d.length ; i++ ) { var l = a.length; var id = d[i].id; if ( id.substring( 0 , l ) == a ) { $( "#" + d[i].id ).hide(); } } } if ( jQuery.isArray( b ) ) { for ( i = 0 ; i < a.length ; i++) { $( "#" + b[i] ).show(); } } else if ( jQuery.isString( b ) ) { $( "#" + b ).show(); } }, popup: function ( thg_id, o, l, t, w, h ) { if ( l == null ) l = 100; if ( t == null ) t = 100; if ( w == null ) w = 400; if ( h == null ) h = 400; var aPopupWin = window.open( '', 'PopupWin', 'scrollbars=yes,menubar=no,location=no,directories=no,statusbar=no,toolbar=no,resizable=yes,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l ); aPopupWin.document.open(); aPopupWin.document.close(); order = ''; if ( o != null ) order = '&order='+o; var p = 'popup.php?id=' + thg_id + order; aPopupWin.document.location.href = p; if( aPopupWin && !aPopupWin.closed ) { aPopupWin.focus(); } }, resizePopup: function() { var mw = 400; if ( parseInt( navigator.appVersion.charAt( 0 ) ) >= 4 ) { NN = ( navigator.appName=="Netscape" ) ? 1 : 0; } if ( document.images[0] ) { ww = ( screen.width ); wh = ( screen.height ); if (NN) { rw = document.images[0].width + 80; rh = document.images[0].height; if ( ww < rw ) rw = ww; if ( rw < mw ) rw = mw; if ( wh < rh ) rh = wh; if ( rh < wh - 140 ) rh = rh + 160; window.top.innerWidth = rw; window.top.innerHeight = rh; } else { rw = document.images[0].width + 80; rh = document.images[0].height; if ( ww < rw ) rw = ww; if ( rw < mw ) rw = mw; if ( wh < rh ) rh = wh; if ( rh < wh - 140 ) rh = rh + 160; window.top.resizeTo( rw, rh ); } parent.window.moveTo( ( screen.width - rw ) / 2, ( screen.height - rh ) / 2 ); } }, inArray: function (a, value) { var i; for ( i=0 ; i < a.length ; i++) { if ( a[i] === value ) { return true; } } return false; }, isAlien: function ( a ) { return jQuery.isObject(a) && typeof a.constructor != 'function'; }, isArray: function ( a ) { return jQuery.isObject(a) && a.constructor == Array; }, isBoolean: function ( a ) { return typeof a == 'boolean'; }, isEmptyObject: function ( o ) { for ( var i in o ) { return false; } return true; }, isEmpty: function(o) { var i, v; if (jQuery.isObject(o)) { for (i in o) { v = o[i]; if (jQuery.isUndefined(v) && jQuery.isFunction(v)) { return false; } } } return true; }, isFunction: function ( a ) { return typeof a == 'function'; }, isNull: function ( a ) { return typeof a == 'object' && !a; }, isNumber: function ( a ) { return typeof a == 'number' && isFinite(a); }, isObject: function ( a ) { return (a && typeof a == 'object') || jQuery.isFunction(a); }, isString: function ( a ) { return typeof a == 'string'; }, isUndefined: function ( a ) { return typeof a == 'undefined'; }, isDomElement: function ( a ) { return a && typeof a == 'object' && !jQuery.isUndefined(a.childNodes); } }); function AjaxNotice( sel ) { this.sel = sel; } AjaxNotice.prototype.start = function ( text ) { if ( text == '...' ) { text = ''; } text && notice_corner_show( text ); $( this.sel ).addClass( 'ajax_notice' ); } AjaxNotice.prototype.stop = function () { notice_corner_hide(); $( this.sel ).removeClass( 'ajax_notice' ); } window.notice_corner_count = 0; function notice_corner_show ( text ) { window.notice_corner_count += 1; var x = document.getElementById( 'corner_notice' ); if ( !x ) { x = document.createElement( 'div' ); x.id = 'corner_notice'; $( document.body ).append( x ); } $( x ).html( text ); $( x ).show(); window.notice_corner_time = (new Date()).getTime(); } function notice_corner_hide () { window.notice_corner_count -= 1 if ( window.notice_corner_count > 0 ) { return; } else { window.notice_corner_count = 0; } var now = (new Date()).getTime(); var dif = now - window.notice_corner_time; if ( dif > 1000 ) { $( '#corner_notice' ).hide(); } else { setTimeout( function () { notice_corner_hide(); }, dif ); } } function docs_validate() { var lm = jQuery.label( 'editinplace.validate.msg' , 'Please input a valid value' ); var lo = jQuery.label( 'editinplace.validate.out' , 'Value out of range' ); return { opts: [[ "validate", {}, "Input format validation" ] ,[ "validate.regexp", null, "Regular expression to validate format" ] ,[ "validate.name", null, "Name of predefined regular expression [integer|float]" ] ,[ "validate.msg", lm, "Alert message to be displayed in case of wrong format" ] ,[ "validate.min", null, "Minimum allowed value" ] ,[ "validate.max", null, "Maximum allowed value" ] ,[ "validate.empty", false, "Input value is allowed to be empty" ] ,[ "validate.blank", false, "Input value is allowed to be empty/whitespace" ] ,[ "validate.out", lo, "Alert message to be displayed in case of out of range number" ] ] }; } function Validate( opts ) { this.opts = opts; if ( "integer" == this.opts.name ) { this.opts.msg = jQuery.label( 'editinplace.validate.integer' , 'Please input an integer number' ); this.opts.regexp = /^\s*[-+]?\d+\s*$/; } else if ( "float" == this.opts.name ) { this.opts.msg = jQuery.label( 'editinplace.validate.float' , 'Please input a number' ); this.opts.regexp = /^\s*[-+]?\d+(\.\d+)?\s*$/; } } Validate.prototype.range = function ( value ) { var fs = {'integer': parseInt, 'float': parseFloat}; var f = fs[this.opts.name] || identity; value = f( value ); return !( this.opts.min && this.opts.min > value || this.opts.max && this.opts.max < value ); } Validate.prototype.value = function ( value ) { return ( this.opts.blank && value.match( /^\s*$/ ) ) || ( this.opts.empty && value == '' ) || ( this.opts.regexp && this.opts.regexp.exec( value ) ) || ( !this.opts.regexp ); } window.handlingOnError = false; window.handledErrors = []; function anyOnError( msg , url , line ) { var exclude = [ "uncaught exception: Permission denied to get property HTMLInputElement.parentNode" , "uncaught exception: Permission denied to get property HTMLDivElement.parentNode" ]; for ( var i in exclude ) { if ( exclude[i] == msg ) { jQuery.log( "Error belongs to blacklist, won't report it." ); return true; } } for ( var i in window.handledErrors ) { if ( window.handledErrors[i] == msg ) { jQuery.log( "Error already reported once on this session" ); return true; } } if ( window.handlingOnError ) { jQuery.log( "Trying to report an error while already busy reporting another one" ); return false; } window.handlingOnError = true; jQuery.log( "Reporting error: " + msg ); window.handledErrors.push( msg ); var params = {}; params.msg = msg; params.pageurl = location.href; params.scripturl = url; params.linenumber = line; params.referrer = document.referrer; anyRest.error.log( params , function ( xml ) { jQuery.log( 'Error was reported!' ); window.handlingOnError = false; } ); return false; } function anyGetComputedStyle( node , cssSelector , inValue ) { var cssSelector = toSelectorCase( cssSelector ); var property = toCamelCase( cssSelector ); if( !node || !node.style ) { return inValue; } else if ( document.defaultView && isDescendantOf( node, node.ownerDocument ) ) { // W3, gecko, KHTML try { var cs = document.defaultView.getComputedStyle( node , "" ); if ( cs ) { return cs.getPropertyValue( cssSelector ); } } catch( e ) { // reports are that Safari can throw an exception above if ( node.style.getPropertyValue ) { // W3 return node.style.getPropertyValue( cssSelector ); } else { return inValue; } } } else if ( node.currentStyle ) { // IE return node.currentStyle[property]; } if ( node.style.getPropertyValue ) { // W3 return node.style.getPropertyValue( cssSelector ); } else { return inValue; } } function toSelectorCase( selector ) { return selector.replace(/([A-Z])/g, "-$1" ).toLowerCase(); } function toCamelCase ( selector ) { var arr = selector.split('-'), cc = arr[0]; for ( var i = 1 ; i < arr.length ; i++ ) { cc += arr[i].charAt( 0 ).toUpperCase() + arr[i].substring( 1 ); } return cc; } function isDescendantOf( node, ancestor, guaranteeDescendant ) { if( guaranteeDescendant && node ) { node = node.parentNode; } while( node ) { if ( node == ancestor ) { return true; } node = node.parentNode; } return false; } function validate_hex( s ) { s = s.replace( /#/, '' ); var h3 = s.match(/[a-fA-F0-9]{3}/); if ( h3 ) { var a = ""; for ( var i = 0; i < 3; i++ ) { var c = s.slice(i,i+1); a += c + c; } s = a; } return s; } function parse_dec_a( elem ) { var color = anyGetComputedStyle( elem, 'background-color' ); var ff_fr = ffrgb_s2dec_a( color ); if ( ff_fr ) { color = ff_fr; } else { color = validate_hex( color ); color = hex_s2dec_a( color ); } return color; } function ffrgb_s2dec_a( x ) { var a = null; var m = x.match(/rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/); if ( m ) { a = []; for ( var i = 1; i < 4 ; i++ ) { a.push( parseInt( m[i] ) ); } } return a; } function throb( selector, color_example ) { var elem = $( selector ).get( 0 ); var exmp = $( color_example ).get( 0 ); if ( !elem || !exmp ) { jQuery.log( 'throb: did not receive the correct arguments' ); return; } var frcolor = parse_dec_a( elem ); var tocolor = parse_dec_a( exmp ); if ( !frcolor || !tocolor ) { jQuery.log( 'throb: color values not parseable' ); return; } var start = (new Date()).getTime(); var total = 5000; var anim = function () { var diff = (new Date()).getTime() - start; if ( diff > total ) { elem.style.backgroundColor = '#' + dec_a2hex_s( frcolor ); } else { var x = []; var f = diff / total; var g = ( Math.cos(6 * Math.PI * f + Math.PI) + 1 ) / 2; for ( var i = 0; i < 3; i++ ) { x[i] = Math.floor( g * tocolor[i] + (1 - g) * frcolor[i] ) } elem.style.backgroundColor = '#' + dec_a2hex_s( x ); } }; setInterval( anim, 20 ); } function lpad( s, n, c ) { while ( s.length < n ) { s = c + s; } return s } function dec_a2hex_s( a ) { var x = ''; for ( var i in a ) { x += lpad( dec2hex( a[i] ), 2, '0' ); } return x; } function hex_s2dec_a( s ) { var r = []; for ( var i = 0; i <= 4; i += 2 ) { r.push( hex2dec( s.slice( i, i + 2 ) ) ); } return r; } function dec2hex( x ) { x = parseInt( x ); var m = 16; var s = ''; while ( x > 0 ) { r = x % m; r = r > 9 ? "abcdef".slice( r-10, r-9 ) : '' + r; s = r + s; x = Math.floor( x / m ); } return s; } function hex2dec( x ) { x = '' + x; x = x.toLowerCase(); s = "0123456789abcdef"; n = 0; for ( var i = 0; i < x.length; i++ ) { n = n * 16 + s.indexOf( x.slice(i,i+1) ); } return n; } function implode( arr, sep ) { var ret = '' for ( var i = 0; i < arr.length; i++ ) { ret += ( i > 0 ? sep : '' ) + arr[i]; } return ret; }