Skip to content

Commit 8e47266

Browse files
committed
fix(ionItem): do not auto add target attr
Closes #3497
1 parent f1ce7b1 commit 8e47266

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

Diff for: js/angular/directive/item.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
var ITEM_TPL_CONTENT_ANCHOR =
2-
'<a class="item-content" ng-href="{{$href()}}" target="{{$target()}}"></a>';
3-
var ITEM_TPL_CONTENT =
4-
'<div class="item-content"></div>';
51
/**
62
* @ngdoc directive
73
* @name ionItem
@@ -45,11 +41,20 @@ IonicModule
4541
/ion-(delete|option|reorder)-button/i.test($element.html());
4642

4743
if (isComplexItem) {
48-
var innerElement = jqLite(isAnchor ? ITEM_TPL_CONTENT_ANCHOR : ITEM_TPL_CONTENT);
44+
var innerElement = jqLite(isAnchor ? '<a></a>' : '<div></div>');
45+
innerElement.addClass('item-content');
46+
47+
if (isDefined($attrs.href) || isDefined($attrs.ngHref)) {
48+
innerElement.attr('ng-href', '{{$href()}}')
49+
if (isDefined($attrs.target)) {
50+
innerElement.attr('target', '{{$target()}}')
51+
}
52+
}
53+
4954
innerElement.append($element.contents());
5055

51-
$element.append(innerElement);
52-
$element.addClass('item item-complex');
56+
$element.addClass('item item-complex')
57+
.append(innerElement);
5358
} else {
5459
$element.addClass('item');
5560
}
@@ -59,7 +64,7 @@ IonicModule
5964
return $attrs.href || $attrs.ngHref;
6065
};
6166
$scope.$target = function() {
62-
return $attrs.target || '_self';
67+
return $attrs.target;
6368
};
6469

6570
var content = $element[0].querySelector('.item-content');

Diff for: test/unit/angular/directive/item.unit.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ describe('ionItem directive', function() {
3434
expect(el.children().attr('href')).toBe('something/44');
3535
});
3636
});
37-
it('complex item should have target self by default', function() {
37+
it('complex item should not have target by default', function() {
3838
var el = setup('href="foo"');
39-
expect(el.find('a').attr('target')).toBe('_self');
39+
expect(el.find('a').attr('target')).toBeUndefined();
4040
});
4141
it('complex item should have target if specified', function() {
4242
var el = setup('href="foo" target="bar"');

0 commit comments

Comments
 (0)