Skip to content

Commit

Permalink
fix(ionItem): do not auto add target attr
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Apr 15, 2015
1 parent f1ce7b1 commit 8e47266
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 13 additions & 8 deletions js/angular/directive/item.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
var ITEM_TPL_CONTENT_ANCHOR =
'<a class="item-content" ng-href="{{$href()}}" target="{{$target()}}"></a>';
var ITEM_TPL_CONTENT =
'<div class="item-content"></div>';
/**
* @ngdoc directive
* @name ionItem
Expand Down Expand Up @@ -45,11 +41,20 @@ IonicModule
/ion-(delete|option|reorder)-button/i.test($element.html());

if (isComplexItem) {
var innerElement = jqLite(isAnchor ? ITEM_TPL_CONTENT_ANCHOR : ITEM_TPL_CONTENT);
var innerElement = jqLite(isAnchor ? '<a></a>' : '<div></div>');
innerElement.addClass('item-content');

if (isDefined($attrs.href) || isDefined($attrs.ngHref)) {
innerElement.attr('ng-href', '{{$href()}}')
if (isDefined($attrs.target)) {
innerElement.attr('target', '{{$target()}}')
}
}

innerElement.append($element.contents());

$element.append(innerElement);
$element.addClass('item item-complex');
$element.addClass('item item-complex')
.append(innerElement);
} else {
$element.addClass('item');
}
Expand All @@ -59,7 +64,7 @@ IonicModule
return $attrs.href || $attrs.ngHref;
};
$scope.$target = function() {
return $attrs.target || '_self';
return $attrs.target;
};

var content = $element[0].querySelector('.item-content');
Expand Down
4 changes: 2 additions & 2 deletions test/unit/angular/directive/item.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ describe('ionItem directive', function() {
expect(el.children().attr('href')).toBe('something/44');
});
});
it('complex item should have target self by default', function() {
it('complex item should not have target by default', function() {
var el = setup('href="foo"');
expect(el.find('a').attr('target')).toBe('_self');
expect(el.find('a').attr('target')).toBeUndefined();
});
it('complex item should have target if specified', function() {
var el = setup('href="foo" target="bar"');
Expand Down

0 comments on commit 8e47266

Please sign in to comment.