diff options
Diffstat (limited to 'src/scenario')
| -rw-r--r-- | src/scenario/Scenario.js | 76 | ||||
| -rw-r--r-- | src/scenario/dsl.js | 6 |
2 files changed, 64 insertions, 18 deletions
diff --git a/src/scenario/Scenario.js b/src/scenario/Scenario.js index a7979342..7e33181c 100644 --- a/src/scenario/Scenario.js +++ b/src/scenario/Scenario.js @@ -345,25 +345,71 @@ function browserTrigger(element, type, keys) { * Finds all bindings with the substring match of name and returns an * array of their values. * - * @param {string} name The name to match + * @param {string} bindExp The name to match * @return {Array.<string>} String of binding values */ -_jQuery.fn.bindings = function(name) { - function contains(text, value) { - return value instanceof RegExp - ? value.test(text) - : text && text.indexOf(value) >= 0; +_jQuery.fn.bindings = function(windowJquery, bindExp) { + var result = [], match, + bindSelector = '.ng-binding:visible'; + if (angular.isString(bindExp)) { + bindExp = bindExp.replace(/\s/g, ''); + match = function (actualExp) { + if (actualExp) { + actualExp = actualExp.replace(/\s/g, ''); + if (actualExp == bindExp) return true; + if (actualExp.indexOf(bindExp) == 0) { + return actualExp.charAt(bindExp.length) == '|'; + } + } + } + } else if (bindExp) { + match = function(actualExp) { + return actualExp && bindExp.exec(actualExp); + } + } else { + match = function(actualExp) { + return !!actualExp; + }; + } + var selection = this.find(bindSelector); + if (this.is(bindSelector)) { + selection = selection.add(this); } - var result = []; - this.find('.ng-binding:visible').each(function() { - var element = new _jQuery(this); - if (!angular.isDefined(name) || - contains(element.attr('ng:bind'), name) || - contains(element.attr('ng:bind-template'), name)) { - if (element.is('input, textarea')) { - result.push(element.val()); + + function push(value) { + if (value == undefined) { + value = ''; + } else if (typeof value != 'string') { + value = angular.toJson(value); + } + result.push('' + value); + } + + selection.each(function() { + var element = windowJquery(this), + binding; + if (binding = element.data('$binding')) { + if (typeof binding == 'string') { + if (match(binding)) { + push(element.scope().$eval(binding)); + } } else { - result.push(element.html()); + if (!angular.isArray(binding)) { + binding = [binding]; + } + for(var fns, j=0, jj=binding.length; j<jj; j++) { + fns = binding[j]; + if (fns.parts) { + fns = fns.parts; + } else { + fns = [fns]; + } + for (var scope, fn, i = 0, ii = fns.length; i < ii; i++) { + if(match((fn = fns[i]).exp)) { + push(fn(scope = scope || element.scope())); + } + } + } } } }); diff --git a/src/scenario/dsl.js b/src/scenario/dsl.js index bbe29948..fb0037e0 100644 --- a/src/scenario/dsl.js +++ b/src/scenario/dsl.js @@ -180,7 +180,7 @@ angular.scenario.dsl('using', function() { angular.scenario.dsl('binding', function() { return function(name) { return this.addFutureAction("select binding '" + name + "'", function($window, $document, done) { - var values = $document.elements().bindings(name); + var values = $document.elements().bindings($window.angular.element, name); if (!values.length) { return done("Binding selector '" + name + "' did not match."); } @@ -260,7 +260,7 @@ angular.scenario.dsl('repeater', function() { chain.column = function(binding) { return this.addFutureAction("repeater '" + this.label + "' column '" + binding + "'", function($window, $document, done) { - done(null, $document.elements().bindings(binding)); + done(null, $document.elements().bindings($window.angular.element, binding)); }); }; @@ -269,7 +269,7 @@ angular.scenario.dsl('repeater', function() { var matches = $document.elements().slice(index, index + 1); if (!matches.length) return done('row ' + index + ' out of bounds'); - done(null, matches.bindings()); + done(null, matches.bindings($window.angular.element)); }); }; |
