mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-13 17:23:11 +00:00
This reverts commit c81d8176cc.
This commit causes several issues (#1651, #1674, #1662) and doesn't even
contain a test that proves that anything on Opera got actually fixed.
If the original Opera resurfaces, we'll fix it properly.
34 lines
979 B
JavaScript
34 lines
979 B
JavaScript
'use strict';
|
|
|
|
/**
|
|
* @ngdoc directive
|
|
* @name ng.directive:a
|
|
* @restrict E
|
|
*
|
|
* @description
|
|
* 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 `ngClick` directive
|
|
* 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();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|