Refactoring API de IndexIterator.
[Plinn.git] / skins / ajax_scripts / javascript_events_api.js
index 14c6dfe..2083018 100644 (file)
@@ -1,4 +1,4 @@
-// (c) Benoît PIN 2006-2009
+// (c) Benoît PIN 2006-2014
 // http://plinn.org
 // Licence GPL
 // 
 // 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.
 // 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.
                                 */
 var removeListener; // (ob, eventName, listenerFunction, group) remove event listener.
 var removeGroupListeners; // (group) remove all listeners in group.
@@ -26,7 +26,11 @@ 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)
                                        */
                                                * 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
 var copyPrototype; // (descendant, parent) lightwheight javascript inheritance
+if (!history.pushState) {
+       history.pushState = function(){};
+}
 
 (function(){
 
 
 (function(){
 
@@ -41,20 +45,22 @@ function buildMetaFunctions() {
        disablePropagation = _build_disablePropagation();
        getWindowWidth = _build_getWindowWidth();
        getWindowHeight = _build_getWindowHeight();
        disablePropagation = _build_disablePropagation();
        getWindowWidth = _build_getWindowWidth();
        getWindowHeight = _build_getWindowHeight();
+       getWindowScrollX = _build_getWindowScrollX();
+       getWindowScrollY = _build_getWindowScrollY();
        clearSelection = _build_clearSelection();
 }
 
        clearSelection = _build_clearSelection();
 }
 
-__groupListeners = {};
+var __groupListeners = {};
 
 function _build_addListener() {
        var _browserSpecific;
 
 function _build_addListener() {
        var _browserSpecific;
-       if (browser.isIE55 || browser.isIE6up) {
+       if (!browser.isDOM2Event) {
                _browserSpecific = function(ob, eventName, listenerFunction) {
                        eventName = "on" + eventName;
                        ob.attachEvent(eventName, listenerFunction);
                };
        }
                _browserSpecific = function(ob, eventName, listenerFunction) {
                        eventName = "on" + eventName;
                        ob.attachEvent(eventName, listenerFunction);
                };
        }
-       else if (browser.isDOM2Event) {
+       else {
                _browserSpecific = function(ob, eventName, listenerFunction) {
                        ob.addEventListener(eventName, listenerFunction, false); // only bubbling events :-(
                };
                _browserSpecific = function(ob, eventName, listenerFunction) {
                        ob.addEventListener(eventName, listenerFunction, false); // only bubbling events :-(
                };
@@ -71,14 +77,14 @@ function _build_addListener() {
 }
 
 function _build_removeListener() {
 }
 
 function _build_removeListener() {
-       if (browser.isIE55 || browser.isIE6up) {
+       if (!browser.isDOM2Event) {
                var _ie_removeListener = function(ob, eventName, listenerFunction) {
                        eventName = "on" + eventName;
                        ob.detachEvent(eventName, listenerFunction);
                };
                return _ie_removeListener;
        }
                var _ie_removeListener = function(ob, eventName, listenerFunction) {
                        eventName = "on" + eventName;
                        ob.detachEvent(eventName, listenerFunction);
                };
                return _ie_removeListener;
        }
-       else if (browser.isDOM2Event) {
+       else {
                var _dom2_removeListener = function(ob, eventName, listenerFunction) {
                        ob.removeEventListener(eventName, listenerFunction, false); // only bubbling events :-(
                };
                var _dom2_removeListener = function(ob, eventName, listenerFunction) {
                        ob.removeEventListener(eventName, listenerFunction, false); // only bubbling events :-(
                };
@@ -98,13 +104,13 @@ removeGroupListeners = function(group) {
 };
 
 function  _build_raiseMouseEvent() {
 };
 
 function  _build_raiseMouseEvent() {
-       if (browser.isIE55 || browser.isIE6up) {
+       if (!browser.isDOM2Event) {
                var _ie_raiseMouseEvent = function(ob, eventName) {
                        ob.fireEvent("on" + eventName);
                };
                return _ie_raiseMouseEvent;
        }
                var _ie_raiseMouseEvent = function(ob, eventName) {
                        ob.fireEvent("on" + eventName);
                };
                return _ie_raiseMouseEvent;
        }
-       else if (browser.isDOM2Event) {
+       else {
                var _dom2_raiseMouseEvent = function(ob, eventName) {
                        var event = document.createEvent("MouseEvents");
                        event.initEvent(eventName, true, true);
                var _dom2_raiseMouseEvent = function(ob, eventName) {
                        var event = document.createEvent("MouseEvents");
                        event.initEvent(eventName, true, true);
@@ -115,13 +121,13 @@ function  _build_raiseMouseEvent() {
 }
 
 function _build_getTargetedObject(){
 }
 
 function _build_getTargetedObject(){
-       if (browser.isIE55 || browser.isIE6up) {
+       if (!browser.isDOM2Event) {
                var _ie_getTargetedObject = function() {
                        return window.event.srcElement;
                };
                return _ie_getTargetedObject;
        }
                var _ie_getTargetedObject = function() {
                        return window.event.srcElement;
                };
                return _ie_getTargetedObject;
        }
-       else if (browser.isDOM2Event) {
+       else {
                var _appleWebKit_getTargetedeObject = function(evt) {
                        var target = evt.target;
                        // is it really safe ?...
                var _appleWebKit_getTargetedeObject = function(evt) {
                        var target = evt.target;
                        // is it really safe ?...
@@ -135,13 +141,13 @@ function _build_getTargetedObject(){
 }
 
 function _build_getEventObject(){
 }
 
 function _build_getEventObject(){
-       if (browser.isIE) {
+       if (!browser.isDOM2Event) {
                var _ie_getEventObject = function() {
                        return window.event;
                };
                return _ie_getEventObject;
        }
                var _ie_getEventObject = function() {
                        return window.event;
                };
                return _ie_getEventObject;
        }
-       else if (browser.isDOM2Event) {
+       else {
                var _dom2_getEventObject = function(evt) {
                        return evt;
                };
                var _dom2_getEventObject = function(evt) {
                        return evt;
                };
@@ -151,13 +157,13 @@ function _build_getEventObject(){
 
 
 function _build_disableDefault(){
 
 
 function _build_disableDefault(){
-       if (browser.isIE55 || browser.isIE6up) {
+       if (!browser.isDOM2Event) {
                var _ie_disableDefault = function() {
                        window.event.returnValue = false;
                };
                return _ie_disableDefault;
        }
                var _ie_disableDefault = function() {
                        window.event.returnValue = false;
                };
                return _ie_disableDefault;
        }
-       else if (browser.isDOM2Event) {
+       else {
                var _dom2_disableDefault = function(evt) {
                        evt.preventDefault();
                };
                var _dom2_disableDefault = function(evt) {
                        evt.preventDefault();
                };
@@ -166,13 +172,13 @@ function _build_disableDefault(){
 }
 
 function _build_disablePropagation() {
 }
 
 function _build_disablePropagation() {
-       if (browser.isIE55 || browser.isIE6up) {
+       if (!browser.isDOM2Event) {
                var _ie_disablePropagation = function() {
                        window.event.cancelBubble = true;
                };
                return _ie_disablePropagation;
        }
                var _ie_disablePropagation = function() {
                        window.event.cancelBubble = true;
                };
                return _ie_disablePropagation;
        }
-       else if (browser.isDOM2Event) {
+       else {
                var _dom2_disablePropagation = function(evt) {
                        evt.stopPropagation();
                };
                var _dom2_disablePropagation = function(evt) {
                        evt.stopPropagation();
                };
@@ -206,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() {
 function _build_clearSelection() {
        if (document.selection) {
                return function() {
@@ -219,9 +251,22 @@ function _build_clearSelection() {
        }
 }
 
        }
 }
 
-
 buildMetaFunctions();
 
 buildMetaFunctions();
 
+addListener(window, 'load', function(evt) {
+       // html5 facade
+       try {
+               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;
+               }
+       }
+       catch (e) {}
+});
+
+
+
 var ELEMENT_NODE = 1;
 var TEXT_NODE = 3;
 var _setAttribute;
 var ELEMENT_NODE = 1;
 var TEXT_NODE = 3;
 var _setAttribute;
@@ -250,7 +295,7 @@ getCopyOfNode = function(node) {
        }
 };
 
        }
 };
 
-if (browser.isIE) {
+if (browser.isIE7max) {
        _setAttribute = function(e, name, value) {
                // workarround IE lack of dom implementation.
                switch(name.toLowerCase()) {
        _setAttribute = function(e, name, value) {
                // workarround IE lack of dom implementation.
                switch(name.toLowerCase()) {
@@ -273,9 +318,10 @@ if (browser.isIE) {
                }
        };
        var reCompoundPropName = /^\s*([^\-]+)\-([a-z])([a-z]+)\s*$/;
                }
        };
        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;}
        };
                else {
                        return s;}
        };
@@ -302,7 +348,7 @@ else {
 * http://www.sitepoint.com/blogs/2006/01/17/javascript-inheritance/
 */
 
 * http://www.sitepoint.com/blogs/2006/01/17/javascript-inheritance/
 */
 
-var copyPrototype = function (descendant, parent) { 
+copyPrototype = function (descendant, parent) { 
        var sConstructor = parent.toString(); 
        var aMatch = sConstructor.match( /\s*function (.*)\(/ );
        if ( aMatch !== null ) { descendant.prototype[aMatch[1]] = parent; }
        var sConstructor = parent.toString(); 
        var aMatch = sConstructor.match( /\s*function (.*)\(/ );
        if ( aMatch !== null ) { descendant.prototype[aMatch[1]] = parent; }