UNPKG

aurelia-kendoui-bridge

Version:

A set of Telerik KendoUI wrappers for Aurelia allowing developers to easily use KendoUI components in their Aurelia application.

62 lines (51 loc) 1.72 kB
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'; @customElement(`${constants.elementPrefix}scrollview`) @generateBindables('kendoMobileScrollView') @inject(Element, WidgetBase, Container) export class Scrollview { constructor(element, widgetBase, container) { this.element = element; this.widgetBase = widgetBase .control('kendoMobileScrollView') .useRootElement(this.element) .linkViewModel(this) .useContainer(container) .useValueBinding(); } subscribe(event, callback) { return this.widgetBase.subscribe(event, callback); } bind(ctx, overrideCtx) { this.widgetBase.useParentCtx(overrideCtx); } attached() { if (isInitFromDiv(this.element)) { this.widgetBase.useElement(this.element.querySelectorAll('div')[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, 'kendoMobileScrollView', templates); this.kWidget = this.widgetBase.recreate(); } destroy() { this.widgetBase.destroy(this.kWidget); } detached() { this.destroy(); } } function isInitFromDiv(element) { return element.querySelectorAll('div').length > 0; }