diff options
| author | Misko Hevery | 2010-04-30 12:22:07 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-04-30 12:22:07 -0700 |
| commit | ac1d02d0658cb74ae3822e364f84809d78cda335 (patch) | |
| tree | 6c5fdbd670d758d65c4d52f2e261818ac1607f47 /src | |
| parent | 549ff73a9b66e718383c79ccd7c28e4f9b25632d (diff) | |
| download | angular.js-ac1d02d0658cb74ae3822e364f84809d78cda335.tar.bz2 | |
make xhr post optional
Diffstat (limited to 'src')
| -rw-r--r-- | src/Browser.js | 4 | ||||
| -rw-r--r-- | src/Compiler.js | 13 | ||||
| -rw-r--r-- | src/services.js | 12 | ||||
| -rw-r--r-- | src/widgets.js | 9 |
4 files changed, 32 insertions, 6 deletions
diff --git a/src/Browser.js b/src/Browser.js index d2e8608d..6ec083fa 100644 --- a/src/Browser.js +++ b/src/Browser.js @@ -53,6 +53,10 @@ Browser.prototype = { }, xhr: function(method, url, post, callback){ + if (isFunction(post)) { + callback = post; + post = null; + } var xhr = new this.XHR(); xhr.open(method, url, true); xhr.onreadystatechange = function() { diff --git a/src/Compiler.js b/src/Compiler.js index c77c6b30..c8910c27 100644 --- a/src/Compiler.js +++ b/src/Compiler.js @@ -77,7 +77,18 @@ function Compiler(textMarkup, attrMarkup, directives, widgets){ Compiler.prototype = { compile: function(rawElement) { rawElement = jqLite(rawElement); - var template = this.templatize(rawElement, 0, 0) || new Template(); + var index = 0, + template, + parent = rawElement.parent(); + if (parent && parent[0]) { + parent = parent[0]; + for(var i = 0; i < parent.childNodes.length; i++) { + if (parent.childNodes[i] == rawElement[0]) { + index = i; + } + } + } + template = this.templatize(rawElement, index, 0) || new Template(); return function(element, parentScope){ element = jqLite(element); var scope = parentScope && parentScope.$eval ? diff --git a/src/services.js b/src/services.js index 16dbcb35..2cf0e4ad 100644 --- a/src/services.js +++ b/src/services.js @@ -192,6 +192,10 @@ angularService('$route', function(location, params){ angularService('$xhr', function($browser){ var self = this; return function(method, url, post, callback){ + if (isFunction(post)) { + callback = post; + post = null; + } if (post && isObject(post)) { post = toJson(post); } @@ -213,6 +217,10 @@ angularService('$xhr.bulk', function($xhr){ callbacks = [], scope = this; function bulkXHR(method, url, post, callback) { + if (isFunction(post)) { + callback = post; + post = null; + } requests.push({method: method, url: url, data:post}); callbacks.push(callback); } @@ -240,6 +248,10 @@ angularService('$xhr.bulk', function($xhr){ angularService('$xhr.cache', function($xhr){ var inflight = {}; function cache(method, url, post, callback){ + if (isFunction(post)) { + callback = post; + post = null; + } if (method == 'GET') { var data; if (data = cache.data[url]) { diff --git a/src/widgets.js b/src/widgets.js index 8a816934..2fade3e3 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -192,22 +192,21 @@ angularWidget('NG:INCLUDE', function(element){ function incrementChange(){ changeCounter++;} this.$watch(srcExp, incrementChange); this.$watch(scopeExp, incrementChange); + scope.$onEval(function(){ + if (childScope) childScope.$eval(); + }); this.$watch(function(){return changeCounter;}, function(){ var src = this.$eval(srcExp), useScope = this.$eval(scopeExp); if (src) { - scope.$browser.xhr('GET', src, function(code, response){ + scope.$xhr.cache('GET', src, function(code, response){ element.html(response); childScope = useScope || createScope(scope); compiler.compile(element)(element, childScope); childScope.$init(); - scope.$root.$eval(); }); } }); - scope.$onEval(function(){ - if (childScope) childScope.$eval(); - }); }; } }); |
