diff options
| author | Igor Minar | 2012-03-08 15:00:38 -0800 | 
|---|---|---|
| committer | Igor Minar | 2012-03-08 22:29:34 -0800 | 
| commit | f54db2ccda399f2677e4ca7588018cb31545a2b4 (patch) | |
| tree | 29ef2f8f834544c84cea1a82e3d08679358fb992 /src/directive/a.js | |
| parent | dd7b0f56fcd9785f7fccae8c4f088a8f3e7b125e (diff) | |
| download | angular.js-f54db2ccda399f2677e4ca7588018cb31545a2b4.tar.bz2 | |
chore(directives,widgets): reorg the code under directive/ dir
Diffstat (limited to 'src/directive/a.js')
| -rw-r--r-- | src/directive/a.js | 29 | 
1 files changed, 29 insertions, 0 deletions
diff --git a/src/directive/a.js b/src/directive/a.js new file mode 100644 index 00000000..bd56f3be --- /dev/null +++ b/src/directive/a.js @@ -0,0 +1,29 @@ +'use strict'; + +/* + * 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> + */ +var htmlAnchorDirective = valueFn({ +  restrict: 'E', +  compile: function(element, attr) { +    // turn <a href ng:click="..">link</a> into a link in IE +    // but only if it doesn't have name attribute, in which case it's an anchor +    if (!attr.href) { +      attr.$set('href', ''); +    } + +    return function(scope, element) { +      element.bind('click', function(event){ +        // if we have no href url, then don't navigate anywhere. +        if (!element.attr('href')) { +          event.preventDefault(); +        } +      }); +    } +  } +});  | 
