.net server control is almost feature complete and functional. All .net examples...
[infodrom/rico3] / ricoClient / js / rico.js
index 86f6c9d..cb46cba 100644 (file)
 var Rico = {
   Version: '3.0b2',
   theme: {},
+  onLoadCallbacks: [],
+  windowIsLoaded: false,
+  preloadMsgs: '',
+  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},
 
   init : function() {
     try {  // fix IE background image flicker (credit: www.mister-pixel.com)
       document.execCommand("BackgroundImageCache", false, true);
     } catch(err) {}
-    if (typeof Rico_CONFIG == 'object') {
-      if (Rico_CONFIG.jsDir) this.setPaths(Rico_CONFIG.jsDir);
-      this.setBackgroundStyles();
-      if (Rico_CONFIG.enableLogging) this.enableLogging();
-    }
-    this.preloadMsgs='';
-    this.baseHref= location.protocol + "//" + location.host;
-    this.windowIsLoaded=false;
-    this.onLoadCallbacks=[];
+    if (typeof Rico_CONFIG == 'object') this.setConfig(Rico_CONFIG);
     this.onLoad(function() { Rico.log('Pre-load messages:\n'+Rico.preloadMsgs); });
   },
 
+  // called by rico2xxx.js
   _bindLoadEvent : function() {
     Rico.eventBind(window,"load", Rico.eventHandle(Rico,'windowLoaded'));
   },
 
-  setPaths : function(jsDir) {
-    this.jsDir = jsDir;
-  },
-
-  setBackgroundStyles: function() {
+  setConfig : function(ConfigObj) {
     var el = document.createElement('style');
     document.getElementsByTagName('head')[0].appendChild(el);
     if (!window.createPopup) { /* For Safari */
       el.appendChild(document.createTextNode(''));
     }
     var s = document.styleSheets[document.styleSheets.length - 1];
-    this.addCssRule(s,'.rico-icon',Rico_CONFIG.imgIcons,'no-repeat');
-    this.addCssRule(s,'.ricoLG_Resize',Rico_CONFIG.imgResize,'repeat');
-    if (Rico_CONFIG.imgHeading) {
-      var repeat='repeat-x scroll left center';
-      this.addCssRule(s,'tr.ricoLG_hdg th',Rico_CONFIG.imgHeading,repeat);
-      this.addCssRule(s,'tr.ricoLG_hdg td',Rico_CONFIG.imgHeading,repeat);
-      this.addCssRule(s,'table.ricoLiveGrid thead td',Rico_CONFIG.imgHeading,repeat);
-      this.addCssRule(s,'table.ricoLiveGrid thead th',Rico_CONFIG.imgHeading,repeat);
-      this.addCssRule(s,'.ricoTitle',Rico_CONFIG.imgHeading,repeat);
-      this.addCssRule(s,'.Rico_accTitle',Rico_CONFIG.imgHeading,repeat);
+    this.addCssBackgroundRule(s,'.rico-icon',ConfigObj.imgIcons,'no-repeat');
+    this.addCssBackgroundRule(s,'.ricoLG_Resize',ConfigObj.imgResize,'repeat');
+    if (ConfigObj.imgHeading) {
+      var repeat='repeat-x';
+      var pos='left center';
+      this.addCssBackgroundRule(s,'tr.ricoLG_hdg th',ConfigObj.imgHeading,repeat,pos);
+      this.addCssBackgroundRule(s,'tr.ricoLG_hdg td',ConfigObj.imgHeading,repeat,pos);
+      this.addCssBackgroundRule(s,'table.ricoLiveGrid thead td',ConfigObj.imgHeading,repeat,pos);
+      this.addCssBackgroundRule(s,'table.ricoLiveGrid thead th',ConfigObj.imgHeading,repeat,pos);
+      this.addCssBackgroundRule(s,'.ricoTitle',ConfigObj.imgHeading,repeat,pos);
+      this.addCssBackgroundRule(s,'.Rico_accTitle',ConfigObj.imgHeading,repeat,pos);
     }
+
+    if (ConfigObj.enableLogging) this.enableLogging();
+    if (ConfigObj.enableHTML5) this._CheckInputTypes();
   },
 
-  addCssRule: function(sheet,selector,imageUrl,repeat) {
+  addCssBackgroundRule: function(sheet,selector,imageUrl,repeat,position) {
     if (!imageUrl) return;
-    var rule="background:url('"+imageUrl+"') "+repeat;
+    this.addCssRule(sheet,selector,"background-image:url('"+imageUrl+"')");
+    this.addCssRule(sheet,selector,"background-repeat:"+repeat);
+    if (position) this.addCssRule(sheet,selector,"background-position:"+position);
+  },
+
+  addCssRule: function(sheet,selector,rule) {
     if (sheet.addRule) {
       sheet.addRule(selector, rule);
     } else if (sheet.insertRule) {
@@ -76,13 +78,6 @@ var Rico = {
     }
   },
 
-  languageInclude : function(lang2) {
-    var el = document.createElement('script');
-    el.type = 'text/javascript';
-    el.src = this.jsDir+"ricoLocale_"+lang2+".js";
-    document.getElementsByTagName('head')[0].appendChild(el);
-  },
-
   // called by the document onload event
   windowLoaded: function() {
     this.windowIsLoaded=true;
@@ -92,6 +87,16 @@ var Rico = {
       if (callback) callback();
     }
   },
+  
+  // check for availability of HTML5 input types
+  _CheckInputTypes: function() {
+    var i = document.createElement("input");
+    for (var itype in this.inputtypes) {
+      i.setAttribute("type", "text");
+      i.setAttribute("type", itype);
+      this.inputtypes[itype]=(i.type !== "text");
+    }
+  },
 
   onLoad: function(callback,frontOfQ) {
     if (frontOfQ)
@@ -551,19 +556,18 @@ getPhraseById: function(phraseId) {
  * Format a positive number (integer or float)
  * @param posnum number to format
  * @param decPlaces the number of digits to display after the decimal point
- * @param thouSep the character to use as the thousands separator
- * @param decPoint the character to use as the decimal point
+ * @param thouSep boolean indicating whether to insert thousands separator
  * @returns formatted string
  */
-formatPosNumber: function(posnum,decPlaces,thouSep,decPoint) {
+formatPosNumber: function(posnum,decPlaces,thouSep) {
   var a=posnum.toFixed(decPlaces).split(/\./);
   if (thouSep) {
     var rgx = /(\d+)(\d{3})/;
     while (rgx.test(a[0])) {
-      a[0]=a[0].replace(rgx, '$1'+thouSep+'$2');
+      a[0]=a[0].replace(rgx, '$1'+Rico.thouSep+'$2');
     }
   }
-  return a.join(decPoint);
+  return a.join(Rico.decPoint);
 },
 
 /**
@@ -575,8 +579,7 @@ formatPosNumber: function(posnum,decPlaces,thouSep,decPoint) {
  * @param fmt may contain any of the following:<dl>
  *   <dt>multiplier </dt><dd> the original number is multiplied by this amount before formatting</dd>
  *   <dt>decPlaces  </dt><dd> number of digits to the right of the decimal point</dd>
- *   <dt>decPoint   </dt><dd> character to be used as the decimal point</dd>
- *   <dt>thouSep    </dt><dd> character to use as the thousands separator</dd>
+ *   <dt>thouSep    </dt><dd> boolean indicating whether to insert thousands separator</dd>
  *   <dt>prefix     </dt><dd> string added to the beginning of the result (e.g. a currency symbol)</dd>
  *   <dt>suffix     </dt><dd> string added to the end of the result (e.g. % symbol)</dd>
  *   <dt>negSign    </dt><dd> specifies format for negative numbers: L=leading minus, T=trailing minus, P=parens</dd>
@@ -587,15 +590,14 @@ formatNumber : function(n,fmt) {
   if (isNaN(n)) return 'NaN';
   if (typeof fmt.multiplier=='number') n*=fmt.multiplier;
   var decPlaces=typeof fmt.decPlaces=='number' ? fmt.decPlaces : 0;
-  var thouSep=typeof fmt.thouSep=='string' ? fmt.thouSep : this.thouSep;
-  var decPoint=typeof fmt.decPoint=='string' ? fmt.decPoint : this.decPoint;
+  var thouSep=typeof fmt.thouSep=='undefined' ? true : this.thouSep;
   var prefix=fmt.prefix || "";
   var suffix=fmt.suffix || "";
   var negSign=typeof fmt.negSign=='string' ? fmt.negSign : "L";
   negSign=negSign.toUpperCase();
   var s,cls;
   if (n<0.0) {
-    s=this.formatPosNumber(-n,decPlaces,thouSep,decPoint);
+    s=this.formatPosNumber(-n,decPlaces,thouSep);
     if (negSign=="P") s="("+s+")";
     s=prefix+s;
     if (negSign=="L") s="-"+s;
@@ -603,7 +605,7 @@ formatNumber : function(n,fmt) {
     cls='negNumber';
   } else {
     cls=n==0.0 ? 'zeroNumber' : 'posNumber';
-    s=prefix+this.formatPosNumber(n,decPlaces,thouSep,decPoint);
+    s=prefix+this.formatPosNumber(n,decPlaces,thouSep);
   }
   return "<span class='"+cls+"'>"+s+suffix+"</span>";
 },
@@ -641,7 +643,7 @@ formatDate : function(d,fmt) {
       datefmt=this.dateFmt;
       break;
   }
-  return datefmt.replace(/(yyyy|yy|mmmm|mmm|mm|dddd|ddd|dd|hh|nn|ss|a\/p)/gi,
+  return datefmt.replace(/(yyyy|yy|mmmm|mmm|mm|dddd|ddd|dd|d|hh|nn|ss|a\/p)/gi,
     function($1) {
       var h;
       switch ($1) {