Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of http://github.com/cpojer/slick

Conflicts:
	Source/Slick.Finder.js
  • Loading branch information...
commit 78099321a74925edf7113a7c893f0755eaeac48b 2 parents 785491a + 83a3c66
@fabiomcosta fabiomcosta authored
Showing with 101 additions and 81 deletions.
  1. +98 −76 Source/Slick.Finder.js
  2. +3 −5 Source/Slick.Parser.js
View
174 Source/Slick.Finder.js
@@ -8,13 +8,9 @@ requires: Slick.Parser
*/
(function(){
-
-var exports = this;
var local = {};
-var timeStamp = +new Date();
-
// Feature / Bug detection
local.isNativeCode = function(fn){
@@ -81,7 +77,7 @@ local.setDocument = function(document){
// IE returns elements with the name instead of just id for getElementById for some documents
try {
- id = 'idgetsname' + timeStamp;
+ id = 'slick_id_gets_name';
testNode.innerHTML = ('<a name='+id+'></a><b id='+id+'></b>');
this.idGetsName = testNode.ownerDocument.getElementById(id) === testNode.firstChild;
} catch(e){};
@@ -122,8 +118,8 @@ local.setDocument = function(document){
};
// contains
-
- this.contains = (root && this.isNativeCode(root.contains)) ? function(context, node){ // FIXME: Add specs: local.contains should be different for xml and html documents?
+ // FIXME: Add specs: local.contains should be different for xml and html documents?
+ this.contains = (root && this.isNativeCode(root.contains)) ? function(context, node){
return context.contains(node);
} : (root && root.compareDocumentPosition) ? function(context, node){
return context === node || !!(context.compareDocumentPosition(node) & 16);
@@ -215,11 +211,15 @@ local.search = function(context, expression, append, first){
// cache elements for the nth selectors
+ /*<pseudo-selectors>*//*<nth-pseudo-selectors>*/
+
this.posNTH = {};
this.posNTHLast = {};
this.posNTHType = {};
this.posNTHTypeLast = {};
+ /*</nth-pseudo-selectors>*//*</pseudo-selectors>*/
+
// should sort if there are nodes in append and if you pass multiple expressions.
// should remove duplicates if append already has items
var shouldUniques = !!(append && append.length);
@@ -305,6 +305,8 @@ local.sort = function(results){
return results;
};
+/*<pseudo-selectors>*//*<nth-pseudo-selectors>*/
+
local.cacheNTH = {};
local.matchNTH = /^([+-]?\d*)?([a-z]+)?([+-]\d+)?$/;
@@ -355,9 +357,11 @@ local.createNTHPseudo = function(child, sibling, positions, ofType){
if (b < pos) return false;
}
return ((pos - b) % a) == 0;
- }
+ };
};
+/*</nth-pseudo-selectors>*//*</pseudo-selectors>*/
+
local.pushArray = function(node, tag, id, classes, attributes, pseudos){
if (this.matchSelector(node, tag, id, classes, attributes, pseudos)) this.found.push(node);
};
@@ -402,8 +406,9 @@ local.matchSelector = function(node, tag, id, classes, attributes, pseudos){
if (node.nodeName != tag) return false;
}
}
- if (id && node.getAttribute('id') != id) return false;
+ if (id && node.getAttribute('id') != id) return false;
+
var i, part, cls;
if (classes) for (i = classes.length; i--;){
cls = ('className' in node) ? node.className : node.getAttribute('class');
@@ -464,21 +469,12 @@ var combinators = {
}
},
- '!': function(node, tag, id, classes, attributes, pseudos){ // all parent nodes up to document
- while ((node = node.parentNode)) if (node !== document) this.push(node, tag, id, classes, attributes, pseudos);
- },
-
'>': function(node, tag, id, classes, attributes, pseudos){ // direct children
if ((node = node.firstChild)) do {
if (node.nodeType === 1) this.push(node, tag, id, classes, attributes, pseudos);
} while ((node = node.nextSibling));
},
- '!>': function(node, tag, id, classes, attributes, pseudos){ // direct parent (one level)
- node = node.parentNode;
- if (node !== document) this.push(node, tag, id, classes, attributes, pseudos);
- },
-
'+': function(node, tag, id, classes, attributes, pseudos){ // next sibling
while ((node = node.nextSibling)) if (node.nodeType === 1){
this.push(node, tag, id, classes, attributes, pseudos);
@@ -486,13 +482,6 @@ var combinators = {
}
},
- '!+': function(node, tag, id, classes, attributes, pseudos){ // previous sibling
- while ((node = node.previousSibling)) if (node.nodeType === 1){
- this.push(node, tag, id, classes, attributes, pseudos);
- break;
- }
- },
-
'^': function(node, tag, id, classes, attributes, pseudos){ // first child
node = node.firstChild;
if (node){
@@ -501,14 +490,6 @@ var combinators = {
}
},
- '!^': function(node, tag, id, classes, attributes, pseudos){ // last child
- node = node.lastChild;
- if (node){
- if (node.nodeType === 1) this.push(node, tag, id, classes, attributes, pseudos);
- else this['combinator:!+'](node, tag, id, classes, attributes, pseudos);
- }
- },
-
'~': function(node, tag, id, classes, attributes, pseudos){ // next siblings
while ((node = node.nextSibling)){
if (node.nodeType !== 1) continue;
@@ -519,16 +500,6 @@ var combinators = {
}
},
- '!~': function(node, tag, id, classes, attributes, pseudos){ // previous siblings
- while ((node = node.previousSibling)){
- if (node.nodeType !== 1) continue;
- var uid = this.getUID(node);
- if (this.bitUniques[uid]) break;
- this.bitUniques[uid] = true;
- this.push(node, tag, id, classes, attributes, pseudos);
- }
- },
-
'++': function(node, tag, id, classes, attributes, pseudos){ // next sibling and previous sibling
this['combinator:+'](node, tag, id, classes, attributes, pseudos);
this['combinator:!+'](node, tag, id, classes, attributes, pseudos);
@@ -537,6 +508,40 @@ var combinators = {
'~~': function(node, tag, id, classes, attributes, pseudos){ // next siblings and previous siblings
this['combinator:~'](node, tag, id, classes, attributes, pseudos);
this['combinator:!~'](node, tag, id, classes, attributes, pseudos);
+ },
+
+ '!': function(node, tag, id, classes, attributes, pseudos){ // all parent nodes up to document
+ while ((node = node.parentNode)) if (node !== document) this.push(node, tag, id, classes, attributes, pseudos);
+ },
+
+ '!>': function(node, tag, id, classes, attributes, pseudos){ // direct parent (one level)
+ node = node.parentNode;
+ if (node !== document) this.push(node, tag, id, classes, attributes, pseudos);
+ },
+
+ '!+': function(node, tag, id, classes, attributes, pseudos){ // previous sibling
+ while ((node = node.previousSibling)) if (node.nodeType === 1){
+ this.push(node, tag, id, classes, attributes, pseudos);
+ break;
+ }
+ },
+
+ '!^': function(node, tag, id, classes, attributes, pseudos){ // last child
+ node = node.lastChild;
+ if (node){
+ if (node.nodeType === 1) this.push(node, tag, id, classes, attributes, pseudos);
+ else this['combinator:!+'](node, tag, id, classes, attributes, pseudos);
+ }
+ },
+
+ '!~': function(node, tag, id, classes, attributes, pseudos){ // previous siblings
+ while ((node = node.previousSibling)){
+ if (node.nodeType !== 1) continue;
+ var uid = this.getUID(node);
+ if (this.bitUniques[uid]) break;
+ this.bitUniques[uid] = true;
+ this.push(node, tag, id, classes, attributes, pseudos);
+ }
}
};
@@ -544,6 +549,8 @@ var combinators = {
for (var c in combinators) local['combinator:' + c] = combinators[c];
var pseudos = {
+
+ /*<pseudo-selectors>*/
'empty': function(node){
var child = node.firstChild;
@@ -575,6 +582,8 @@ var pseudos = {
while ((next = next.nextSibling)) if (next.nodeType === 1) return false;
return true;
},
+
+ /*<nth-pseudo-selectors>*/
'nth-child': local.createNTHPseudo('firstChild', 'nextSibling', 'posNTH'),
@@ -584,6 +593,22 @@ var pseudos = {
'nth-last-of-type': local.createNTHPseudo('lastChild', 'previousSibling', 'posNTHTypeLast', true),
+ 'index': function(node, index){
+ return this['pseudo:nth-child'](node, '' + index + 1);
+ },
+
+ 'even': function(node, argument){
+ return this['pseudo:nth-child'](node, '2n');
+ },
+
+ 'odd': function(node, argument){
+ return this['pseudo:nth-child'](node, '2n+1');
+ },
+
+ /*</nth-pseudo-selectors>*/
+
+ /*<of-type-pseudo-selectors>*/
+
'first-of-type': function(node){
var nodeName = node.nodeName;
while ((node = node.previousSibling)) if (node.nodeName === nodeName) return false;
@@ -603,21 +628,11 @@ var pseudos = {
while ((next = next.nextSibling)) if (next.nodeName === nodeName) return false;
return true;
},
+
+ /*</of-type-pseudo-selectors>*/
// custom pseudos
- 'index': function(node, index){
- return this['pseudo:nth-child'](node, '' + index + 1);
- },
-
- 'even': function(node, argument){
- return this['pseudo:nth-child'](node, '2n');
- },
-
- 'odd': function(node, argument){
- return this['pseudo:nth-child'](node, '2n+1');
- },
-
'enabled': function(node){
return (node.disabled === false);
},
@@ -637,6 +652,8 @@ var pseudos = {
'focus': function(node){
return !this.isXMLDocument && this.document.activeElement === node && (node.href || node.type || this.hasAttribute(node, 'tabindex'));
}
+
+ /*</pseudo-selectors>*/
};
for (var p in pseudos) local['pseudo:' + p] = pseudos[p];
@@ -680,6 +697,10 @@ local.override = function(regexp, method){
this.overrides.push({regexp: regexp, method: method});
};
+/*<overrides>*/
+
+/*<query-selector-override>*/
+
local.override(/./, function(expression, found, first){ //querySelectorAll override
if (!this.querySelectorAll || this.nodeType != 9 || local.isXMLDocument || local.brokenMixedCaseQSA || Slick.disableQSA) return false;
@@ -706,6 +727,10 @@ local.override(/./, function(expression, found, first){ //querySelectorAll overr
});
+/*</query-selector-override>*/
+
+/*<tag-override>*/
+
local.override(/^[\w-]+$|^\*$/, function(expression, found, first){ // tag override
var tag = expression;
if (tag == '*' && local.brokenStarGEBTN) return false;
@@ -724,6 +749,10 @@ local.override(/^[\w-]+$|^\*$/, function(expression, found, first){ // tag overr
return true;
});
+/*</tag-override>*/
+
+/*<class-override>*/
+
local.override(/^\.[\w-]+$/, function(expression, found, first){ // class override
if (local.isXMLDocument || (!this.getElementsByClassName && this.querySelectorAll)) return false;
@@ -748,6 +777,10 @@ local.override(/^\.[\w-]+$/, function(expression, found, first){ // class overri
return (first) ? null : true;
});
+/*</class-override>*/
+
+/*<id-override>*/
+
local.override(/^#[\w-]+$/, function(expression, found, first){ // ID override
if (local.isXMLDocument || this.nodeType != 9) return false;
@@ -761,11 +794,15 @@ local.override(/^#[\w-]+$/, function(expression, found, first){ // ID override
return true;
});
+/*</id-override>*/
+
+/*</overrides>*/
+
if (typeof document != 'undefined') local.setDocument(document);
// Slick
-var Slick = local.Slick = exports.Slick || {};
+var Slick = local.Slick = (this.Slick || {});
Slick.version = '0.9dev';
@@ -837,27 +874,12 @@ Slick.override = function(regexp, fn){
return this;
};
-// De-duplication of an array of HTML elements.
-
-Slick.uniques = function(nodes, append){
- var uniques = {}, i, node, uid;
- if (!append) append = [];
- for (i = 0; node = append[i++];) uniques[local.getUIDHTML(node)] = true;
-
- for (i = 0; node = nodes[i++];){
- uid = local.getUIDHTML(node);
- if (!uniques[uid]){
- uniques[uid] = true;
- append.push(node);
- }
- }
- return append;
-};
-
Slick.isXML = local.isXML;
-// export Slick
+Slick.uidOf = function(node){
+ return local.getUIDHTML(node);
+};
-if (!exports.Slick) exports.Slick = Slick;
+if (!this.Slick) this.Slick = Slick;
-}).apply((typeof exports != 'undefined') ? exports : this);
+}).apply(/*<CommonJS>*/(typeof exports != 'undefined') ? exports : /*</CommonJS>*/this);
View
8 Source/Slick.Parser.js
@@ -8,8 +8,6 @@ provides: Slick.Parser
(function(){
-var exports = this;
-
var parsed,
separatorIndex,
combinatorIndex,
@@ -204,7 +202,7 @@ function parser(
// Slick NS
-var Slick = exports.Slick || {};
+var Slick = (this.Slick || {});
Slick.parse = function(expression){
return parse(expression);
@@ -212,6 +210,6 @@ Slick.parse = function(expression){
Slick.escapeRegExp = escapeRegExp;
-if (!exports.Slick) exports.Slick = Slick;
+if (!this.Slick) this.Slick = Slick;
-}).apply((typeof exports != 'undefined') ? exports : this);
+}).apply(/*<CommonJS>*/(typeof exports != 'undefined') ? exports : /*</CommonJS>*/this);
Please sign in to comment.
Something went wrong with that request. Please try again.