Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / documentation / DocumentationURLProvider.js
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
3 // found in the LICENSE file.
4
5 /**
6  * @constructor
7  */
8 WebInspector.DocumentationURLProvider = function()
9 {
10 }
11
12 /**
13  * @const
14  * @type {!Array.<{source: !Object, url: string, name: string}>}
15  */
16 WebInspector.DocumentationURLProvider._sources = [
17     { source: window, url: "javascript/", name: "Global" },
18     { source: window.Node.prototype, url: "dom/Node/", name: "Node.prototype" },
19     { source: window.Node, url: "dom/Node/", name: "Node" },
20     { source: window.Object.prototype, url: "javascript/Object/", name: "Object.prototype" },
21     { source: window.Object, url: "javascript/Object/", name: "Object" },
22     { source: window.Math, url: "javascript/Math/", name: "Math" },
23     { source: window.Array.prototype, url: "javascript/Array/", name: "Array.prototype" },
24     { source: window.Array, url: "javascript/Array/", name: "Array" },
25     { source: window.String.prototype, url: "javascript/String/", name: "String.prototype" },
26     { source: window.String, url: "javascript/String/", name: "String" },
27     { source: window.Date.prototype, url: "javascript/Date/", name: "Date.prototype" },
28     { source: window.Date, url: "javascript/Date/", name: "Date" },
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.prototype"},
33     { source: window.RegExp.prototype, url: "javascript/RegExp/", name: "RegExp.prototype"}
34 ];
35
36 /**
37  * @const
38  */
39 WebInspector.DocumentationURLProvider._urlFormat = "http://docs.webplatform.org/w/api.php?action=query&titles=%s%s&prop=revisions&rvprop=timestamp|content&format=json"
40
41 /**
42  * @typedef {{url: string, name: string, searchItem: string}}
43  */
44 WebInspector.DocumentationURLProvider.ItemDescriptor;
45
46 WebInspector.DocumentationURLProvider.prototype = {
47     /**
48      * @param {string} searchTerm
49      * @return {!Array.<!WebInspector.DocumentationURLProvider.ItemDescriptor>}
50      */
51     itemDescriptors: function(searchTerm)
52     {
53         var descriptors = [];
54         for (var i = 0; i < WebInspector.DocumentationURLProvider._sources.length; ++i) {
55             var sourceRef = WebInspector.DocumentationURLProvider._sources[i];
56             if (!sourceRef.source.hasOwnProperty(searchTerm))
57                 continue;
58             descriptors.push(createDescriptor(searchTerm.toUpperCase() === searchTerm ? "constants" : searchTerm));
59         }
60         return descriptors;
61
62         /**
63          * @param {string} searchTerm
64          * @return {!WebInspector.DocumentationURLProvider.ItemDescriptor}
65          */
66         function createDescriptor(searchTerm)
67         {
68             return {
69                 url: String.sprintf(WebInspector.DocumentationURLProvider._urlFormat, sourceRef.url, searchTerm),
70                 name: sourceRef.name,
71                 searchItem: searchTerm
72             };
73         }
74     }
75 }