[thelist] site help

david.landy at somerfield.co.uk david.landy at somerfield.co.uk
Fri Jun 25 12:11:31 CDT 2004


>
> And if you don't care about IE, you could just put the :hover on the 
> <div> itself. But I bet you do care about IE, as we are all forced to :)
>
div.textbox:hover ? doesnt seem to work....

Try this...

<attach event="ondocumentready" handler="parseStylesheets" />
<script language="JScript">
/**
 *	HOVER - V1.11.040203 - whatever:hover in IE
 *	---------------------------------------------
 *	Peterned - http://www.xs4all.nl/~peterned/
 *	(c) 2004 - Peter Nederlof
 *
 *	Credits  - Arnoud Berendsen 
 *		for finding some really -sick- bugs
 *
 *	howto: body { behavior:url("csshover.htc"); }
 *	---------------------------------------------
 */

var currentSheet, doc = window.document;
function parseStylesheets() {
	var sheets = doc.styleSheets, l = sheets.length;
	for(var i=0; i<l; i++) 
		parseStylesheet(sheets[i]);
}
	function parseStylesheet(sheet) {
		var l, rules, imports;
		if(sheet.imports) {
			imports = sheet.imports, l = imports.length;
			for(var i=0; i<l; i++) 
				parseStylesheet(sheet.imports[i]);
		}

		rules = (currentSheet = sheet).rules, l = rules.length;
		for(var j=0; j<l; j++) parseCSSRule(rules[j]);
	}

	function parseCSSRule(rule) {
		var select = rule.selectorText, style = rule.style.cssText;
		if(!(/(^|\s)(([^a]([^ ]+)?)|(a([^#.][^
]+)+)):hover/i).test(select)) return;
		
		var newSelect =
select.replace(/(\.([a-z0-9_-]+):hover)|(:hover)/g, '.$2onHover');
		var hasClass = (/(\.([a-z0-9_-]+):hover)/g).exec(select);
		var className = (hasClass? hasClass[2]:'') + 'onHover';
		var affected = select.replace(/:hover.*$/g, '');
		var elements = getElementsBySelect(affected);
		
		currentSheet.addRule(newSelect, style);
		for(var i=0; i<elements.length; i++)
			new HoverElement(elements[i], className);
	}

function HoverElement(node, className) {
	if(!node.hovers) node.hovers = {};
	if(node.hovers[className]) return;
	node.hovers[className] = true;
	node.attachEvent('onmouseover',
		function() { node.className += ' ' + className; });
	node.attachEvent('onmouseout',
		function() { node.className = 
			node.className.replace((new
RegExp('\\s+'+className)),''); });
}

function getElementsBySelect(rule) {
	var parts, nodes = [doc];
	parts = rule.split(' ');
	for(var i=0; i<parts.length; i++) {
		nodes = getSelectedNodes(parts[i], nodes);
	}	return nodes;
}
	function getSelectedNodes(select, elements) {
		var result, node, nodes = [];
		var classname = (/\.([a-z0-9_-]+)/i).exec(select);
		var identify = (/\#([a-z0-9_-]+)/i).exec(select);
		var tagName = (/^[a-z0-9]+/i).exec(select.toUpperCase()) ||
'*';
		for(var i=0; i<elements.length; i++) {
			result = elements[i].getElementsByTagName(tagName);
			for(var j=0; j<result.length; j++) {
				node = result[j];
				if((identify && node.id != identify[1]) ||
(classname && !(new RegExp('\\b' +
					classname[1] +
'\\b').exec(node.className)))) continue;
				nodes[nodes.length] = node;
			}
		}	return nodes;
	}
</script>
 
If you are not the intended recipient of this e-mail, please preserve the
confidentiality of it and advise the sender immediately of any error in
transmission. Any disclosure, copying, distribution or action taken, or
omitted to be taken, by an unauthorised recipient in reliance upon the
contents of this e-mail is prohibited. Somerfield cannot accept liability
for any damage which you may sustain as a result of software viruses so
please carry out your own virus checks before opening an attachment. In
replying to this e-mail you are granting the right for that reply to be
forwarded to any other individual within the business and also to be read by
others. Any views expressed by an individual within this message do not
necessarily reflect the views of Somerfield.  Somerfield reserves the right
to intercept, monitor and record communications for lawful business
purposes.



More information about the thelist mailing list