2 * (c) 2005-2012 Richard Cowin (http://openrico.org)
3 * (c) 2005-2012 Matt Brown (http://dowdybrown.com)
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6 * file except in compliance with the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the
11 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12 * either express or implied. See the License for the specific language governing permissions
13 * and limitations under the License.
18 Rico.onLoadCallbacks=[];
19 Rico.windowIsLoaded=false;
20 Rico.inputtypes={search: 0, number: 0, range: 0, color: 0, tel: 0, url: 0, email: 0, date: 0, month: 0, week: 0, time: 0, datetime: 0, 'datetime-local': 0};
22 // called by the document onload event
23 Rico.windowLoaded=function() {
24 this.windowIsLoaded=true;
25 if (typeof Rico_CONFIG == 'object') {
26 if (Rico_CONFIG.enableLogging) this.enableLogging();
27 if (Rico_CONFIG.enableHTML5) this._CheckInputTypes();
29 Rico.writeDebugMsg=Rico.log; // for backwards compatibility
30 Rico.log('Processing callbacks');
31 while (this.onLoadCallbacks.length > 0) {
32 var callback=this.onLoadCallbacks.shift();
33 if (callback) callback();
37 // check for availability of HTML5 input types
38 Rico._CheckInputTypes=function() {
39 var i = document.createElement("input");
40 for (var itype in this.inputtypes) {
41 i.setAttribute("type", "text");
42 i.setAttribute("type", itype);
43 this.inputtypes[itype]=(i.type !== "text");
47 Rico.onLoad=function(callback,frontOfQ) {
48 if (this.windowIsLoaded)
51 this.onLoadCallbacks.unshift(callback);
53 this.onLoadCallbacks.push(callback);
56 Rico.isKonqueror=navigator.userAgent.toLowerCase().indexOf("konqueror") > -1;
57 Rico.isIE=!!(window.attachEvent && navigator.userAgent.indexOf('Opera') === -1);
58 Rico.isOpera=navigator.userAgent.indexOf('Opera') > -1;
59 Rico.isWebKit=navigator.userAgent.indexOf('AppleWebKit/') > -1;
60 Rico.isGecko=navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') === -1;
61 Rico.ieVersion=/MSIE (\d+\.\d+);/.test(navigator.userAgent) ? new Number(RegExp.$1) : null;
65 Rico.startTime=new Date();
67 Rico.timeStamp=function() {
68 var stamp = new Date();
69 return (stamp.getTime()-this.startTime.getTime())+": ";
72 Rico.setDebugArea=function(id, forceit) {
73 if (!this.debugArea || forceit) {
74 var newarea=document.getElementById(id);
76 this.debugArea=newarea;
81 Rico.log=function() {};
83 Rico.enableLogging=function() {
85 this.log = function(msg, resetFlag) {
86 if (resetFlag) this.debugArea.value='';
87 this.debugArea.value+=this.timeStamp()+msg+"\n";
89 } else if (window.console) {
90 if (window.console.firebug)
91 this.log = function(msg) { window.console.log(this.timeStamp(),msg); };
93 this.log = function(msg) { window.console.log(this.timeStamp()+msg); };
\r
94 } else if (window.opera) {
95 this.log = function(msg) { window.opera.postError(this.timeStamp()+msg); };
100 return typeof e == 'string' ? document.getElementById(e) : e;
103 Rico.runLater=function() {
104 var args = Array.prototype.slice.call(arguments);
105 var msec = args.shift();
106 var object = args.shift();
107 var method = args.shift();
108 return setTimeout(function() { object[method].apply(object,args); },msec);
111 Rico.visible=function(element) {
112 return Rico.getStyle(element,"display") != 'none';
115 Rico.show=function(element) {
116 element.style.display = '';
119 Rico.hide=function(element) {
120 element.style.display = 'none';
123 Rico.toggle=function(element) {
124 element.style.display = element.style.display == 'none' ? '' : 'none';
128 Rico.direction=function(element) {
129 return (Rico.getStyle(element,'direction') || 'ltr').toLowerCase();
132 Rico.viewportOffset=function(element) {
133 var offset=Rico.cumulativeOffset(element);
134 offset.left -= this.docScrollLeft();
135 offset.top -= this.docScrollTop();
140 * Return text within an html element
142 * @param xImg true to exclude img tag info
143 * @param xForm true to exclude input, select, and textarea tags
144 * @param xClass exclude elements with a class name of xClass
146 Rico.getInnerText=function(el,xImg,xForm,xClass) {
148 case 'string': return el;
149 case 'undefined': return el;
150 case 'number': return el.toString();
152 var cs = el.childNodes;
155 for (var i = 0; i < l; i++) {
156 switch (cs[i].nodeType) {
157 case 1: //ELEMENT_NODE
158 if (this.getStyle(cs[i],'display')=='none') continue;
159 if (xClass && this.hasClass(cs[i],xClass)) continue;
160 switch (cs[i].tagName.toLowerCase()) {
161 case 'img': if (!xImg) str += cs[i].alt || cs[i].title || cs[i].src; break;
162 case 'input': if (!xForm && !cs[i].disabled && cs[i].type.toLowerCase()=='text') str += cs[i].value; break;
163 case 'select': if (!xForm && cs[i].selectedIndex>=0) str += cs[i].options[cs[i].selectedIndex].text; break;
164 case 'textarea': if (!xForm && !cs[i].disabled) str += cs[i].value; break;
165 default: str += this.getInnerText(cs[i],xImg,xForm,xClass); break;
169 str += cs[i].nodeValue;
177 * Return value of a node in an XML response.
178 * For Konqueror 3.5, isEncoded must be true.
180 Rico.getContentAsString=function( parentNode, isEncoded ) {
181 if (isEncoded) return this._getEncodedContent(parentNode);
182 if (typeof parentNode.xml != 'undefined') return this._getContentAsStringIE(parentNode);
183 return this._getContentAsStringMozilla(parentNode);
186 Rico._getEncodedContent=function(parentNode) {
187 if (parentNode.innerHTML) return parentNode.innerHTML;
188 switch (parentNode.childNodes.length) {
190 case 1: return parentNode.firstChild.nodeValue;
191 default: return parentNode.childNodes[1].nodeValue;
195 Rico._getContentAsStringIE=function(parentNode) {
197 for ( var i = 0 ; i < parentNode.childNodes.length ; i++ ) {
198 var n = parentNode.childNodes[i];
199 contentStr += (n.nodeType == 4) ? n.nodeValue : n.xml;
204 Rico._getContentAsStringMozilla=function(parentNode) {
205 var xmlSerializer = new XMLSerializer();
207 for ( var i = 0 ; i < parentNode.childNodes.length ; i++ ) {
208 var n = parentNode.childNodes[i];
209 if (n.nodeType == 4) { // CDATA node
210 contentStr += n.nodeValue;
213 contentStr += xmlSerializer.serializeToString(n);
220 * @param n a number (or a string to be converted using parseInt)
221 * @returns the integer value of n, or 0 if n is not a number
223 Rico.nan2zero=function(n) {
224 if (typeof(n)=='string') n=parseInt(n,10);
225 return isNaN(n) || typeof(n)=='undefined' ? 0 : n;
228 Rico.stripTags=function(s) {
229 return s.replace(/<\/?[^>]+>/gi, '');
232 Rico.truncate=function(s,length) {
233 return s.length > length ? s.substr(0, length - 3) + '...' : s;
236 Rico.zFill=function(n,slen, radix) {
237 var s=n.toString(radix || 10);
238 while (s.length<slen) s='0'+s;
242 Rico.keys=function(obj) {
250 * @param e event object
251 * @returns the key code stored in the event
253 Rico.eventKey=function(e) {
254 if( typeof( e.keyCode ) == 'number' ) {
255 return e.keyCode; //DOM
256 } else if( typeof( e.which ) == 'number' ) {
257 return e.which; //NS 4 compatible
258 } else if( typeof( e.charCode ) == 'number' ) {
259 return e.charCode; //also NS 6+, Mozilla 0.9+
261 return -1; //total failure, we have no way of obtaining the key code
264 Rico.eventLeftClick=function(e) {
265 return (((e.which) && (e.which == 1)) ||
266 ((e.button) && (e.button == 1)));
269 Rico.eventRelatedTarget=function(e) {
270 return e.relatedTarget;
274 * Return the previous sibling that has the specified tagName
276 Rico.getPreviosSiblingByTagName=function(el,tagName) {
277 var sib=el.previousSibling;
279 if ((sib.tagName==tagName) && (sib.style.display!='none')) return sib;
280 sib=sib.previousSibling;
286 * Return the parent of el that has the specified tagName.
288 * @param tagName tag to search for
289 * @param className optional
291 Rico.getParentByTagName=function(el,tagName,className) {
293 tagName=tagName.toLowerCase();
295 if (par.tagName && par.tagName.toLowerCase()==tagName) {
296 if (!className || par.className.indexOf(className)>=0) return par;
304 * Wrap the children of a DOM element in a new element
305 * @param el the element whose children are to be wrapped
306 * @param cls class name of the wrapper (optional)
307 * @param id id of the wrapper (optional)
308 * @param wrapperTag type of wrapper element to be created (optional, defaults to DIV)
309 * @returns new wrapper element
311 Rico.wrapChildren=function(el,cls,id,wrapperTag) {
312 var wrapper = document.createElement(wrapperTag || 'div');
313 if (id) wrapper.id=id;
314 if (cls) wrapper.className=cls;
315 while (el.firstChild) {
316 wrapper.appendChild(el.firstChild);
318 el.appendChild(wrapper);
323 * Positions ctl over icon
324 * @param ctl (div with position:absolute)
325 * @param icon element (img, button, etc) that ctl should be displayed next to
327 Rico.positionCtlOverIcon=function(ctl,icon) {
329 var offsets=this.cumulativeOffset(icon);
330 var scrTop=this.docScrollTop();
331 var scrLeft=this.docScrollLeft();
332 var winHt=this.windowHeight();
333 if (ctl.style.display=='none') ctl.style.display='block';
334 var correction=2; // based on a 1px border
335 if (Rico.direction(icon) == 'rtl') {
336 //var margin=this.nan2zero(this.getStyle(icon,'marginRight'));
337 ctl.style.left = (offsets.left + icon.offsetWidth - ctl.offsetWidth)+'px';
339 var margin=this.nan2zero(this.getStyle(icon,'marginLeft'));
340 ctl.style.left = (offsets.left+margin+correction+scrLeft)+'px';
342 var newTop=offsets.top + correction;// + scrTop;
343 var ctlht=ctl.offsetHeight;
344 var iconht=icon.offsetHeight;
345 var margin=10; // account for shadow
346 if (newTop+iconht+ctlht+margin < winHt+scrTop) {
347 newTop+=iconht; // display below icon
349 newTop=Math.max(newTop-ctlht,scrTop); // display above icon
351 ctl.style.top = newTop+'px';
355 * Creates a form element
356 * @param parent new element will be appended to this node
357 * @param elemTag element to be created (input, button, select, textarea, ...)
358 * @param elemType for input tag this specifies the type (checkbox, radio, text, ...)
359 * @param id id for new element
360 * @param name name for new element, if not specified then name will be the same as the id
361 * @returns new element
363 Rico.createFormField=function(parent,elemTag,elemType,id,name) {
365 if (typeof name!='string') name=id;
366 if (this.isIE && this.ieVersion < 8) {
367 // IE cannot set NAME attribute on dynamically created elements
368 var s=elemTag+' id="'+id+'"';
370 s+=' type="'+elemType+'"';
372 if (elemTag.match(/^(form|input|select|textarea|object|button|img)$/)) {
373 s+=' name="'+name+'"';
375 field=document.createElement('<'+s+' />');
377 field=document.createElement(elemTag);
382 if (typeof field.name=='string') {
386 parent.appendChild(field);
391 * Adds a new option to the end of a select list
392 * @returns new option element
394 Rico.addSelectOption=function(elem,value,text) {
395 var opt=document.createElement('option');
396 if (typeof value=='string') opt.value=value;
407 * @returns the value of the specified cookie (or null if it doesn't exist)
409 Rico.getCookie=function(itemName) {
410 var arg = itemName+'=';
411 var alen = arg.length;
412 var clen = document.cookie.length;
416 if (document.cookie.substring(i, j) == arg) {
417 var endstr = document.cookie.indexOf (';', j);
419 endstr=document.cookie.length;
421 return unescape(document.cookie.substring(j, endstr));
423 i = document.cookie.indexOf(' ', i) + 1;
429 Rico.getTBody=function(tab) {
430 return tab.tBodies.length==0 ? tab.appendChild(document.createElement("tbody")) : tab.tBodies[0];
434 * Write information to a cookie.
435 * For cookies to be retained for the current session only, set daysToKeep=null.
436 * To erase a cookie, pass a negative daysToKeep value.
437 * @see <a href="http://www.quirksmode.org/js/cookies.html">Quirksmode article</a> for more information about cookies.
439 Rico.setCookie=function(itemName,itemValue,daysToKeep,cookiePath,cookieDomain) {
440 var c = itemName+"="+escape(itemValue);
441 if (typeof(daysToKeep)=='number') {
442 var date = new Date();
443 date.setTime(date.getTime()+(daysToKeep*24*60*60*1000));
444 c+="; expires="+date.toGMTString();
446 if (typeof(cookiePath)=='string') {
447 c+="; path="+cookiePath;
449 if (typeof(cookieDomain)=='string') {
450 c+="; domain="+cookieDomain;
455 Rico.phrasesById = {};
456 /** thousands separator for number formatting */
458 /** decimal point for number formatting */
460 /** target language (2 character code) */
461 Rico.langCode = "en";
463 Rico.dateFmt = "mm/dd/yyyy";
465 Rico.timeFmt = "hh:nn:ss a/pm";
466 /** month name array (Jan is at index 0) */
467 Rico.monthNames = ['January','February','March','April','May','June','July','August','September','October','November','December'];
468 /** day of week array (Sunday is at index 0) */
469 Rico.dayNames = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
472 * @param monthIdx 0-11
473 * @returns month abbreviation
475 Rico.monthAbbr=function(monthIdx) {
476 return this.monthNamesShort ? this.monthNamesShort[monthIdx] : this.monthNames[monthIdx].substr(0,3);
480 * @param dayIdx 0-6 (Sunday=0)
481 * @returns day of week abbreviation
483 Rico.dayAbbr=function(dayIdx) {
484 return this.dayNamesShort ? this.dayNamesShort[dayIdx] : this.dayNames[dayIdx].substr(0,3);
487 Rico.addPhraseId=function(phraseId, phrase) {
488 this.phrasesById[phraseId]=phrase;
491 Rico.getPhraseById=function(phraseId) {
492 var phrase=this.phrasesById[phraseId];
494 alert('Error: missing phrase for '+phraseId);
497 if (arguments.length <= 1) return phrase;
499 return phrase.replace(/(\$\d)/g,
501 var idx=parseInt($1.charAt(1),10);
502 return (idx < a.length) ? a[idx] : '';
508 * Format a positive number (integer or float)
509 * @param posnum number to format
510 * @param decPlaces the number of digits to display after the decimal point
511 * @param thouSep boolean indicating whether to insert thousands separator
512 * @returns formatted string
514 Rico.formatPosNumber=function(posnum,decPlaces,thouSep) {
515 var a=posnum.toFixed(decPlaces).split(/\./);
517 var rgx = /(\d+)(\d{3})/;
518 while (rgx.test(a[0])) {
519 a[0]=a[0].replace(rgx, '$1'+Rico.thouSep+'$2');
522 return a.join(Rico.decPoint);
526 * Format a number according to the specs in fmt object.
527 * @returns string, wrapped in a span element with a class of: negNumber, zeroNumber, posNumber
528 * These classes can be set in CSS to display negative numbers in red, for example.
530 * @param n number to be formatted
531 * @param fmt may contain any of the following:<dl>
532 * <dt>multiplier </dt><dd> the original number is multiplied by this amount before formatting</dd>
533 * <dt>decPlaces </dt><dd> number of digits to the right of the decimal point</dd>
534 * <dt>thouSep </dt><dd> boolean indicating whether to insert thousands separator</dd>
535 * <dt>prefix </dt><dd> string added to the beginning of the result (e.g. a currency symbol)</dd>
536 * <dt>suffix </dt><dd> string added to the end of the result (e.g. % symbol)</dd>
537 * <dt>negSign </dt><dd> specifies format for negative numbers: L=leading minus, T=trailing minus, P=parens</dd>
540 Rico.formatNumber=function(n,fmt) {
541 if (typeof n=='string') n=parseFloat(n.replace(/,/,'.'),10);
542 if (isNaN(n)) return 'NaN';
543 if (typeof fmt.multiplier=='number') n*=fmt.multiplier;
544 var decPlaces=typeof fmt.decPlaces=='number' ? fmt.decPlaces : 0;
545 var thouSep=typeof fmt.thouSep=='undefined' ? true : fmt.thouSep;
546 var prefix=fmt.prefix || "";
547 var suffix=fmt.suffix || "";
548 var negSign=typeof fmt.negSign=='string' ? fmt.negSign : "L";
549 negSign=negSign.toUpperCase();
552 s=this.formatPosNumber(-n,decPlaces,thouSep);
553 if (negSign=="P") s="("+s+")";
555 if (negSign=="L") s="-"+s;
556 if (negSign=="T") s+="-";
559 cls=n==0.0 ? 'zeroNumber' : 'posNumber';
560 s=prefix+this.formatPosNumber(n,decPlaces,thouSep);
562 return "<span class='"+cls+"'>"+s+suffix+"</span>";
566 * Converts a date to a string according to specs in fmt
567 * @returns formatted string
568 * @param d date to be formatted
569 * @param fmt string specifying the output format, may be one of the following:<dl>
570 * <dt>locale or localeDateTime</dt>
571 * <dd>use javascript's built-in toLocaleString() function</dd>
572 * <dt>localeDate or 'Long Date'</dt>
573 * <dd>use javascript's built-in toLocaleDateString() function</dd>
574 * <dt>translate or translateDateTime</dt>
575 * <dd>use the formats specified in the Rico.dateFmt and Rico.timeFmt properties</dd>
576 * <dt>translateDate or 'Short Date'</dt>
577 * <dd>use the date format specified in the Rico.dateFmt property</dd>
579 * <dd>Any combination of: yyyy, yy, mmmm, mmm, mm, m, dddd, ddd, dd, d, hh, h, HH, H, nn, ss, a/p</dd>
582 Rico.formatDate=function(d,fmt) {
583 var datefmt=(typeof fmt=='string') ? fmt : 'translateDate';
586 case 'localeDateTime':
587 return d.toLocaleString();
590 return d.toLocaleDateString();
592 case 'translateDateTime':
593 datefmt=this.dateFmt+' '+this.timeFmt;
596 case 'translateDate':
597 datefmt=this.dateFmt;
600 return datefmt.replace(/(yyyy|yy|mmmm|mmm|mm|dddd|ddd|dd|d|hh|nn|ss|a\/p)/gi,
604 case 'yyyy': return d.getFullYear();
605 case 'yy': return d.getFullYear().toString().substr(2);
606 case 'mmmm': return Rico.monthNames[d.getMonth()];
607 case 'mmm': return Rico.monthAbbr(d.getMonth());
608 case 'mm': return Rico.zFill(d.getMonth() + 1, 2);
609 case 'm': return (d.getMonth() + 1);
610 case 'dddd': return Rico.dayNames[d.getDay()];
611 case 'ddd': return Rico.dayAbbr(d.getDay());
612 case 'dd': return Rico.zFill(d.getDate(), 2);
613 case 'd': return d.getDate();
614 case 'hh': return Rico.zFill((h = d.getHours() % 12) ? h : 12, 2);
615 case 'h': return ((h = d.getHours() % 12) ? h : 12);
616 case 'HH': return Rico.zFill(d.getHours(), 2);
617 case 'H': return d.getHours();
618 case 'nn': return Rico.zFill(d.getMinutes(), 2);
619 case 'ss': return Rico.zFill(d.getSeconds(), 2);
620 case 'a/p': return d.getHours() < 12 ? 'a' : 'p';
627 * Converts a string in ISO 8601 format to a date object.
628 * @returns date object, or false if string is not a valid date or date-time.
629 * @param string value to be converted
630 * @param offset can be used to bias the conversion and must be in minutes if provided
631 * @see Based on <a href='http://delete.me.uk/2005/03/iso8601.html'>delete.me.uk article</a>
633 Rico.setISO8601=function (string,offset) {
634 if (!string) return false;
635 var d = string.match(/(\d\d\d\d)(?:-?(\d\d)(?:-?(\d\d)(?:[T ](\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|(?:([-+])(\d\d)(?::?(\d\d))?)?)?)?)?)?/);
636 if (!d) return false;
637 if (!offset) offset=0;
638 var date = new Date(d[1], 0, 1);
640 if (d[2]) { date.setMonth(d[2] - 1); }
641 if (d[3]) { date.setDate(d[3]); }
642 if (d[4]) { date.setHours(d[4]); }
643 if (d[5]) { date.setMinutes(d[5]); }
644 if (d[6]) { date.setSeconds(d[6]); }
645 if (d[7]) { date.setMilliseconds(Number("0." + d[7]) * 1000); }
647 if (d[10] && d[11]) {
648 offset = (Number(d[10]) * 60) + Number(d[11]);
650 offset *= ((d[9] == '-') ? 1 : -1);
651 offset -= date.getTimezoneOffset();
653 var time = (Number(date) + (offset * 60 * 1000));
654 date.setTime(Number(time));
659 * Convert date to an ISO 8601 formatted string.
660 * @param date date object to be converted
661 * @param format an integer in the range 1-6 (default is 6):<dl>
663 * <dd>YYYY (eg 1997)</dd>
664 * <dt>2 (year and month)</dt>
665 * <dd>YYYY-MM (eg 1997-07)</dd>
666 * <dt>3 (complete date)</dt>
667 * <dd>YYYY-MM-DD (eg 1997-07-16)</dd>
668 * <dt>4 (complete date plus hours and minutes)</dt>
669 * <dd>YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)</dd>
670 * <dt>5 (complete date plus hours, minutes and seconds)</dt>
671 * <dd>YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)</dd>
672 * <dt>6 (complete date plus hours, minutes, seconds and a decimal
673 * fraction of a second)</dt>
674 * <dd>YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)</dd>
676 * @see Based on: <a href='http://www.codeproject.com/jscript/dateformat.asp'>codeproject.com article</a>
678 Rico.toISO8601String=function (date, format, offset) {
679 if (!format) format=6;
683 var d = offset.match(/([-+])([0-9]{2}):([0-9]{2})/);
684 var offsetnum = (Number(d[2]) * 60) + Number(d[3]);
685 offsetnum *= ((d[1] == '-') ? -1 : 1);
686 date = new Date(Number(Number(date) + (offsetnum * 60000)));
689 var zeropad = function (num) { return ((num < 10) ? '0' : '') + num; };
691 var str = date.getUTCFullYear();
692 if (format > 1) { str += "-" + zeropad(date.getUTCMonth() + 1); }
693 if (format > 2) { str += "-" + zeropad(date.getUTCDate()); }
695 str += "T" + zeropad(date.getUTCHours()) +
696 ":" + zeropad(date.getUTCMinutes());
699 var secs = Number(date.getUTCSeconds() + "." +
700 ((date.getUTCMilliseconds() < 100) ? '0' : '') +
701 zeropad(date.getUTCMilliseconds()));
702 str += ":" + zeropad(secs);
703 } else if (format > 4) {
704 str += ":" + zeropad(date.getUTCSeconds());
707 if (format > 3) { str += offset; }
712 * Returns a new XML document object
714 Rico.createXmlDocument=function() {
715 if (document.implementation && document.implementation.createDocument) {
716 var doc = document.implementation.createDocument("", "", null);
717 // some older versions of Moz did not support the readyState property
718 // and the onreadystate event so we patch it!
719 if (doc.readyState == null) {
721 doc.addEventListener("load", function () {
723 if (typeof doc.onreadystatechange == "function") {
724 doc.onreadystatechange();
731 if (window.ActiveXObject)
732 return Rico.tryFunctions(
733 function() { return new ActiveXObject('MSXML2.DomDocument'); },
734 function() { return new ActiveXObject('Microsoft.DomDocument');},
735 function() { return new ActiveXObject('MSXML.DomDocument'); },
736 function() { return new ActiveXObject('MSXML3.DomDocument'); }
742 * Update the contents of an HTML element via an AJAX call
744 Rico.ajaxUpdater = function(elem,url,options) {
745 this.updateSend(elem,url,options);
748 Rico.ajaxUpdater.prototype = {
749 updateSend : function(elem,url,options) {
751 this.onComplete=options.onComplete;
753 options.onComplete=function(xhr) { self.updateComplete(xhr); };
754 new Rico.ajaxRequest(url,options);
757 updateComplete : function(xhr) {
758 this.element.innerHTML=xhr.responseText;
759 if (this.onComplete) this.onComplete(xhr);
763 try { // fix IE background image flicker (credit: www.mister-pixel.com)
764 document.execCommand("BackgroundImageCache", false, true);
766 Rico.eventBind(window,"load", Rico.eventHandle(Rico,'windowLoaded'));