diff options
| author | Igor Minar | 2010-09-30 23:07:36 +0800 | 
|---|---|---|
| committer | Misko Hevery | 2010-10-01 07:44:46 +0800 | 
| commit | 8248e77a7b910bcbc71ca25c06bef44dd6712990 (patch) | |
| tree | 333b5b91e914a96f27b214bac3ef61c8d04e5b4d /src/widgets.js | |
| parent | 0af763dcec8b9f6b17208ac58607cd1124382f63 (diff) | |
| download | angular.js-8248e77a7b910bcbc71ca25c06bef44dd6712990.tar.bz2 | |
'A' tag widget and ng:click propagation change
* added a widget for A (anchor) tag, that modifies the default behavior
  and prevent default action (location change and page reload) for tags
  with empty href attribute
* stopped event propagation for all ng:click handlers
Diffstat (limited to 'src/widgets.js')
| -rw-r--r-- | src/widgets.js | 22 | 
1 files changed, 22 insertions, 0 deletions
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  | 
