From d7ba5bc83ba9a8937384ea677331c5156ed6772d Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Tue, 25 Oct 2011 08:47:02 -0700 Subject: 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 --- src/Angular.js | 40 +++++++++++++++++----------------------- src/angular-bootstrap.js | 4 +--- src/angular.suffix | 4 +++- 3 files changed, 21 insertions(+), 27 deletions(-) (limited to 'src') 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); -- cgit v1.2.3