mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-22 09:30:28 +00:00
Apparently there is a really weird bug in IE6-8 that causes anchor textContent to be reset with href content when both contain @ symbol. Inserting a bogus comment node into all anchor elements in IE works around this browser bug. I'm fixing the issue via directive because that way we'll fix it for jQuery as well. I fixed an e2e test too because it was incorrect. Closes #1949
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
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) {
|
|
|
|
if (msie <= 8) {
|
|
|
|
// turn <a href ng-click="..">link</a> into a stylable link in IE
|
|
// but only if it doesn't have name attribute, in which case it's an anchor
|
|
if (!attr.href && !attr.name) {
|
|
attr.$set('href', '');
|
|
}
|
|
|
|
// add a comment node to anchors to workaround IE bug that causes element content to be reset
|
|
// to new attribute content if attribute is updated with value containing @ and element also
|
|
// contains value with @
|
|
// see issue #1949
|
|
element.append(document.createComment('IE fix'));
|
|
}
|
|
|
|
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();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|