diff options
| author | Igor Minar | 2011-10-25 08:47:02 -0700 |
|---|---|---|
| committer | Igor Minar | 2011-10-26 12:57:15 -0700 |
| commit | d7ba5bc83ba9a8937384ea677331c5156ed6772d (patch) | |
| tree | aef0e0eb9873265d6f1cbe90a6f3da360e8367ca /src | |
| parent | 950d02b4d4b1d574dfbb9bbdd56b8dc430db0a93 (diff) | |
| download | angular.js-d7ba5bc83ba9a8937384ea677331c5156ed6772d.tar.bz2 | |
feat(bootstrap): drop angular.js file name restrictions for autobind
The last script element in the dom is always us if the script that
contains angular is loaded synchronously.
For async loading manual bootstrap needs to be performed.
Close #621
Diffstat (limited to 'src')
| -rw-r--r-- | src/Angular.js | 40 | ||||
| -rw-r--r-- | src/angular-bootstrap.js | 4 | ||||
| -rw-r--r-- | src/angular.suffix | 4 |
3 files changed, 21 insertions, 27 deletions
diff --git a/src/Angular.js b/src/Angular.js index c5a35e4e..ab031049 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -116,7 +116,6 @@ var _undefined = undefined, angularService = extensionMap(angular, 'service'), angularCallbacks = extensionMap(angular, 'callbacks'), nodeName_, - rngScript = /^(|.*\/)angular(-.*?)?(\.min)?.js(\?[^#]*)?(#(.*))?$/, uid = ['0', '0', '0'], DATE_ISOSTRING_LN = 24; @@ -953,35 +952,30 @@ function angularInit(config, document){ var autobind = config.autobind; if (autobind) { - var element = isString(autobind) ? document.getElementById(autobind) : document, - scope = compile(element)(createScope()), - $browser = scope.$service('$browser'); - - if (config.css) - $browser.addCss(config.base_url + config.css); - scope.$apply(); + var element = isString(autobind) ? document.getElementById(autobind) : document; + compile(element)().$apply(); } } function angularJsConfig(document) { bindJQuery(); - var scripts = document.getElementsByTagName("script"), + var scripts = document.getElementsByTagName('script'), + script = scripts[scripts.length-1], + scriptSrc = script.src, config = {}, - match; - for(var j = 0; j < scripts.length; j++) { - match = (scripts[j].src || "").match(rngScript); - if (match) { - config.base_url = match[1]; - extend(config, parseKeyValue(match[6])); - eachAttribute(jqLite(scripts[j]), function(value, name){ - if (/^ng:/.exec(name)) { - name = name.substring(3).replace(/-/g, '_'); - value = value || true; - config[name] = value; - } - }); + hashPos; + + hashPos = scriptSrc.indexOf('#'); + if (hashPos != -1) extend(config, parseKeyValue(scriptSrc.substr(hashPos+1))); + + eachAttribute(jqLite(script), function(value, name){ + if (/^ng:/.exec(name)) { + name = name.substring(3).replace(/-/g, '_'); + value = value || true; + config[name] = value; } - } + }); + return config; } diff --git a/src/angular-bootstrap.js b/src/angular-bootstrap.js index 7a1752d2..fb2acbeb 100644 --- a/src/angular-bootstrap.js +++ b/src/angular-bootstrap.js @@ -99,9 +99,7 @@ // empty the cache to prevent mem leaks globalVars = {}; - var config = angularJsConfig(document); - - angularInit(config, document); + angularInit({autobind:true}, document); } if (window.addEventListener) { diff --git a/src/angular.suffix b/src/angular.suffix index e8bb83b7..d38d3130 100644 --- a/src/angular.suffix +++ b/src/angular.suffix @@ -1,6 +1,8 @@ + var config = angularJsConfig(document); + jqLiteWrap(document).ready(function() { - angularInit(angularJsConfig(document), document); + angularInit(config, document); }); })(window, document); |
