Files
ionic-framework/js/angular/directive/item.js
2014-05-05 11:14:27 -06:00

64 lines
1.7 KiB
JavaScript

var ITEM_TPL_CONTENT_ANCHOR =
'<a class="item-content" ng-href="{{$href()}}"></a>';
var ITEM_TPL_CONTENT =
'<div class="item-content"></div>';
/**
* @ngdoc directive
* @name ionItem
* @parent ionic.directive:ionList
* @module ionic
* @restrict E
* Creates a list-item that can easily be swiped,
* deleted, reordered, edited, and more.
*
* See {@link ionic.directive:ionList} for a complete example & explanation.
*
* Can be assigned any item class name. See the
* [list CSS documentation](/docs/components/#list).
*
* @usage
*
* ```html
* <ion-list>
* <ion-item>Hello!</ion-item>
* </ion-list>
* ```
*/
IonicModule
.directive('ionItem', [
'$animate',
'$compile',
function($animate, $compile) {
return {
restrict: 'E',
controller: ['$scope', '$element', function($scope, $element) {
this.$scope = $scope;
this.$element = $element;
}],
scope: true,
compile: function($element, $attrs) {
var isAnchor = angular.isDefined($attrs.href) || angular.isDefined($attrs.ngHref);
var isComplexItem = isAnchor ||
//Lame way of testing, but we have to know at compile what to do with the element
/ion-(delete|option|reorder)-button/i.test($element.html());
if (isComplexItem) {
var innerElement = angular.element(isAnchor ? ITEM_TPL_CONTENT_ANCHOR : ITEM_TPL_CONTENT);
innerElement.append($element.contents());
$element.append(innerElement);
$element.addClass('item item-complex');
} else {
$element.addClass('item');
}
return function link($scope, $element, $attrs) {
$scope.$href = function() {
return $attrs.href || $attrs.ngHref;
};
};
}
};
}]);