![James Slagle](/assets/img/avatar_default.png)
Co-Authored-By: Ana Krivokapic <akrivoka@redhat.com> Co-Authored-By: Ben Nemec <bnemec@redhat.com> Co-Authored-By: Ben Nemec <cybertron@nemebean.com> Co-Authored-By: Brad P. Crochet <brad@redhat.com> Co-Authored-By: Crag Wolfe <cwolfe@redhat.com> Co-Authored-By: Dan Sneddon <dsneddon@redhat.com> Co-Authored-By: David Kranz <dkranz@redhat.com> Co-Authored-By: Derek Higgins <derekh@redhat.com> Co-Authored-By: Dimitri Savineau <dsavinea@redhat.com> Co-Authored-By: Dmitry Tantsur <divius.inside@gmail.com> Co-Authored-By: Dmitry Tantsur <dtantsur@redhat.com> Co-Authored-By: Dougal Matthews <dougal@redhat.com> Co-Authored-By: François Charlier <francois.charlier@redhat.com> Co-Authored-By: Giulio Fidente <gfidente@redhat.com> Co-Authored-By: Imre Farkas <ifarkas@redhat.com> Co-Authored-By: James Slagle <jslagle@redhat.com> Co-Authored-By: Jan Provaznik <jprovazn@redhat.com> Co-Authored-By: Jaromir Coufal <jcoufal@redhat.com> Co-Authored-By: Jay Dobies <jason.dobies@redhat.com> Co-Authored-By: Jeff Peeler <jpeeler@redhat.com> Co-Authored-By: Jiri Stransky <jistr@redhat.com> Co-Authored-By: Jiri Tomasek <jtomasek@redhat.com> Co-Authored-By: John Trowbridge <trown@redhat.com> Co-Authored-By: Lennart Regebro <regebro@gmail.com> Co-Authored-By: Lucas Alvares Gomes <lucasagomes@gmail.com> Co-Authored-By: Marek Aufart <maufart@redhat.com> Co-Authored-By: Ronelle Landy <rlandy@redhat.com> Co-Authored-By: Sasha Chuzhoy <sasha@redhat.com> Co-Authored-By: Sasha Chuzhoy <sashac88@hotmail.com> Co-Authored-By: Steven Hardy <shardy@redhat.com> Co-Authored-By: Zane Bitter <zbitter@redhat.com> Co-Authored-By: marios <marios@redhat.com>
59 lines
1.7 KiB
JavaScript
59 lines
1.7 KiB
JavaScript
/*
|
|
This function will search for all classes matching all IDs which are under
|
|
#admonition_selector element and display/hide their content.
|
|
|
|
State is saved in cookies so user doesn't lose his settings after page
|
|
reload or changing pages.
|
|
|
|
To make this feature work, you need to:
|
|
- add checkbox to _templates/layout.html file with proper ID
|
|
- in admonitions use proper class which matches above mentioned ID
|
|
*/
|
|
|
|
|
|
|
|
// after document is loaded
|
|
$(document).ready(function() {
|
|
|
|
// for each checkbox in #admonition_selector do
|
|
$('#admonition_selector :checkbox').each(function() {
|
|
|
|
// check value of cookies and set state to the related element
|
|
if ($.cookie($(this).attr("id")) == "true") {
|
|
$(this).prop("checked", true);
|
|
} else if (($.cookie($(this).attr("id")) == "false")) {
|
|
$(this).prop("checked", false);
|
|
}
|
|
|
|
// show/hide elements after page loaded
|
|
toggle_admonition($(this).attr("id"));
|
|
});
|
|
|
|
// when user clicks on the checkbox, react
|
|
$('#admonition_selector :checkbox').change(function() {
|
|
|
|
// show/hide related elements
|
|
toggle_admonition($(this).attr("id"));
|
|
|
|
// save the state in the cookies
|
|
$.cookie($(this).attr("id"), $(this).is(':checked'), { path: '/' });
|
|
});
|
|
});
|
|
|
|
|
|
// function to show/hide elements based on checkbox state
|
|
// checkbox has ID and it toggles elements having class named same way as the ID
|
|
function toggle_admonition(admonition) {
|
|
|
|
// for each element having class as the checkbox's ID
|
|
$(".admonition." + admonition).each(function() {
|
|
|
|
// set show/hide
|
|
if($("#" + admonition).is(':checked')) {
|
|
$(this).show();
|
|
} else {
|
|
$(this).hide();
|
|
}
|
|
});
|
|
}
|