diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Angular.js | 17 | ||||
| -rw-r--r-- | src/Compiler.js | 2 | ||||
| -rw-r--r-- | src/Scope.js | 2 | ||||
| -rw-r--r-- | src/angular.prefix | 2 | ||||
| -rw-r--r-- | src/angular.suffix | 8 | ||||
| -rw-r--r-- | src/directives.js | 1 | ||||
| -rw-r--r-- | src/filters.js (renamed from src/Filters.js) | 0 | ||||
| -rw-r--r-- | src/formatters.js (renamed from src/Formatters.js) | 0 | ||||
| -rw-r--r-- | src/validators.js (renamed from src/Validators.js) | 0 | ||||
| -rw-r--r-- | src/widgets.js (renamed from src/Widgets.js) | 57 |
10 files changed, 69 insertions, 20 deletions
diff --git a/src/Angular.js b/src/Angular.js index 2d67b2cb..3b5e1c90 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -102,7 +102,7 @@ function isTextNode(node) { return nodeName(node) == '#text'; } function lowercase(value){ return isString(value) ? value.toLowerCase() : value; } function uppercase(value){ return isString(value) ? value.toUpperCase() : value; } function trim(value) { return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value; } -function nodeName(element) { return (element[0] || element || {}).nodeName; } +function nodeName(element) { return (element[0] || element).nodeName; } function map(obj, iterator, context) { var results = []; foreach(obj, function(value, index, list) { @@ -274,6 +274,8 @@ function escapeAttr(html) { } function bind(_this, _function) { + if (!isFunction(_function)) + throw "Not a function!"; var curryArgs = slice.call(arguments, 2, arguments.length); return function() { return _function.apply(_this, curryArgs.concat(slice.call(arguments, 0, arguments.length))); @@ -347,3 +349,16 @@ function angularInit(config){ scope.$init(); } } + +function angularJsConfig(document) { + var filename = /(.*)\/angular(-(.*))?.js(#(.*))?/, + scripts = document.getElementsByTagName("SCRIPT"), + match; + for(var j = 0; j < scripts.length; j++) { + match = (scripts[j].src || "").match(filename); + if (match) { + return match[5]; + } + } + return ""; +} diff --git a/src/Compiler.js b/src/Compiler.js index 67c22461..ae2bcdb6 100644 --- a/src/Compiler.js +++ b/src/Compiler.js @@ -1,5 +1,5 @@ /** -= * Template provides directions an how to bind to a given element. + * Template provides directions an how to bind to a given element. * It contains a list of init functions which need to be called to * bind to a new instance of elements. It also provides a list * of child paths which contain child templates diff --git a/src/Scope.js b/src/Scope.js index b41f7436..0bc551c4 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -17,7 +17,7 @@ function getter(instance, path, unboundFn) { type = angular[type.charAt(0).toUpperCase()+type.substring(1)]; var fn = type ? type[[key.substring(1)]] : undefined; if (fn) { - instance = bind(fn, lastInstance, lastInstance); + instance = bind(lastInstance, fn, lastInstance); return instance; } } diff --git a/src/angular.prefix b/src/angular.prefix index 0552b2ed..a1b4e151 100644 --- a/src/angular.prefix +++ b/src/angular.prefix @@ -21,4 +21,4 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -(function(window, document, onLoadDelegate){ +(function(window, document, previousOnLoad){ diff --git a/src/angular.suffix b/src/angular.suffix index c5754df2..36d73df2 100644 --- a/src/angular.suffix +++ b/src/angular.suffix @@ -1 +1,9 @@ + + window.onload = function(){ + try { + if (previousOnLoad) previousOnLoad(); + } catch(e) {} + angularInit(parseKeyValue(angularJsConfig(document))); + }; + })(window, document, window.onload); diff --git a/src/directives.js b/src/directives.js index d1b1dba3..5cee0978 100644 --- a/src/directives.js +++ b/src/directives.js @@ -12,6 +12,7 @@ angularDirective("ng-controller", function(expression){ if (!isFunction(controller)) throw "Reference '"+expression+"' is not a class."; this.$become(controller); + (this.init || noop)(); }; }); diff --git a/src/Filters.js b/src/filters.js index dac8d31d..dac8d31d 100644 --- a/src/Filters.js +++ b/src/filters.js diff --git a/src/Formatters.js b/src/formatters.js index ee63c1a5..ee63c1a5 100644 --- a/src/Formatters.js +++ b/src/formatters.js diff --git a/src/Validators.js b/src/validators.js index e3da0a81..e3da0a81 100644 --- a/src/Validators.js +++ b/src/validators.js diff --git a/src/Widgets.js b/src/widgets.js index 8e668c8f..3e9ba236 100644 --- a/src/Widgets.js +++ b/src/widgets.js @@ -159,28 +159,42 @@ angularWidget('SELECT', function(element){ angularWidget('NG:INCLUDE', function(element){ var compiler = this, src = element.attr("src"); - return element.attr('switch-instance') ? null : function(element){ - var scope = this, childScope; - element.attr('switch-instance', 'compiled'); - scope.$browser.xhr('GET', src, function(code, response){ - element.html(response); - childScope = createScope(scope); - compiler.compile(element)(element, childScope); - childScope.$init(); - }); - scope.$onEval(function(){ if (childScope) childScope.$eval(); }); - }; + if (element.attr('switch-instance')) { + this.descend(true); + this.directives(true); + } else { + return function(element){ + var scope = this, childScope; + element.attr('switch-instance', 'compiled'); + scope.$browser.xhr('GET', src, function(code, response){ + element.html(response); + childScope = createScope(scope); + compiler.compile(element)(element, childScope); + childScope.$init(); + scope.$root.$eval(); + }); + scope.$onEval(function(){ + if (childScope) childScope.$eval(); + }); + }; + } }); -angularWidget('NG:SWITCH', function(element){ +angularWidget('NG:SWITCH', function ngSwitch(element){ var compiler = this, watchExpr = element.attr("on"), + whenFn = ngSwitch[element.attr("using") || 'equals']; + changeExpr = element.attr('change') || '', cases = []; + if (!whenFn) throw "Using expression '" + usingExpr + "' unknown."; eachNode(element, function(caseElement){ var when = caseElement.attr('ng-switch-when'); if (when) { cases.push({ - when: function(value){ return value == when; }, + when: function(scope, value){ + return whenFn.call(scope, value, when); + }, + change: changeExpr, element: caseElement, template: compiler.compile(caseElement) }); @@ -188,17 +202,28 @@ angularWidget('NG:SWITCH', function(element){ }); element.html(''); return function(element){ - var scope = this; + var scope = this, childScope; this.$watch(watchExpr, function(value){ element.html(''); + childScope = null; foreach(cases, function(switchCase){ - if (switchCase.when(value)) { + if (switchCase.when(childScope, value)) { element.append(switchCase.element); - var childScope = createScope(scope); + childScope = createScope(scope); + childScope.$tryEval(switchCase.change, element); switchCase.template(switchCase.element, childScope); childScope.$init(); } }); }); + scope.$onEval(function(){ + if (childScope) childScope.$eval(); + }); }; +}, { + equals: function(on, when) { + return on == when; + }, + route: function(on, when) { + } }); |
