Skip to content

Commit

Permalink
* Adding an injectCombinator to Element.js, fixes #933 and similar
Browse files Browse the repository at this point in the history
  • Loading branch information
cpojer committed Aug 29, 2010
1 parent 3042947 commit fb8d85c
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions Source/Element/Element.js
Expand Up @@ -348,6 +348,20 @@ Object.each(inserters, function(inserter, where){

//</1.2compat>

var injectCombinator = function(expression, combinator){
if (!expression) return combinator;

expression = Slick.parse(expression);

var expressions = expression.expressions;
for (var i = expressions.length; i--;){
var first = expressions[i][0];
first.combinator = combinator + (first.combinator == ' ' ? '' : first.combinator);

This comment has been minimized.

Copy link
@fabiomcosta

fabiomcosta Aug 29, 2010

Shouldnt it be:
first.combinator = combinator;

did you add specs for the mentioned problem on the ticket?
Good job!

This comment has been minimized.

This comment has been minimized.

Copy link
@cpojer

cpojer Aug 29, 2010

Author Owner

(yes, I did specs)

This comment has been minimized.

Copy link
@fabiomcosta

fabiomcosta Aug 29, 2010

great!!

}

return expression;
};

Element.implement({

set: function(prop, value){
Expand Down Expand Up @@ -465,44 +479,44 @@ Element.implement({
return this.replaces(el).grab(el, where);
},

getPrevious: function(match){
return document.id(Slick.find(this, '!~ ' + (match || '')));
getPrevious: function(expression){
return document.id(Slick.find(this, injectCombinator(expression, '!~')));
},

getAllPrevious: function(match){
return Slick.search(this, '!~ ' + (match || ''), new Elements);
getAllPrevious: function(expression){
return Slick.search(this, injectCombinator(expression, '!~'), new Elements);
},

getNext: function(match){
return document.id(Slick.find(this, '~ ' + (match || '')));
getNext: function(expression){
return document.id(Slick.find(this, injectCombinator(expression, '~')));
},

getAllNext: function(match){
return Slick.search(this, '~ ' + (match || ''), new Elements);
getAllNext: function(expression){
return Slick.search(this, injectCombinator(expression, '~'), new Elements);
},

getFirst: function(match){
return document.id(Slick.find(this, '> ' + (match || '')));
getFirst: function(expression){
return document.id(Slick.find(this, injectCombinator(expression, '>')));
},

getLast: function(match){
return document.id(Slick.find(this, '!^ ' + (match || '')));
getLast: function(expression){
return document.id(Slick.find(this, injectCombinator(expression, '!^')));
},

getParent: function(match){
return document.id(Slick.find(this, '! ' + (match || '')));
getParent: function(expression){
return document.id(Slick.find(this, injectCombinator(expression, '!')));
},

getParents: function(match){
return Slick.search(this, '! ' + (match || ''), new Elements);
getParents: function(expression){
return Slick.search(this, injectCombinator(expression, '!'), new Elements);
},

getSiblings: function(match){
return Slick.search(this, '~~ ' + (match || ''), new Elements);
getSiblings: function(expression){
return Slick.search(this, injectCombinator(expression, '~~'), new Elements);
},

getChildren: function(match){
return Slick.search(this, '> ' + (match || ''), new Elements);
getChildren: function(expression){
return Slick.search(this, injectCombinator(expression, '>'), new Elements);
},

getWindow: function(){
Expand Down

0 comments on commit fb8d85c

Please sign in to comment.