Skip to content

Instantly share code, notes, and snippets.

@joellesenne
Forked from thomaspark/bootswatchlet.js
Created September 9, 2012 08:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joellesenne/3683316 to your computer and use it in GitHub Desktop.
Save joellesenne/3683316 to your computer and use it in GitHub Desktop.
Bootswatch bookmarklet
if($('.bootswatcher')[0]){
$('.bootswatcher').remove();
} else {
var $e = $('<select class="bootswatcher"><option>Amelia</option><option>Cerulean</option><option>Cyborg</option><option>Journal</option><option>Readable</option><option>Simplex</option><option>Slate</option><option>Spacelab</option><option>Spruce</option><option>Superhero</option><option>United</option></select>');
var l = 1 + Math.floor(Math.random() * $e.children().length);
$e.css({'z-index': '99999', 'position': 'fixed', 'top': '5px', 'right': '5px', 'opacity': '0.5'}
).hover(
function(){$(this).css('opacity', '1');},
function(){$(this).css('opacity', '0.5');}
).change(function(){
if(!$('link.bootswatcher')[0]){
$('head').append('<link rel="stylesheet" class="bootswatcher">');
}
$('link.bootswatcher').attr('href', 'http://bootswatch.com/' + $(this).find(':selected').text().toLowerCase() + '/bootstrap.min.css');
})
.find('option:nth-child(' + l + ')').attr('selected', 'selected').end()
.trigger('change');
$('body').append($e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment