Vieux vieux bug…
[Plinn.git] / skins / ajax_scripts / javascript_events_api.js
index bff4300..a1b9268 100644 (file)
@@ -1,4 +1,4 @@
-// (c) Benoît PIN 2006-2009
+// (c) Benoît PIN 2006-2014
 // http://plinn.org
 // Licence GPL
 // 
@@ -6,7 +6,7 @@
 // Meta functions for events management.
 
 var addListener; /* (ob, eventName, listenerFunction, group) add event listener eventName without "on" prefix.
-                                *  optionally, listeners can be grouped to make removing convenient.
+                                *      optionally, listeners can be grouped to make removing convenient.
                                 */
 var removeListener; // (ob, eventName, listenerFunction, group) remove event listener.
 var removeGroupListeners; // (group) remove all listeners in group.
@@ -26,9 +26,10 @@ var getCopyOfNode; /* (node) returns a clone of the given node.
                                                * the node came from a foreign document (eg. XmlHttpRequest xml reponse)
                                                * to inject HMTL code inside tags where innerHtml is read only (IE)
                                        */
+
 var copyPrototype; // (descendant, parent) lightwheight javascript inheritance
 if (!history.pushState) {
-    history.pushState = function(){};
+       history.pushState = function(){};
 }
 
 (function(){
@@ -44,6 +45,8 @@ function buildMetaFunctions() {
        disablePropagation = _build_disablePropagation();
        getWindowWidth = _build_getWindowWidth();
        getWindowHeight = _build_getWindowHeight();
+       getWindowScrollX = _build_getWindowScrollX();
+       getWindowScrollY = _build_getWindowScrollY();
        clearSelection = _build_clearSelection();
 }
 
@@ -209,6 +212,32 @@ function _build_getWindowHeight() {
        }
 }
 
+function _build_getWindowScrollX() {
+       if (window.scrollX !== undefined) {
+               return function(){
+                       return window.scrollX;
+               };
+       }
+       else {
+               return function(){
+                       return document.documentElement.scrollLeft;
+               };
+       }
+}
+
+function _build_getWindowScrollY() {
+       if (window.scrollY !== undefined) {
+               return function(){
+                       return window.scrollY;
+               };
+       }
+       else {
+               return function(){
+                       return document.documentElement.scrollTop;
+               };
+       }
+}
+
 function _build_clearSelection() {
        if (document.selection) {
                return function() {
@@ -222,9 +251,19 @@ function _build_clearSelection() {
        }
 }
 
-
 buildMetaFunctions();
 
+addListener(window, 'load', function(evt) {
+       // html5 facade
+       if (!document.body.classList) {
+               var nop = function(){};
+               var fakeDOMTokenList = {'length':0, 'item':nop, 'contains':nop, 'add':nop, 'remove':nop, 'toggle':nop};
+               Element.prototype.classList = fakeDOMTokenList;
+       }
+});
+
+
+
 var ELEMENT_NODE = 1;
 var TEXT_NODE = 3;
 var _setAttribute;
@@ -253,7 +292,7 @@ getCopyOfNode = function(node) {
        }
 };
 
-if (browser.isIE) {
+if (browser.isIE10max) {
        _setAttribute = function(e, name, value) {
                // workarround IE lack of dom implementation.
                switch(name.toLowerCase()) {
@@ -276,9 +315,10 @@ if (browser.isIE) {
                }
        };
        var reCompoundPropName = /^\s*([^\-]+)\-([a-z])([a-z]+)\s*$/;
-       var _capitalizeCssPropName = function (s, g1, g2, g3) { // gN args match above regexp groups 
-               if(g2) {
-                       return g1 + g2.toUpperCase() + g3;}
+       var _capitalizeCssPropName = function (s) {
+               var g = reCompoundPropName.exec(s);
+               if(g) {
+                       return g[1] + g[2].toUpperCase() + g[3];}
                else {
                        return s;}
        };