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 */ | 7 */ |
8 WebInspector.DocumentationURLProvider = function() | 8 WebInspector.DocumentationURLProvider = function() |
9 { | 9 { |
10 } | 10 } |
11 | 11 |
12 /** | 12 /** |
13 * @const | 13 * @const |
14 * @type {!Array.<{source: !Object, url: string, name: string}>} | 14 * @type {!Array.<{source: !Object, url: string, name: string}>} |
15 */ | 15 */ |
16 WebInspector.DocumentationURLProvider._sources = [ | 16 WebInspector.DocumentationURLProvider._sources = [ |
17 { source: window, url: "javascript/", name: "Global" }, | 17 { source: window, url: "javascript/", name: "Global" }, |
18 { source: window.Node.prototype, url: "dom/Node/", name: "Node.prototype" }, | 18 { source: window.Node.prototype, url: "dom/Node/", name: "Node.prototype" }, |
19 { source: window.Node, url: "dom/Node/", name: "Node" }, | 19 { source: window.Node, url: "dom/Node/", name: "Node" }, |
20 { source: window.Object.prototype, url: "javascript/Object/", name: "Object. prototype" }, | 20 { source: window.Object.prototype, url: "javascript/Object/", name: "Object. prototype" }, |
21 { source: window.Object, url: "javascript/Object/", name: "Object" }, | 21 { source: window.Object, url: "javascript/Object/", name: "Object" }, |
22 { source: window.Math, url: "javascript/Math/", name: "Math" }, | 22 { source: window.Math, url: "javascript/Math/", name: "Math" }, |
23 { source: window.Array.prototype, url: "javascript/Array/", name: "Array.pro totype" }, | 23 { source: window.Array.prototype, url: "javascript/Array/", name: "Array.pro totype" }, |
24 { source: window.Array, url: "javascript/Array/", name: "Array" }, | 24 { source: window.Array, url: "javascript/Array/", name: "Array" }, |
25 { source: window.String.prototype, url: "javascript/String/", name: "String. prototype" }, | 25 { source: window.String.prototype, url: "javascript/String/", name: "String. prototype" }, |
26 { source: window.String, url: "javascript/String/", name: "String" }, | 26 { source: window.String, url: "javascript/String/", name: "String" }, |
27 { source: window.Date.prototype, url: "javascript/Date/", name: "Date.protot ype" }, | 27 { source: window.Date.prototype, url: "javascript/Date/", name: "Date.protot ype" }, |
28 { source: window.Date, url: "javascript/Date/", name: "Date" }, | 28 { source: window.Date, url: "javascript/Date/", name: "Date" }, |
29 { source: window.JSON, url: "javascript/JSON/", name: "JSON" } | 29 { source: window.JSON, url: "javascript/JSON/", name: "JSON" }, |
30 { source: window.Number, url: "javascript/Number/", name: "Number"}, | |
31 { source: window.Number.prototype, url: "javascript/Number/", name: "Number. prototype"}, | |
32 { source: window.Error.prototype, url: "javascript/Error/", name: "Error.pro totype"}, | |
33 { source: window.RegExp.prototype, url: "javascript/RegExp/", name: "RegExp. prototype"} | |
30 ]; | 34 ]; |
31 | 35 |
32 /** | 36 /** |
33 * @const | 37 * @const |
34 */ | 38 */ |
35 WebInspector.DocumentationURLProvider._urlFormat = "http://docs.webplatform.org/ w/api.php?action=query&titles=%s%s&prop=revisions&rvprop=timestamp|content&forma t=json" | 39 WebInspector.DocumentationURLProvider._urlFormat = "http://docs.webplatform.org/ w/api.php?action=query&titles=%s%s&prop=revisions&rvprop=timestamp|content&forma t=json" |
36 | 40 |
41 // FIXME: method hasOwnProperty can be used with every source object. | |
apavlov
2014/08/13 14:33:30
Please remove these comment lines. Since we check
| |
42 // Documentation is only on javascript/Object/hasOwnProperty | |
37 WebInspector.DocumentationURLProvider.prototype = { | 43 WebInspector.DocumentationURLProvider.prototype = { |
38 /** | 44 /** |
39 * @param {string} searchTerm | 45 * @param {string} searchTerm |
40 * @return {!Array.<{url: string, name: string}>} | 46 * @return {!Array.<{url: string, name: string}>} |
41 */ | 47 */ |
42 itemDescriptors: function(searchTerm) | 48 itemDescriptors: function(searchTerm) |
43 { | 49 { |
44 var possibleProperties = []; | 50 var descriptors = []; |
45 for (var i = 0; i < WebInspector.DocumentationURLProvider._sources.lengt h; ++i) { | 51 for (var i = 0; i < WebInspector.DocumentationURLProvider._sources.lengt h; ++i) { |
46 var sourceRef = WebInspector.DocumentationURLProvider._sources[i]; | 52 var sourceRef = WebInspector.DocumentationURLProvider._sources[i]; |
47 if (sourceRef.source[searchTerm] instanceof Function) { | 53 if (!sourceRef.source.hasOwnProperty(searchTerm)) |
48 var property = { | 54 continue; |
49 url: String.sprintf(WebInspector.DocumentationURLProvider._u rlFormat, sourceRef.url, searchTerm), | 55 descriptors.push(createDescriptor(searchTerm.toUpperCase() === searc hTerm ? "constants" : searchTerm)); |
50 name: sourceRef.name | |
51 }; | |
52 possibleProperties.push(property); | |
53 } | |
54 } | 56 } |
55 return possibleProperties; | 57 return descriptors; |
58 | |
59 /** | |
60 * @param {string} searchTerm | |
61 * @return {{url: string, name: string}} | |
62 */ | |
63 function createDescriptor(searchTerm) | |
64 { | |
65 return { | |
66 url: String.sprintf(WebInspector.DocumentationURLProvider._urlFo rmat, sourceRef.url, searchTerm), | |
67 name: sourceRef.name | |
68 }; | |
69 } | |
56 } | 70 } |
57 } | 71 } |
OLD | NEW |