Jump to content

strange script


gongpex
 Share

Recommended Posts

Hello everyone, today I found this script on google :

<attach event="ondocumentready" handler="parseStylesheets" /><script>var csshoverReg = /(^|\s)(([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active)/i,currentSheet, doc = window.document, hoverEvents = [], activators = {onhover:{on:'onmouseover', off:'onmouseout'},onactive:{on:'onmousedown', off:'onmouseup'}}function parseStylesheets() {if(!/MSIE (5|6)/.test(navigator.userAgent)) return;window.attachEvent('onunload', unhookHoverEvents);var sheets = doc.styleSheets, l = sheets.length;for(var i=0; i<l; i++)  parseStylesheet(sheets[i]);}function parseStylesheet(sheet) {  if(sheet.imports) {   try {	var imports = sheet.imports, l = imports.length;	for(var i=0; i<l; i++) parseStylesheet(sheet.imports[i]);   } catch(securityException){}  }  try {   var rules = (currentSheet = sheet).rules, l = rules.length;   for(var j=0; j<l; j++) parseCSSRule(rules[j]);  } catch(securityException){}}function parseCSSRule(rule) {  var select = rule.selectorText, style = rule.style.cssText;  if(!csshoverReg.test(select) || !style) return;  var pseudo = select.replace(/[^:]+[a-z-]+).*/i, 'on$1');  var newSelect = select.replace(/(\.([a-z0-9_-]+):[a-z]+)|(:[a-z]+)/gi, '.$2' + pseudo);  var className = (/\.([a-z0-9_-]*on(hover|active))/i).exec(newSelect)[1];  var affected = select.replace(/:(hover|active).*$/, '');  var elements = getElementsBySelect(affected);  if(elements.length == 0) return;  currentSheet.addRule(newSelect, style);  for(var i=0; i<elements.length; i++)   new HoverElement(elements[i], className, activators[pseudo]);}function HoverElement(node, className, events) {if(!node.hovers) node.hovers = {};if(node.hovers[className]) return;node.hovers[className] = true;hookHoverEvent(node, events.on, function() { node.className += ' ' + className; });hookHoverEvent(node, events.off, function() { node.className = node.className.replace(new RegExp('\\s+'+className, 'g'),''); });}function hookHoverEvent(node, type, handler) {  node.attachEvent(type, handler);  hoverEvents[hoverEvents.length] = {   node:node, type:type, handler:handler  };}function unhookHoverEvents() {  for(var e,i=0; i<hoverEvents.length; i++) {   e = hoverEvents[i];   e.node.detachEvent(e.type, e.handler);  }}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 identify = (/\#([a-z0-9_-]+)/i).exec(select);  if(identify) {   var element = doc.getElementById(identify[1]);   return element? [element]:nodes;  }   var classname = (/\.([a-z0-9_-]+)/i).exec(select);  var tagName = select.replace(/(\.|\#|\[a-z0-9_-]+/i, '');  var classReg = classname? new RegExp('\\b' + classname[1] + '\\b'):false;  for(var i=0; i<elements.length; i++) {   result = tagName? elements[i].all.tags(tagName):elements[i].all;   for(var j=0; j<result.length; j++) {	node = result[j];	if(classReg && !classReg.test(node.className)) continue;	nodes[nodes.length] = node;   }  }   return nodes;}</script>

really this script use for what? During I learn javascript I never meet with script such like this, especially : /(^|\s)(([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active)/i, please someone explain to me, what the mean of this script (especially) Thanks

Edited by gong
Link to comment
Share on other sites

This is called reguler expression. more info about ithttp://reguler-expressions.infohttp://w3schools.com...ref_replace.asp

Edited by birbal
Link to comment
Share on other sites

About this taq, I don't know this used for what, and I don't find at w3 schools
<attach event="ondocumentready" handler="parseStylesheets" />

if there is someone who knows, please tell to me thanks

That looks like a script for Internet Explorer's .htc files. It's not part of the HTML specification and is only used for CSS behaviors.
Link to comment
Share on other sites

till now I still not understand about .htc use, it's actually used for what, I don't understand, and about regular expression, actually it used for what? because during I learn on w3schools it looks using to search same letter, of course I think in application it's used for to create simple search engine I really2 confuse...... hope there is someone can explain to me. thanks

Link to comment
Share on other sites

htc is what some developers use to make up for Internet Explorer's lack of support for CSS 3. Regular expressions are used to define a set of rules that a string must follow. Strings that follow these rules get matched, while other strings don't. You use regular expressions when you want to find or validate strings that have a specific format, for example "4 numeric digits and a hyphen".

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...