2017-02-08 15:24:58 -05:00
|
|
|
define(['$.utils', '$.proto'], function (utils, proto) {
|
2017-02-07 15:19:23 -05:00
|
|
|
|
2017-02-08 15:24:58 -05:00
|
|
|
// Create a custom edition of Array, extended with $.proto
|
2017-02-22 16:22:28 -05:00
|
|
|
function ElementArray () {};
|
2017-02-08 15:24:58 -05:00
|
|
|
ElementArray.prototype = new Array;
|
|
|
|
for(var key in proto) ElementArray.prototype[key] = proto[key];
|
2017-02-07 15:19:23 -05:00
|
|
|
|
2017-02-08 15:24:58 -05:00
|
|
|
// Create to actual dollar function
|
|
|
|
function Dollar (selector) {
|
2017-02-07 15:19:23 -05:00
|
|
|
|
|
|
|
var match,
|
2017-02-08 15:24:58 -05:00
|
|
|
matches = new ElementArray();
|
|
|
|
|
|
|
|
if (selector !== undefined) {
|
|
|
|
if (selector === document) {
|
|
|
|
matches.push(document);
|
|
|
|
} else if (selector === window) {
|
|
|
|
matches.push(window);
|
|
|
|
} else {
|
|
|
|
if ((match = document.querySelectorAll(selector))) {
|
|
|
|
for( var i=0; i < match.length; i++) {
|
|
|
|
matches.push(match[i]);
|
2017-02-07 15:19:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return matches;
|
2017-02-08 15:24:58 -05:00
|
|
|
|
2017-02-07 15:19:23 -05:00
|
|
|
}
|
|
|
|
|
2017-02-08 15:24:58 -05:00
|
|
|
// Add utils to Dollar
|
|
|
|
for(var key in utils) Dollar[key] = utils[key];
|
2017-02-07 15:19:23 -05:00
|
|
|
|
2017-02-08 15:24:58 -05:00
|
|
|
return Dollar;
|
2017-02-07 15:19:23 -05:00
|
|
|
|
|
|
|
});
|