$(document).ready(function(){
var show_text = 'show details';
var hide_text = 'hide details';
// hide the sub-level checkboxes in contextual areas, add a link to hook hide/show behaviour to
$('.contextual').hide().before('<a class="revealer" href="#">'+show_text+'</a>');
// add the hide/show behaviour
$('.revealer').click(function(){
$(this).next().toggle();
var new_text = ( $(this).text() == show_text ) ? hide_text : show_text ;
updateRevealerText( $(this), new_text );
return false;
})
// we want all sub-level-checkboxes to be checked by default, but disable them so they are not submitted
$('.contextual input[type="checkbox"]').attr('checked','checked').attr('disabled',true);
// clicking a checkbox will open its sub-level options for more detail
$('input[type="checkbox"]').change(function(){
var contextual = $(this).parent().find('.contextual').first();
if ( $(this).is(':checked') ) {
contextual.show();
contextual.find('input').removeAttr('disabled');
updateRevealerText( contextual.prev(), hide_text );
} else {
contextual.hide();
contextual.find('input').attr('disabled',true);
updateRevealerText( contextual.prev(), show_text );
}
})
function updateRevealerText( el, new_text ) {
if ( el.text() != new_text ) { el.text(new_text) }
}
})
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!