aurelia-kendoui-bridge
Version:
A set of Telerik KendoUI wrappers for Aurelia allowing developers to easily use KendoUI components in their Aurelia application.
61 lines (50 loc) • 1.67 kB
JavaScript
import {inject, Container} from 'aurelia-dependency-injection';
import {customElement} from 'aurelia-templating';
import {WidgetBase} from '../common/widget-base';
import {generateBindables} from '../common/decorators';
import {constants} from '../common/constants';
export class TreeView {
constructor(element, widgetBase, container) {
this.element = element;
this.widgetBase = widgetBase
.control('kendoTreeView')
.useRootElement(this.element)
.linkViewModel(this)
.useContainer(container);
}
subscribe(event, callback) {
return this.widgetBase.subscribe(event, callback);
}
bind(ctx, overrideCtx) {
this.widgetBase.useParentCtx(overrideCtx);
}
attached() {
if (isInitFromUl(this.element)) {
this.widgetBase.useElement(this.element.querySelectorAll('ul')[0]);
} else {
let target = document.createElement('div');
this.element.appendChild(target);
this.widgetBase.useElement(target);
}
if (!this.kNoInit) {
this.recreate();
}
}
recreate() {
let templates = this.widgetBase.util.getChildrenVMs(this.element, `${constants.elementPrefix}template`);
this.widgetBase.useTemplates(this, 'kendoTreeView', templates);
this.kWidget = this.widgetBase.recreate();
}
destroy() {
this.widgetBase.destroy(this.kWidget);
}
detached() {
this.destroy();
}
}
function isInitFromUl(element) {
return element.querySelectorAll('ul').length > 0;
}