Last active
December 16, 2015 21:39
Revisions
-
Shogo Sensui revised this gist
Oct 27, 2015 . 1 changed file with 24 additions and 31 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,34 +1,27 @@ const rx = { id: /^#([\w\-]+)$/, className: /^\.([\w\-]+)$/, tagName: /^[\w\-]+$/, name: /^\[name=["']?([\w\-]+)["']?\]$/ }; function $(selector, context) { let result; let m; if(!context || !context.querySelector) { context = document; } if (m = rx.id.exec(selector)) { let element = document.getElementById(m[1]); result = element ? [element] : []; } else if (m = rx.className.exec(selector)) { result = context.getElementsByClassName(m[1]); } else if (m = rx.tagName.exec(selector)) { result = context.getElementsByTagName(m[1]); } else if (m = rx.name.exec(selector)) { result = context.getElementsByName(m[1]); } else { result = context.querySelectorAll(selector); } return Array.of(result); }; -
1000ch revised this gist
Jun 14, 2013 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,13 +9,18 @@ var rx = { var nativeSlice = [].slice; //select element with filtering id, className, tagName, name selector. function select(selector, context) { var result, m; if(!context || !context.querySelector) { context = document; } if(m = rx.id.exec(selector)) { var element = document.getElementById(m[1]); if(element) { result = [element]; } else { result = []; } } else if(m = rx.className.exec(selector)) { result = context.getElementsByClassName(m[1]); } else if(m = rx.tagName.exec(selector)) { @@ -26,9 +31,4 @@ var ConciseSelector = function(selector, context) { result = context.querySelectorAll(selector); } return nativeSlice.call(result); }; -
1000ch revised this gist
May 8, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,5 +30,5 @@ var ConciseSelector = function(selector, context) { //create alias var $ = function(selector, context) { return ConciseSelector(selector, context); }; -
1000ch revised this gist
May 2, 2013 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ //wasting var rx = { id: /^#([\w\-]+)$/, className: /^\.([\w\-]+)$/, -
1000ch revised this gist
May 2, 2013 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,8 @@ var rx = { name: /^\[name=["']?([\w\-]+)["']?\]$/ }; var nativeSlice = [].slice; //select element with filtering id, className, tagName, name selector. var ConciseSelector = function(selector, context) { var result, m; @@ -22,6 +24,7 @@ var ConciseSelector = function(selector, context) { } else { result = context.querySelectorAll(selector); } return nativeSlice.call(result); }; //create alias -
1000ch revised this gist
May 2, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ var rx = { //select element with filtering id, className, tagName, name selector. var ConciseSelector = function(selector, context) { var result, m; if(!context || !context.querySelector) { context = document; } if(m = rx.id.exec(selector)) { -
1000ch revised this gist
May 2, 2013 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,7 @@ var rx = { name: /^\[name=["']?([\w\-]+)["']?\]$/ }; //select element with filtering id, className, tagName, name selector. var ConciseSelector = function(selector, context) { var result, m; if(!context) { @@ -22,6 +23,8 @@ var ConciseSelector = function(selector, context) { result = context.querySelectorAll(selector); } }; //create alias var $ = function(selector, context) { return new ConciseSelector(selector, context); }; -
1000ch created this gist
May 2, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ var rx = { id: /^#([\w\-]+)$/, className: /^\.([\w\-]+)$/, tagName: /^[\w\-]+$/, name: /^\[name=["']?([\w\-]+)["']?\]$/ }; var ConciseSelector = function(selector, context) { var result, m; if(!context) { context = document; } if(m = rx.id.exec(selector)) { result = [document.getElementById(m[1])]; } else if(m = rx.className.exec(selector)) { result = context.getElementsByClassName(m[1]); } else if(m = rx.tagName.exec(selector)) { result = context.getElementsByTagName(m[1]); } else if(m = rx.name.exec(selector)) { result = context.getElementsByName(m[1]); } else { result = context.querySelectorAll(selector); } }; var $ = function(selector, context) { return new ConciseSelector(selector, context); };