From 0a5c00abf8664fdbdc5d16b13adb1989b4531cdf Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 7 Feb 2011 13:28:42 -0800 Subject: Add public API to retrieve scope from element. --- src/Angular.js | 9 ++++++++- src/Compiler.js | 12 ------------ src/jqLite.js | 9 +++++++++ src/widgets.js | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/Angular.js b/src/Angular.js index b856aa24..9a1ab4a2 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -1032,5 +1032,12 @@ function angularJsConfig(document, config) { function bindJQuery(){ // bind to jQuery if present; jQuery = window.jQuery; - angular.element = jqLite = jQuery || jqLiteWrap; + // reset to jQuery or default to us. + if (window.jQuery) { + jqLite = window.jQuery; + jqLite.fn.scope = JQLite.prototype.scope; + } else { + jqLite = jqLiteWrap; + } + angular.element = jqLite; } diff --git a/src/Compiler.js b/src/Compiler.js index 472ec625..d1505404 100644 --- a/src/Compiler.js +++ b/src/Compiler.js @@ -69,18 +69,6 @@ Template.prototype = { } }; -/* - * Function walks up the element chain looking for the scope associated with the give element. - */ -function retrieveScope(element) { - var scope; - element = jqLite(element); - while (element && element.length && !(scope = element.data($$scope))) { - element = element.parent(); - } - return scope; -} - /////////////////////////////////// //Compiler ////////////////////////////////// diff --git a/src/jqLite.js b/src/jqLite.js index ad7734c9..206c1d70 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -87,6 +87,15 @@ JQLite.prototype = { })(this[0]); }, + scope: function() { + var scope, element = this; + while (element && element.length && !(scope = element.data($$scope))) { + element = element.parent(); + } + return scope; + }, + + ready: function(fn) { var fired = false; diff --git a/src/widgets.js b/src/widgets.js index 461684ac..f8efae60 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -561,7 +561,7 @@ angularWidget('option', function(){ return function(option) { var select = option.parent(); var isMultiple = select[0].type == 'select-multiple'; - var scope = retrieveScope(select); + var scope = select.scope(); var model = modelAccessor(scope, select); //if parent select doesn't have a name, don't bother doing anything any more -- cgit v1.2.3