1 /* This file is part of NIT ( http://www.nitlanguage.org ).
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
15 Documentation generator for the nit language.
16 Generate API documentation in HTML format from nit source code.
19 var Nitdoc
= Nitdoc ||
{};
24 * Enhance nitdoc usability with JS features
27 Nitdoc
.UI
= function() {
29 // Allow user to fold sidebar nav elements on click
30 var enableFolding
= function(containerSelector
) {
31 var container
= $
(containerSelector
);
32 var foldLink
= $
(document
.createElement("a"))
33 .addClass("nitdoc-ui-fold")
36 container
.find("nav h3")
38 .css("cursor", "pointer")
41 $
(this).find("a.nitdoc-ui-fold").html("+");
42 $
(this).nextAll().toggle();
45 $
(this).find("a.nitdoc-ui-fold").html("-");
46 $
(this).nextAll().toggle();
51 // Allow user to copy signatures to clipboard with ZeroClipboard flahs plugin
52 // See: https://github.com/zeroclipboard/ZeroClipboard
53 var enableCopyToClipboard
= function(copySelector
) {
54 $
(copySelector
).each(function() {
55 var btn
= $
(document
.createElement("button"))
56 .addClass("nitdoc-ui-copy")
57 .attr("data-clipboard-text", $
(this).attr("data-untyped-signature"))
59 $
(document
.createElement("img"))
60 .attr("src", './resources/icons/copy.png')
65 var clip
= new ZeroClipboard($
("button.nitdoc-ui-copy"), {
66 moviePath
: "./ZeroClipboard.swf"
70 // Allow user to filter sidebar box entries by name
71 var enableSidebarTextFilters
= function(filterSelector
) {
72 var div
= $
(document
.createElement("div"))
73 .addClass("nitdoc-ui-filter")
75 $
(document
.createElement("input"))
76 .addClass("nitdoc-ui-filter-field")
77 .addClass("nitdoc-ui-filter-field-notused")
79 .attr("value", "filter...")
81 var box
= $
(this).parents("nav.filterable");
82 var value
= $
(this).val();
83 box
.find("ul li:not(:icontains('" + value
+ "'))").hide();
84 box
.find("ul li:icontains('" + value
+ "')").show();
86 .focusout(function() {
87 if($
(this).val() == "") {
88 $
(this).addClass("nitdoc-ui-filter-field-notused");
89 $
(this).val("filter...");
93 if($
(this).val() == "filter...") {
94 $
(this).removeClass("nitdoc-ui-filter-field-notused");
99 $
(filterSelector
).after(div
);
100 preloadSidebarTextFilters();
103 // Prealod filters using search query
104 var preloadSidebarTextFilters
= function() {
105 var anchor
= Nitdoc
.Utils
.extractAnchor(document
.location
.hash
);
106 if(!anchor || anchor
.indexOf("q=") == -1) return;
108 var query
= anchor
.substring(2);
111 $
(".nitdoc-ui-filter input:text")
113 .removeClass("nitdoc-ui-notused")
117 // Allow user to filter side bar box entries by Introduced/Refined/inHerited type
118 var enableSidebarTypeFilters
= function(filterSelector
) {
119 var box
= $
(filterSelector
);
122 box
.find("li").each(function() {
123 var span
= $
(this).find("span:first");
124 if(!types
[span
.html()]) types
[span
.html()] = {
125 title
: span
.attr("title"),
126 class: $
(this).attr("class")
130 for(var type
in types
) {
131 var a
= $
(document
.createElement("a"))
132 .addClass("nitdoc-ui-filter-link")
134 .attr("title", "Hide " + types
[type].title
)
135 .attr("data-filter-class", types
[type].class)
138 var hclass
= $
(this).attr("data-filter-class");
139 $
(this).parents(filterSelector
).find("li." + hclass
).hide();
140 $
(this).addClass("nitdoc-ui-filter-hidden")
143 var hclass
= $
(this).attr("data-filter-class");
144 $
(this).parents(filterSelector
).find("li." + hclass
).show();
145 $
(this).removeClass("nitdoc-ui-filter-hidden")
148 $
(filterSelector
).find(".nitdoc-ui-filter").append(a
);
154 enableFolding
: enableFolding
,
155 enableCopyToClipboard
: enableCopyToClipboard
,
156 enableSidebarTextFilters
: enableSidebarTextFilters
,
157 enableSidebarTypeFilters
: enableSidebarTypeFilters
163 // Init UI on page load
164 $
(document
).ready(function() {
165 Nitdoc
.UI
.enableFolding(".sidebar");
166 Nitdoc
.UI
.enableCopyToClipboard(".signature");
167 Nitdoc
.UI
.enableSidebarTextFilters("nav.filterable h3");
168 Nitdoc
.UI
.enableSidebarTypeFilters("nav.filterable");
177 Nitdoc
.Utils
= function() {
179 // Extract anchor part (after #) from URL string
180 var extractAnchor
= function(url
) {
181 var index
= url
.indexOf("#");
183 return url
.substring(index
+ 1);
190 extractAnchor
: extractAnchor
196 // JQuery Case Insensitive :icontains selector
197 $
.expr
[':'].icontains
= function(obj
, index
, meta
, stack
){
198 return (obj
.textContent
.replace(/\
[[0-9]+\
]/g
, "") || obj
.innerText
.replace(/\
[[0-9]+\
]/g
, "") ||
jQuery(obj
).text().replace(/\
[[0-9]+\
]/g
, "") ||
'').toLowerCase().indexOf(meta
[3].toLowerCase()) >= 0;