forked from jaspervanderhoek/JavaConcepts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpText.js
More file actions
144 lines (126 loc) · 3.69 KB
/
HelpText.js
File metadata and controls
144 lines (126 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
The Help Text Viewer provides the possibility to enhance your forms by adding help buttons.
These buttons display a help message when clicked or hovered.
Optionally, the buttons can be hidden by default, with a global switch (the Help Text Trigger) to show or hide them.
*/
dojo.provide("HelpText.widget.HelpText");
mxui/widget.declare('HelpText.widget.HelpText', {
inputargs: {
text : '',
startvisible : false,
showonhover : true,
width : 300,
height : 300,
closeClick : false,
position : 'popup'
},
//IMPLEMENTATION
domNode: null,
topic : "CustomWidget/HelpText",
imgNode : null,
handle : null,
helpNode : null,
helpvisible: false,
windowEvt : null,
postCreate : function(){
logger.debug(this.id + ".postCreate");
//img node
this.imgNode = mxui/dom.div({
'class' : 'HelpTextButton'
});
this.domNode.appendChild(this.imgNode);
this.connect(this.imgNode, 'onclick', dojo.hitch(this, this.toggleHelp, true));
if (this.showonhover) {
this.connect(this.imgNode, 'onmouseenter', dojo.hitch(this, this.showHelp, true, false));
this.connect(this.imgNode, 'onmouseleave', dojo.hitch(this, this.showHelp, false, false));
}
//help node
this.createHelp();
this.stateChange(this.startvisible);
this.handle = dojo.subscribe(this.topic, this, this.stateChange);
this.actLoaded();
},
stateChange : function(newstate) {
if (newstate)
dojo.style(this.imgNode, "display", "block")
else if (!this.startvisible) {
this.helpvisible = false;
dojo.style(this.imgNode, "display", "none");
this.showHelp(false);
}
},
createHelp : function () {
this.helpNode = mxui.dom.div({'class' : 'HelpTextBox'});
var input = this.text.replace(/\n/g, '<br />');
dojo.html.set(this.helpNode, input);
dojo.style(this.helpNode, {
'width' : this.width + 'px',
'maxHeight' : this.height + 'px'
});
this.connect(this.helpNode, 'onclick', dojo.hitch(this, this.toggleHelp, true));
//document.body.appendChild(this.helpNode);
if (this.position == 'popup')
dojo.body().appendChild(this.helpNode);
else {
this.domNode.appendChild(this.helpNode);
dojo.style(this.domNode, 'position', 'relative');
}
},
toggleHelp : function(clicked, e) {
this.helpvisible = !this.helpvisible;
this.showHelp(this.helpvisible, clicked);
if (e)
dojo.stopEvent(e);
},
windowClick : function () {
this.disconnect(this.windowEvt);
this.windowEvt = null;
this.toggleHelp(true);
},
showHelp : function(show, clicked) {
if (show || this.helpvisible) {
if (this.closeClick && clicked)
this.windowEvt = this.connect(document.body, 'onclick', this.windowClick);
if (this.position == 'popup') {
var coords = dojo.coords(this.imgNode, true);
dojo.style(this.helpNode, {
'display' : 'block',
'top' : (coords.y + 30)+'px',
'left': (window.innerWidth < coords.x + 30 + this.width ? coords.x - this.height - 30 : coords.x + 30)+'px'
});
}
else {
dojo.style(this.helpNode, {
'display' : 'block',
'top' : '30px',
'left': this.position == 'right' ? '30px' : (-30 - this.width) + 'px'
});
}
}
else
dojo.style(this.helpNode, 'display', 'none');
},
suspended : function() {
if (this.windowEvt != null) {
this.disconnect(this.windowEvt);
this.windowEvt = null;
}
this.showHelp(false);
},
uninitialize : function() {
try {
if (this.windowEvt != null) {
this.disconnect(this.windowEvt);
this.windowEvt = null;
logger.debug(this.id + ".uninitialize");
}
if (this.helpNode != null)
document.body.removeChild(this.helpNode);
if (this.handle != null)
dojo.unsubscribe(this.handle);
}
catch(e) {
logger.warn("error on helptextviewer unload: " + e);
}
}
});