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