OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @constructor | 6 * @constructor |
7 * @extends {WebInspector.View} | 7 * @extends {WebInspector.View} |
8 */ | 8 */ |
9 WebInspector.DocumentationView = function() | 9 WebInspector.DocumentationView = function() |
10 { | 10 { |
11 WebInspector.View.call(this); | 11 WebInspector.View.call(this); |
12 this.element.classList.add("documentation-view"); | 12 this.element.classList.add("documentation-view"); |
13 this.registerRequiredCSS("documentationView.css"); | 13 this.registerRequiredCSS("documentationView.css"); |
14 } | 14 } |
15 | 15 |
16 /** | 16 /** |
17 * @param {string} url | 17 * @param {string} url |
18 * @param {string} searchItem | 18 * @param {string} searchItem |
19 */ | 19 */ |
20 WebInspector.DocumentationView.showDocumentationURL = function(url, searchItem) | 20 WebInspector.DocumentationView.showDocumentationURL = function(url, searchItem) |
21 { | 21 { |
22 if (!WebInspector.DocumentationView._view) | 22 if (!WebInspector.DocumentationView._view) |
23 WebInspector.DocumentationView._view = new WebInspector.DocumentationVie w(); | 23 WebInspector.DocumentationView._view = new WebInspector.DocumentationVie w(); |
24 var view = WebInspector.DocumentationView._view; | 24 var view = WebInspector.DocumentationView._view; |
25 view.element.removeChildren(); | |
25 WebInspector.inspectorView.showCloseableViewInDrawer("documentation", WebIns pector.UIString("Documentation"), view); | 26 WebInspector.inspectorView.showCloseableViewInDrawer("documentation", WebIns pector.UIString("Documentation"), view); |
26 view.showDocumentation(url, searchItem); | 27 view.showDocumentation(url, searchItem); |
27 } | 28 } |
28 | 29 |
29 WebInspector.DocumentationView._languageToMimeType = { | 30 WebInspector.DocumentationView._languageToMimeType = { |
30 "javascript": "text/javascript", | 31 "javascript": "text/javascript", |
31 "html": "text/html" | 32 "html": "text/html" |
32 }; | 33 }; |
33 | 34 |
34 WebInspector.DocumentationView.prototype = { | 35 WebInspector.DocumentationView.prototype = { |
(...skipping 19 matching lines...) Expand all Loading... | |
54 _createArticle: function(searchItem, responseText) | 55 _createArticle: function(searchItem, responseText) |
55 { | 56 { |
56 var json = JSON.parse(responseText); | 57 var json = JSON.parse(responseText); |
57 var pages = json["query"]["pages"]; | 58 var pages = json["query"]["pages"]; |
58 var wikiKeys = Object.keys(pages); | 59 var wikiKeys = Object.keys(pages); |
59 if (wikiKeys.length === 1 && wikiKeys[0] === "-1") { | 60 if (wikiKeys.length === 1 && wikiKeys[0] === "-1") { |
60 this._createEmptyPage(); | 61 this._createEmptyPage(); |
61 return; | 62 return; |
62 } | 63 } |
63 var wikiMarkupText = pages[wikiKeys[0]]["revisions"]["0"]["*"]; | 64 var wikiMarkupText = pages[wikiKeys[0]]["revisions"]["0"]["*"]; |
64 var article = WebInspector.JSArticle.parse(wikiMarkupText); | 65 try { |
66 var article = WebInspector.JSArticle.parse(wikiMarkupText); | |
67 } catch (error) { | |
68 this._createEmptyPage(); | |
69 } | |
65 if (!article) { | 70 if (!article) { |
66 this._createEmptyPage(); | 71 this._createEmptyPage(); |
67 return; | 72 return; |
68 } | 73 } |
69 | 74 |
75 this.element.removeChildren(); | |
70 var renderer = new WebInspector.DocumentationView.Renderer(article, sear chItem); | 76 var renderer = new WebInspector.DocumentationView.Renderer(article, sear chItem); |
71 this.element.removeChildren(); | |
72 this.element.appendChild(renderer.renderJSArticle()); | 77 this.element.appendChild(renderer.renderJSArticle()); |
73 }, | 78 }, |
74 | 79 |
75 _createEmptyPage: function() | 80 _createEmptyPage: function() |
76 { | 81 { |
77 this.element.removeChildren(); | 82 this.element.removeChildren(); |
78 var pageTitle = this.element.createChild("div", "documentation-page-titl e"); | 83 var pageTitle = this.element.createChild("div", "documentation-page-titl e"); |
79 pageTitle.textContent = WebInspector.UIString("Documentation not availab le"); | 84 pageTitle.textContent = WebInspector.UIString("Documentation not availab le"); |
80 }, | 85 }, |
81 | 86 |
87 _createPageForError: function(message) | |
loislo
2014/09/09 08:05:04
I don't see where you are using it.
iliia
2014/09/09 08:19:28
Done.
| |
88 { | |
89 this.element.removeChildren(); | |
90 var pageTitle = this.element.createChild("div", "documentation-page-titl e"); | |
91 pageTitle.textContent = WebInspector.UIString("We have some problems"); | |
92 var error = this.element.createChild("div", "documentation-text"); | |
93 error.textContent = WebInspector.UIString("Error message: " + message); | |
94 }, | |
95 | |
82 __proto__: WebInspector.View.prototype | 96 __proto__: WebInspector.View.prototype |
83 } | 97 } |
84 | 98 |
85 /** | 99 /** |
86 * @constructor | 100 * @constructor |
87 * @param {!WebInspector.JSArticle} article | 101 * @param {!WebInspector.JSArticle} article |
88 * @param {string} searchItem | 102 * @param {string} searchItem |
89 */ | 103 */ |
90 WebInspector.DocumentationView.Renderer = function(article, searchItem) | 104 WebInspector.DocumentationView.Renderer = function(article, searchItem) |
91 { | 105 { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 title.textContent = "Examples"; | 221 title.textContent = "Examples"; |
208 | 222 |
209 for (var i = 0; i < examples.length; ++i) { | 223 for (var i = 0; i < examples.length; ++i) { |
210 var example = section.createChild("div", "documentation-example"); | 224 var example = section.createChild("div", "documentation-example"); |
211 var exampleDescription = example.createChild("div", "documentation-e xample-description-section"); | 225 var exampleDescription = example.createChild("div", "documentation-e xample-description-section"); |
212 if (examples[i].liveUrl) { | 226 if (examples[i].liveUrl) { |
213 var liveUrl = exampleDescription.createChild("a", "documentation -example-link"); | 227 var liveUrl = exampleDescription.createChild("a", "documentation -example-link"); |
214 liveUrl.href = examples[i].liveUrl; | 228 liveUrl.href = examples[i].liveUrl; |
215 liveUrl.textContent = WebInspector.UIString("Example"); | 229 liveUrl.textContent = WebInspector.UIString("Example"); |
216 } | 230 } |
217 exampleDescription.appendChild(this._renderBlock(examples[i].descrip tion)); | 231 if (examples[i].description) |
232 exampleDescription.appendChild(this._renderBlock(examples[i].des cription)); | |
218 var code = example.createChild("div", "documentation-example-code"); | 233 var code = example.createChild("div", "documentation-example-code"); |
219 code.classList.add("source-code"); | 234 code.classList.add("source-code"); |
220 code.textContent = examples[i].code; | 235 code.textContent = examples[i].code; |
221 if (!examples[i].language) | 236 if (!examples[i].language) |
222 continue; | 237 continue; |
223 var syntaxHighlighter = new WebInspector.DOMSyntaxHighlighter(WebIns pector.DocumentationView._languageToMimeType[examples[i].language.toLowerCase()] , true); | 238 var syntaxHighlighter = new WebInspector.DOMSyntaxHighlighter(WebIns pector.DocumentationView._languageToMimeType[examples[i].language.toLowerCase()] , true); |
224 syntaxHighlighter.syntaxHighlightNode(code); | 239 syntaxHighlighter.syntaxHighlightNode(code); |
225 } | 240 } |
226 }, | 241 }, |
227 | 242 |
228 /** | 243 /** |
229 * @param {!WebInspector.WikiParser.ArticleElement} article | 244 * @param {!WebInspector.WikiParser.ArticleElement} article |
230 * @return {!Element} | 245 * @return {?Element} |
231 */ | 246 */ |
232 _renderBlock: function(article) | 247 _renderBlock: function(article) |
233 { | 248 { |
234 var element; | 249 var element; |
235 var elementTypes = WebInspector.WikiParser.ArticleElement.Type; | 250 var elementTypes = WebInspector.WikiParser.ArticleElement.Type; |
236 | 251 |
237 switch (article.type()) { | 252 switch (article.type()) { |
238 case elementTypes.Inline: | 253 case elementTypes.Inline: |
239 element = document.createElement("span"); | 254 element = document.createElement("span"); |
240 break; | 255 break; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 function computeDescriptors(column) | 352 function computeDescriptors(column) |
338 { | 353 { |
339 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column); | 354 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column); |
340 if (!token) | 355 if (!token) |
341 return []; | 356 return []; |
342 var tokenText = textEditor.line(textSelection.startLine).substring(t oken.startColumn, token.endColumn); | 357 var tokenText = textEditor.line(textSelection.startLine).substring(t oken.startColumn, token.endColumn); |
343 return urlProvider.itemDescriptors(tokenText); | 358 return urlProvider.itemDescriptors(tokenText); |
344 } | 359 } |
345 } | 360 } |
346 } | 361 } |
OLD | NEW |