Browse files

refactor pseudo classes

  • Loading branch information...
1 parent 8522b9d commit 5d6874cd280913f83e3ada91e79ee705170aa1d1 @chjj committed May 30, 2012
Showing with 11 additions and 8 deletions.
  1. +11 −8 lib/zest.js
View
19 lib/zest.js
@@ -109,6 +109,14 @@ var replace = function(regex, name, val) {
return new RegExp(regex);
};
+var truncateUrl = function(url, num) {
+ return url
+ .replace(/^(?:\w+:\/\/|\/+)/, '')
+ .replace(/(?:\/+|\/*#.*?)$/, '')
+ .split('/', num)
+ .join('/');
+};
+
/**
* Handle `nth` Selectors
*/
@@ -341,7 +349,7 @@ var selectors = {
return el === context;
},
':any-link': function(el) {
- return el.nodeName.toLowerCase() === 'a';
+ return typeof el.href === 'string';
},
':local-link': function(el) {
if (el.nodeName) {
@@ -354,13 +362,7 @@ var selectors = {
var url = window.location + ''
, href = el + '';
- url = url.replace(/^\w+:\/\/|^\/+|\/*#?.*?$/g, '');
- url = url.split('/').slice(0, param).join('/');
-
- href = href.replace(/^\w+:\/\/|^\/+|\/*#?.*?$/g, '');
- href = href.split('/').slice(0, param).join('/');
-
- return url === href;
+ return truncateUrl(url, param) === truncateUrl(href, param);
};
},
':default': function(el) {
@@ -392,6 +394,7 @@ var selectors = {
, name = el.nodeName.toLowerCase();
name = name !== 'input' && name !== 'textarea';
+
return (name || el.disabled) && attr == null && prop !== 'true';
},
':read-write': function(el) {

0 comments on commit 5d6874c

Please sign in to comment.