]>
git.proxmox.com Git - rustc.git/blob - src/librustdoc/html/static/main.js
fb8f511795e87d01d084460dd6ebed083b9184bb
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 /*jslint browser: true, es5: true */
12 /*globals $: true, rootPath: true */
17 // This mapping table should match the discriminants of
18 // `rustdoc::html::item_type::ItemType` type in Rust.
19 var itemTypes
= ["mod",
37 "associatedconstant"];
39 // used for special search precedence
40 var TY_PRIMITIVE
= itemTypes
.indexOf("primitive");
42 $('.js-only').removeClass('js-only');
44 function getQueryStringParams() {
46 window
.location
.search
.substring(1).split("&").
48 var pair
= s
.split("=");
49 params
[decodeURIComponent(pair
[0])] =
50 typeof pair
[1] === "undefined" ?
51 null : decodeURIComponent(pair
[1]);
56 function browserSupportsHistoryApi() {
57 return window
.history
&& typeof window
.history
.pushState
=== "function";
60 function highlightSourceLines(ev
) {
61 var i
, from, to
, match
= window
.location
.hash
.match(/^#?(\d+)(?:-(\d+))?$/);
63 from = parseInt(match
[1], 10);
64 to
= Math
.min(50000, parseInt(match
[2] || match
[1], 10));
65 from = Math
.min(from, to
);
66 if ($('#' + from).length
=== 0) {
69 if (ev
=== null) { $('#' + from)[0].scrollIntoView(); };
70 $('.line-numbers span').removeClass('line-highlighted');
71 for (i
= from; i
<= to
; ++i
) {
72 $('#' + i
).addClass('line-highlighted');
76 highlightSourceLines(null);
77 $(window
).on('hashchange', highlightSourceLines
);
79 $(document
).on('keyup', function handleKeyboardShortcut(e
) {
80 if (document
.activeElement
.tagName
=== 'INPUT') {
84 if (e
.which
=== 191) { // question mark
85 if (e
.shiftKey
&& $('#help').hasClass('hidden')) {
87 $('#help').removeClass('hidden');
89 } else if (e
.which
=== 27) { // esc
90 if (!$('#help').hasClass('hidden')) {
92 $('#help').addClass('hidden');
93 } else if (!$('#search').hasClass('hidden')) {
95 $('#search').addClass('hidden');
96 $('#main').removeClass('hidden');
98 } else if (e
.which
=== 83) { // S
100 $('.search-input').focus();
102 }).on('click', function(e
) {
103 if (!$(e
.target
).closest('#help').length
) {
104 $('#help').addClass('hidden');
108 $('.version-selector').on('change', function() {
110 url
= document
.location
.href
,
112 len
= rootPath
.match(/\.\.\//g).length
+ 1;
114 for (i
= 0; i
< len
; ++i
) {
115 match
= url
.match(/\/[^\/]*$/);
117 stripped
= match
[0] + stripped
;
119 url
= url
.substring(0, url
.length
- match
[0].length
);
122 url
+= '/' + $('.version-selector').val() + stripped
;
124 document
.location
.href
= url
;
127 * A function to compute the Levenshtein distance between two strings
128 * Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported
129 * Full License can be found at http://creativecommons.org/licenses/by-sa/3.0/legalcode
130 * This code is an unmodified version of the code written by Marco de Wit
131 * and was found at http://stackoverflow.com/a/18514751/745719
133 var levenshtein
= (function() {
135 return function(s1
, s2
) {
139 var s1_len
= s1
.length
, s2_len
= s2
.length
;
140 if (s1_len
&& s2_len
) {
141 var i1
= 0, i2
= 0, a
, b
, c
, c2
, row
= row2
;
142 while (i1
< s1_len
) {
145 while (i2
< s2_len
) {
146 c2
= s2
.charCodeAt(i2
);
150 for (i1
= 0; i1
< s1_len
; ++i1
) {
151 c
= a
+ (s1
.charCodeAt(i1
) !== c2
? 1 : 0);
153 b
= b
< a
? (b
< c
? b
+ 1 : c
) : (a
< c
? a
+ 1 : c
);
159 return s1_len
+ s2_len
;
163 function initSearch(rawSearchIndex
) {
164 var currentResults
, index
, searchIndex
;
165 var MAX_LEV_DISTANCE
= 3;
166 var params
= getQueryStringParams();
168 // Populate search bar with query string search term when provided,
169 // but only if the input bar is empty. This avoid the obnoxious issue
170 // where you start trying to do a search, and the index loads, and
171 // suddenly your search is gone!
172 if ($(".search-input")[0].value
=== "") {
173 $(".search-input")[0].value
= params
.search
|| '';
177 * Executes the query and builds an index of results
178 * @param {[Object]} query [The user query]
179 * @param {[type]} max [The maximum results returned]
180 * @param {[type]} searchWords [The list of search words to query
182 * @return {[type]} [A search index of results]
184 function execQuery(query
, max
, searchWords
) {
185 var valLower
= query
.query
.toLowerCase(),
187 typeFilter
= itemTypeFromName(query
.type
),
189 split
= valLower
.split("::");
191 // remove empty keywords
192 for (var j
= 0; j
< split
.length
; ++j
) {
193 split
[j
].toLowerCase();
194 if (split
[j
] === "") {
199 // quoted values mean literal search
200 var nSearchWords
= searchWords
.length
;
201 if ((val
.charAt(0) === "\"" || val
.charAt(0) === "'") &&
202 val
.charAt(val
.length
- 1) === val
.charAt(0))
204 val
= val
.substr(1, val
.length
- 2);
205 for (var i
= 0; i
< nSearchWords
; ++i
) {
206 if (searchWords
[i
] === val
) {
207 // filter type: ... queries
208 if (typeFilter
< 0 || typeFilter
=== searchIndex
[i
].ty
) {
209 results
.push({id
: i
, index
: -1});
212 if (results
.length
=== max
) {
217 } else if (val
.search("->") > -1) {
218 var trimmer = function (s
) { return s
.trim(); };
219 var parts
= val
.split("->").map(trimmer
);
220 var input
= parts
[0];
221 // sort inputs so that order does not matter
222 var inputs
= input
.split(",").map(trimmer
).sort();
223 var output
= parts
[1];
225 for (var i
= 0; i
< nSearchWords
; ++i
) {
226 var type
= searchIndex
[i
].type
;
231 // sort index inputs so that order does not matter
232 var typeInputs
= type
.inputs
.map(function (input
) {
236 // allow searching for void (no output) functions as well
237 var typeOutput
= type
.output
? type
.output
.name
: "";
238 if (inputs
.toString() === typeInputs
.toString() &&
239 output
== typeOutput
) {
240 results
.push({id
: i
, index
: -1, dontValidate
: true});
244 // gather matching search results up to a certain maximum
245 val
= val
.replace(/\_/g, "");
246 for (var i
= 0; i
< split
.length
; ++i
) {
247 for (var j
= 0; j
< nSearchWords
; ++j
) {
249 if (searchWords
[j
].indexOf(split
[i
]) > -1 ||
250 searchWords
[j
].indexOf(val
) > -1 ||
251 searchWords
[j
].replace(/_
/g
, "").indexOf(val
) > -1)
253 // filter type: ... queries
254 if (typeFilter
< 0 || typeFilter
=== searchIndex
[j
].ty
) {
257 index
: searchWords
[j
].replace(/_
/g
, "").indexOf(val
),
262 (lev_distance
= levenshtein(searchWords
[j
], val
)) <=
264 if (typeFilter
< 0 || typeFilter
=== searchIndex
[j
].ty
) {
268 // we want lev results to go lower than others
273 if (results
.length
=== max
) {
280 var nresults
= results
.length
;
281 for (var i
= 0; i
< nresults
; ++i
) {
282 results
[i
].word
= searchWords
[results
[i
].id
];
283 results
[i
].item
= searchIndex
[results
[i
].id
] || {};
285 // if there are no results then return to default and fail
286 if (results
.length
=== 0) {
290 results
.sort(function sortResults(aaa
, bbb
) {
293 // Sort by non levenshtein results and then levenshtein results by the distance
294 // (less changes required to match means higher rankings)
297 if (a
!== b
) { return a
- b
; }
299 // sort by crate (non-current crate goes later)
300 a
= (aaa
.item
.crate
!== window
.currentCrate
);
301 b
= (bbb
.item
.crate
!== window
.currentCrate
);
302 if (a
!== b
) { return a
- b
; }
304 // sort by exact match (mismatch goes later)
305 a
= (aaa
.word
!== valLower
);
306 b
= (bbb
.word
!== valLower
);
307 if (a
!== b
) { return a
- b
; }
309 // sort by item name length (longer goes later)
312 if (a
!== b
) { return a
- b
; }
314 // sort by item name (lexicographically larger goes later)
317 if (a
!== b
) { return (a
> b
? +1 : -1); }
319 // sort by index of keyword in item name (no literal occurrence goes later)
322 if (a
!== b
) { return a
- b
; }
323 // (later literal occurrence, if any, goes later)
326 if (a
!== b
) { return a
- b
; }
328 // special precedence for primitive pages
329 if ((aaa
.item
.ty
=== TY_PRIMITIVE
) && (bbb
.item
.ty
!== TY_PRIMITIVE
)) {
333 // sort by description (no description goes later)
334 a
= (aaa
.item
.desc
=== '');
335 b
= (bbb
.item
.desc
=== '');
336 if (a
!== b
) { return a
- b
; }
338 // sort by type (later occurrence in `itemTypes` goes later)
341 if (a
!== b
) { return a
- b
; }
343 // sort by path (lexicographically larger goes later)
346 if (a
!== b
) { return (a
> b
? +1 : -1); }
352 // remove duplicates, according to the data provided
353 for (var i
= results
.length
- 1; i
> 0; i
-= 1) {
354 if (results
[i
].word
=== results
[i
- 1].word
&&
355 results
[i
].item
.ty
=== results
[i
- 1].item
.ty
&&
356 results
[i
].item
.path
=== results
[i
- 1].item
.path
&&
357 (results
[i
].item
.parent
|| {}).name
=== (results
[i
- 1].item
.parent
|| {}).name
)
362 for (var i
= 0; i
< results
.length
; ++i
) {
363 var result
= results
[i
],
364 name
= result
.item
.name
.toLowerCase(),
365 path
= result
.item
.path
.toLowerCase(),
366 parent
= result
.item
.parent
;
368 // this validation does not make sense when searching by types
369 if (result
.dontValidate
) {
373 var valid
= validateResult(name
, path
, split
, parent
);
382 * Validate performs the following boolean logic. For example:
383 * "File::open" will give IF A PARENT EXISTS => ("file" && "open")
384 * exists in (name || path || parent) OR => ("file" && "open") exists in
387 * This could be written functionally, but I wanted to minimise
388 * functions on stack.
390 * @param {[string]} name [The name of the result]
391 * @param {[string]} path [The path of the result]
392 * @param {[string]} keys [The keys to be used (["file", "open"])]
393 * @param {[object]} parent [The parent of the result]
394 * @return {[boolean]} [Whether the result is valid or not]
396 function validateResult(name
, path
, keys
, parent
) {
397 for (var i
= 0; i
< keys
.length
; ++i
) {
398 // each check is for validation so we negate the conditions and invalidate
400 // check for an exact name match
401 name
.toLowerCase().indexOf(keys
[i
]) > -1 ||
402 // then an exact path match
403 path
.toLowerCase().indexOf(keys
[i
]) > -1 ||
404 // next if there is a parent, check for exact parent match
405 (parent
!== undefined &&
406 parent
.name
.toLowerCase().indexOf(keys
[i
]) > -1) ||
407 // lastly check to see if the name was a levenshtein match
408 levenshtein(name
.toLowerCase(), keys
[i
]) <=
416 function getQuery() {
417 var matches
, type
, query
, raw
= $('.search-input').val();
420 matches
= query
.match(/^(fn|mod|struct|enum|trait|t(ype)?d(ef)?)\s*:\s*/i);
422 type
= matches
[1].replace(/^td$/, 'typedef')
423 .replace(/^tdef$/, 'typedef')
424 .replace(/^typed$/, 'typedef');
425 query
= query
.substring(matches
[0].length
);
436 function initSearchNav() {
437 var hoverTimeout
, $results
= $('.search-results .result');
439 $results
.on('click', function() {
440 var dst
= $(this).find('a')[0];
441 if (window
.location
.pathname
=== dst
.pathname
) {
442 $('#search').addClass('hidden');
443 $('#main').removeClass('hidden');
444 document
.location
.href
= dst
.href
;
446 }).on('mouseover', function() {
448 clearTimeout(hoverTimeout
);
449 hoverTimeout
= setTimeout(function() {
450 $results
.removeClass('highlighted');
451 $el
.addClass('highlighted');
455 $(document
).off('keydown.searchnav');
456 $(document
).on('keydown.searchnav', function(e
) {
457 var $active
= $results
.filter('.highlighted');
459 if (e
.which
=== 38) { // up
461 if (!$active
.length
|| !$active
.prev()) {
465 $active
.prev().addClass('highlighted');
466 $active
.removeClass('highlighted');
467 } else if (e
.which
=== 40) { // down
469 if (!$active
.length
) {
470 $results
.first().addClass('highlighted');
471 } else if ($active
.next().length
) {
472 $active
.next().addClass('highlighted');
473 $active
.removeClass('highlighted');
475 } else if (e
.which
=== 13) { // return
477 if ($active
.length
) {
478 document
.location
.href
= $active
.find('a').prop('href');
481 $active
.removeClass('highlighted');
486 function escape(content
) {
487 return $('<h1/>').text(content
).html();
490 function showResults(results
) {
491 var output
, shown
, query
= getQuery();
493 currentResults
= query
.id
;
494 output
= '<h1>Results for ' + escape(query
.query
) +
495 (query
.type
? ' (type: ' + escape(query
.type
) + ')' : '') + '</h1>';
496 output
+= '<table class="search-results">';
498 if (results
.length
> 0) {
501 results
.forEach(function(item
) {
502 var name
, type
, href
, displayPath
;
504 if (shown
.indexOf(item
) !== -1) {
510 type
= itemTypes
[item
.ty
];
512 if (type
=== 'mod') {
513 displayPath
= item
.path
+ '::';
514 href
= rootPath
+ item
.path
.replace(/::/g, '/') + '/' +
515 name
+ '/index.html';
516 } else if (type
=== 'static' || type
=== 'reexport') {
517 displayPath
= item
.path
+ '::';
518 href
= rootPath
+ item
.path
.replace(/::/g, '/') +
520 } else if (item
.parent
!== undefined) {
521 var myparent
= item
.parent
;
522 var anchor
= '#' + type
+ '.' + name
;
523 displayPath
= item
.path
+ '::' + myparent
.name
+ '::';
524 href
= rootPath
+ item
.path
.replace(/::/g, '/') +
525 '/' + itemTypes
[myparent
.ty
] +
526 '.' + myparent
.name
+
529 displayPath
= item
.path
+ '::';
530 href
= rootPath
+ item
.path
.replace(/::/g, '/') +
531 '/' + type
+ '.' + name
+ '.html';
534 output
+= '<tr class="' + type
+ ' result"><td>' +
535 '<a href="' + href
+ '">' +
536 displayPath
+ '<span class="' + type
+ '">' +
537 name
+ '</span></a></td><td>' +
538 '<a href="' + href
+ '">' +
539 '<span class="desc">' + item
.desc
+
540 ' </span></a></td></tr>';
543 output
+= 'No results :( <a href="https://duckduckgo.com/?q=' +
544 encodeURIComponent('rust ' + query
.query
) +
545 '">Try on DuckDuckGo?</a>';
549 $('#main.content').addClass('hidden');
550 $('#search.content').removeClass('hidden').html(output
);
551 $('#search .desc').width($('#search').width() - 40 -
552 $('#search td:first-child').first().width());
563 var params
= getQueryStringParams();
570 if (!query
.query
|| query
.id
=== currentResults
) {
574 // Update document title to maintain a meaningful browser history
575 $(document
).prop("title", "Results for " + query
.query
+ " - Rust");
577 // Because searching is incremental by character, only the most
578 // recent search query is added to the browser history.
579 if (browserSupportsHistoryApi()) {
580 if (!history
.state
&& !params
.search
) {
581 history
.pushState(query
, "", "?search=" +
582 encodeURIComponent(query
.raw
));
584 history
.replaceState(query
, "", "?search=" +
585 encodeURIComponent(query
.raw
));
589 resultIndex
= execQuery(query
, 20000, index
);
590 len
= resultIndex
.length
;
591 for (i
= 0; i
< len
; ++i
) {
592 if (resultIndex
[i
].id
> -1) {
593 obj
= searchIndex
[resultIndex
[i
].id
];
594 filterdata
.push([obj
.name
, obj
.ty
, obj
.path
, obj
.desc
]);
597 if (results
.length
>= maxResults
) {
602 showResults(results
);
605 function itemTypeFromName(typename
) {
606 for (var i
= 0; i
< itemTypes
.length
; ++i
) {
607 if (itemTypes
[i
] === typename
) { return i
; }
612 function buildIndex(rawSearchIndex
) {
614 var searchWords
= [];
615 for (var crate
in rawSearchIndex
) {
616 if (!rawSearchIndex
.hasOwnProperty(crate
)) { continue; }
618 // an array of [(Number) item type,
620 // (String) full path or empty string for previous path,
621 // (String) description,
622 // (Number | null) the parent path index to `paths`]
623 // (Object | null) the type of the function (if any)
624 var items
= rawSearchIndex
[crate
].items
;
625 // an array of [(Number) item type,
627 var paths
= rawSearchIndex
[crate
].paths
;
629 // convert `paths` into an object form
630 var len
= paths
.length
;
631 for (var i
= 0; i
< len
; ++i
) {
632 paths
[i
] = {ty
: paths
[i
][0], name
: paths
[i
][1]};
635 // convert `items` into an object form, and construct word indices.
637 // before any analysis is performed lets gather the search terms to
638 // search against apart from the rest of the data. This is a quick
639 // operation that is cached for the life of the page state so that
640 // all other search operations have access to this cached data for
641 // faster analysis operations
642 var len
= items
.length
;
644 for (var i
= 0; i
< len
; ++i
) {
645 var rawRow
= items
[i
];
646 var row
= {crate
: crate
, ty
: rawRow
[0], name
: rawRow
[1],
647 path
: rawRow
[2] || lastPath
, desc
: rawRow
[3],
648 parent
: paths
[rawRow
[4]], type
: rawRow
[5]};
649 searchIndex
.push(row
);
650 if (typeof row
.name
=== "string") {
651 var word
= row
.name
.toLowerCase();
652 searchWords
.push(word
);
654 searchWords
.push("");
662 function startSearch() {
664 $('.do-search').on('click', search
);
665 $('.search-input').on('keyup', function() {
666 clearTimeout(keyUpTimeout
);
667 keyUpTimeout
= setTimeout(search
, 500);
670 // Push and pop states are used to add search results to the browser
672 if (browserSupportsHistoryApi()) {
673 $(window
).on('popstate', function(e
) {
674 var params
= getQueryStringParams();
675 // When browsing back from search results the main page
676 // visibility must be reset.
677 if (!params
.search
) {
678 $('#main.content').removeClass('hidden');
679 $('#search.content').addClass('hidden');
681 // When browsing forward to search results the previous
682 // search will be repeated, so the currentResults are
683 // cleared to ensure the search is successful.
684 currentResults
= null;
685 // Synchronize search bar with query string state and
686 // perform the search. This will empty the bar if there's
687 // nothing there, which lets you really go back to a
688 // previous state with nothing in the bar.
689 $('.search-input').val(params
.search
);
690 // Some browsers fire 'onpopstate' for every page load
691 // (Chrome), while others fire the event only when actually
692 // popping a state (Firefox), which is why search() is
693 // called both here and at the end of the startSearch()
701 function plainSummaryLine(markdown
) {
702 markdown
.replace(/\n/g, ' ')
704 .replace(/^#+? (.+?)/, "$1")
705 .replace(/\[(.*?)\]\(.*?\)/g, "$1")
706 .replace(/\[(.*?)\]\[.*?\]/g, "$1");
709 index = buildIndex(rawSearchIndex);
712 // Draw a convenient sidebar of known crates if we have a listing
713 if (rootPath === '../') {
714 var sidebar = $('.sidebar
');
715 var div = $('<div
>').attr('class', 'block crate
');
716 div.append($('<h2
>').text('Crates
'));
719 for (var crate in rawSearchIndex) {
720 if (!rawSearchIndex.hasOwnProperty(crate)) { continue; }
724 for (var i = 0; i < crates.length; ++i) {
726 if (crates[i] === window.currentCrate) {
729 if (rawSearchIndex[crates[i]].items[0]) {
730 var desc = rawSearchIndex[crates[i]].items[0][3];
731 div.append($('<a
>', {'href
': '../' + crates[i] + '/index.html
',
732 'title
': plainSummaryLine(desc),
733 'class': klass}).text(crates[i]));
740 window.initSearch = initSearch;
742 // delayed sidebar rendering.
743 function initSidebarItems(items) {
744 var sidebar = $('.sidebar
');
745 var current = window.sidebarCurrent;
747 function block(shortty, longty) {
748 var filtered = items[shortty];
749 if (!filtered) { return; }
751 var div = $('<div
>').attr('class', 'block
' + shortty);
752 div.append($('<h2
>').text(longty));
754 for (var i = 0; i < filtered.length; ++i) {
755 var item = filtered[i];
757 var desc = item[1]; // can be null
760 if (name === current.name && shortty === current.ty) {
764 if (shortty === 'mod
') {
765 path = name + '/index
.html
';
767 path = shortty + '.' + name + '.html
';
769 div.append($('<a
>', {'href
': current.relpath + path,
771 'class': klass}).text(name));
776 block("mod", "Modules");
777 block("struct", "Structs");
778 block("enum", "Enums");
779 block("trait", "Traits");
780 block("fn", "Functions");
781 block("macro", "Macros");
784 window.initSidebarItems = initSidebarItems;
786 window.register_implementors = function(imp) {
787 var list = $('#implementors
-list
');
788 var libs = Object.getOwnPropertyNames(imp);
789 for (var i = 0; i < libs.length; ++i) {
790 if (libs[i] === currentCrate) { continue; }
791 var structs = imp[libs[i]];
792 for (var j = 0; j < structs.length; ++j) {
793 var code = $('<code
>').append(structs[j]);
794 $.each(code.find('a
'), function(idx, a) {
795 var href = $(a).attr('href
');
796 if (href && href.indexOf('http
') !== 0) {
797 $(a).attr('href
', rootPath + href);
800 var li = $('<li
>').append(code);
805 if (window.pending_implementors) {
806 window.register_implementors(window.pending_implementors);
809 // See documentation in html/render.rs for what this is doing.
810 var query = getQueryStringParams();
811 if (query['gotosrc
']) {
812 window.location = $('#src
-' + query['gotosrc
']).attr('href
');
814 if (query['gotomacrosrc
']) {
815 window.location = $('.srclink
').attr('href
');
818 function labelForToggleButton(sectionIsCollapsed) {
819 if (sectionIsCollapsed) {
820 // button will expand the section
823 // button will collapse the section
824 // note that this text is also set in the HTML template in render.rs
825 return "\u2212"; // "\u2212" is '−' minus sign
828 $("#toggle-all-docs").on("click", function() {
829 var toggle = $("#toggle-all-docs");
830 if (toggle.hasClass("will-expand")) {
831 toggle.removeClass("will-expand");
832 toggle.children(".inner").text(labelForToggleButton(false));
833 toggle.attr("title", "collapse all docs");
834 $(".docblock").show();
835 $(".toggle-label").hide();
836 $(".toggle-wrapper").removeClass("collapsed");
837 $(".collapse-toggle").children(".inner").text(labelForToggleButton(false));
839 toggle.addClass("will-expand");
840 toggle.children(".inner").text(labelForToggleButton(true));
841 toggle.attr("title", "expand all docs");
842 $(".docblock").hide();
843 $(".toggle-label").show();
844 $(".toggle-wrapper").addClass("collapsed");
845 $(".collapse-toggle").children(".inner").text(labelForToggleButton(true));
849 $(document).on("click", ".collapse-toggle", function() {
850 var toggle = $(this);
851 var relatedDoc = toggle.parent().next();
852 if (relatedDoc.is(".stability")) {
853 relatedDoc = relatedDoc.next();
855 if (relatedDoc.is(".docblock")) {
856 if (relatedDoc.is(":visible")) {
857 relatedDoc.slideUp({duration: 'fast
', easing: 'linear
'});
858 toggle.parent(".toggle-wrapper").addClass("collapsed");
859 toggle.children(".inner").text(labelForToggleButton(true));
860 toggle.children(".toggle-label").fadeIn();
862 relatedDoc.slideDown({duration: 'fast
', easing: 'linear
'});
863 toggle.parent(".toggle-wrapper").removeClass("collapsed");
864 toggle.children(".inner").text(labelForToggleButton(false));
865 toggle.children(".toggle-label").hide();
871 var toggle = $("<a/>", {'href
': 'javascript
:void(0)', 'class': 'collapse
-toggle
'})
872 .html("[<span class='inner
'></span>]");
873 toggle.children(".inner").text(labelForToggleButton(false));
875 $(".method").each(function() {
876 if ($(this).next().is(".docblock") ||
877 ($(this).next().is(".stability") && $(this).next().next().is(".docblock"))) {
878 $(this).children().first().after(toggle.clone());
884 $('<span
/>', {'class': 'toggle
-label
'})
885 .css('display
', 'none
')
886 .html(' 
;Expand
 
;description
'));
887 var wrapper = $("<div class='toggle
-wrapper
'>").append(mainToggle);
888 $("#main > .docblock").before(wrapper);
891 $('pre
.line
-numbers
').on('click
', 'span
', function() {
894 function set_fragment(name) {
895 if (history.replaceState) {
896 history.replaceState(null, null, '#' + name);
897 $(window).trigger('hashchange
');
899 location.replace('#' + name);
903 return function(ev) {
904 var cur_id = parseInt(ev.target.id, 10);
906 if (ev.shiftKey && prev_id) {
907 if (prev_id > cur_id) {
913 set_fragment(prev_id + '-' + cur_id);
917 set_fragment(cur_id);