diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/directives.js | 11 | ||||
| -rw-r--r-- | src/widgets.js | 22 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/directives.js b/src/directives.js index 69648e31..4443cc9d 100644 --- a/src/directives.js +++ b/src/directives.js @@ -198,13 +198,22 @@ angularWidget("@ng:repeat", function(expression, element){ }; }); + +/* + * A directive that allows creation of custom onclick handlers that are defined as angular + * expressions and are compiled and executed within the current scope. + * + * Events that are handled via these handler are always configured not to propagate further. + * + * TODO: maybe we should consider allowing users to control even propagation in the future. + */ angularDirective("ng:click", function(expression, element){ return function(element){ var self = this; element.bind('click', function(event){ self.$tryEval(expression, element); self.$root.$eval(); - event.preventDefault(); + event.stopPropagation(); }); }; }); diff --git a/src/widgets.js b/src/widgets.js index fbca8436..24eba900 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -340,3 +340,25 @@ var ngSwitch = angularWidget('ng:switch', function (element){ }, route: switchRouteMatcher }); + + +/* + * Modifies the default behavior of html A tag, so that the default action is prevented when href + * attribute is empty. + * + * The reasoning for this change is to allow easy creation of action links with ng:click without + * changing the location or causing page reloads, e.g.: + * <a href="" ng:click="model.$save()">Save</a> + */ +angular.widget('a', function() { + this.descend(true); + this.directives(true); + + return function(element) { + if (element.attr('href') === '') { + element.bind('click', function(event){ + event.preventDefault(); + }); + } + }; +});
\ No newline at end of file |
