diff options
| author | Misko Hevery | 2010-03-16 15:21:01 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-03-16 15:21:01 -0700 |
| commit | f1b50b92ac69f5c58984f5e88015507552d29df2 (patch) | |
| tree | 397b4ada18f9e2bdd05db93fa3f4d811000e42d2 | |
| parent | c9aba8b442adce496f0600c88764f7ffcc166879 (diff) | |
| parent | 34d48489d5fb3afbd10b9993fe80d753e0cf48bd (diff) | |
| download | angular.js-f1b50b92ac69f5c58984f5e88015507552d29df2.tar.bz2 | |
Merge branch 'directives' of github.com:angular/angular.js
| -rw-r--r-- | src/directives.js | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/src/directives.js b/src/directives.js new file mode 100644 index 00000000..0e99d633 --- /dev/null +++ b/src/directives.js @@ -0,0 +1,121 @@ + +angular.directive("auth", function(expression, element){ + return function(){ + if(expression == "eager") { + this.$users.fetchCurrent(); + } + } +}); + + +//expression = "book=Book:{year=2000}" +angular.directive("entity", function(expression, element){ + //parse expression, ignore element + var entityName; // "Book"; + var instanceName; // "book"; + var defaults; // {year: 2000}; + + parse(expression); + + return function(){ + this[entityName] = this.$datastore.entity(entityName, defaults); + this[instanceName] = this[entityName](); + this.$watch("$anchor."+instanceName, function(newAnchor){ + this[instanceName] = this[entityName].get(this.$anchor[instanceName]); + }); + }; +}); + + +angular.directive("init", function(expression, element){ + return function(){ + this.$eval(expresssion); + } +}); + + +//translation of {{ }} to ng-bind is external to this +angular.directive("bind", function(expression, element){ + return function() { + this.$watch(expression, function(value){ + element.innerText = value; + }); + }; +}); + + +// translation of {{ }} to ng-bind-attr is external to this +// <a href="http://example.com?id={{book.$id}}" alt="{{book.$name}}">link</a> +// becomes +// <a href="" ng-bind-attr="{href:'http://example.com?id={{book.$id}}', alt:'{{book.$name}}'}">link</a> +angular.directive("bind-attr", function(expression, element){ + var jElement = jQuery(element); + return function(){ + this.$watch(expression, _(jElement.attr).bind(jElement)); + }; +}); + +angular.directive("repeat", function(expression, element){ + var anchor = document.createComment(expression); + jQuery(element).replace(anchor); + var template = this.compile(element); + var lhs = "item"; + var rhs = "items"; + var children = []; + return function(){ + this.$watch(rhs, function(items){ + foreach(children, function(child){ + child.element.remove(); + }); + foreach(items, function(item){ + var child = template(item); // create scope + element.addChild(child.element, anchor); + children.push(child); + }); + }); + }; +}); + + +//ng-non-bindable +angular.directive("non-bindable", function(expression, element){ + return false; +}); + +//Styling +// +//ng-class +//ng-class-odd, ng-class-even +//ng-style +//ng-show, ng-hide + + +angular.directive("action", function(expression, element){ + return function(){ + var self = this; + jQuery(element).click(function(){ + self.$eval(expression); + }); + }; +}); + +//ng-eval +angular.directive("eval", function(expression, element){ + return function(){ + this.$onUpdate( expression); + } +}); +//ng-watch +// <div ng-watch="$anchor.book: book=Book.get();"/> +angular.directive("watch", function(expression, element){ + var watches = { + 'lhs':'rhs' + }; // parse + return function(){ + this.$watch(watches); + } +}); + +//widget related +//ng-validate, ng-required, ng-formatter +//ng-error |
