##// END OF EJS Templates
Added DjxFragment...
cin -
r19:8f4d5e2c719a v1.0.0-rc8 default
parent child
Show More
@@ -0,0 +1,23
1 import { _Widget } from "./WidgetContext";
2 import { MapOf } from "@implab/core-amd/interfaces";
3
4 /** Special widget used to create a document fragment */
5 export class DjxFragment implements _Widget {
6
7 domNode: Node;
8
9 containerNode?: Node;
10
11 constructor() {
12 this.domNode = this.containerNode = document.createDocumentFragment();
13 }
14
15 get(attr: string) {
16 return undefined;
17 }
18 set(attr: string, value: any): void;
19 set(attrs: MapOf<any>): void;
20 set() {
21 /* do nothing */
22 }
23 } No newline at end of file
@@ -68,6 +68,7 class DomInject {
68 trace.log("done {0}", url);
68 trace.log("done {0}", url);
69 } catch (e) {
69 } catch (e) {
70 trace.error("failed {0}: {1}", url, e);
70 trace.error("failed {0}: {1}", url, e);
71 throw e;
71 }
72 }
72 }
73 }
73
74
@@ -87,6 +88,7 class DomInject {
87 trace.log("done {0}", url);
88 trace.log("done {0}", url);
88 } catch (e) {
89 } catch (e) {
89 trace.error("failed {0}: {1}", url, e);
90 trace.error("failed {0}: {1}", url, e);
91 throw e;
90 }
92 }
91 }
93 }
92 };
94 };
@@ -1,4 +1,4
1 import { isNull, mixin, argumentNotNull } from "@implab/core-amd/safe";
1 import { isNull, mixin } from "@implab/core-amd/safe";
2 import { isPlainObject, isNode, isBuildContext, DojoNodePosition, BuildContext } from "./traits";
2 import { isPlainObject, isNode, isBuildContext, DojoNodePosition, BuildContext } from "./traits";
3
3
4 import dom = require("dojo/dom-construct");
4 import dom = require("dojo/dom-construct");
@@ -37,13 +37,13 export abstract class BuildContextBase i
37 } else if (isNode(v)) {
37 } else if (isNode(v)) {
38 return v;
38 return v;
39 } else if (isBuildContext(v)) {
39 } else if (isBuildContext(v)) {
40 return v.getDomElement();
40 return v.getDomNode();
41 } else {
41 } else {
42 throw new Error("Invalid parameter");
42 throw new Error("Invalid parameter");
43 }
43 }
44 }
44 }
45
45
46 abstract _getDomElement(): HTMLElement;
46 abstract _getDomNode(): Node;
47
47
48 ensureCreated() {
48 ensureCreated() {
49 if (!this._created) {
49 if (!this._created) {
@@ -54,13 +54,18 export abstract class BuildContextBase i
54 }
54 }
55 }
55 }
56
56
57 /** @deprecated use getDomNode() */
57 getDomElement() {
58 getDomElement() {
59 return this.getDomNode();
60 }
61
62 getDomNode() {
58 this.ensureCreated();
63 this.ensureCreated();
59 return this._getDomElement();
64 return this._getDomNode();
60 }
65 }
61
66
62 placeAt(refNode: string | Node, position?: DojoNodePosition) {
67 placeAt(refNode: string | Node, position?: DojoNodePosition) {
63 dom.place(this.getDomElement(), refNode, position);
68 dom.place(this.getDomNode(), refNode, position);
64 }
69 }
65
70
66 abstract _addChild(child: any): void;
71 abstract _addChild(child: any): void;
@@ -11,7 +11,7 import { Handle } from "dojo/interfaces"
11 export abstract class DjxWidgetBase extends djbase(_WidgetBase, _AttachMixin) {
11 export abstract class DjxWidgetBase extends djbase(_WidgetBase, _AttachMixin) {
12
12
13 buildRendering() {
13 buildRendering() {
14 this.domNode = this.render().getDomElement();
14 this.domNode = this.render().getDomNode();
15 super.buildRendering();
15 super.buildRendering();
16 }
16 }
17
17
@@ -35,7 +35,7 export class HtmlElementContext extends
35 children.forEach(v => this._addChild(v));
35 children.forEach(v => this._addChild(v));
36 }
36 }
37
37
38 _getDomElement() {
38 _getDomNode() {
39 if (!this._element)
39 if (!this._element)
40 throw new Error("The HTML element isn't created");
40 throw new Error("The HTML element isn't created");
41
41
@@ -1,16 +1,28
1 import dom = require("dojo/dom-construct");
1 import dom = require("dojo/dom-construct");
2 import { argumentNotNull } from "@implab/core-amd/safe";
2 import { argumentNotNull } from "@implab/core-amd/safe";
3 import _WidgetBase = require("dijit/_WidgetBase");
4 import { BuildContextBase } from "./BuildContextBase";
3 import { BuildContextBase } from "./BuildContextBase";
4 import { MapOf } from "@implab/core-amd/interfaces";
5
5
6 type _WidgetBaseConstructor = typeof _WidgetBase;
6 // tslint:disable-next-line: class-name
7 export interface _Widget {
8 domNode: Node;
9
10 get(attr: string): any;
11
12 set(attr: string, value: any): void;
13 set(attrs: MapOf<any>): void;
14
15 containerNode?: Node
16 }
17
18 export type _WidgetCtor = new (attrs: any, srcNode?: string | Node) => _Widget;
7
19
8 export class WidgetContext extends BuildContextBase {
20 export class WidgetContext extends BuildContextBase {
9 widgetClass: _WidgetBaseConstructor;
21 widgetClass: _WidgetCtor;
10
22
11 _instance: _WidgetBase | undefined;
23 _instance: _Widget | undefined;
12
24
13 constructor(widgetClass: _WidgetBaseConstructor) {
25 constructor(widgetClass: _WidgetCtor) {
14 super();
26 super();
15 argumentNotNull(widgetClass, "widgetClass");
27 argumentNotNull(widgetClass, "widgetClass");
16
28
@@ -34,7 +46,7 export class WidgetContext extends Build
34 children.forEach(x => this._addChild(x));
46 children.forEach(x => this._addChild(x));
35 }
47 }
36
48
37 _getDomElement() {
49 _getDomNode() {
38 if (!this._instance)
50 if (!this._instance)
39 throw new Error("The instance of the widget isn't created");
51 throw new Error("The instance of the widget isn't created");
40 return this._instance.domNode;
52 return this._instance.domNode;
@@ -5,15 +5,43 type _WidgetBaseConstructor = typeof _Wi
5 export type DojoNodePosition = "first" | "after" | "before" | "last" | "replace" | "only" | number;
5 export type DojoNodePosition = "first" | "after" | "before" | "last" | "replace" | "only" | number;
6
6
7 export interface BuildContext {
7 export interface BuildContext {
8 getDomElement(): HTMLElement;
8 getDomNode(): Node;
9
9
10 placeAt(refNode: string | Node, position?: DojoNodePosition): void;
10 placeAt(refNode: string | Node, position?: DojoNodePosition): void;
11 }
11 }
12
12
13 export function isNode(el: any): el is HTMLElement {
13 export function isNode(el: any): el is Node {
14 return el && el.nodeName && el.nodeType;
14 return el && el.nodeName && el.nodeType;
15 }
15 }
16
16
17 export function isElementNode(el: any): el is Element {
18 return isNode(el) && el.nodeType === 1;
19 }
20
21 export function isTextNode(el: any): el is Text {
22 return isNode(el) && el.nodeType === 3;
23 }
24
25 export function isProcessingInstructionNode(el: any): el is ProcessingInstruction {
26 return isNode(el) && el.nodeType === 7;
27 }
28
29 export function isCommentNode(el: any): el is Comment {
30 return isNode(el) && el.nodeType === 8;
31 }
32
33 export function isDocumentNode(el: any): el is Document {
34 return isNode(el) && el.nodeType === 9;
35 }
36
37 export function isDocumentTypeNode(el: any): el is DocumentType {
38 return isNode(el) && el.nodeType === 10;
39 }
40
41 export function isDocumentFragmentNode(el: any): el is DocumentFragment {
42 return isNode(el) && el.nodeType === 11;
43 }
44
17 export function isWidget(v: any): v is _WidgetBase {
45 export function isWidget(v: any): v is _WidgetBase {
18 return v && "domNode" in v;
46 return v && "domNode" in v;
19 }
47 }
General Comments 0
You need to be logged in to leave comments. Login now