Correctifs
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage_django / media / js / csshover.htc
1 <attach event="ondocumentready" handler="parseStylesheets" />\r
2 <script>\r
3 /**\r
4  *      Whatever:hover - V1.42.060206 - hover & active\r
5  *      ------------------------------------------------------------\r
6  *      (c) 2005 - Peter Nederlof\r
7  *      Peterned - http://www.xs4all.nl/~peterned/\r
8  *      License  - http://creativecommons.org/licenses/LGPL/2.1/\r
9  *\r
10  *      Whatever:hover is free software; you can redistribute it and/or\r
11  *      modify it under the terms of the GNU Lesser General Public\r
12  *      License as published by the Free Software Foundation; either\r
13  *      version 2.1 of the License, or (at your option) any later version.\r
14  *\r
15  *      Whatever:hover is distributed in the hope that it will be useful,\r
16  *      but WITHOUT ANY WARRANTY; without even the implied warranty of\r
17  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
18  *      Lesser General Public License for more details.\r
19  *\r
20  *      Credits and thanks to:\r
21  *      Arnoud Berendsen, Martin Reurings, Robert Hanson\r
22  *\r
23  *      howto: body { behavior:url("csshover.htc"); }\r
24  *      ------------------------------------------------------------\r
25  */\r
26 \r
27 var csshoverReg = /(^|\s)(([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active)/i,\r
28 currentSheet, doc = window.document, hoverEvents = [], activators = {\r
29         onhover:{on:'onmouseover', off:'onmouseout'},\r
30         onactive:{on:'onmousedown', off:'onmouseup'}\r
31 }\r
32 \r
33 function parseStylesheets() {\r
34         if(!/MSIE (5|6)/.test(navigator.userAgent)) return;\r
35         window.attachEvent('onunload', unhookHoverEvents);\r
36         var sheets = doc.styleSheets, l = sheets.length;\r
37         for(var i=0; i<l; i++) \r
38                 parseStylesheet(sheets[i]);\r
39 }\r
40         function parseStylesheet(sheet) {\r
41                 if(sheet.imports) {\r
42                         try {\r
43                                 var imports = sheet.imports, l = imports.length;\r
44                                 for(var i=0; i<l; i++) parseStylesheet(sheet.imports[i]);\r
45                         } catch(securityException){}\r
46                 }\r
47 \r
48                 try {\r
49                         var rules = (currentSheet = sheet).rules, l = rules.length;\r
50                         for(var j=0; j<l; j++) parseCSSRule(rules[j]);\r
51                 } catch(securityException){}\r
52         }\r
53 \r
54         function parseCSSRule(rule) {\r
55                 var select = rule.selectorText, style = rule.style.cssText;\r
56                 if(!csshoverReg.test(select) || !style) return;\r
57 \r
58                 var pseudo = select.replace(/[^:]+:([a-z-]+).*/i, 'on$1');\r
59                 var newSelect = select.replace(/(\.([a-z0-9_-]+):[a-z]+)|(:[a-z]+)/gi, '.$2' + pseudo);\r
60                 var className = (/\.([a-z0-9_-]*on(hover|active))/i).exec(newSelect)[1];\r
61                 var affected = select.replace(/:(hover|active).*$/, '');\r
62                 var elements = getElementsBySelect(affected);\r
63                 if(elements.length == 0) return;\r
64 \r
65                 currentSheet.addRule(newSelect, style);\r
66                 for(var i=0; i<elements.length; i++)\r
67                         new HoverElement(elements[i], className, activators[pseudo]);\r
68         }\r
69 \r
70 function HoverElement(node, className, events) {\r
71         if(!node.hovers) node.hovers = {};\r
72         if(node.hovers[className]) return;\r
73         node.hovers[className] = true;\r
74         hookHoverEvent(node, events.on, function() { node.className += ' ' + className; });\r
75         hookHoverEvent(node, events.off, function() { node.className = node.className.replace(new RegExp('\\s+'+className, 'g'),''); });\r
76 }\r
77         function hookHoverEvent(node, type, handler) {\r
78                 node.attachEvent(type, handler);\r
79                 hoverEvents[hoverEvents.length] = { \r
80                         node:node, type:type, handler:handler \r
81                 };\r
82         }\r
83 \r
84         function unhookHoverEvents() {\r
85                 for(var e,i=0; i<hoverEvents.length; i++) {\r
86                         e = hoverEvents[i]; \r
87                         e.node.detachEvent(e.type, e.handler);\r
88                 }\r
89         }\r
90 \r
91 function getElementsBySelect(rule) {\r
92         var parts, nodes = [doc];\r
93         parts = rule.split(' ');\r
94         for(var i=0; i<parts.length; i++) {\r
95                 nodes = getSelectedNodes(parts[i], nodes);\r
96         }       return nodes;\r
97 }\r
98         function getSelectedNodes(select, elements) {\r
99                 var result, node, nodes = [];\r
100                 var identify = (/\#([a-z0-9_-]+)/i).exec(select);\r
101                 if(identify) {\r
102                         var element = doc.getElementById(identify[1]);\r
103                         return element? [element]:nodes;\r
104                 }\r
105                 \r
106                 var classname = (/\.([a-z0-9_-]+)/i).exec(select);\r
107                 var tagName = select.replace(/(\.|\#|\:)[a-z0-9_-]+/i, '');\r
108                 var classReg = classname? new RegExp('\\b' + classname[1] + '\\b'):false;\r
109                 for(var i=0; i<elements.length; i++) {\r
110                         result = tagName? elements[i].all.tags(tagName):elements[i].all; \r
111                         for(var j=0; j<result.length; j++) {\r
112                                 node = result[j];\r
113                                 if(classReg && !classReg.test(node.className)) continue;\r
114                                 nodes[nodes.length] = node;\r
115                         }\r
116                 }       \r
117                 \r
118                 return nodes;\r
119         }\r
120 </script>