@progress/kendo-angular-dropdowns
Version:
Dropdowns Package for Angular 2
97 lines (96 loc) • 4.67 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var list_item_directive_1 = require("./list-item.directive");
var util_1 = require("./util");
var selection_service_1 = require("./selection.service");
require("rxjs/add/operator/map");
require("rxjs/add/operator/merge");
/**
* @hidden
*/
var ListComponent = (function () {
function ListComponent(selectionService) {
this.data = [];
this.selected = [];
this.focused = -1;
this.multipleSelection = false;
this.onClick = new core_1.EventEmitter();
this.selectionService = selectionService;
this.scrollSubscription = this.selectionService
.onSelect
.map(function (args) { return args.indices[0]; })
.merge(this.selectionService.onFocus)
.subscribe(this.scrollToItem.bind(this));
}
ListComponent.prototype.ngAfterViewInit = function () {
if (this.show === true) {
this.scrollToItem(this.selectionService.focused);
}
};
ListComponent.prototype.ngOnDestroy = function () {
this.scrollSubscription.unsubscribe();
};
ListComponent.prototype.setContainerClasses = function () {
return {
'k-list-scroller': true
};
};
ListComponent.prototype.getHeight = function () {
return this.height + "px";
};
ListComponent.prototype.getText = function (dataItem) {
return util_1.getter(dataItem, this.textField);
};
ListComponent.prototype.getValue = function (dataItem) {
return util_1.getter(dataItem, this.valueField);
};
ListComponent.prototype.scrollToItem = function (index) {
var items = this.items.toArray();
if (util_1.isPresent(items[index]) && index !== -1) {
this.scroll(items[index].element);
}
};
ListComponent.prototype.scroll = function (item) {
if (!item) {
return;
}
var nativeElement = item.nativeElement;
var content = this.content.nativeElement, itemOffsetTop = nativeElement.offsetTop, itemOffsetHeight = nativeElement.offsetHeight, contentScrollTop = content.scrollTop, contentOffsetHeight = content.clientHeight, bottomDistance = itemOffsetTop + itemOffsetHeight;
if (contentScrollTop > itemOffsetTop) {
contentScrollTop = itemOffsetTop;
}
else if (bottomDistance > (contentScrollTop + contentOffsetHeight)) {
contentScrollTop = (bottomDistance - contentOffsetHeight);
}
content.scrollTop = contentScrollTop;
};
return ListComponent;
}());
ListComponent.decorators = [
{ type: core_1.Component, args: [{
selector: 'kendo-list',
template: "\n <div #content [ngClass]=\"setContainerClasses()\" [style.maxHeight]=\"getHeight()\" unselectable=\"on\">\n <ul role=\"listbox\" [attr.id]=\"id\" [attr.aria-hidden]=\"!show\" [ngClass]=\"{ 'k-list': true, 'k-reset': true }\">\n <li role=\"option\"\n *ngFor=\"let dataItem of data; let index = index\"\n kendoDropDownsSelectable\n [index]=\"index\"\n [multipleSelection]=\"multipleSelection\"\n [attr.id]=\"optionPrefix + '-' + getValue(dataItem)\"\n [attr.tabIndex]=\"-1\"\n [ngClass]=\"{'k-item': true}\">\n <ng-template *ngIf=\"template\"\n [templateContext]=\"{\n templateRef: template.templateRef,\n $implicit: dataItem\n }\">\n </ng-template>\n <ng-template [ngIf]=\"!template\">{{ getText(dataItem) }}</ng-template>\n </li>\n </ul>\n </div>\n "
},] },
];
/** @nocollapse */
ListComponent.ctorParameters = function () { return [
{ type: selection_service_1.SelectionService, },
]; };
ListComponent.propDecorators = {
'data': [{ type: core_1.Input },],
'selected': [{ type: core_1.Input },],
'focused': [{ type: core_1.Input },],
'textField': [{ type: core_1.Input },],
'valueField': [{ type: core_1.Input },],
'height': [{ type: core_1.Input },],
'template': [{ type: core_1.Input },],
'show': [{ type: core_1.Input },],
'id': [{ type: core_1.Input },],
'optionPrefix': [{ type: core_1.Input },],
'multipleSelection': [{ type: core_1.Input },],
'onClick': [{ type: core_1.Output },],
'items': [{ type: core_1.ViewChildren, args: [list_item_directive_1.ListItemDirective,] },],
'content': [{ type: core_1.ViewChild, args: ['content',] },],
};
exports.ListComponent = ListComponent;
;