From d34ebce6aaf659a7166ecdbeefa4c2675d504a17 Mon Sep 17 00:00:00 2001 From: Christoph Pojer Date: Tue, 18 Jan 2011 00:37:09 +0100 Subject: [PATCH] * Slick update --- Source/Slick/Slick.Finder.js | 41 +++++++++++++++++++++++------------------ Source/Slick/Slick.Parser.js | 6 ++++-- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/Source/Slick/Slick.Finder.js b/Source/Slick/Slick.Finder.js index 445dd4a4..abaad444 100644 --- a/Source/Slick/Slick.Finder.js +++ b/Source/Slick/Slick.Finder.js @@ -64,9 +64,9 @@ local.setDocument = function(document){ } catch(e){}; if (this.isHTMLDocument){ - + testNode.style.display = 'none'; - + // IE returns comment nodes for getElementsByTagName('*') for some documents testNode.appendChild(document.createComment('')); starSelectsComments = (testNode.getElementsByTagName('*').length > 0); @@ -114,19 +114,19 @@ local.setDocument = function(document){ } catch(e){}; this.brokenGEBCN = cachedGetElementsByClassName || brokenSecondClassNameGEBCN; - + // Webkit dont return selected options on querySelectorAll try { testNode.innerHTML = ''; this.brokenCheckedQSA = (testNode.querySelectorAll(':checked').length == 0); } catch(e){}; - + // IE returns incorrect results for attr[*^$]="" selectors on querySelectorAll try { testNode.innerHTML = ''; this.brokenEmptyAttributeQSA = (testNode.querySelectorAll('[class*=""]').length != 0); } catch(e){}; - + } root.removeChild(testNode); @@ -353,12 +353,12 @@ local.createNTHPseudo = function(child, sibling, positions, ofType){ if (ofType){ var nodeName = node.nodeName; do { - if (el.nodeName !== nodeName) continue; + if (el.nodeName != nodeName) continue; this[positions][this.getUID(el)] = count++; } while ((el = el[sibling])); } else { do { - if (el.nodeType !== 1) continue; + if (el.nodeType != 1) continue; this[positions][this.getUID(el)] = count++; } while ((el = el[sibling])); } @@ -404,7 +404,7 @@ local.matchNode = function(node, selector){ simpleExpCounter++; } } - + if (simpleExpCounter == parsed.length) return false; var nodes = this.search(this.document, parsed), item; @@ -423,10 +423,11 @@ local.matchPseudo = function(node, name, argument){ local.matchSelector = function(node, tag, id, classes, attributes, pseudos){ if (tag){ + var nodeName = (this.isXMLDocument) ? node.nodeName : node.nodeName.toUpperCase(); if (tag == '*'){ - if (node.nodeName < '@') return false; // Fix for comment nodes and closed nodes + if (nodeName < '@') return false; // Fix for comment nodes and closed nodes } else { - if (node.nodeName != tag) return false; + if (nodeName != tag) return false; } } @@ -434,7 +435,7 @@ local.matchSelector = function(node, tag, id, classes, attributes, pseudos){ var i, part, cls; if (classes) for (i = classes.length; i--;){ - cls = ('className' in node) ? node.className : node.getAttribute('class'); + cls = node.getAttribute('class') || node.className; if (!(cls && classes[i].regexp.test(cls))) return false; } if (attributes) for (i = attributes.length; i--;){ @@ -466,7 +467,7 @@ var combinators = { for (i = 0; item = children[i++];) if (item.getAttributeNode('id').nodeValue == id){ this.push(item, tag, null, classes, attributes, pseudos); break; - } + } return; } if (!item){ @@ -675,7 +676,7 @@ var pseudos = { 'root': function(node){ return (node === this.root); }, - + 'selected': function(node){ return node.selected; } @@ -690,7 +691,7 @@ for (var p in pseudos) local['pseudo:' + p] = pseudos[p]; local.attributeGetters = { 'class': function(){ - return ('className' in this) ? this.className : this.getAttribute('class'); + return this.getAttribute('class') || this.className; }, 'for': function(){ @@ -703,6 +704,11 @@ 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; } }; @@ -713,7 +719,7 @@ local.getAttribute = function(node, name){ var method = this.attributeGetters[name]; if (method) return method.call(node); var attributeNode = node.getAttributeNode(name); - return attributeNode ? attributeNode.nodeValue : null; + return (attributeNode) ? attributeNode.nodeValue : null; }; // overrides @@ -744,7 +750,7 @@ local.override(/./, function(expression, found, first){ //querySelectorAll overr this.setAttribute('id', id); expression = '#' + id + ' ' + expression; } - + try { if (first) return this.querySelector(expression) || null; else nodes = this.querySelectorAll(expression); @@ -849,7 +855,7 @@ if (typeof document != 'undefined') local.setDocument(document); var Slick = local.Slick = (this.Slick || {}); -Slick.version = '1.0'; +Slick.version = '1.0.0'; // Slick finder @@ -879,7 +885,6 @@ Slick.getAttribute = function(node, name){ Slick.match = function(node, selector){ if (!(node && selector)) return false; if (!selector || selector === node) return true; - if (typeof selector != 'string') return false; local.setDocument(node); return local.matchNode(node, selector); }; diff --git a/Source/Slick/Slick.Parser.js b/Source/Slick/Slick.Parser.js index 21d53968..73ca4552 100644 --- a/Source/Slick/Slick.Parser.js +++ b/Source/Slick/Slick.Parser.js @@ -90,7 +90,7 @@ __END__ )?\ )" */ - "^(?:\\s*(,)\\s*|\\s*(+)\\s*|(\\s+)|(+|\\*)|\\#(+)|\\.(+)|\\[\\s*(+)(?:\\s*([*^$!~|]?=)(?:\\s*(?:([\"']?)(.*?)\\9)))?\\s*\\](?!\\])|:+(+)(?:\\((?:(?:([\"'])([^\\12]*)\\12)|((?:\\([^)]+\\)|[^()]*)+))\\))?)" + "^(?:\\s*(,)\\s*|\\s*(+)\\s*|(\\s+)|(+|\\*)|\\#(+)|\\.(+)|\\[\\s*(+)(?:\\s*([*^$!~|]?=)(?:\\s*(?:([\"']?)(.*?)\\9)))?\\s*\\](?!\\])|(:+)(+)(?:\\((?:(?:([\"'])([^\\13]*)\\13)|((?:\\([^)]+\\)|[^()]*)+))\\))?)" .replace(//, '[' + escapeRegExp(">+~`!@$%^&={}\\;/g, '(?:[\\w\\u00a1-\\uFFFF-]|\\\\[^\\s0-9a-f])') .replace(//g, '(?:[:\\w\\u00a1-\\uFFFF-]|\\\\[^\\s0-9a-f])') @@ -112,6 +112,7 @@ function parser( attributeQuote, attributeValue, + pseudoMarker, pseudoClass, pseudoQuote, pseudoClassQuotedValue, @@ -157,7 +158,8 @@ function parser( if (!currentParsed.pseudos) currentParsed.pseudos = []; currentParsed.pseudos.push({ key: pseudoClass.replace(reUnescape, ''), - value: pseudoClassValue + value: pseudoClassValue, + type: pseudoMarker.length == 1 ? 'class' : 'element' }); } else if (attributeKey){ -- 2.11.4.GIT