DjxWidgetBase.ts
51 lines
| 2.0 KiB
| video/mp2t
|
TypeScriptLexer
cin
|
r0 | import { djbase, djclass } from "../declare"; | ||
import _WidgetBase = require("dijit/_WidgetBase"); | ||||
import _AttachMixin = require("dijit/_AttachMixin"); | ||||
import { BuildContext, isNode } from "./traits"; | ||||
import registry = require("dijit/registry"); | ||||
cin
|
r4 | // import { Handle } from "dojo/interfaces"; | ||
type Handle = dojo.Handle; | ||||
cin
|
r0 | |||
@djclass | ||||
export abstract class DjxWidgetBase extends djbase(_WidgetBase, _AttachMixin) { | ||||
buildRendering() { | ||||
this.domNode = this.render().getDomElement(); | ||||
super.buildRendering(); | ||||
} | ||||
abstract render(): BuildContext; | ||||
_processTemplateNode<T extends (Element | Node | _WidgetBase)>( | ||||
baseNode: T, | ||||
getAttrFunc: (baseNode: T, attr: string) => string, | ||||
cin
|
r1 | // tslint:disable-next-line: ban-types | ||
cin
|
r2 | attachFunc: (node: T, type: string, func?: Function) => Handle | ||
cin
|
r0 | ): boolean { | ||
if (isNode(baseNode)) { | ||||
const w = registry.byNode(baseNode); | ||||
if (w) { | ||||
// from dijit/_WidgetsInTemplateMixin | ||||
this._processTemplateNode(w, | ||||
cin
|
r1 | (n, p) => n.get(p), // callback to get a property of a widget | ||
cin
|
r0 | (widget, type, callback) => { | ||
cin
|
r1 | if (!callback) | ||
throw new Error("The callback must be specified"); | ||||
cin
|
r0 | // callback to do data-dojo-attach-event to a widget | ||
if (type in widget) { | ||||
// back-compat, remove for 2.0 | ||||
cin
|
r1 | return widget.connect(widget, type, callback as EventListener); | ||
cin
|
r0 | } else { | ||
// 1.x may never hit this branch, but it's the default for 2.0 | ||||
return widget.on(type, callback); | ||||
} | ||||
cin
|
r1 | |||
cin
|
r0 | }); | ||
// don't process widgets internals | ||||
return false; | ||||
} | ||||
} | ||||
return super._processTemplateNode(baseNode, getAttrFunc, attachFunc); | ||||
} | ||||
} | ||||