dir tree refactored
[xynt.git] / web / xynt / xynt-commons.js
diff --git a/web/xynt/xynt-commons.js b/web/xynt/xynt-commons.js
new file mode 100644 (file)
index 0000000..cb8076f
--- /dev/null
@@ -0,0 +1,99 @@
+function $(id) { return document.getElementById(id); }
+
+function getStyle(x,IEstyleProp, MozStyleProp) 
+{
+    if (x.currentStyle) {
+        var y = x.currentStyle[IEstyleProp];
+    } else if (window.getComputedStyle) {
+        var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(MozStyleProp);
+    }
+    return y;
+}
+
+  /* replacement of setInterval on IE */
+(function(){
+    /*if not IE, do nothing*/
+    if(!document.uniqueID){return;};
+
+    /*Copy the default setInterval behavior*/
+    var nativeSetInterval = window.setInterval;
+    window.setInterval = function(fn,ms) {              
+        var param = [];
+        if(arguments.length <= 2)       {
+            return nativeSetInterval(fn,ms);
+        }
+        else {
+            for(var i=2;i<arguments.length;i+=1) {
+                param[i-2] =  arguments[i];
+            }   
+        }
+        
+        if(typeof(fn)=='function') {
+            
+            return (function (fn,ms,param) {
+                var fo = function () {                                                          
+                    fn.apply(window,param);
+                };                      
+                return nativeSetInterval(fo,ms); 
+            })(fn,ms,param);
+        }
+        else if(typeof(fn)=='string')
+        {
+            return  nativeSetInterval(fn,ms);
+        }
+        else
+        {
+            throw Error('setInterval Error\nInvalid function type');
+        };
+    };
+
+    /*Copy the default setTimeout behavior*/
+    var nativeSetTimeout = window.setTimeout;
+    window.setTimeout = function(fn,ms) {               
+        var param = [];
+        if(arguments.length <= 2)       {
+            return nativeSetTimeout(fn,ms);
+        }
+        else {
+            for(var i=2;i<arguments.length;i+=1) {
+                param[i-2] =  arguments[i];
+            }   
+        }
+        
+        if(typeof(fn)=='function') {
+            
+            return (function (fn,ms,param) {
+                var fo = function () {                                                          
+                    fn.apply(window,param);
+                };                      
+                return nativeSetTimeout(fo,ms); 
+            })(fn,ms,param);
+        }
+        else if(typeof(fn)=='string')
+        {
+            return  nativeSetTimeout(fn,ms);
+        }
+        else
+        {
+            throw Error('setTimeout Error\nInvalid function type');
+        };
+    };
+
+})()
+
+function getStyle(x,IEstyleProp, MozStyleProp) 
+{
+    if (x.currentStyle) {
+        var y = x.currentStyle[IEstyleProp];
+    } else if (window.getComputedStyle) {
+        var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(MozStyleProp);
+    }
+    return y;
+}
+
+function doSomething(e) {
+       if (!e) var e = window.event
+       // handle event
+       e.cancelBubble = true;
+       if (e.stopPropagation) e.stopPropagation();
+}
\ No newline at end of file