3 * Copyright 2005 Sabre Airline Solutions
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.
17 // This module does NOT depend on prototype.js
24 try { // fix IE background image flicker (credit: www.mister-pixel.com)
25 document.execCommand("BackgroundImageCache", false, true);
28 var elements = document.getElementsByTagName('script');
29 this.baseHref= location.protocol + "//" + location.host;
32 this.windowIsLoaded=false;
33 this.onLoadCallbacks=[];
34 for (var i=0; i<elements.length; i++) {
35 if (!elements[i].src) continue;
36 var src = elements[i].src;
37 var slashIdx = src.lastIndexOf('/');
38 var path = src.substring(0, slashIdx+1);
39 var filename = src.substring(slashIdx+1);
40 this.loadedFiles[filename]=this.loadComplete;
41 if (filename == 'rico.js') {
43 this.cssDir= path+'css/';
44 this.imgDir= path+'images/';
49 if (typeof Prototype=='undefined')
50 this.include('prototype.js');
51 this.include('ricoCommon.js');
52 var func=function() { Rico.windowLoaded(); };
53 if (window.addEventListener)
54 window.addEventListener('load', func, false);
55 else if (window.attachEvent)
56 window.attachEvent('onload', func);
57 this.onLoad(function() { Rico.writeDebugMsg('Pre-load messages:\n'+Rico.preloadMsgs); });
60 // Array entries can reference a javascript file or css stylesheet
61 // A dependency on another module can be indicated with a plus-sign prefix: '+DependsOnModule'
62 moduleDependencies : {
63 Accordion : ['ricoBehaviors.js','ricoEffects.js','ricoComponents.js'],
64 Color : ['ricoColor.js'],
65 Corner : ['ricoStyles.js'],
66 DragAndDrop: ['ricoDragDrop.js'],
67 Effect : ['ricoEffects.js'],
68 Calendar : ['ricoCalendar.js', 'ricoCalendar.css'],
69 Tree : ['ricoTree.js', 'ricoTree.css'],
70 ColorPicker: ['ricoColorPicker.js', 'ricoStyles.js'],
71 SimpleGrid : ['ricoCommon.js', 'ricoGridCommon.js', 'ricoGrid.css', 'ricoSimpleGrid.js'],
72 LiveGrid : ['ricoCommon.js', 'ricoGridCommon.js', 'ricoGrid.css', 'ricoBehaviors.js', 'ricoLiveGrid.js'],
73 CustomMenu : ['ricoMenu.js', 'ricoMenu.css'],
74 LiveGridMenu : ['+CustomMenu', 'ricoLiveGridMenu.js'],
75 LiveGridAjax : ['+LiveGrid', 'ricoLiveGridAjax.js'],
76 LiveGridForms: ['+LiveGridAjax', '+LiveGridMenu', '+Accordion', '+Corner', 'ricoLiveGridForms.js', 'ricoLiveGridForms.css'],
77 SpreadSheet : ['+SimpleGrid', 'ricoSheet.js']
80 // not reliable when used with XSLT
81 loadModule : function(name) {
82 var dep=this.moduleDependencies[name];
84 for (var i=0; i<dep.length; i++)
85 if (dep[i].substring(0,1)=='+')
86 this.loadModule(dep[i].slice(1));
91 // not reliable when used with XSLT
92 include : function(filename) {
93 if (this.loadedFiles[filename]) return;
94 this.addPreloadMsg('include: '+filename);
95 var ext = filename.substr(filename.lastIndexOf('.')+1);
96 switch (ext.toLowerCase()) {
98 this.loadQueue.push(filename);
99 this.loadedFiles[filename]=this.loadRequested;
100 this.checkLoadQueue();
103 var el = document.createElement('link');
104 el.type = 'text/css';
105 el.rel = 'stylesheet'
106 el.href = this.cssDir+filename;
107 this.loadedFiles[filename]=this.loadComplete;
108 document.getElementsByTagName('head')[0].appendChild(el);
113 checkLoadQueue: function() {
114 if (this.loadQueue.length==0) return;
115 if (this.inProcess) return; // seems to only be required by IE, but applied to all browsers just to be safe
116 this.addScriptToDOM(this.loadQueue.shift());
119 addScriptToDOM: function(filename) {
120 this.addPreloadMsg('addScriptToDOM: '+filename);
121 var js = document.createElement('script');
122 js.type = 'text/javascript';
123 js.src = this.jsDir+filename;
124 this.loadedFiles[filename]=this.loadRequested;
125 this.inProcess=filename;
126 var head=document.getElementsByTagName('head')[0];
127 if (filename.substring(0,4)=='rico') {
128 head.appendChild(js);
129 } else if(/WebKit|Khtml/i.test(navigator.userAgent)) {
130 head.appendChild(js);
131 this.includeLoaded(filename);
133 js.onload = js.onreadystatechange = function() {
134 if (js.readyState && js.readyState != 'loaded' && js.readyState != 'complete') return;
135 js.onreadystatechange = js.onload = null;
136 Rico.includeLoaded(filename);
138 head.appendChild(js);
142 // called after a script file has finished loading
143 includeLoaded: function(filename) {
144 this.addPreloadMsg('loaded: '+filename);
145 this.loadedFiles[filename]=this.loadComplete;
146 if (filename==this.inProcess) {
148 this.checkLoadQueue();
149 this.checkIfComplete();
153 // called by the document onload event
154 windowLoaded: function() {
155 this.windowIsLoaded=true;
156 this.checkIfComplete();
159 checkIfComplete: function() {
160 var waitingFor=this.windowIsLoaded ? '' : 'window';
161 for(var filename in this.loadedFiles) {
162 if (this.loadedFiles[filename]==this.loadRequested)
163 waitingFor+=' '+filename;
165 //window.status='waitingFor: '+waitingFor;
166 this.addPreloadMsg('waitingFor: '+waitingFor);
167 if (waitingFor.length==0) {
168 this.addPreloadMsg('Processing callbacks');
169 while (this.onLoadCallbacks.length > 0) {
170 var callback=this.onLoadCallbacks.pop();
171 if (callback) callback();
176 onLoad: function(callback) {
177 this.onLoadCallbacks.push(callback);
178 this.checkIfComplete();
181 isKonqueror : navigator.userAgent.toLowerCase().indexOf("konqueror") >= 0,
185 startTime : new Date(),
187 timeStamp: function() {
188 var stamp = new Date();
189 return (stamp.getTime()-this.startTime.getTime())+": ";
192 setDebugArea: function(id, forceit) {
193 if (!this.debugArea || forceit) {
194 var newarea=document.getElementById(id);
195 if (!newarea) return;
196 this.debugArea=newarea;
201 addPreloadMsg: function(msg) {
202 this.preloadMsgs+=Rico.timeStamp()+msg+"\n";
205 writeDebugMsg: function(msg, resetFlag) {
206 if (this.debugArea) {
207 if (resetFlag) this.debugArea.value='';
208 this.debugArea.value+=this.timeStamp()+msg+"\n";