Converted Rico3 icons to CSS sprites. Moved minsrc and baselibs directories out of...
[infodrom/rico3] / ricoClient / js / rico.js
index 239684f..9118ebc 100644 (file)
@@ -18,8 +18,6 @@
  */
 var Rico = {
   Version: '3.0b2',
-  loadRequested: 1,
-  loadComplete: 2,
   theme: {},
 
   init : function() {
@@ -27,105 +25,66 @@ var Rico = {
       document.execCommand("BackgroundImageCache", false, true);
     } catch(err) {}
     if (typeof Rico_CONFIG == 'object') {
-      this.setPaths(Rico_CONFIG.jsDir,Rico_CONFIG.cssDir,Rico_CONFIG.imgDir);
+      this.setPaths(Rico_CONFIG.jsDir);
+      this.setBackgroundStyles();
       if (Rico_CONFIG.enableLogging) this.enableLogging();
     }
     this.preloadMsgs='';
     this.baseHref= location.protocol + "//" + location.host;
-    this.loadedFiles={};
     this.windowIsLoaded=false;
     this.onLoadCallbacks=[];
     this.onLoad(function() { Rico.log('Pre-load messages:\n'+Rico.preloadMsgs); });
   },
-  
+
   _bindLoadEvent : function() {
     Rico.eventBind(window,"load", Rico.eventHandle(Rico,'windowLoaded'));
   },
 
-  setPaths : function(jsDir,cssDir,imgDir,htmDir) {
+  setPaths : function(jsDir,htmDir) {
     this.jsDir = jsDir;
-    this.cssDir = cssDir;
-    this.imgDir = imgDir;
     this.htmDir = htmDir || jsDir;
   },
 
-  languages : {
-    de: "translations/ricoLocale_de.js",
-    en: "translations/ricoLocale_en.js",
-    es: "translations/ricoLocale_es.js",
-    fr: "translations/ricoLocale_fr.js",
-    it: "translations/ricoLocale_it.js",
-    ja: "translations/ricoLocale_ja.js",
-    ko: "translations/ricoLocale_ko.js",
-    pt: "translations/ricoLocale_pt.js",
-    zh: "translations/ricoLocale_zh.js"
-  },
-
-  languageInclude : function(lang2) {
-    var filename=this.languages[lang2];
-    if (filename) this.include(filename);
-    return !!filename;\r
-  },
-
-  acceptLanguage : function(acceptLang) {
-    var arLang=acceptLang.toLowerCase().split(',');\r
-    for (var i=0; i<arLang.length; i++) {\r
-      var lang2=arLang[i].match(/\w\w/);
-      if (!lang2) continue;\r
-      if (this.languageInclude(lang2)) return true;\r
+  setBackgroundStyles: function() {
+    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) {
+      this.addCssRule(s,'tr.ricoLG_hdg th, tr.ricoLG_hdg td, table.ricoLiveGrid thead td, table.ricoLiveGrid thead th, .ricoTitle, .Rico_accTitle',Rico_CONFIG.imgHeading,'repeat-x scroll center left');
     }
-    return false;\r
   },
 
-  include : function(filename) {
-    if (this.loadedFiles[filename]) return;
-    this.addPreloadMsg('include: '+filename);
-    var ext = filename.substr(filename.lastIndexOf('.')+1);
-    switch (ext.toLowerCase()) {
-      case 'js':
-        this.loadedFiles[filename]=filename.substring(0,4)=='rico' ? this.loadRequested : this.loadComplete;
-        var el = document.createElement('script');
-        el.type = 'text/javascript';
-        el.src = this.jsDir+filename;
-        document.getElementsByTagName('head')[0].appendChild(el);
-        break;
-      case 'css':
-        var el = document.createElement('link');
-        el.type = 'text/css';
-        el.rel = 'stylesheet';
-        el.href = this.cssDir+filename;
-        this.loadedFiles[filename]=this.loadComplete;
-        document.getElementsByTagName('head')[0].appendChild(el);
-        break;
+  addCssRule: function(sheet,selector,imageUrl,repeat) {
+    if (!imageUrl) return;
+    var rule="background:url('"+imageUrl+"') "+repeat;
+    if (sheet.addRule) {
+      sheet.addRule(selector, rule);
+    } else if (sheet.insertRule) {
+      sheet.insertRule (selector+" { "+rule+" }", 0);
+    } else {
+      alert('unable to add rule: '+rule);
     }
   },
 
-  // called after a script file has finished loading
-  includeLoaded: function(filename) {
-    this.loadedFiles[filename]=this.loadComplete;
-    this.checkIfComplete();
+  languageInclude : function(lang2) {
+    var el = document.createElement('script');
+    el.type = 'text/javascript';
+    el.src = this.jsDir+"translations/ricoLocale_"+lang2+".js";
+    document.getElementsByTagName('head')[0].appendChild(el);
   },
 
   // called by the document onload event
   windowLoaded: function() {
     this.windowIsLoaded=true;
-    this.checkIfComplete();
-  },
-
-  checkIfComplete: function() {
-    var waitingFor=this.windowIsLoaded ? '' : 'window';
-    for(var filename in  this.loadedFiles) {
-      if (this.loadedFiles[filename]==this.loadRequested)
-        waitingFor+=' '+filename;
-    }
-    //window.status='waitingFor: '+waitingFor;
-    this.addPreloadMsg('waitingFor: '+waitingFor);
-    if (waitingFor.length==0) {
-      this.addPreloadMsg('Processing callbacks');
-      while (this.onLoadCallbacks.length > 0) {
-        var callback=this.onLoadCallbacks.shift();
-        if (callback) callback();
-      }
+    this.addPreloadMsg('Processing callbacks');
+    while (this.onLoadCallbacks.length > 0) {
+      var callback=this.onLoadCallbacks.shift();
+      if (callback) callback();
     }
   },
 
@@ -134,7 +93,7 @@ var Rico = {
       this.onLoadCallbacks.unshift(callback);
     else
       this.onLoadCallbacks.push(callback);
-    this.checkIfComplete();
+    if (this.windowIsLoaded) this.windowLoaded();
   },
 
   isKonqueror : navigator.userAgent.toLowerCase().indexOf("konqueror") > -1,
@@ -795,7 +754,7 @@ createXmlDocument : function() {
   if (document.implementation && document.implementation.createDocument) {
     var doc = document.implementation.createDocument("", "", null);
     // some older versions of Moz did not support the readyState property
-    // and the onreadystate event so we patch it! 
+    // and the onreadystate event so we patch it!
     if (doc.readyState == null) {
       doc.readyState = 1;
       doc.addEventListener("load", function () {