Skip to content

Commit

Permalink
a minor refactor for cleanliness.
Browse files Browse the repository at this point in the history
  • Loading branch information
anutron committed Nov 5, 2011
1 parent a85bdf1 commit ff6602b
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions Source/Behavior.Startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,35 @@ requires: [/Behavior, /Delegator]
provides: [Behavior.Startup]
...
*/

Behavior.addGlobalFilter('Startup', {
setup: function(el, api){
//get the delegators to set up
var delegators = api.get('delegators');
if (delegators) {
Object.each(delegators, function(conditional, delegator){
var targets = [];
//get the target of these delegators
if (api.get('targets')){
targets = el.getElement(api.get('targets'));
} else if (api.get('target') && api.get('target') != 'self'){
var target = el.getElement(api.get('target'));
if (target) targets = new Elements([target]);
} else {
targets = new Elements(el);
}
if (targets.length == 0) api.fail('could not find targets for startup delegator: ', delegator, api.get('targets'));
//check the targets for the conditionals
var fire = targets.some(function(target){
if (conditional.property) return element.get(conditional.property) === conditional.value;
else if (conditional.method) return element[method].apply(element, conditional.arguments || []) === conditiona.value;
(function(){
var check = function(el, conditional, delegator, api){
var targets = [];
//get the target of these delegators
if (conditional.targets){
targets = el.getElement(conditional.targets);
} else if (conditional.target && conditional.target != 'self'){
var target = el.getElement(conditional.target);
if (target) targets = new Elements([target]);
} else {
targets = new Elements([el]);
}
if (targets.length == 0) api.fail('could not find targets for startup delegator: ', delegator, conditional.targets);
//check the targets for the conditionals
return targets.some(function(target){
if (conditional.property) return target.get(conditional.property) === conditional.value;
else if (conditional.method) return target[method].apply(element, conditional.arguments || []) === conditiona.value;
});
};
Behavior.addGlobalFilter('Startup', {
setup: function(el, api){
//get the delegators to set up
var delegators = api.get('delegators');
if (delegators){
Object.each(delegators, function(conditional, delegator){
//if any were true, fire the delegator ON THIS ELEMENT
if (check(el, conditional, delegator, api)) api.getDelegator().trigger(delegator, el);
});
//if any were true, fire the delegator ON THIS ELEMENT
if (fire) api.getDelegator().trigger(delegator, el);
});
}
}
}
});
});
})();

0 comments on commit ff6602b

Please sign in to comment.