Skip to content

Commit

Permalink
works for simple id selector
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiomcosta committed Jan 23, 2011
1 parent f29662d commit 467d9b1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
5 changes: 5 additions & 0 deletions assets/jasmine-1.0.1/jasmine-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
}
};

runner.env.specFilter = function(){
return self.specFilter.apply(self, arguments);
};

};

jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
Expand Down
38 changes: 27 additions & 11 deletions src/uSelector.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
/**
* @author Fabio Miranda Costa <fabio [at] solucione [dot] info>
* http://meiocodigo.com
* author: Fabio Miranda Costa
* github: fabiomcosta
* twitter: @fabiomiranda
* website: http://meiocodigo.com
* license: MIT-style license
*/

(function(global){
(function(global, document){

var $u = function(id, tagNames, className, root){
root = root || document;
var $u = function(selector, context, append){
var elements = append || [];
if (!context) context = $u.context;

selector.replace(/([\w-]*)(?:([#.])([^#.]*))*/, function(all, tag, simbol, name){
//if (!tag) tag = '*';
if (simbol == '#'){
var el = context.getElementById(name);
if (el) elements.push(el);
}
return '';
});

/*
if (className && root.getElementsByClassName){
return root.getElementsByClassName(className);
}
Expand All @@ -17,13 +32,14 @@
for (var j = 0, el; el = els[j++];){
if (!className || (' ' + el.className + ' ').indexOf(' ' + className + ' ') > -1) elsArray.push(el);
}
}
return elsArray;
}
*/
return elements;
};

$u.context = document;

global['uSelector'] = $u;
if (!global['$u']){
global['$u'] = $u;
}
if (!global['$u']) global['$u'] = $u;

})(this);
})(this, document);
12 changes: 10 additions & 2 deletions tests/specs.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
var microSpecs = function(context){

describe('Micro Selector', function() {


var $u = uSelector;
$u.context = context.document;

describe('id selector', function(){
it('should select some id', function(){
expect(1).toEqual(2);
expect($u('#title').length).toEqual(1);
expect($u('#other').length).toEqual(0);
});
});

Expand All @@ -15,6 +19,10 @@ describe('Micro Selector', function() {
xdescribe('class selector', function(){

});

xdescribe('mixed selectors', function(){

});

});

Expand Down

0 comments on commit 467d9b1

Please sign in to comment.