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) {
188 if (Rico.isGecko && navigator.productSub >= "20100101")
189 parentNode.innerHTML.replace(/</g,'<').replace(/>/g,'>').replace(/&/g,'&');
191 return parentNode.innerHTML;
194 switch (parentNode.childNodes.length) {
196 case 1: return parentNode.firstChild.nodeValue;
197 default: return parentNode.childNodes[1].nodeValue;
201 Rico._getContentAsStringIE=function(parentNode) {
203 for ( var i = 0 ; i < parentNode.childNodes.length ; i++ ) {
204 var n = parentNode.childNodes[i];
205 contentStr += (n.nodeType == 4) ? n.nodeValue : n.xml;
210 Rico._getContentAsStringMozilla=function(parentNode) {
211 var xmlSerializer = new XMLSerializer();
213 for ( var i = 0 ; i < parentNode.childNodes.length ; i++ ) {
214 var n = parentNode.childNodes[i];
215 if (n.nodeType == 4) { // CDATA node
216 contentStr += n.nodeValue;
219 contentStr += xmlSerializer.serializeToString(n);
226 * @param n a number (or a string to be converted using parseInt)
227 * @returns the integer value of n, or 0 if n is not a number
229 Rico.nan2zero=function(n) {
230 if (typeof(n)=='string') n=parseInt(n,10);
231 return isNaN(n) || typeof(n)=='undefined' ? 0 : n;
234 Rico.stripTags=function(s) {
235 return s.replace(/<\/?[^>]+>/gi, '');
238 Rico.truncate=function(s,length) {
239 return s.length > length ? s.substr(0, length - 3) + '...' : s;
242 Rico.zFill=function(n,slen, radix) {
243 var s=n.toString(radix || 10);
244 while (s.length<slen) s='0'+s;
248 Rico.keys=function(obj) {
256 * @param e event object
257 * @returns the key code stored in the event
259 Rico.eventKey=function(e) {
260 if( typeof( e.keyCode ) == 'number' ) {
261 return e.keyCode; //DOM
262 } else if( typeof( e.which ) == 'number' ) {
263 return e.which; //NS 4 compatible
264 } else if( typeof( e.charCode ) == 'number' ) {
265 return e.charCode; //also NS 6+, Mozilla 0.9+
267 return -1; //total failure, we have no way of obtaining the key code
270 Rico.eventLeftClick=function(e) {
271 return (((e.which) && (e.which == 1)) ||
272 ((e.button) && (e.button == 1)));
275 Rico.eventRelatedTarget=function(e) {
276 return e.relatedTarget;
280 * Return the previous sibling that has the specified tagName
282 Rico.getPreviosSiblingByTagName=function(el,tagName) {
283 var sib=el.previousSibling;
285 if ((sib.tagName==tagName) && (sib.style.display!='none')) return sib;
286 sib=sib.previousSibling;
292 * Return the parent of el that has the specified tagName.
294 * @param tagName tag to search for
295 * @param className optional
297 Rico.getParentByTagName=function(el,tagName,className) {
299 tagName=tagName.toLowerCase();
301 if (par.tagName && par.tagName.toLowerCase()==tagName) {
302 if (!className || par.className.indexOf(className)>=0) return par;
310 * Wrap the children of a DOM element in a new element
311 * @param el the element whose children are to be wrapped
312 * @param cls class name of the wrapper (optional)
313 * @param id id of the wrapper (optional)
314 * @param wrapperTag type of wrapper element to be created (optional, defaults to DIV)
315 * @returns new wrapper element
317 Rico.wrapChildren=function(el,cls,id,wrapperTag) {
318 var wrapper = document.createElement(wrapperTag || 'div');
319 if (id) wrapper.id=id;
320 if (cls) wrapper.className=cls;
321 while (el.firstChild) {
322 wrapper.appendChild(el.firstChild);
324 el.appendChild(wrapper);
329 * Positions ctl over icon
330 * @param ctl (div with position:absolute)
331 * @param icon element (img, button, etc) that ctl should be displayed next to
333 Rico.positionCtlOverIcon=function(ctl,icon) {
335 var offsets=this.cumulativeOffset(icon);
336 var scrTop=this.docScrollTop();
337 var scrLeft=this.docScrollLeft();
338 var winHt=this.windowHeight();
339 if (ctl.style.display=='none') ctl.style.display='block';
340 var correction=2; // based on a 1px border
341 if (Rico.direction(icon) == 'rtl') {
342 //var margin=this.nan2zero(this.getStyle(icon,'marginRight'));
343 ctl.style.left = (offsets.left + icon.offsetWidth - ctl.offsetWidth)+'px';
345 var margin=this.nan2zero(this.getStyle(icon,'marginLeft'));
346 ctl.style.left = (offsets.left+margin+correction+scrLeft)+'px';
348 var newTop=offsets.top + correction;// + scrTop;
349 var ctlht=ctl.offsetHeight;
350 var iconht=icon.offsetHeight;
351 var margin=10; // account for shadow
352 if (newTop+iconht+ctlht+margin < winHt+scrTop) {
353 newTop+=iconht; // display below icon
355 newTop=Math.max(newTop-ctlht,scrTop); // display above icon
357 ctl.style.top = newTop+'px';
361 * Creates a form element
362 * @param parent new element will be appended to this node
363 * @param elemTag element to be created (input, button, select, textarea, ...)
364 * @param elemType for input tag this specifies the type (checkbox, radio, text, ...)
365 * @param id id for new element
366 * @param name name for new element, if not specified then name will be the same as the id
367 * @returns new element
369 Rico.createFormField=function(parent,elemTag,elemType,id,name) {
371 if (typeof name!='string') name=id;
372 if (this.isIE && this.ieVersion < 8) {
373 // IE cannot set NAME attribute on dynamically created elements
374 var s=elemTag+' id="'+id+'"';
376 s+=' type="'+elemType+'"';
378 if (elemTag.match(/^(form|input|select|textarea|object|button|img)$/)) {
379 s+=' name="'+name+'"';
381 field=document.createElement('<'+s+' />');
383 field=document.createElement(elemTag);
388 if (typeof field.name=='string') {
392 parent.appendChild(field);
397 * Adds a new option to the end of a select list
398 * @returns new option element
400 Rico.addSelectOption=function(elem,value,text) {
401 var opt=document.createElement('option');
402 if (typeof value=='string') opt.value=value;
413 * @returns the value of the specified cookie (or null if it doesn't exist)
415 Rico.getCookie=function(itemName) {
416 var arg = itemName+'=';
417 var alen = arg.length;
418 var clen = document.cookie.length;
422 if (document.cookie.substring(i, j) == arg) {
423 var endstr = document.cookie.indexOf (';', j);
425 endstr=document.cookie.length;
427 return unescape(document.cookie.substring(j, endstr));
429 i = document.cookie.indexOf(' ', i) + 1;
435 Rico.getTBody=function(tab) {
436 return tab.tBodies.length==0 ? tab.appendChild(document.createElement("tbody")) : tab.tBodies[0];
440 * Write information to a cookie.
441 * For cookies to be retained for the current session only, set daysToKeep=null.
442 * To erase a cookie, pass a negative daysToKeep value.
443 * @see <a href="http://www.quirksmode.org/js/cookies.html">Quirksmode article</a> for more information about cookies.
445 Rico.setCookie=function(itemName,itemValue,daysToKeep,cookiePath,cookieDomain) {
446 var c = itemName+"="+escape(itemValue);
447 if (typeof(daysToKeep)=='number') {
448 var date = new Date();
449 date.setTime(date.getTime()+(daysToKeep*24*60*60*1000));
450 c+="; expires="+date.toGMTString();
452 if (typeof(cookiePath)=='string') {
453 c+="; path="+cookiePath;
455 if (typeof(cookieDomain)=='string') {
456 c+="; domain="+cookieDomain;
461 Rico.phrasesById = {};
462 /** thousands separator for number formatting */
464 /** decimal point for number formatting */
466 /** target language (2 character code) */
467 Rico.langCode = "en";
469 Rico.dateFmt = "mm/dd/yyyy";
471 Rico.timeFmt = "hh:nn:ss a/pm";
472 /** month name array (Jan is at index 0) */
473 Rico.monthNames = ['January','February','March','April','May','June','July','August','September','October','November','December'];
474 /** day of week array (Sunday is at index 0) */
475 Rico.dayNames = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
478 * @param monthIdx 0-11
479 * @returns month abbreviation
481 Rico.monthAbbr=function(monthIdx) {
482 return this.monthNamesShort ? this.monthNamesShort[monthIdx] : this.monthNames[monthIdx].substr(0,3);
486 * @param dayIdx 0-6 (Sunday=0)
487 * @returns day of week abbreviation
489 Rico.dayAbbr=function(dayIdx) {
490 return this.dayNamesShort ? this.dayNamesShort[dayIdx] : this.dayNames[dayIdx].substr(0,3);
493 Rico.addPhraseId=function(phraseId, phrase) {
494 this.phrasesById[phraseId]=phrase;
497 Rico.getPhraseById=function(phraseId) {
498 var phrase=this.phrasesById[phraseId];
500 alert('Error: missing phrase for '+phraseId);
503 if (arguments.length <= 1) return phrase;
505 return phrase.replace(/(\$\d)/g,
507 var idx=parseInt($1.charAt(1),10);
508 return (idx < a.length) ? a[idx] : '';
514 * Format a positive number (integer or float)
515 * @param posnum number to format
516 * @param decPlaces the number of digits to display after the decimal point
517 * @param thouSep boolean indicating whether to insert thousands separator
518 * @returns formatted string
520 Rico.formatPosNumber=function(posnum,decPlaces,thouSep) {
521 var a=posnum.toFixed(decPlaces).split(/\./);
523 var rgx = /(\d+)(\d{3})/;
524 while (rgx.test(a[0])) {
525 a[0]=a[0].replace(rgx, '$1'+Rico.thouSep+'$2');
528 return a.join(Rico.decPoint);
532 * Format a number according to the specs in fmt object.
533 * @returns string, wrapped in a span element with a class of: negNumber, zeroNumber, posNumber
534 * These classes can be set in CSS to display negative numbers in red, for example.
536 * @param n number to be formatted
537 * @param fmt may contain any of the following:<dl>
538 * <dt>multiplier </dt><dd> the original number is multiplied by this amount before formatting</dd>
539 * <dt>decPlaces </dt><dd> number of digits to the right of the decimal point</dd>
540 * <dt>thouSep </dt><dd> boolean indicating whether to insert thousands separator</dd>
541 * <dt>prefix </dt><dd> string added to the beginning of the result (e.g. a currency symbol)</dd>
542 * <dt>suffix </dt><dd> string added to the end of the result (e.g. % symbol)</dd>
543 * <dt>negSign </dt><dd> specifies format for negative numbers: L=leading minus, T=trailing minus, P=parens</dd>
546 Rico.formatNumber=function(n,fmt) {
547 if (typeof n=='string') n=parseFloat(n.replace(/,/,'.'),10);
548 if (isNaN(n)) return 'NaN';
549 if (typeof fmt.multiplier=='number') n*=fmt.multiplier;
550 var decPlaces=typeof fmt.decPlaces=='number' ? fmt.decPlaces : 0;
551 var thouSep=typeof fmt.thouSep=='undefined' ? true : fmt.thouSep;
552 var prefix=fmt.prefix || "";
553 var suffix=fmt.suffix || "";
554 var negSign=typeof fmt.negSign=='string' ? fmt.negSign : "L";
555 negSign=negSign.toUpperCase();
558 s=this.formatPosNumber(-n,decPlaces,thouSep);
559 if (negSign=="P") s="("+s+")";
561 if (negSign=="L") s="-"+s;
562 if (negSign=="T") s+="-";
565 cls=n==0.0 ? 'zeroNumber' : 'posNumber';
566 s=prefix+this.formatPosNumber(n,decPlaces,thouSep);
568 return "<span class='"+cls+"'>"+s+suffix+"</span>";
572 * Converts a date to a string according to specs in fmt
573 * @returns formatted string
574 * @param d date to be formatted
575 * @param fmt string specifying the output format, may be one of the following:<dl>
576 * <dt>locale or localeDateTime</dt>
577 * <dd>use javascript's built-in toLocaleString() function</dd>
578 * <dt>localeDate or 'Long Date'</dt>
579 * <dd>use javascript's built-in toLocaleDateString() function</dd>
580 * <dt>translate or translateDateTime</dt>
581 * <dd>use the formats specified in the Rico.dateFmt and Rico.timeFmt properties</dd>
582 * <dt>translateDate or 'Short Date'</dt>
583 * <dd>use the date format specified in the Rico.dateFmt property</dd>
585 * <dd>Any combination of: yyyy, yy, mmmm, mmm, mm, m, dddd, ddd, dd, d, hh, h, HH, H, nn, ss, a/p</dd>
588 Rico.formatDate=function(d,fmt) {
589 var datefmt=(typeof fmt=='string') ? fmt : 'translateDate';
592 case 'localeDateTime':
593 return d.toLocaleString();
596 return d.toLocaleDateString();
598 case 'translateDateTime':
599 datefmt=this.dateFmt+' '+this.timeFmt;
602 case 'translateDate':
603 datefmt=this.dateFmt;
606 return datefmt.replace(/(yyyy|yy|mmmm|mmm|mm|dddd|ddd|dd|d|hh|nn|ss|a\/p)/gi,
610 case 'yyyy': return d.getFullYear();
611 case 'yy': return d.getFullYear().toString().substr(2);
612 case 'mmmm': return Rico.monthNames[d.getMonth()];
613 case 'mmm': return Rico.monthAbbr(d.getMonth());
614 case 'mm': return Rico.zFill(d.getMonth() + 1, 2);
615 case 'm': return (d.getMonth() + 1);
616 case 'dddd': return Rico.dayNames[d.getDay()];
617 case 'ddd': return Rico.dayAbbr(d.getDay());
618 case 'dd': return Rico.zFill(d.getDate(), 2);
619 case 'd': return d.getDate();
620 case 'hh': return Rico.zFill((h = d.getHours() % 12) ? h : 12, 2);
621 case 'h': return ((h = d.getHours() % 12) ? h : 12);
622 case 'HH': return Rico.zFill(d.getHours(), 2);
623 case 'H': return d.getHours();
624 case 'nn': return Rico.zFill(d.getMinutes(), 2);
625 case 'ss': return Rico.zFill(d.getSeconds(), 2);
626 case 'a/p': return d.getHours() < 12 ? 'a' : 'p';
633 * Converts a string in ISO 8601 format to a date object.
634 * @returns date object, or false if string is not a valid date or date-time.
635 * @param string value to be converted
636 * @param offset can be used to bias the conversion and must be in minutes if provided
637 * @see Based on <a href='http://delete.me.uk/2005/03/iso8601.html'>delete.me.uk article</a>
639 Rico.setISO8601=function (string,offset) {
640 if (!string) return false;
641 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))?)?)?)?)?)?/);
642 if (!d) return false;
643 if (!offset) offset=0;
644 var date = new Date(d[1], 0, 1);
646 if (d[2]) { date.setMonth(d[2] - 1); }
647 if (d[3]) { date.setDate(d[3]); }
648 if (d[4]) { date.setHours(d[4]); }
649 if (d[5]) { date.setMinutes(d[5]); }
650 if (d[6]) { date.setSeconds(d[6]); }
651 if (d[7]) { date.setMilliseconds(Number("0." + d[7]) * 1000); }
653 if (d[10] && d[11]) {
654 offset = (Number(d[10]) * 60) + Number(d[11]);
656 offset *= ((d[9] == '-') ? 1 : -1);
657 offset -= date.getTimezoneOffset();
659 var time = (Number(date) + (offset * 60 * 1000));
660 date.setTime(Number(time));
665 * Convert date to an ISO 8601 formatted string.
666 * @param date date object to be converted
667 * @param format an integer in the range 1-6 (default is 6):<dl>
669 * <dd>YYYY (eg 1997)</dd>
670 * <dt>2 (year and month)</dt>
671 * <dd>YYYY-MM (eg 1997-07)</dd>
672 * <dt>3 (complete date)</dt>
673 * <dd>YYYY-MM-DD (eg 1997-07-16)</dd>
674 * <dt>4 (complete date plus hours and minutes)</dt>
675 * <dd>YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)</dd>
676 * <dt>5 (complete date plus hours, minutes and seconds)</dt>
677 * <dd>YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)</dd>
678 * <dt>6 (complete date plus hours, minutes, seconds and a decimal
679 * fraction of a second)</dt>
680 * <dd>YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)</dd>
682 * @see Based on: <a href='http://www.codeproject.com/jscript/dateformat.asp'>codeproject.com article</a>
684 Rico.toISO8601String=function (date, format, offset) {
685 if (!format) format=6;
689 var d = offset.match(/([-+])([0-9]{2}):([0-9]{2})/);
690 var offsetnum = (Number(d[2]) * 60) + Number(d[3]);
691 offsetnum *= ((d[1] == '-') ? -1 : 1);
692 date = new Date(Number(Number(date) + (offsetnum * 60000)));
695 var zeropad = function (num) { return ((num < 10) ? '0' : '') + num; };
697 var str = date.getUTCFullYear();
698 if (format > 1) { str += "-" + zeropad(date.getUTCMonth() + 1); }
699 if (format > 2) { str += "-" + zeropad(date.getUTCDate()); }
701 str += "T" + zeropad(date.getUTCHours()) +
702 ":" + zeropad(date.getUTCMinutes());
705 var secs = Number(date.getUTCSeconds() + "." +
706 ((date.getUTCMilliseconds() < 100) ? '0' : '') +
707 zeropad(date.getUTCMilliseconds()));
708 str += ":" + zeropad(secs);
709 } else if (format > 4) {
710 str += ":" + zeropad(date.getUTCSeconds());
713 if (format > 3) { str += offset; }
718 * Returns a new XML document object
720 Rico.createXmlDocument=function() {
721 if (document.implementation && document.implementation.createDocument) {
722 var doc = document.implementation.createDocument("", "", null);
723 // some older versions of Moz did not support the readyState property
724 // and the onreadystate event so we patch it!
725 if (doc.readyState == null) {
727 doc.addEventListener("load", function () {
729 if (typeof doc.onreadystatechange == "function") {
730 doc.onreadystatechange();
737 if (window.ActiveXObject)
738 return Rico.tryFunctions(
739 function() { return new ActiveXObject('MSXML2.DomDocument'); },
740 function() { return new ActiveXObject('Microsoft.DomDocument');},
741 function() { return new ActiveXObject('MSXML.DomDocument'); },
742 function() { return new ActiveXObject('MSXML3.DomDocument'); }
748 * Update the contents of an HTML element via an AJAX call
750 Rico.ajaxUpdater = function(elem,url,options) {
751 this.updateSend(elem,url,options);
754 Rico.ajaxUpdater.prototype = {
755 updateSend : function(elem,url,options) {
757 this.onComplete=options.onComplete;
759 options.onComplete=function(xhr) { self.updateComplete(xhr); };
760 new Rico.ajaxRequest(url,options);
763 updateComplete : function(xhr) {
764 this.element.innerHTML=xhr.responseText;
765 if (this.onComplete) this.onComplete(xhr);
769 try { // fix IE background image flicker (credit: www.mister-pixel.com)
770 document.execCommand("BackgroundImageCache", false, true);
772 Rico.eventBind(window,"load", Rico.eventHandle(Rico,'windowLoaded'));