Provide all jquery functions as futures

This commit is contained in:
Shyam Seshadri
2010-08-14 03:05:50 +08:00
committed by Shyam Seshadri
parent 9260f4867a
commit 60eeeb9f20
2 changed files with 42 additions and 23 deletions

View File

@@ -102,18 +102,30 @@ angular.scenario.dsl.repeater = function(selector) {
};
angular.scenario.dsl.element = function(selector) {
var nameSuffix = "element '" + selector + "'";
return $scenario.addFuture('Find ' + nameSuffix, function(done) {
var self = this, repeaterArray = [], ngBindPattern;
var startIndex = selector.search(angular.scenario.dsl.NG_BIND_PATTERN);
if (startIndex >= 0) {
ngBindPattern = selector.substring(startIndex + 2, selector.length - 2);
var element = this.testDocument.find('*').filter(function() {
return self.jQuery(this).attr('ng:bind') == ngBindPattern;
});
done(element);
} else {
done(this.testDocument.find(selector));
}
});
var namePrefix = "Element '" + selector + "'";
var futureJquery = {};
for (key in _jQuery.fn) {
(function(){
var jqFnName = key;
var jqFn = _jQuery.fn[key];
futureJquery[key] = function() {
var jqArgs = arguments;
return $scenario.addFuture(namePrefix + "." + jqFnName + "()",
function(done) {
var self = this, repeaterArray = [], ngBindPattern;
var startIndex = selector.search(angular.scenario.dsl.NG_BIND_PATTERN);
if (startIndex >= 0) {
ngBindPattern = selector.substring(startIndex + 2, selector.length - 2);
var element = this.testDocument.find('*').filter(function() {
return self.jQuery(this).attr('ng:bind') == ngBindPattern;
});
done(jqFn.apply(element, jqArgs));
} else {
done(jqFn.apply(this.testDocument.find(selector), jqArgs));
}
});
};
})();
}
return futureJquery;
};