Permalink
Browse files

Added support for pure id selectors (thus supporting old Webkit 2 - i…

….e. Nokia 5800) and removed redelcation of variable.
  • Loading branch information...
1 parent be23919 commit 7457b7a1dfed5a26fd18a34c2c6f78cda9c935a9 @remy remy committed Dec 5, 2009
Showing with 11 additions and 3 deletions.
  1. +11 −3 src/js/xui.js
View
@@ -78,7 +78,9 @@ var xui;
var xui = function(q) {
q = q || document;
return this.find(q);
- };
+ },
+
+ idExpr = /^#([\w-]+)$/;
xui.extend = function(obj) {
var original = this.prototype;
@@ -96,7 +98,13 @@ var xui;
var qlen = q.length;
var list, size;
var i, j;
-
+
+ // fast matching for pure ID selectors
+ if (typeof q == 'string' && idExpr.test(q)) {
+ this.elements.push(document.getelementsById(q));
+ return this; // return okay here?
+ }
+
for(i = 0; i < qlen; i++ ) {
if (typeof q[i] == 'string' ) { // one selector
list = document.querySelectorAll(q[i]);
@@ -207,7 +215,7 @@ var xui;
* at the given index
* */
eq: function(idx1,idx2) {
- var idx2 = idx2 ? idx2 + 1 : idx1 + 1;
+ idx2 = idx2 ? idx2 + 1 : idx1 + 1;
this.elements = this.elements.slice(idx1,idx2);
return this;
},

0 comments on commit 7457b7a

Please sign in to comment.