Moved rico.js to minsrc and is now part of rico_min.js. Files are now sent to the...
[infodrom/rico3] / ricoClient / js / rico2doj.js
index 61a47a5..bab0e0a 100644 (file)
@@ -1,5 +1,5 @@
 /**
-  *  Copyright (c) 2009 Matt Brown
+  *  Copyright (c) 2009-2011 Matt Brown
   *
   *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
   *  file except in compliance with the License. You may obtain a copy of the License at
 
 if (typeof dojo=='undefined') throw('This version of Rico requires the Dojo library');
 
-Rico.Lib='dojo';
-Rico.LibVersion=dojo.version.toString();
-Rico.extend=dojo.mixin;
-Rico.trim=dojo.trim;
-
-Rico.tryFunctions = function() {
-  for (var i=0; i<arguments.length; i++) {
-               try {
-                       return arguments[i]();
-               } catch(e){}
-       }
-       return null;
-};
+var Rico = {
+  Lib: 'dojo',
+  LibVersion: dojo.version.toString(),
+  extend: dojo.mixin,
+  trim: dojo.trim,
+
+  tryFunctions: function() {
+    for (var i=0; i<arguments.length; i++) {
+      try {
+        return arguments[i]();
+      } catch(e){}
+    }
+    return null;
+  },
 
-Rico.select=dojo.query;
-  
-Rico.eventBind=function(element, eventName, handler) {
-  handler.connection=dojo.connect(Rico.$(element), eventName, handler.object, handler.method);
-};
+  select: dojo.query,
 
-Rico.eventUnbind=function(element, eventName, handler) {
-  dojo.disconnect(handler.connection);
-};
+  eventBind: function(element, eventName, handler) {
+    handler.connection=dojo.connect(Rico.$(element), eventName, handler.object, handler.method);
+  },
 
-Rico.eventElement=function(ev) {
-  return ev.target;
-};
+  eventUnbind: function(element, eventName, handler) {
+    dojo.disconnect(handler.connection);
+  },
 
-// the Dojo native function has problems on IE
-Rico.eventStop=function(ev) {
-  if (window.attachEvent) {
-    window.event.returnValue = false;
-    window.event.cancelBubble = true;
-  } else {
-    ev.preventDefault();
-    ev.stopPropagation();
-  }
-};
+  eventElement: function(ev) {
+    return ev.target;
+  },
 
-Rico.eventClient=function(ev) {
-  return {x:ev.pageX, y:ev.pageY};
-};
+  eventStop: dojo.stopEvent,
 
-Rico.eventHandle=function(object, method) {
-  return { object: object, method: method };
-};
+  eventClient: function(ev) {
+    return {x:ev.pageX, y:ev.pageY};
+  },
 
-Rico.addClass=dojo.addClass;
-Rico.removeClass=dojo.removeClass;
-Rico.hasClass=dojo.hasClass;
+  eventHandle: function(object, method) {
+    return { object: object, method: method };
+  },
 
-Rico.getStyle=function(element, name) {
-  var camelCase = name.replace(/\-(\w)/g, function(all, letter){
-    return letter.toUpperCase();
-  });
-  return dojo.style(element,camelCase);
-};
+  addClass: dojo.addClass,
+  removeClass: dojo.removeClass,
+  hasClass: dojo.hasClass,
 
-Rico.setStyle=dojo.style;
-
-// tried to use dojo._abs - 1.3.0 was broken in webkit, nightlies broken on IE8
-Rico.cumulativeOffset=function(element) {
-//  var offset=dojo._abs(element);
-//  return {top:offset.y, left:offset.x};
-  element=Rico.$(element);
-  var valueT = 0, valueL = 0;
-  do {
-    valueT += element.offsetTop  || 0;
-    valueL += element.offsetLeft || 0;
-    element = element.offsetParent;
-  } while (element);
-  return {left: valueL, top: valueT};
-};
+  getStyle: function(element, name) {
+    var camelCase = name.replace(/\-(\w)/g, function(all, letter){
+      return letter.toUpperCase();
+    });
+    return dojo.style(element,camelCase);
+  },
+
+  setStyle: dojo.style,
+
+  // tried to use dojo._abs - 1.3.0 was broken in webkit, nightlies broken on IE8
+  cumulativeOffset: function(element) {
+  //  var offset=dojo._abs(element);
+  //  return {top:offset.y, left:offset.x};
+    element=Rico.$(element);
+    var valueT = 0, valueL = 0;
+    do {
+      valueT += element.offsetTop  || 0;
+      valueL += element.offsetLeft || 0;
+      element = element.offsetParent;
+    } while (element);
+    return {left: valueL, top: valueT};
+  },
 
-Rico.positionedOffset=function(element) {
-  element=Rico.$(element);
-  var p, valueT = 0, valueL = 0;
-  do {
-    valueT += element.offsetTop  || 0;
-    valueL += element.offsetLeft || 0;
-    element = element.offsetParent;
-    if (element) {
-      p = dojo.style(element,'position');
-      if (p == 'relative' || p == 'absolute') break;
+  positionedOffset: function(element) {
+    element=Rico.$(element);
+    var p, valueT = 0, valueL = 0;
+    do {
+      valueT += element.offsetTop  || 0;
+      valueL += element.offsetLeft || 0;
+      element = element.offsetParent;
+      if (element) {
+        p = dojo.style(element,'position');
+        if (p == 'relative' || p == 'absolute') break;
+      }
+    } while (element);
+    return {left: valueL, top: valueT};
+  },
+
+  getDirectChildrenByTag: function(element, tagName) {
+    var kids = [];
+    var allKids = element.childNodes;
+    tagName=tagName.toLowerCase();
+    for( var i = 0 ; i < allKids.length ; i++ ) {
+      if ( allKids[i] && allKids[i].tagName && allKids[i].tagName.toLowerCase() == tagName )
+        kids.push(allKids[i]);
     }
-  } while (element);
-  return {left: valueL, top: valueT};
-};
+    return kids;
+  },
 
-Rico.getDirectChildrenByTag=function(element, tagName) {
-  var kids = [];
-  var allKids = element.childNodes;
-  tagName=tagName.toLowerCase();
-  for( var i = 0 ; i < allKids.length ; i++ ) {
-    if ( allKids[i] && allKids[i].tagName && allKids[i].tagName.toLowerCase() == tagName )
-      kids.push(allKids[i]);
-  }
-  return kids;
-};
+  // logic borrowed from Prototype
+  _getWinDimension: function(D) {
+    if (this.isWebKit && !document.evaluate) {
+      // Safari <3.0 needs self.innerWidth/Height
+      return self['inner' + D];
+    } else if (this.isOpera && parseFloat(window.opera.version()) < 9.5) {
+      // Opera <9.5 needs document.body.clientWidth/Height
+      return document.body['client' + D]
+    } else {
+      return document.documentElement['client' + D];
+    }
+  },
 
-// logic borrowed from Prototype
-Rico._getWinDimension=function(D) {
-  if (this.isWebKit && !document.evaluate) {
-    // Safari <3.0 needs self.innerWidth/Height
-    return self['inner' + D];
-  } else if (this.isOpera && parseFloat(window.opera.version()) < 9.5) {
-    // Opera <9.5 needs document.body.clientWidth/Height
-    return document.body['client' + D]
-  } else {
-    return document.documentElement['client' + D];
-  }
-};
+  windowHeight: function() {
+    return this._getWinDimension('Height');
+  },
 
-Rico.windowHeight=function() {
-  return this._getWinDimension('Height');
-};
+  windowWidth: function() {
+    return this._getWinDimension('Width');
+  },
 
-Rico.windowWidth=function() {
-  return this._getWinDimension('Width');
-};
+  docScrollLeft: function() {
+    return dojo._docScroll().x;
+  },
 
-Rico.docScrollLeft=function() {
-  return dojo._docScroll().x;
-};
+  docScrollTop: function() {
+    return dojo._docScroll().y;
+  },
 
-Rico.docScrollTop=function() {
-  return dojo._docScroll().y;
-};
+  // Animation
+
+  fadeIn: function(element,duration,onEnd) {
+    var a=dojo.fadeIn({node:element, duration:duration});
+    if (onEnd) dojo.connect(a,"onEnd",onEnd);
+    a.play();
+  },
+
+  fadeOut: function(element,duration,onEnd) {
+    var a=dojo.fadeOut({node:element, duration:duration});
+    if (onEnd) dojo.connect(a,"onEnd",onEnd);
+    a.play();
+  },
+
+  animate: function(element,options,properties) {
+    options.node=element;
+    options.properties=properties;
+    a=dojo.animateProperty(options);
+    a.play();
+  },
+
+  // AJAX
 
-Rico.ajaxRequest=function(url,options) {
-  this.dojoSend(url,options);
-}
+  toQueryString: dojo.objectToQuery,
+
+  getJSON: function(xhr) { return dojo.fromJson(xhr.responseText); },
+
+  ajaxRequest: function(url,options) {
+    this.dojoSend(url,options);
+  }
+};
 
 Rico.ajaxRequest.prototype = {
   dojoSend : function(url,options) {
@@ -164,49 +184,22 @@ Rico.ajaxRequest.prototype = {
     var method=options.method.toUpperCase();
     dojo.xhr(method, dOptions, method=='POST');
   },
-  
+
   dojoComplete : function(dataORerror, ioArgs) {
     if (this.onComplete) this.onComplete(ioArgs.xhr);
   },
-  
+
   dojoError : function(response, ioArgs) {
     if (this.onFailure) this.onFailure(ioArgs.xhr);
   },
-  
+
   dojoLoad : function(response, ioArgs) {
     if (this.onSuccess) this.onSuccess(ioArgs.xhr);
   }
-}
-
-Rico.getJSON=function(xhr) { return dojo.fromJson(xhr.responseText); };
+};
 
 Rico.ajaxSubmit=function(form,url,options) {
   options.form=form;
   if (!options.method) options.method='post';
   new Rico.ajaxRequest(url,options);
-}
-
-Rico.toQueryString=dojo.objectToQuery;
-
-// Animation
-
-Rico.fadeIn=function(element,duration,onEnd) {
-  var a=dojo.fadeIn({node:element, duration:duration});
-  if (onEnd) dojo.connect(a,"onEnd",onEnd);
-  a.play();
-};
-
-Rico.fadeOut=function(element,duration,onEnd) {
-  var a=dojo.fadeOut({node:element, duration:duration});
-  if (onEnd) dojo.connect(a,"onEnd",onEnd);
-  a.play();
 };
-
-Rico.animate=function(element,options,properties) {
-  options.node=element;
-  options.properties=properties;
-  a=dojo.animateProperty(options);
-  a.play();
-};
-
-Rico._bindLoadEvent();