Rollup merge of #41307 - GuillaumeGomez:jquery-removal, r=frewsxcv

Remove jquery dependency

r? @rust-lang/docs

Fixes #39159.
This commit is contained in:
Corey Farwell 2017-05-05 17:35:24 -04:00 committed by GitHub
commit 31a4d73e73
6 changed files with 465 additions and 254 deletions

View File

@ -137,7 +137,6 @@ r##"<!DOCTYPE html>
window.rootPath = "{root_path}"; window.rootPath = "{root_path}";
window.currentCrate = "{krate}"; window.currentCrate = "{krate}";
</script> </script>
<script src="{root_path}jquery.js"></script>
<script src="{root_path}main.js"></script> <script src="{root_path}main.js"></script>
<script defer src="{root_path}search-index.js"></script> <script defer src="{root_path}search-index.js"></script>
</body> </body>

View File

@ -660,8 +660,6 @@ fn write_shared(cx: &Context,
// Add all the static files. These may already exist, but we just // Add all the static files. These may already exist, but we just
// overwrite them anyway to make sure that they're fresh and up-to-date. // overwrite them anyway to make sure that they're fresh and up-to-date.
write(cx.dst.join("jquery.js"),
include_bytes!("static/jquery-2.1.4.min.js"))?;
write(cx.dst.join("main.js"), write(cx.dst.join("main.js"),
include_bytes!("static/main.js"))?; include_bytes!("static/main.js"))?;
write(cx.dst.join("rustdoc.css"), write(cx.dst.join("rustdoc.css"),

View File

@ -27,11 +27,6 @@ included, and carry their own copyright notices and license terms:
Licensed under the SIL Open Font License, Version 1.1. Licensed under the SIL Open Font License, Version 1.1.
See Heuristica-LICENSE.txt. See Heuristica-LICENSE.txt.
* jQuery (jquery-2.1.4.min.js):
Copyright 2005, 2015 jQuery Foundation, Inc.
Licensed under the MIT license (see LICENSE-MIT.txt).
* rustdoc.css, main.js, and playpen.js: * rustdoc.css, main.js, and playpen.js:
Copyright 2015 The Rust Developers. Copyright 2015 The Rust Developers.

File diff suppressed because one or more lines are too long

View File

@ -37,10 +37,63 @@
"associatedconstant", "associatedconstant",
"union"]; "union"];
function hasClass(elem, className) {
if (elem && className && elem.className) {
var elemClass = elem.className;
var start = elemClass.indexOf(className);
if (start == -1) {
return false;
} else if (elemClass.length == className.length) {
return true;
} else {
if (start > 0 && elemClass[start - 1] != ' ') {
return false;
}
var end = start + className.length;
if (end < elemClass.length && elemClass[end] != ' ') {
return false;
}
return true;
}
}
return false;
}
function addClass(elem, className) {
if (elem && className && !hasClass(elem, className)) {
if (elem.className && elem.className.length > 0) {
elem.className += ' ' + className;
} else {
elem.className = className;
}
}
}
function removeClass(elem, className) {
if (elem && className && elem.className) {
elem.className = (" " + elem.className + " ").replace(" " + className + " ", " ")
.trim();
}
}
function onEach(arr, func) {
if (arr && arr.length > 0 && func) {
for (var i = 0; i < arr.length; i++) {
func(arr[i]);
}
}
}
function isHidden(elem) {
return (elem.offsetParent === null)
}
// used for special search precedence // used for special search precedence
var TY_PRIMITIVE = itemTypes.indexOf("primitive"); var TY_PRIMITIVE = itemTypes.indexOf("primitive");
$('.js-only').removeClass('js-only'); onEach(document.getElementsByClassName('js-only'), function(e) {
removeClass(e, 'js-only');
});
function getQueryStringParams() { function getQueryStringParams() {
var params = {}; var params = {};
@ -65,18 +118,28 @@
from = parseInt(match[1], 10); from = parseInt(match[1], 10);
to = Math.min(50000, parseInt(match[2] || match[1], 10)); to = Math.min(50000, parseInt(match[2] || match[1], 10));
from = Math.min(from, to); from = Math.min(from, to);
if ($('#' + from).length === 0) { var elem = document.getElementById(from);
if (!elem) {
return; return;
} }
if (ev === null) { $('#' + from)[0].scrollIntoView(); }; if (ev === null) {
$('.line-numbers span').removeClass('line-highlighted'); var x = document.getElementById(from);
if (x) {
x.scrollIntoView();
}
};
onEach(document.getElementsByClassName('line-numbers'), function(e) {
onEach(e.getElementsByTagName('span'), function(i_e) {
removeClass(i_e, 'line-highlighted');
});
})
for (i = from; i <= to; ++i) { for (i = from; i <= to; ++i) {
$('#' + i).addClass('line-highlighted'); addClass(document.getElementById(i), 'line-highlighted');
} }
} }
} }
highlightSourceLines(null); highlightSourceLines(null);
$(window).on('hashchange', highlightSourceLines); window.onhashchange = highlightSourceLines;
// Gets the human-readable string for the virtual-key code of the // Gets the human-readable string for the virtual-key code of the
// given KeyboardEvent, ev. // given KeyboardEvent, ev.
@ -99,23 +162,25 @@
} }
function handleShortcut(ev) { function handleShortcut(ev) {
if (document.activeElement.tagName == "INPUT") if (document.activeElement.tagName === "INPUT")
return; return;
// Don't interfere with browser shortcuts // Don't interfere with browser shortcuts
if (ev.ctrlKey || ev.altKey || ev.metaKey) if (ev.ctrlKey || ev.altKey || ev.metaKey)
return; return;
var help = document.getElementById("help");
switch (getVirtualKey(ev)) { switch (getVirtualKey(ev)) {
case "Escape": case "Escape":
if (!$("#help").hasClass("hidden")) { var search = document.getElementById("search");
if (!hasClass(help, "hidden")) {
ev.preventDefault(); ev.preventDefault();
$("#help").addClass("hidden"); addClass(help, "hidden");
$("body").removeClass("blur"); removeClass(document.body, "blur");
} else if (!$("#search").hasClass("hidden")) { } else if (!hasClass(search, "hidden")) {
ev.preventDefault(); ev.preventDefault();
$("#search").addClass("hidden"); addClass(search, "hidden");
$("#main").removeClass("hidden"); removeClass(document.getElementById("main"), "hidden");
} }
break; break;
@ -131,42 +196,76 @@
break; break;
case "?": case "?":
if (ev.shiftKey && $("#help").hasClass("hidden")) { if (ev.shiftKey && hasClass(help, "hidden")) {
ev.preventDefault(); ev.preventDefault();
$("#help").removeClass("hidden"); removeClass(help, "hidden");
$("body").addClass("blur"); addClass(document.body, "blur");
} }
break; break;
} }
} }
$(document).on("keypress", handleShortcut); document.onkeypress = handleShortcut;
$(document).on("keydown", handleShortcut); document.onkeydown = handleShortcut;
$(document).on("click", function(ev) { document.onclick = function(ev) {
if (!$(ev.target).closest("#help > div").length) { if (hasClass(ev.target, 'collapse-toggle')) {
$("#help").addClass("hidden"); collapseDocs(ev.target);
$("body").removeClass("blur"); } else if (hasClass(ev.target.parentNode, 'collapse-toggle')) {
} collapseDocs(ev.target.parentNode);
}); } else if (ev.target.tagName === 'SPAN' && hasClass(ev.target.parentNode, 'line-numbers')) {
var prev_id = 0;
$('.version-selector').on('change', function() { function set_fragment(name) {
var i, match, if (browserSupportsHistoryApi()) {
url = document.location.href, history.replaceState(null, null, '#' + name);
stripped = '', window.hashchange();
len = rootPath.match(/\.\.\//g).length + 1; } else {
location.replace('#' + name);
for (i = 0; i < len; ++i) { }
match = url.match(/\/[^\/]*$/);
if (i < len - 1) {
stripped = match[0] + stripped;
} }
url = url.substring(0, url.length - match[0].length);
var cur_id = parseInt(ev.target.id, 10);
if (ev.shiftKey && prev_id) {
if (prev_id > cur_id) {
var tmp = prev_id;
prev_id = cur_id;
cur_id = tmp;
}
set_fragment(prev_id + '-' + cur_id);
} else {
prev_id = cur_id;
set_fragment(cur_id);
}
} else if (!hasClass(document.getElementById("help"), "hidden")) {
addClass(document.getElementById("help"), "hidden");
removeClass(document.body, "blur");
} }
};
url += '/' + $('.version-selector').val() + stripped; var x = document.getElementsByClassName('version-selector');
if (x.length > 0) {
x[0].onchange = function() {
var i, match,
url = document.location.href,
stripped = '',
len = rootPath.match(/\.\.\//g).length + 1;
document.location.href = url; for (i = 0; i < len; ++i) {
}); match = url.match(/\/[^\/]*$/);
if (i < len - 1) {
stripped = match[0] + stripped;
}
url = url.substring(0, url.length - match[0].length);
}
url += '/' + document.getElementsByClassName('version-selector')[0].value + stripped;
document.location.href = url;
};
}
/** /**
* A function to compute the Levenshtein distance between two strings * A function to compute the Levenshtein distance between two strings
@ -214,8 +313,8 @@
// but only if the input bar is empty. This avoid the obnoxious issue // but only if the input bar is empty. This avoid the obnoxious issue
// where you start trying to do a search, and the index loads, and // where you start trying to do a search, and the index loads, and
// suddenly your search is gone! // suddenly your search is gone!
if ($(".search-input")[0].value === "") { if (document.getElementsByClassName("search-input")[0].value === "") {
$(".search-input")[0].value = params.search || ''; document.getElementsByClassName("search-input")[0].value = params.search || '';
} }
/** /**
@ -484,7 +583,8 @@
} }
function getQuery() { function getQuery() {
var matches, type, query, raw = $('.search-input').val(); var matches, type, query, raw =
document.getElementsByClassName('search-input')[0].value;
query = raw; query = raw;
matches = query.match(/^(fn|mod|struct|enum|trait|type|const|macro)\s*:\s*/i); matches = query.match(/^(fn|mod|struct|enum|trait|type|const|macro)\s*:\s*/i);
@ -502,54 +602,92 @@
} }
function initSearchNav() { function initSearchNav() {
var hoverTimeout, $results = $('.search-results .result'); var hoverTimeout;
$results.on('click', function() { var click_func = function(e) {
var dst = $(this).find('a')[0]; var el = e.target;
// to retrieve the real "owner" of the event.
while (el.tagName !== 'TR') {
el = el.parentNode;
}
var dst = e.target.getElementsByTagName('a');
if (dst.length < 1) {
return;
}
dst = dst[0];
if (window.location.pathname === dst.pathname) { if (window.location.pathname === dst.pathname) {
$('#search').addClass('hidden'); addClass(document.getElementById('search'), 'hidden');
$('#main').removeClass('hidden'); removeClass(document.getElementById('main'), 'hidden');
document.location.href = dst.href; document.location.href = dst.href;
} }
}).on('mouseover', function() { };
var $el = $(this); var mouseover_func = function(e) {
var el = e.target;
// to retrieve the real "owner" of the event.
while (el.tagName !== 'TR') {
el = el.parentNode;
}
clearTimeout(hoverTimeout); clearTimeout(hoverTimeout);
hoverTimeout = setTimeout(function() { hoverTimeout = setTimeout(function() {
$results.removeClass('highlighted'); onEach(document.getElementsByClassName('search-results'), function(e) {
$el.addClass('highlighted'); onEach(e.getElementsByClassName('result'), function(i_e) {
removeClass(i_e, 'highlighted');
});
});
addClass(el, 'highlighted');
}, 20); }, 20);
};
onEach(document.getElementsByClassName('search-results'), function(e) {
onEach(e.getElementsByClassName('result'), function(i_e) {
i_e.onclick = click_func;
i_e.onmouseover = mouseover_func;
});
}); });
$(document).off('keydown.searchnav'); var search_input = document.getElementsByClassName('search-input')[0];
$(document).on('keydown.searchnav', function(e) { search_input.onkeydown = null;
var $active = $results.filter('.highlighted'); search_input.onkeydown = function(e) {
var actives = [];
onEach(document.getElementsByClassName('search-results'), function(e) {
onEach(document.getElementsByClassName('highlighted'), function(e) {
actives.push(e);
});
});
if (e.which === 38) { // up if (e.which === 38) { // up
if (!$active.length || !$active.prev()) { if (!actives.length || !actives[0].previousElementSibling) {
return; return;
} }
$active.prev().addClass('highlighted'); addClass(actives[0].previousElementSibling, 'highlighted');
$active.removeClass('highlighted'); removeClass(actives[0], 'highlighted');
} else if (e.which === 40) { // down } else if (e.which === 40) { // down
if (!$active.length) { if (!actives.length) {
$results.first().addClass('highlighted'); var results = document.getElementsByClassName('search-results');
} else if ($active.next().length) { if (results.length > 0) {
$active.next().addClass('highlighted'); var res = results[0].getElementsByClassName('result');
$active.removeClass('highlighted'); if (res.length > 0) {
addClass(res[0], 'highlighted');
}
}
} else if (actives[0].nextElementSibling) {
addClass(actives[0].nextElementSibling, 'highlighted');
removeClass(actives[0], 'highlighted');
} }
} else if (e.which === 13) { // return } else if (e.which === 13) { // return
if ($active.length) { if (actives.length) {
document.location.href = $active.find('a').prop('href'); document.location.href = actives[0].getElementsByTagName('a')[0].href;
} }
} else { } else if (actives.length > 0) {
$active.removeClass('highlighted'); removeClass(actives[0], 'highlighted');
} }
}); };
} }
function escape(content) { function escape(content) {
return $('<h1/>').text(content).html(); let h1 = document.createElement('h1');
h1.textContent = content;
return h1.innerHTML;
} }
function showResults(results) { function showResults(results) {
@ -619,10 +757,19 @@
} }
output += "</p>"; output += "</p>";
$('#main.content').addClass('hidden'); addClass(document.getElementById('main'), 'hidden');
$('#search.content').removeClass('hidden').html(output); var search = document.getElementById('search');
$('#search .desc').width($('#search').width() - 40 - removeClass(search, 'hidden');
$('#search td:first-child').first().width()); search.innerHTML = output;
var tds = search.getElementsByTagName('td');
var td_width = 0;
if (tds.length > 0) {
td_width = tds[0].offsetWidth;
}
var width = search.offsetWidth - 40 - td_width;
onEach(search.getElementsByClassName('desc'), function(e) {
e.style.width = width + 'px';
});
initSearchNav(); initSearchNav();
} }
@ -645,17 +792,15 @@
} }
// Update document title to maintain a meaningful browser history // Update document title to maintain a meaningful browser history
$(document).prop("title", "Results for " + query.query + " - Rust"); document.title = "Results for " + query.query + " - Rust";
// Because searching is incremental by character, only the most // Because searching is incremental by character, only the most
// recent search query is added to the browser history. // recent search query is added to the browser history.
if (browserSupportsHistoryApi()) { if (browserSupportsHistoryApi()) {
if (!history.state && !params.search) { if (!history.state && !params.search) {
history.pushState(query, "", "?search=" + history.pushState(query, "", "?search=" + encodeURIComponent(query.raw));
encodeURIComponent(query.raw));
} else { } else {
history.replaceState(query, "", "?search=" + history.replaceState(query, "", "?search=" + encodeURIComponent(query.raw));
encodeURIComponent(query.raw));
} }
} }
@ -744,49 +889,68 @@
function startSearch() { function startSearch() {
var searchTimeout; var searchTimeout;
$(".search-input").on("keyup input",function() { var callback = function() {
var search_input = document.getElementsByClassName('search-input');
if (search_input.length < 1) { return; }
search_input = search_input[0];
clearTimeout(searchTimeout); clearTimeout(searchTimeout);
if ($(this).val().length === 0) { if (search_input.value.length === 0) {
if (browserSupportsHistoryApi()) { if (browserSupportsHistoryApi()) {
history.replaceState("", "std - Rust", "?search="); history.replaceState("", "std - Rust", "?search=");
} }
$('#main.content').removeClass('hidden'); var main = document.getElementById('main');
$('#search.content').addClass('hidden'); if (hasClass(main, 'content')) {
removeClass(main, 'hidden');
}
var search_c = document.getElementById('search');
if (hasClass(search_c, 'content')) {
addClass(search_c, 'hidden');
}
} else { } else {
searchTimeout = setTimeout(search, 500); searchTimeout = setTimeout(search, 500);
} }
}); };
$('.search-form').on('submit', function(e){ var search_input = document.getElementsByClassName("search-input")[0];
search_input.onkeyup = callback;
search_input.oninput = callback;
document.getElementsByClassName("search-form")[0].onsubmit = function(e){
e.preventDefault(); e.preventDefault();
clearTimeout(searchTimeout); clearTimeout(searchTimeout);
search(); search();
}); };
$('.search-input').on('change paste', function(e) { search_input.onchange = function(e) {
// Do NOT e.preventDefault() here. It will prevent pasting. // Do NOT e.preventDefault() here. It will prevent pasting.
clearTimeout(searchTimeout); clearTimeout(searchTimeout);
// zero-timeout necessary here because at the time of event handler execution the // zero-timeout necessary here because at the time of event handler execution the
// pasted content is not in the input field yet. Shouldnt make any difference for // pasted content is not in the input field yet. Shouldnt make any difference for
// change, though. // change, though.
setTimeout(search, 0); setTimeout(search, 0);
}); };
search_input.onpaste = search_input.onchange;
// Push and pop states are used to add search results to the browser // Push and pop states are used to add search results to the browser
// history. // history.
if (browserSupportsHistoryApi()) { if (browserSupportsHistoryApi()) {
// Store the previous <title> so we can revert back to it later. // Store the previous <title> so we can revert back to it later.
var previousTitle = $(document).prop("title"); var previousTitle = document.title;
$(window).on('popstate', function(e) { window.onpopstate = function(e) {
var params = getQueryStringParams(); var params = getQueryStringParams();
// When browsing back from search results the main page // When browsing back from search results the main page
// visibility must be reset. // visibility must be reset.
if (!params.search) { if (!params.search) {
$('#main.content').removeClass('hidden'); var main = document.getElementById('main');
$('#search.content').addClass('hidden'); if (hasClass(main, 'content')) {
removeClass(main, 'hidden');
}
var search = document.getElementById('search');
if (hasClass(main, 'content')) {
addClass(main, 'hidden');
}
} }
// Revert to the previous title manually since the History // Revert to the previous title manually since the History
// API ignores the title parameter. // API ignores the title parameter.
$(document).prop("title", previousTitle); document.title = previousTitle;
// When browsing forward to search results the previous // When browsing forward to search results the previous
// search will be repeated, so the currentResults are // search will be repeated, so the currentResults are
// cleared to ensure the search is successful. // cleared to ensure the search is successful.
@ -795,14 +959,14 @@
// perform the search. This will empty the bar if there's // perform the search. This will empty the bar if there's
// nothing there, which lets you really go back to a // nothing there, which lets you really go back to a
// previous state with nothing in the bar. // previous state with nothing in the bar.
$('.search-input').val(params.search); document.getElementsByClassName('search-input')[0].value = params.search;
// Some browsers fire 'onpopstate' for every page load // Some browsers fire 'onpopstate' for every page load
// (Chrome), while others fire the event only when actually // (Chrome), while others fire the event only when actually
// popping a state (Firefox), which is why search() is // popping a state (Firefox), which is why search() is
// called both here and at the end of the startSearch() // called both here and at the end of the startSearch()
// function. // function.
search(); search();
}); };
} }
search(); search();
} }
@ -812,10 +976,12 @@
// Draw a convenient sidebar of known crates if we have a listing // Draw a convenient sidebar of known crates if we have a listing
if (rootPath === '../') { if (rootPath === '../') {
var sidebar = $('.sidebar'); var sidebar = document.getElementsByClassName('sidebar')[0];
var div = $('<div>').attr('class', 'block crate'); var div = document.createElement('div');
div.append($('<h3>').text('Crates')); div.className = 'block crate';
var ul = $('<ul>').appendTo(div); div.innerHTML = '<h3>Crates</h3>';
var ul = document.createElement('ul');
div.appendChild(ul);
var crates = []; var crates = [];
for (var crate in rawSearchIndex) { for (var crate in rawSearchIndex) {
@ -828,12 +994,17 @@
if (crates[i] === window.currentCrate) { if (crates[i] === window.currentCrate) {
klass += ' current'; klass += ' current';
} }
var link = $('<a>', {'href': '../' + crates[i] + '/index.html', var link = document.createElement('a');
'title': rawSearchIndex[crates[i]].doc, link.href = '../' + crates[i] + '/index.html';
'class': klass}).text(crates[i]); link.title = rawSearchIndex[crates[i]].doc;
ul.append($('<li>').append(link)); link.className = klass;
link.textContent = crates[i];
var li = document.createElement('li');
li.appendChild(link);
ul.appendChild(li);
} }
sidebar.append(div); sidebar.appendChild(div);
} }
} }
@ -841,16 +1012,19 @@
// delayed sidebar rendering. // delayed sidebar rendering.
function initSidebarItems(items) { function initSidebarItems(items) {
var sidebar = $('.sidebar'); var sidebar = document.getElementsByClassName('sidebar')[0];
var current = window.sidebarCurrent; var current = window.sidebarCurrent;
function block(shortty, longty) { function block(shortty, longty) {
var filtered = items[shortty]; var filtered = items[shortty];
if (!filtered) { return; } if (!filtered) { return; }
var div = $('<div>').attr('class', 'block ' + shortty); var div = document.createElement('div');
div.append($('<h3>').text(longty)); div.className = 'block ' + shortty;
var ul = $('<ul>').appendTo(div); var h3 = document.createElement('h3');
h3.textContent = longty;
div.appendChild(h3);
var ul = document.createElement('ul');
for (var i = 0; i < filtered.length; ++i) { for (var i = 0; i < filtered.length; ++i) {
var item = filtered[i]; var item = filtered[i];
@ -867,12 +1041,17 @@
} else { } else {
path = shortty + '.' + name + '.html'; path = shortty + '.' + name + '.html';
} }
var link = $('<a>', {'href': current.relpath + path, var link = document.createElement('a');
'title': desc, link.href = current.relpath + path;
'class': klass}).text(name); link.title = desc;
ul.append($('<li>').append(link)); link.className = klass;
link.textContent = name;
var li = document.createElement('li');
li.appendChild(link);
ul.appendChild(li);
} }
sidebar.append(div); div.appendChild(ul);
sidebar.appendChild(div);
} }
block("primitive", "Primitive Types"); block("primitive", "Primitive Types");
@ -890,21 +1069,25 @@
window.initSidebarItems = initSidebarItems; window.initSidebarItems = initSidebarItems;
window.register_implementors = function(imp) { window.register_implementors = function(imp) {
var list = $('#implementors-list'); var list = document.getElementById('implementors-list');
var libs = Object.getOwnPropertyNames(imp); var libs = Object.getOwnPropertyNames(imp);
for (var i = 0; i < libs.length; ++i) { for (var i = 0; i < libs.length; ++i) {
if (libs[i] === currentCrate) { continue; } if (libs[i] === currentCrate) { continue; }
var structs = imp[libs[i]]; var structs = imp[libs[i]];
for (var j = 0; j < structs.length; ++j) { for (var j = 0; j < structs.length; ++j) {
var code = $('<code>').append(structs[j]); var code = document.createElement('code');
$.each(code.find('a'), function(idx, a) { code.innerHTML = structs[j];
var href = $(a).attr('href');
var x = code.getElementsByTagName('a');
for (var i = 0; i < x.length; i++) {
var href = x[i].href;
if (href && href.indexOf('http') !== 0) { if (href && href.indexOf('http') !== 0) {
$(a).attr('href', rootPath + href); x[i].href = rootPath + href;
} }
}); }
var li = $('<li>').append(code); var li = document.createElement('li');
list.append(li); li.appendChild(code);
list.appendChild(li);
} }
} }
}; };
@ -922,146 +1105,186 @@
return "\u2212"; // "\u2212" is '' minus sign return "\u2212"; // "\u2212" is '' minus sign
} }
function toggleAllDocs() { function onEveryMatchingChild(elem, className, func) {
var toggle = $("#toggle-all-docs"); if (elem && className && func) {
if (toggle.hasClass("will-expand")) { for (var i = 0; i < elem.childNodes.length; i++) {
toggle.removeClass("will-expand"); if (hasClass(elem.childNodes[i], className)) {
toggle.children(".inner").text(labelForToggleButton(false)); func(elem.childNodes[i]);
toggle.attr("title", "collapse all docs");
$(".docblock").show();
$(".toggle-label").hide();
$(".toggle-wrapper").removeClass("collapsed");
$(".collapse-toggle").children(".inner").text(labelForToggleButton(false));
} else {
toggle.addClass("will-expand");
toggle.children(".inner").text(labelForToggleButton(true));
toggle.attr("title", "expand all docs");
$(".docblock").hide();
$(".toggle-label").show();
$(".toggle-wrapper").addClass("collapsed");
$(".collapse-toggle").children(".inner").text(labelForToggleButton(true));
}
}
function collapseDocs(toggle, animate) {
var relatedDoc = toggle.parent().next();
if (relatedDoc.is(".stability")) {
relatedDoc = relatedDoc.next();
}
if (relatedDoc.is(".docblock")) {
if (relatedDoc.is(":visible")) {
if (animate === true) {
relatedDoc.slideUp({
duration: 'fast',
easing: 'linear',
complete: function() {
toggle.children(".toggle-label").fadeIn();
toggle.parent(".toggle-wrapper").addClass("collapsed");
toggle.children(".inner").text(labelForToggleButton(true));
},
});
} else { } else {
relatedDoc.hide(); onEveryMatchingChild(elem.childNodes[i], className, func);
toggle.children(".toggle-label").show();
toggle.parent(".toggle-wrapper").addClass("collapsed");
toggle.children(".inner").text(labelForToggleButton(true));
} }
} else {
relatedDoc.slideDown({duration: 'fast', easing: 'linear'});
toggle.parent(".toggle-wrapper").removeClass("collapsed");
toggle.children(".inner").text(labelForToggleButton(false));
toggle.children(".toggle-label").hide();
} }
} }
} }
$("#toggle-all-docs").on("click", toggleAllDocs); function toggleAllDocs() {
var toggle = document.getElementById("toggle-all-docs");
if (hasClass(toggle, "will-expand")) {
removeClass(toggle, "will-expand");
onEveryMatchingChild(toggle, "inner", function(e) {
e.innerHTML = labelForToggleButton(false);
});
toggle.title = "collapse all docs";
onEach(document.getElementsByClassName("docblock"), function(e) {
e.style.display = 'block';
});
onEach(document.getElementsByClassName("toggle-label"), function(e) {
e.style.display = 'none';
});
onEach(document.getElementsByClassName("toggle-wrapper"), function(e) {
removeClass(e, "collapsed");
});
onEach(document.getElementsByClassName("collapse-toggle"), function(e) {
onEveryMatchingChild(e, "inner", function(i_e) {
i_e.innerHTML = labelForToggleButton(false);
});
});
} else {
addClass(toggle, "will-expand");
onEveryMatchingChild(toggle, "inner", function(e) {
e.innerHTML = labelForToggleButton(true);
});
toggle.title = "expand all docs";
onEach(document.getElementsByClassName("docblock"), function(e) {
e.style.display = 'none';
});
onEach(document.getElementsByClassName("toggle-label"), function(e) {
e.style.display = 'inline-block';
});
onEach(document.getElementsByClassName("toggle-wrapper"), function(e) {
addClass(e, "collapsed");
});
onEach(document.getElementsByClassName("collapse-toggle"), function(e) {
onEveryMatchingChild(e, "inner", function(i_e) {
i_e.innerHTML = labelForToggleButton(true);
});
});
}
}
$(document).on("click", ".collapse-toggle", function() { function collapseDocs(toggle) {
collapseDocs($(this), true) if (!toggle || !toggle.parentNode) {
}); return;
}
$(function() { var relatedDoc = toggle.parentNode.nextElementSibling;
var toggle = $("<a/>", {'href': 'javascript:void(0)', 'class': 'collapse-toggle'}) if (hasClass(relatedDoc, "stability")) {
.html("[<span class='inner'></span>]"); relatedDoc = relatedDoc.nextElementSibling;
toggle.children(".inner").text(labelForToggleButton(false)); }
if (hasClass(relatedDoc, "docblock")) {
$(".method, .impl-items > .associatedconstant").each(function() { if (!isHidden(relatedDoc)) {
if ($(this).next().is(".docblock") || relatedDoc.style.display = 'none';
($(this).next().is(".stability") && $(this).next().next().is(".docblock"))) { onEach(toggle.childNodes, function(e) {
$(this).children().last().after(toggle.clone()); if (hasClass(e, 'toggle-label')) {
} e.style.display = 'inline-block';
}); }
if (hasClass(e, 'inner')) {
var mainToggle = e.innerHTML = labelForToggleButton(true);
$(toggle.clone()).append( }
$('<span/>', {'class': 'toggle-label'}) });
.css('display', 'none') addClass(toggle.parentNode, 'collapsed');
.html('&nbsp;Expand&nbsp;description'));
var wrapper = $("<div class='toggle-wrapper'>").append(mainToggle);
$("#main > .docblock").before(wrapper);
$(".docblock.autohide").each(function() {
var wrap = $(this).prev();
if (wrap.is(".toggle-wrapper")) {
var toggle = wrap.children().first();
if ($(this).children().first().is("h3")) {
toggle.children(".toggle-label")
.text(" Show " + $(this).children().first().text());
}
$(this).hide();
wrap.addClass("collapsed");
toggle.children(".inner").text(labelForToggleButton(true));
toggle.children(".toggle-label").show();
}
});
var mainToggle =
$(toggle).append(
$('<span/>', {'class': 'toggle-label'})
.css('display', 'none')
.html('&nbsp;Expand&nbsp;attributes'));
var wrapper = $("<div class='toggle-wrapper toggle-attributes'>").append(mainToggle);
$("#main > pre > .attributes").each(function() {
$(this).before(wrapper);
collapseDocs($($(this).prev().children()[0]), false);
});
});
$('pre.line-numbers').on('click', 'span', function() {
var prev_id = 0;
function set_fragment(name) {
if (browserSupportsHistoryApi()) {
history.replaceState(null, null, '#' + name);
$(window).trigger('hashchange');
} else { } else {
location.replace('#' + name); relatedDoc.style.display = 'block';
removeClass(toggle.parentNode, 'collapsed');
onEach(toggle.childNodes, function(e) {
if (hasClass(e, 'toggle-label')) {
e.style.display = 'none';
}
if (hasClass(e, 'inner')) {
e.innerHTML = labelForToggleButton(false);
}
});
} }
} }
}
return function(ev) { var x = document.getElementById('toggle-all-docs');
var cur_id = parseInt(ev.target.id, 10); if (x) {
x.onclick = toggleAllDocs;
}
if (ev.shiftKey && prev_id) { function insertAfter(newNode, referenceNode) {
if (prev_id > cur_id) { referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
var tmp = prev_id; }
prev_id = cur_id;
cur_id = tmp; var toggle = document.createElement('a');
toggle.href = 'javascript:void(0)';
toggle.className = 'collapse-toggle';
toggle.innerHTML = "[<span class='inner'>"+labelForToggleButton(false)+"</span>]";
var func = function(e) {
var next = e.nextElementSibling;
if (!next) {
return;
}
if (hasClass(next, 'docblock') ||
(hasClass(next, 'stability') &&
hasClass(next.nextElementSibling, 'docblock'))) {
insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]);
}
}
onEach(document.getElementsByClassName('method'), func);
onEach(document.getElementsByClassName('impl-items'), function(e) {
onEach(e.getElementsByClassName('associatedconstant'), func);
});
var span = document.createElement('span');
span.className = 'toggle-label';
span.style.display = 'none';
span.innerHTML = '&nbsp;Expand&nbsp;description';
var mainToggle = toggle.cloneNode(true);
mainToggle.appendChild(span);
var wrapper = document.createElement('div');
wrapper.className = 'toggle-wrapper';
wrapper.appendChild(mainToggle);
onEach(document.getElementById('main').getElementsByClassName('docblock'), function(e) {
if (e.parentNode.id === "main") {
e.parentNode.insertBefore(wrapper, e);
}
});
onEach(document.getElementsByClassName('docblock'), function(e) {
if (hasClass(e, 'autohide')) {
var wrap = e.previousElementSibling;
if (wrap && hasClass(wrap, 'toggle-wrapper')) {
var toggle = wrap.childNodes[0];
if (e.childNodes[0].tagName === 'H3') {
onEach(toggle.getElementsByClassName('toggle-label'), function(i_e) {
i_e.innerHTML = " Show " + e.childNodes[0].innerHTML;
});
} }
e.style.display = 'none';
set_fragment(prev_id + '-' + cur_id); addClass(wrap, 'collapsed');
} else { onEach(toggle.getElementsByClassName('inner'), function(e) {
prev_id = cur_id; e.innerHTML = labelForToggleButton(true);
});
set_fragment(cur_id); onEach(toggle.getElementsByClassName('toggle-label'), function(e) {
e.style.display = 'block';
});
} }
}; }
}()); })
var span = document.createElement('span');
span.className = 'toggle-label';
span.style.display = 'none';
span.innerHTML = '&nbsp;Expand&nbsp;attributes';
toggle.appendChild(span);
var wrapper = document.createElement('div');
wrapper.className = 'toggle-wrapper toggle-attributes';
wrapper.appendChild(toggle);
onEach(document.getElementById('main').getElementsByTagName('pre'), function(e) {
onEach(e.getElementsByClassName('attributes'), function(i_e) {
i_e.parentNode.insertBefore(wrapper, i_e);
collapseDocs(i_e.previousSibling.childNodes[0]);
});
});
}()); }());
// Sets the focus on the search bar at the top of the page // Sets the focus on the search bar at the top of the page
function focusSearchBar() { function focusSearchBar() {
$('.search-input').focus(); document.getElementsByClassName('search-input')[0].focus();
} }

View File

@ -101,7 +101,7 @@ pub fn check(path: &Path, bad: &mut bool) {
filename.starts_with(".#") { filename.starts_with(".#") {
return return
} }
if filename == "miniz.c" || filename.contains("jquery") { if filename == "miniz.c" {
return return
} }