1 <attach event="ondocumentready" handler="parseStylesheets" />
2 <script type="text/javascript">
4 * PSUEDOS - V1.21.041022 - hover & active
5 * ---------------------------------------------
6 * Peterned - http://www.xs4all.nl/~peterned/
7 * (c) 2004 - Peter Nederlof
9 * Credits - Arnoud Berendsen
11 * for inspiring me and finding really sick bugs
13 * howto: body { behavior:url("csshover.htc"); }
14 * ---------------------------------------------
17 var currentSheet, doc = window.document;
19 onhover:{on:'onmouseover', off:'onmouseout'},
20 onactive:{on:'onmousedown', off:'onmouseup'}
23 function parseStylesheets() {
24 var sheets = doc.styleSheets, l = sheets.length;
25 for(var i=0; i<l; i++)
26 parseStylesheet(sheets[i]);
28 function parseStylesheet(sheet) {
29 var l, rules, imports;
31 imports = sheet.imports, l = imports.length;
32 for(var i=0; i<l; i++)
33 parseStylesheet(sheet.imports[i]);
36 rules = (currentSheet = sheet).rules, l = rules.length;
37 for(var j=0; j<l; j++) parseCSSRule(rules[j]);
40 function parseCSSRule(rule) {
41 var select = rule.selectorText, style = rule.style.cssText;
42 if(!(/(^|\s)(([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active)/i).test(select) || !style) return;
44 var pseudo = select.replace(/[^:]+:([a-z-]+).*/i, 'on$1');
45 var newSelect = select.replace(/(\.([a-z0-9_-]+):[a-z]+)|(:[a-z]+)/gi, '.$2' + pseudo);
46 var className = (/\.([a-z0-9_-]*on(hover|active))/i).exec(newSelect)[1];
47 var affected = select.replace(/:hover.*$/, '');
48 var elements = getElementsBySelect(affected);
50 currentSheet.addRule(newSelect, style);
51 for(var i=0; i<elements.length; i++)
52 new HoverElement(elements[i], className, activators[pseudo]);
55 function HoverElement(node, className, events) {
56 if(!node.hovers) node.hovers = {};
57 if(node.hovers[className]) return;
58 node.hovers[className] = true;
59 node.attachEvent(events.on,
60 function() { node.className += ' ' + className; });
61 node.attachEvent(events.off,
62 function() { node.className =
63 node.className.replace(new RegExp('\\s+'+className, 'g'),''); });
66 function getElementsBySelect(rule) {
67 var parts, nodes = [doc];
68 parts = rule.split(' ');
69 for(var i=0; i<parts.length; i++) {
70 nodes = getSelectedNodes(parts[i], nodes);
73 function getSelectedNodes(select, elements) {
74 var result, node, nodes = [];
75 var classname = (/\.([a-z0-9_-]+)/i).exec(select);
76 var identify = (/\#([a-z0-9_-]+)/i).exec(select);
77 var tagName = (/^[a-z0-9]+/i).exec(select.toUpperCase()) || '*';
78 for(var i=0; i<elements.length; i++) {
79 result = elements[i].getElementsByTagName(tagName);
80 for(var j=0; j<result.length; j++) {
82 if((identify && node.id != identify[1]) || (classname && !(new RegExp('\\b' +
83 classname[1] + '\\b').exec(node.className)))) continue;
84 nodes[nodes.length] = node;