1318 |
alexandre_ |
1 |
/*
|
|
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
|
|
3 |
All Rights Reserved.
|
|
|
4 |
|
|
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
|
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
|
|
7 |
|
|
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
|
|
9 |
*/
|
|
|
10 |
|
1422 |
alexandre_ |
11 |
|
|
|
12 |
|
1318 |
alexandre_ |
13 |
dojo.provide("dojo.widget.DocPane");
|
|
|
14 |
dojo.require("dojo.widget.*");
|
|
|
15 |
dojo.require("dojo.io.*");
|
|
|
16 |
dojo.require("dojo.event.*");
|
|
|
17 |
dojo.require("dojo.widget.HtmlWidget");
|
|
|
18 |
dojo.require("dojo.widget.Editor2");
|
|
|
19 |
dojo.require("dojo.widget.Dialog");
|
|
|
20 |
dojo.require("dojo.html.common");
|
|
|
21 |
dojo.require("dojo.html.display");
|
|
|
22 |
dojo.widget.DocPane = function () {
|
|
|
23 |
dojo.event.topic.subscribe("/docs/function/results", this, "onDocResults");
|
|
|
24 |
dojo.event.topic.subscribe("/docs/package/results", this, "onPkgResults");
|
|
|
25 |
dojo.event.topic.subscribe("/docs/function/detail", this, "onDocSelectFunction");
|
|
|
26 |
};
|
|
|
27 |
dojo.widget.defineWidget("dojo.widget.DocPane", dojo.widget.HtmlWidget, {dialog:null, dialogBg:null, dialogFg:null, logIn:null, edit:null, save:null, cancel:null, detail:null, result:null, packag:null, fn:null, fnLink:null, count:null, row:null, summary:null, description:null, variables:null, vRow:null, vLink:null, vDesc:null, methods:null, mRow:null, mLink:null, mDesc:null, requires:null, rRow:null, rRow2:null, rH3:null, rLink:null, parameters:null, pRow:null, pLink:null, pDesc:null, pOpt:null, pType:null, sType:null, sName:null, sParams:null, sPType:null, sPTypeSave:null, sPName:null, sPNameSave:null, pkgDescription:null, _appends:[], templateString:"<div class=\"dojoDocPane\">\n\t<div dojoAttachPoint=\"containerNode\" class=\"container\"></div>\n\n\t<div dojoAttachPoint=\"dialog\" class=\"dialog\">\n\t\t<div class=\"container\" dojoAttachPoint=\"dialogBg\">\n\t\t\t<div class=\"docDialog\" dojoAttachPoint=\"dialogFg\">\n\t\t\t\t<h2>Log In</h2>\n\t\t\t\t<p><input id=\"dojoDocUserName\" dojoAttachPoint=\"userName\"><label for=\"dojoDocUserName\">User Name:</label></p>\n\t\t\t\t<p><input id=\"dojoDocPassword\" dojoAttachPoint=\"password\" type=\"password\"><label for=\"dojoDocPassword\">Password:</label></p>\n\t\t\t\t<p><input type=\"button\" dojoAttachPoint=\"cancel\" value=\"cancel\"> <input type=\"button\" dojoAttachPoint=\"logIn\" value=\"Log In\"></p>\n\t\t\t\t<p></p>\n\t\t\t</div>\n\t\t</div>\n\t</div>\n\n\t<div dojoAttachPoint=\"nav\" class=\"nav\"><span>Detail</span> | <span>Source</span> | <span>Examples</span> | <span>Walkthrough</span></div>\n\n\t<div dojoAttachPoint=\"detail\" class=\"detail\">\n\t\t<h1>Detail: <span class=\"fn\" dojoAttachPoint=\"fn\">dojo.select</span></h1>\n\t\t<div class=\"description\" dojoAttachPoint=\"description\">Description</div>\n\t\t<div class=\"params\" dojoAttachPoint=\"parameters\">\n\t\t\t<h2>Parameters</h2>\n\t\t\t<div class=\"row\" dojoAttachPoint=\"pRow\">\n\t\t\t\t<span dojoAttachPoint=\"pOpt\"><em>optional</em> </span>\n\t\t\t\t<span><span dojoAttachPoint=\"pType\">type</span> </span>\n\t\t\t\t<a href=\"#\" dojoAttachPoint=\"pLink\">variable</a>\n\t\t\t\t<span> - <span dojoAttachPoint=\"pDesc\"></span></span>\n\t\t\t</div>\n\t\t</div>\n\t\t<div class=\"variables\" dojoAttachPoint=\"variables\">\n\t\t\t<h2>Variables</h2>\n\t\t\t<div class\"row\" dojoAttachPoint=\"vRow\">\n\t\t\t\t<a href=\"#\" dojoAttachPoint=\"vLink\">variable</a><span> - <span dojoAttachPoint=\"vDesc\"></span></span>\n\t\t\t</div>\n\t\t</div>\n\t\t<div class=\"signature\">\n\t\t\t<h2>Signature</h2>\n\t\t\t<div class=\"source\">\n\t\t\t\t<span class=\"return\" dojoAttachPoint=\"sType\">returnType</span> \n\t\t\t\t<span class=\"function\" dojoAttachPoint=\"sName\">foo</span>\n\t\t\t\t(<span class=\"params\" dojoAttachPoint=\"sParams\">\n\t\t\t\t\t<span class=\"type\" dojoAttachPoint=\"sPType\">type </span>\n\t\t\t\t\t<span class=\"name\" dojoAttachPoint=\"sPName\">paramName</span>\n\t\t\t\t</span>)\n\t\t\t</div>\n\t\t</div>\n\t</div>\n\t\n\t<div dojoAttachPoint=\"result\" class=\"result\">\n\t\t<h1>Search Results: <span dojoAttachPoint=\"count\">0</span> matches</h1>\n\t\t<div class=\"row\" dojoAttachPoint=\"row\">\n\t\t\t<a href=\"#\" dojoAttachPoint=\"fnLink\">dojo.fnLink</a>\n\t\t\t<span> - <span class=\"summary\" dojoAttachPoint=\"summary\">summary</span></span>\n\t\t</div>\n\t</div>\n\n\t<div dojoAttachPoint=\"packag\" class=\"package\">\n\t\t<h1>Package: \n\t\t\t<span class=\"pkg\" dojoAttachPoint=\"pkg\">dojo.package</span> \n\t\t\t<span class=\"edit\" dojoAttachPoint=\"edit\">[edit]</span> \n\t\t\t<span class=\"save\" dojoAttachPoint=\"save\">[save]</span>\n\t\t</h1>\n\t\t<div dojoAttachPoint=\"pkgDescription\" class=\"description\">Description</div>\n\t\t<div class=\"methods\" dojoAttachPoint=\"methods\">\n\t\t\t<h2>Methods</h2>\n\t\t\t<div class=\"row\" dojoAttachPoint=\"mRow\">\n\t\t\t\t<a href=\"#\" dojoAttachPoint=\"mLink\">method</a>\n\t\t\t\t<span> - <span class=\"description\" dojoAttachPoint=\"mDesc\"></span></span>\n\t\t\t</div>\n\t\t</div>\n\t\t<div class=\"requires\" dojoAttachPoint=\"requires\">\n\t\t\t<h2>Requires</h2>\n\t\t\t<div class=\"row\" dojoAttachPoint=\"rRow\">\n\t\t\t\t<h3 dojoAttachPoint=\"rH3\">Environment</h3>\n\t\t\t\t<div dojoAttachPoint=\"rRow2\"><a href=\"#\" dojoAttachPoint=\"rLink\" class=\"package\">require</a></div>\n\t\t\t</div>\n\t\t</div>\n\t</div>\n</div>\n", templateCssString:".dojoDocPane { padding:1em; font: 1em Georgia,Times,\"Times New Roman\",serif; }\n\n.dojoDocPane .container{ }\n\n.dojoDocPane .dialog{ }\n.dojoDocPane .dialog .container{ padding: 0.5em; background: #fff; border: 2px solid #333; }\n.dojoDocPane .dialog .docDialog{ background: transparent; width: 20em; }\n.dojoDocPane .dialog .docDialog h2{ margin-top: 0; padding-top: 0; }\n.dojoDocPane .dialog .docDialog input { float: right; margin-right: 1em; }\n.dojoDocPane .dialog .docDialog p{ clear: both; }\n#dojoDocUserName, #dojoDocPassword { width: 10em; }\n\n.dojoDocPane .nav{ }\n.dojoDocPane .nav span{ }\n\n.dojoDocPane .detail{ }\n.dojoDocPane .detail h1{ }\n.dojoDocPane .detail h1 span.fn{ }\n.dojoDocPane .detail .description{ }\n.dojoDocPane .detail .params{ }\n.dojoDocPane .detail .params .row{ }\n.dojoDocPane .detail .params .row span{ }\n.dojoDocPane .detail .variables{ }\n.dojoDocPane .detail .variables .row{ }\n.dojoDocPane .detail .signature{ }\n.dojoDocPane .detail .signature .source{ white-space: pre; font: 0.8em Monaco, Courier, \"Courier New\", monospace; }\n.dojoDocPane .detail .signature .source .return{ color:#369; }\n.dojoDocPane .detail .signature .source .function{ color: #98543F; font-weight: bold; }\n.dojoDocPane .detail .signature .source .params{ }\n.dojoDocPane .detail .signature .source .params .type{ font-style: italic; color: #d17575; }\n.dojoDocPane .detail .signature .source .params .name{ color: #d14040; }\n\n.dojoDocPane .result{ }\n.dojoDocPane .result h1{ }\n.dojoDocPane .result .row{ }\n.dojoDocPane .result .row .summary{ }\n\n.dojoDocPane .package{ }\n.dojoDocPane .package h1{ }\n.dojoDocPane .package .row{ }\n.dojoDocPane .package .row .summary{ }\n.dojoDocPane .package .description{ }\n.dojoDocPane .package .methods{ }\n.dojoDocPane .package .methods h2{ }\n.dojoDocPane .package .methods .row{ }\n.dojoDocPane .package .methods .row .description{ }\n.dojoDocPane .package .requires{ }\n.dojoDocPane .package .requires h2{ }\n.dojoDocPane .package .requires .row{ }\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/DocPane.css"), isContainer:true, fillInTemplate:function () {
|
|
|
28 |
this.requires = dojo.html.removeNode(this.requires);
|
|
|
29 |
this.rRow.style.display = "none";
|
|
|
30 |
this.rRow2.style.display = "none";
|
|
|
31 |
this.methods = dojo.html.removeNode(this.methods);
|
|
|
32 |
this.mRow.style.display = "none";
|
|
|
33 |
this.dialog = dojo.widget.createWidget("dialog", {}, this.dialog);
|
|
|
34 |
this.dialog.setCloseControl(this.cancel);
|
|
|
35 |
dojo.html.setOpacity(this.dialogBg, 0.8);
|
|
|
36 |
dojo.html.setOpacity(this.dialogFg, 1);
|
|
|
37 |
dojo.event.connect(this.edit, "onclick", dojo.lang.hitch(this, function () {
|
|
|
38 |
if (!this._isLoggedIn) {
|
|
|
39 |
this.dialog.show();
|
|
|
40 |
}
|
|
|
41 |
}));
|
|
|
42 |
dojo.event.connect(this.logIn, "onclick", this, "_logIn");
|
|
|
43 |
dojo.event.connect(this.save, "onclick", this, "_save");
|
|
|
44 |
dojo.event.connect(dojo.docs, "logInSuccess", this, "_loggedIn");
|
|
|
45 |
this.homeSave = this.containerNode.cloneNode(true);
|
|
|
46 |
this.detailSave = dojo.html.removeNode(this.detail);
|
|
|
47 |
this.resultSave = dojo.html.removeNode(this.result);
|
|
|
48 |
this.packageSave = dojo.html.removeNode(this.packag);
|
|
|
49 |
this.results = dojo.html.removeNode(this.results);
|
|
|
50 |
this.rowParent = this.row.parentNode;
|
|
|
51 |
this.rowSave = dojo.html.removeNode(this.row);
|
|
|
52 |
this.vParent = this.vRow.parentNode;
|
|
|
53 |
this.vSave = dojo.html.removeNode(this.vRow);
|
|
|
54 |
this.pParent = this.pRow.parentNode;
|
|
|
55 |
this.pSave = dojo.html.removeNode(this.pRow);
|
|
|
56 |
this.sPTypeSave = dojo.html.removeNode(this.sPType);
|
|
|
57 |
this.sPNameSave = dojo.html.removeNode(this.sPName);
|
|
|
58 |
this.navSave = dojo.html.removeNode(this.nav);
|
|
|
59 |
}, _logIn:function () {
|
|
|
60 |
dojo.docs.setUserName(this.userName.value);
|
|
|
61 |
dojo.docs.setPassword(this.password.value);
|
|
|
62 |
}, _loggedIn:function () {
|
|
|
63 |
this._isLoggedIn = true;
|
|
|
64 |
this.dialog.hide();
|
|
|
65 |
this.pkgEditor = dojo.widget.createWidget("editor2", {toolbarAlwaysVisible:true}, this.pkgDescription);
|
|
|
66 |
}, _save:function () {
|
|
|
67 |
if (this.pkgEditor) {
|
|
|
68 |
dojo.docs.savePackage(this._pkgPath, {description:this.pkgEditor.getEditorContent()});
|
|
|
69 |
}
|
|
|
70 |
}, onDocSelectFunction:function (message) {
|
|
|
71 |
dojo.debug("onDocSelectFunction()");
|
|
|
72 |
for (var key in message) {
|
|
|
73 |
dojo.debug(key + ": " + dojo.json.serialize(message[key]));
|
|
|
74 |
}
|
|
|
75 |
var meta = message.meta;
|
|
|
76 |
if (meta) {
|
|
|
77 |
var variables = meta.variables;
|
|
|
78 |
var this_variables = meta.this_variables;
|
|
|
79 |
var child_variables = meta.child_variables;
|
|
|
80 |
var parameters = meta.parameters;
|
|
|
81 |
}
|
|
|
82 |
var doc = message.doc;
|
|
|
83 |
dojo.debug(dojo.json.serialize(doc));
|
|
|
84 |
var appends = this._appends;
|
|
|
85 |
dojo.html.removeChildren(this.domNode);
|
|
|
86 |
this.fn.innerHTML = message.name;
|
|
|
87 |
this.variables.style.display = "block";
|
|
|
88 |
var all = [];
|
|
|
89 |
if (variables) {
|
|
|
90 |
all = variables;
|
|
|
91 |
}
|
|
|
92 |
if (this_variables) {
|
|
|
93 |
all = all.concat(this_variables);
|
|
|
94 |
}
|
|
|
95 |
if (child_variables) {
|
|
|
96 |
all = all.concat(child_variables);
|
|
|
97 |
}
|
|
|
98 |
if (!all.length) {
|
|
|
99 |
this.variables.style.display = "none";
|
|
|
100 |
} else {
|
|
|
101 |
for (var i = 0, one; one = all[i]; i++) {
|
|
|
102 |
this.vLink.innerHTML = one;
|
|
|
103 |
this.vDesc.parentNode.style.display = "none";
|
|
|
104 |
appends.push(this.vParent.appendChild(this.vSave.cloneNode(true)));
|
|
|
105 |
}
|
|
|
106 |
}
|
|
|
107 |
this.sParams.innerHTML = "";
|
|
|
108 |
var first = true;
|
|
|
109 |
for (var param in parameters) {
|
|
|
110 |
var paramType = parameters[param].type;
|
|
|
111 |
var paramSummary = parameters[param].summary;
|
|
|
112 |
var paramName = param;
|
|
|
113 |
this.parameters.style.display = "block";
|
|
|
114 |
this.pLink.innerHTML = paramName;
|
|
|
115 |
this.pOpt.style.display = "none";
|
|
|
116 |
if (parameters[param].opt) {
|
|
|
117 |
this.pOpt.style.display = "inline";
|
|
|
118 |
}
|
|
|
119 |
this.pType.parentNode.style.display = "none";
|
|
|
120 |
if (parameters[param][0]) {
|
|
|
121 |
this.pType.parentNode.style.display = "inline";
|
|
|
122 |
this.pType.innerHTML = paramType;
|
|
|
123 |
}
|
|
|
124 |
this.pDesc.parentNode.style.display = "none";
|
|
|
125 |
if (paramSummary) {
|
|
|
126 |
this.pDesc.parentNode.style.display = "inline";
|
|
|
127 |
this.pDesc.innerHTML = paramSummary;
|
|
|
128 |
}
|
|
|
129 |
appends.push(this.pParent.appendChild(this.pSave.cloneNode(true)));
|
|
|
130 |
if (!first) {
|
|
|
131 |
this.sParams.appendChild(document.createTextNode(", "));
|
|
|
132 |
}
|
|
|
133 |
first = false;
|
|
|
134 |
if (paramType) {
|
|
|
135 |
dojo.debug(this.sPTypeSave);
|
|
|
136 |
this.sPTypeSave.innerHTML = paramType;
|
|
|
137 |
this.sParams.appendChild(this.sPTypeSave.cloneNode(true));
|
|
|
138 |
this.sParams.appendChild(document.createTextNode(" "));
|
|
|
139 |
}
|
|
|
140 |
dojo.debug(this.sPNameSave);
|
|
|
141 |
this.sPNameSave.innerHTML = paramName;
|
|
|
142 |
this.sParams.appendChild(this.sPNameSave.cloneNode(true));
|
|
|
143 |
}
|
|
|
144 |
if (message.returns) {
|
|
|
145 |
this.sType.innerHTML = message.returns;
|
|
|
146 |
} else {
|
|
|
147 |
this.sType.innerHTML = "void";
|
|
|
148 |
}
|
|
|
149 |
this.sName.innerHTML = message.name;
|
|
|
150 |
this.domNode.appendChild(this.navSave);
|
|
|
151 |
this.domNode.appendChild(this.detailSave.cloneNode(true));
|
|
|
152 |
for (var i = 0, append; append = appends[i]; i++) {
|
|
|
153 |
dojo.html.removeNode(append);
|
|
|
154 |
}
|
|
|
155 |
}, onPkgResult:function (results) {
|
|
|
156 |
if (this.pkgEditor) {
|
|
|
157 |
this.pkgEditor.close(true);
|
|
|
158 |
dojo.debug(this.pkgDescription);
|
|
|
159 |
}
|
|
|
160 |
var methods = results.methods;
|
|
|
161 |
var requires = results.requires;
|
|
|
162 |
var description = results.description;
|
|
|
163 |
this._pkgPath = results.path;
|
|
|
164 |
var requireLinks = [];
|
|
|
165 |
var appends = this._appends;
|
|
|
166 |
while (appends.length) {
|
|
|
167 |
dojo.html.removeNode(appends.shift());
|
|
|
168 |
}
|
|
|
169 |
dojo.html.removeChildren(this.domNode);
|
|
|
170 |
this.pkg.innerHTML = results.pkg;
|
|
|
171 |
var hasRequires = false;
|
|
|
172 |
for (var env in requires) {
|
|
|
173 |
hasRequires = true;
|
|
|
174 |
this.rH3.style.display = "none";
|
|
|
175 |
if (env != "common") {
|
|
|
176 |
this.rH3.style.display = "";
|
|
|
177 |
this.rH3.innerHTML = env;
|
|
|
178 |
}
|
|
|
179 |
for (var i = 0, require; require = requires[env][i]; i++) {
|
|
|
180 |
requireLinks.push({name:require});
|
|
|
181 |
this.rLink.innerHTML = require;
|
|
|
182 |
this.rLink.href = "#" + require;
|
|
|
183 |
var rRow2 = this.rRow2.parentNode.insertBefore(this.rRow2.cloneNode(true), this.rRow2);
|
|
|
184 |
rRow2.style.display = "";
|
|
|
185 |
appends.push(rRow2);
|
|
|
186 |
}
|
|
|
187 |
var rRow = this.rRow.parentNode.insertBefore(this.rRow.cloneNode(true), this.rRow);
|
|
|
188 |
rRow.style.display = "";
|
|
|
189 |
appends.push(rRow);
|
|
|
190 |
}
|
|
|
191 |
if (hasRequires) {
|
|
|
192 |
appends.push(this.packageSave.appendChild(this.requires.cloneNode(true)));
|
|
|
193 |
}
|
|
|
194 |
if (results.size) {
|
|
|
195 |
for (var i = 0, method; method = methods[i]; i++) {
|
|
|
196 |
this.mLink.innerHTML = method.name;
|
|
|
197 |
this.mLink.href = "#" + method.name;
|
|
|
198 |
this.mDesc.parentNode.style.display = "none";
|
|
|
199 |
if (method.summary) {
|
|
|
200 |
this.mDesc.parentNode.style.display = "inline";
|
|
|
201 |
this.mDesc.innerHTML = method.summary;
|
|
|
202 |
}
|
|
|
203 |
var mRow = this.mRow.parentNode.insertBefore(this.mRow.cloneNode(true), this.mRow);
|
|
|
204 |
mRow.style.display = "";
|
|
|
205 |
appends.push(mRow);
|
|
|
206 |
}
|
|
|
207 |
appends.push(this.packageSave.appendChild(this.methods.cloneNode(true)));
|
|
|
208 |
}
|
|
|
209 |
this.domNode.appendChild(this.packageSave);
|
|
|
210 |
this.pkgDescription.innerHTML = description;
|
|
|
211 |
function makeSelect(fOrP, x) {
|
|
|
212 |
return function (e) {
|
|
|
213 |
dojo.event.topic.publish("/docs/" + fOrP + "/select", x);
|
|
|
214 |
};
|
|
|
215 |
}
|
|
|
216 |
var as = this.domNode.getElementsByTagName("a");
|
|
|
217 |
for (var i = 0, a; a = as[i]; i++) {
|
|
|
218 |
if (a.className == "docMLink") {
|
|
|
219 |
dojo.event.connect(a, "onclick", makeSelect("function", methods[i]));
|
|
|
220 |
} else {
|
|
|
221 |
if (a.className == "docRLink") {
|
|
|
222 |
dojo.event.connect(a, "onclick", makeSelect("package", requireLinks[i]));
|
|
|
223 |
}
|
|
|
224 |
}
|
|
|
225 |
}
|
|
|
226 |
}, onDocResults:function (fns) {
|
|
|
227 |
dojo.debug("onDocResults(): called");
|
|
|
228 |
if (fns.length == 1) {
|
|
|
229 |
dojo.event.topic.publish("/docs/function/select", fns[0]);
|
|
|
230 |
return;
|
|
|
231 |
}
|
|
|
232 |
dojo.html.removeChildren(this.domNode);
|
|
|
233 |
this.count.innerHTML = fns.length;
|
|
|
234 |
var appends = [];
|
|
|
235 |
for (var i = 0, fn; fn = fns[i]; i++) {
|
|
|
236 |
this.fnLink.innerHTML = fn.name;
|
|
|
237 |
this.fnLink.href = "#" + fn.name;
|
|
|
238 |
if (fn.id) {
|
|
|
239 |
this.fnLink.href = this.fnLink.href + "," + fn.id;
|
|
|
240 |
}
|
|
|
241 |
this.summary.parentNode.style.display = "none";
|
|
|
242 |
if (fn.summary) {
|
|
|
243 |
this.summary.parentNode.style.display = "inline";
|
|
|
244 |
this.summary.innerHTML = fn.summary;
|
|
|
245 |
}
|
|
|
246 |
appends.push(this.rowParent.appendChild(this.rowSave.cloneNode(true)));
|
|
|
247 |
}
|
|
|
248 |
function makeSelect(x) {
|
|
|
249 |
return function (e) {
|
|
|
250 |
dojo.event.topic.publish("/docs/function/select", x);
|
|
|
251 |
};
|
|
|
252 |
}
|
|
|
253 |
this.domNode.appendChild(this.resultSave.cloneNode(true));
|
|
|
254 |
var as = this.domNode.getElementsByTagName("a");
|
|
|
255 |
for (var i = 0, a; a = as[i]; i++) {
|
|
|
256 |
dojo.event.connect(a, "onclick", makeSelect(fns[i]));
|
|
|
257 |
}
|
|
|
258 |
for (var i = 0, append; append = appends[i]; i++) {
|
|
|
259 |
this.rowParent.removeChild(append);
|
|
|
260 |
}
|
|
|
261 |
}});
|
|
|
262 |
|