-
Notifications
You must be signed in to change notification settings - Fork 0
/
Documentation.js
186 lines (146 loc) · 8.56 KB
/
Documentation.js
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// This file is part of DQX - (C) Copyright 2014, Paul Vauterin, Ben Jeffery, Alistair Miles <[email protected]>
// This program is free software licensed under the GNU Affero General Public License.
// You can find a copy of this license in LICENSE in the top directory of the source code or at <http://opensource.org/licenses/AGPL-3.0>
/************************************************************************************************************************************
*************************************************************************************************************************************
Handles the display of documentation (help) in a popup mini-browser
Use Documentation.showHelp to show a help topic
*************************************************************************************************************************************
*************************************************************************************************************************************/
define(["jquery", "DQX/Utils", "DQX/DocEl", "DQX/Msg", "DQX/Popup"],
function ($, DQX, DocEl, Msg, Popup) {
var Documentation = {};
Documentation.topicStack = [];
Documentation.topicStackPointer = -1;
Documentation._onCancel = function () {
$('#DocuBoxBackGround').remove();
DQX.unRegisterGlobalKeyDownReceiver('DocuBox');
}
closeDocumentation = function () {
Documentation._onCancel();
}
Documentation._onPrevious = function () {
if (Documentation.topicStackPointer > 0) {
Documentation.topicStackPointer--;
Documentation._displayHelp(Documentation.topicStack[Documentation.topicStackPointer].url, Documentation.topicStack[Documentation.topicStackPointer].scrollPos);
}
}
Documentation._onNext = function () {
if (Documentation.topicStackPointer < Documentation.topicStack.length - 1) {
Documentation.topicStackPointer++;
Documentation._displayHelp(Documentation.topicStack[Documentation.topicStackPointer].url, Documentation.topicStack[Documentation.topicStackPointer].scrollPos);
}
}
Documentation._createBox = function () {
if ($('#DocuBoxBackGround').length > 0)
return;
Documentation.topicStack = [];
Documentation.topicStackPointer = -1;
var background = DocEl.Div({ id: 'DocuBoxBackGround' });
background.addStyle("position", "absolute");
background.addStyle("left", '0px');
background.addStyle("top", '0px');
background.addStyle('width', '100%');
background.addStyle('height', '100%');
var wizbackcol = 'rgba(100,100,100,0.4)';
background.addStyle('background-color', wizbackcol);
background.addStyle('z-index', '2000');
$('#DQXUtilContainer').append(background.toString());
$('#DocuBoxBackGround').mousedown(function (ev) {
if (ev.target.id == 'DocuBoxBackGround') {
$('#DocuBoxBackGround').css('background-color', 'rgba(50,50,50,0.6)');
setTimeout(function () {
$('#DocuBoxBackGround').css('background-color', wizbackcol);
setTimeout(function () {
$('#DocuBoxBackGround').css('background-color', 'rgba(50,50,50,0.6)');
setTimeout(function () {
$('#DocuBoxBackGround').css('background-color', wizbackcol);
}, 150);
}, 150);
}, 150);
//alert("Please close the wizard if you want to return to the application");
}
});
var pageSizeX = DQX.getWindowClientW();
var pageSizeY = DQX.getWindowClientH();
var boxSizeX = Math.min(800, pageSizeX - 100);
var box = DocEl.Div({ id: 'DocuBox' });
box.addStyle("position", "absolute");
box.addStyle("left", (pageSizeX - boxSizeX) / 2 + 'px');
box.addStyle("top", 50 + 'px');
box.addStyle('width', boxSizeX + 'px');
box.setCssClass("DQXDocuBox");
//box.addStyle("overflow", "hidden");
var thecloser = DocEl.JavaScriptBitmaplink(DQX.BMP("close2.png"), "Close", "closeDocumentation();");
box.addElem(thecloser);
thecloser.addStyle('position', 'absolute');
thecloser.addStyle('right', '-16px');
thecloser.addStyle('top', '-16px');
var boxHeader = DocEl.Div({ id: 'DocuBoxHeader', parent: box });
boxHeader.setCssClass("DQXDocuBoxHeader DQXDragHeader");
//boxHeader.addElem('Help');
var boxFooter = DocEl.Div({ id: 'DocuBoxFooter', parent: box });
boxFooter.setCssClass("DQXDocuBoxFooter");
var boxButtons = DocEl.Div({ id: 'DocuBoxButtons', parent: boxFooter });
var buttons = [
// { id: 'DocuBoxButtonCancel', name: '', bitmap: DQX.BMP('cancel.png'), handler: Documentation._onCancel },
{id: 'DocuBoxButtonPrevious', name: '', bitmap: DQX.BMP('arrow5left.png'), handler: Documentation._onPrevious },
{ id: 'DocuBoxButtonNext', name: '', bitmap: DQX.BMP('arrow5right.png'), handler: Documentation._onNext },
];
for (var buttonNr = 0; buttonNr < buttons.length; buttonNr++) {
var button = buttons[buttonNr];
var boxButtonCancel = DocEl.Div({ id: button.id, parent: boxButtons });
boxButtonCancel.setCssClass("DQXDocuButton");
boxButtonCancel.addElem('<IMG SRC="' + button.bitmap + '" border=0 ALT="" style="margin-right:3px;margin-left:3px"></IMG>');
boxButtonCancel.addElem(button.name);
}
//boxButtons.addElem("<b>This is the title</b>");
var boxContent = DocEl.Div({ id: 'DocuBoxContent', parent: box });
boxContent.setCssClass("DQXDocuBoxBody");
boxContent.addStyle('max-height', (pageSizeY - 100 - 100) + 'px');
//boxContent.setHeightPx(boxSizeY - 4 - 105);
$('#DocuBoxBackGround').append(box.toString());
Popup.makeDraggable('DocuBox');
for (var buttonNr = 0; buttonNr < buttons.length; buttonNr++) {
var button = buttons[buttonNr];
$('#' + button.id).click($.proxy(button.handler, this));
}
DQX.registerGlobalKeyDownReceiver(function (ev) {
if (ev.isEscape) Documentation._onCancel('DocuBox');
}, 'DocuBox');
//Documentation.scrollHelper = DQX.scrollHelper($('#DocuBoxContent'));
}
//Show a help box corresponding to a help id item in the DOM
Documentation.showHelp = function (url) {
if (Documentation.topicStackPointer >= 0)
Documentation.topicStack[Documentation.topicStackPointer].scrollPos = $('#DocuBoxContent').scrollTop();
Documentation._createBox();
Documentation.topicStack = Documentation.topicStack.slice(0, Documentation.topicStackPointer + 1);
Documentation.topicStack.push({ url: url, scrollPos: 0 });
Documentation.topicStackPointer = Documentation.topicStack.length - 1;
Documentation._displayHelp(url,0);
}
Documentation._displayHelp = function (url, scrollPos) {
$('#DocuBoxButtonPrevious').css('opacity', (Documentation.topicStackPointer > 0) ? 1 : 0.3);
$('#DocuBoxButtonNext').css('opacity', (Documentation.topicStackPointer < Documentation.topicStack.length - 1) ? 1 : 0.3);
DQX.setProcessing("Downloading...");
$.get(url, {})
.done(function (data) {
DQX.stopProcessing();
$('#DocuBoxContent').html($('<div/>').append(DQX.interpolate(data)).find('.DQXHelpContent').html());
if (scrollPos)
$('#DocuBoxContent').scrollTop(scrollPos);
else
$('#DocuBoxContent').scrollTop(0);
//Documentation.scrollHelper.update();
})
.fail(function () {
DQX.stopProcessing();
alert("Failed to download documentation item '" + url + "'");
});
}
Msg.listen('', { type: 'ShowHelp' }, function (context, helpid) {
Documentation.showHelp(helpid);
});
return Documentation;
});