Permalink
Browse files

Merge pull request #45 from arian/master

Fix Slick.getAttribute, expose Slick.hasAttribute so it can be used as MooTools getProperty
  • Loading branch information...
2 parents c2c66e8 + 9904f03 commit ae7e75c441878e9f982647f10fc0265807187884 @subtleGradient subtleGradient committed Aug 12, 2011
Showing with 22 additions and 9 deletions.
  1. +22 −9 Source/Slick.Finder.js
View
@@ -74,7 +74,7 @@ local.setDocument = function(document){
var selected, id = 'slick_uniqueid';
var testNode = document.createElement('div');
-
+
var testRoot = document.body || document.getElementsByTagName('body')[0] || root;
testRoot.appendChild(testNode);
@@ -125,7 +125,7 @@ local.setDocument = function(document){
features.brokenGEBCN = cachedGetElementsByClassName || brokenSecondClassNameGEBCN;
}
-
+
if (testNode.querySelectorAll){
// IE 8 returns closed nodes (EG:"</foo>") for querySelectorAll('*') for some documents
try {
@@ -251,7 +251,7 @@ var reSimpleSelector = /^([#.]?)((?:[\w-]+|\*))$/,
local.search = function(context, expression, append, first){
var found = this.found = (first) ? null : (append || []);
-
+
if (!context) return found;
else if (context.navigator) context = context.document; // Convert the node from a window to a document
else if (!context.nodeType) return found;
@@ -557,12 +557,12 @@ local.matchNode = function(node, selector){
return this.nativeMatchesSelector.call(node, selector.replace(/\[([^=]+)=\s*([^'"\]]+?)\s*\]/g, '[$1="$2"]'));
} catch(matchError) {}
}
-
+
var parsed = this.Slick.parse(selector);
if (!parsed) return true;
// simple (single) selectors
- var expressions = parsed.expressions, reversedExpressions, simpleExpCounter = 0, i;
+ var expressions = parsed.expressions, simpleExpCounter = 0, i;
for (i = 0; (currentExpression = expressions[i]); i++){
if (currentExpression.length == 1){
var exp = currentExpression[0];
@@ -636,7 +636,7 @@ var combinators = {
this.push(item, tag, null, classes, attributes, pseudos);
break;
}
- }
+ }
return;
}
if (!item){
@@ -845,7 +845,7 @@ var pseudos = {
'root': function(node){
return (node === this.root);
},
-
+
'selected': function(node){
return node.selected;
}
@@ -857,7 +857,7 @@ for (var p in pseudos) local['pseudo:' + p] = pseudos[p];
// attributes methods
-local.attributeGetters = {
+var attributeGetters = local.attributeGetters = {
'class': function(){
return this.getAttribute('class') || this.className;
@@ -874,18 +874,25 @@ local.attributeGetters = {
'style': function(){
return (this.style) ? this.style.cssText : this.getAttribute('style');
},
-
+
'tabindex': function(){
var attributeNode = this.getAttributeNode('tabindex');
return (attributeNode && attributeNode.specified) ? attributeNode.nodeValue : null;
},
'type': function(){
return this.getAttribute('type');
+ },
+
+ 'maxlength': function(){
+ var attributeNode = this.getAttributeNode('maxLength');
+ return (attributeNode && attributeNode.specified) ? attributeNode.nodeValue : null;
}
};
+attributeGetters.MAXLENGTH = attributeGetters.maxLength = attributeGetters.maxlength;
+
// Slick
var Slick = local.Slick = (this.Slick || {});
@@ -912,9 +919,15 @@ Slick.contains = function(container, node){
// Slick attribute getter
Slick.getAttribute = function(node, name){
+ local.setDocument(node);
return local.getAttribute(node, name);
};
+Slick.hasAttribute = function(node, name){
+ local.setDocument(node);
+ return local.hasAttribute(node, name);
+};
+
// Slick matcher
Slick.match = function(node, selector){

0 comments on commit ae7e75c

Please sign in to comment.