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.
22 * Enhance nitdoc usability with JS features
28 ], function($
, ZeroClipboard
, utils
) {
32 // Allow user to fold sidebar nav elements on click
33 enableFolding
: function(containerSelector
) {
34 var container
= $
(containerSelector
);
35 var foldLink
= $
(document
.createElement("a"))
36 .addClass("nitdoc-ui-fold")
39 container
.find("nav h3")
41 .css("cursor", "pointer")
44 $
(this).find("a.nitdoc-ui-fold").html("+");
45 $
(this).nextAll().toggle();
48 $
(this).find("a.nitdoc-ui-fold").html("-");
49 $
(this).nextAll().toggle();
54 // Allow user to copy signatures to clipboard with ZeroClipboard flahs plugin
55 // See: https://github.com/zeroclipboard/ZeroClipboard
56 enableCopyToClipboard
: function(copySelector
) {
57 $
(copySelector
).each(function() {
58 var btn
= $
(document
.createElement("button"))
59 .addClass("nitdoc-ui-copy")
60 .attr("data-clipboard-text", $
(this).attr("data-untyped-signature"))
62 $
(document
.createElement("img"))
63 .attr("src", './resources/icons/copy.png')
68 var clip
= new ZeroClipboard($
("button.nitdoc-ui-copy"), {
69 moviePath
: "./ZeroClipboard.swf"
73 // Allow user to filter sidebar box entries by name
74 enableSidebarTextFilters
: function(filterSelector
) {
75 var div
= $
(document
.createElement("div"))
76 .addClass("nitdoc-ui-filter")
78 $
(document
.createElement("input"))
79 .addClass("nitdoc-ui-filter-field")
80 .addClass("nitdoc-ui-filter-field-notused")
82 .attr("value", "filter...")
84 var box
= $
(this).parents("nav.filterable");
85 var value
= $
(this).val();
86 box
.find("ul li:not(:icontains('" + value
+ "'))").hide();
87 box
.find("ul li:icontains('" + value
+ "')").show();
89 .focusout(function() {
90 if($
(this).val() == "") {
91 $
(this).addClass("nitdoc-ui-filter-field-notused");
92 $
(this).val("filter...");
96 if($
(this).val() == "filter...") {
97 $
(this).removeClass("nitdoc-ui-filter-field-notused");
102 $
(filterSelector
).after(div
);
103 this.preloadSidebarTextFilters();
106 // Prealod filters using search query
107 preloadSidebarTextFilters
: function() {
108 var anchor
= utils
.extractAnchor(document
.location
.hash
);
109 if(!anchor || anchor
.indexOf("q=") == -1) return;
111 var query
= anchor
.substring(2);
114 $
(".nitdoc-ui-filter input:text")
116 .removeClass("nitdoc-ui-notused")
120 // Allow user to filter side bar box entries by Introduced/Refined/inHerited type
121 enableSidebarTypeFilters
: function(filterSelector
) {
122 var box
= $
(filterSelector
);
125 box
.find("li").each(function() {
126 var span
= $
(this).find("span:first");
127 if(!types
[span
.html()]) types
[span
.html()] = {
128 title
: span
.attr("title"),
129 class: $
(this).attr("class")
133 for(var type
in types
) {
134 var a
= $
(document
.createElement("a"))
135 .addClass("nitdoc-ui-filter-link")
137 .attr("title", "Hide " + types
[type].title
)
138 .attr("data-filter-class", types
[type].class)
141 var hclass
= $
(this).attr("data-filter-class");
142 $
(this).parents(filterSelector
).find("li." + hclass
).hide();
143 $
(this).addClass("nitdoc-ui-filter-hidden")
146 var hclass
= $
(this).attr("data-filter-class");
147 $
(this).parents(filterSelector
).find("li." + hclass
).show();
148 $
(this).removeClass("nitdoc-ui-filter-hidden")
151 $
(filterSelector
).find(".nitdoc-ui-filter").append(a
);
155 // Allow user to filter sidebar box entries by name
156 enableSearchPageField
: function(filterSelector
) {
157 var div
= $
(document
.createElement("div"))
158 .addClass("nitdoc-ui-searchpage-filter")
160 $
(document
.createElement("input"))
161 .addClass("nitdoc-ui-searchpage-field")
162 .addClass("nitdoc-ui-filter-field-notused")
163 .attr("type", "text")
164 .attr("value", "filter...")
166 var box
= $
(this).parents(".content.fullpage").find("article.filterable");
167 var value
= $
(this).val();
168 box
.find("ul li:not(:icontains('" + value
+ "'))").hide();
169 box
.find("ul li:icontains('" + value
+ "')").show();
171 .focusout(function() {
172 if($
(this).val() == "") {
173 $
(this).addClass("nitdoc-ui-filter-field-notused");
174 $
(this).val("filter...");
177 .focusin(function() {
178 if($
(this).val() == "filter...") {
179 $
(this).removeClass("nitdoc-ui-filter-field-notused");
184 $
(filterSelector
).after(div
);
185 this.preloadSearchPageField();
188 // Prealod filter using search query
189 preloadSearchPageField
: function() {
190 var anchor
= utils
.extractAnchor(document
.location
.hash
);
191 if(!anchor || anchor
.indexOf("q=") == -1) return;
193 var query
= anchor
.substring(2);
196 $
(".nitdoc-ui-searchpage-field")
198 .removeClass("nitdoc-ui-notused")
203 UI
.enableFolding(".sidebar");
204 UI
.enableCopyToClipboard(".signature");
205 UI
.enableSidebarTextFilters("nav.filterable h3");
206 UI
.enableSidebarTypeFilters("nav.filterable");
207 UI
.enableSearchPageField(".content.fullpage h1:contains('Search')");