Created
August 16, 2012 04:32
-
-
Save thomaspark/3366870 to your computer and use it in GitHub Desktop.
Bootswatch bookmarklet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if($('.bootswatcher')[0]){ | |
$('.bootswatcher').remove(); | |
} else { | |
var $e = $('<select class="bootswatcher"><option>Amelia</option><option>Cerulean</option><option>Cosmo</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); | |
var r = '<link rel="stylesheet" href="http://bootswatch.com/default/bootstrap-responsive.min.css">'; | |
$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">' + r); | |
} | |
$('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); | |
} |
Have you thought about using the API rather than hardcoding the select list? This is the modified version I use.
https://gist.github.com/TuckerWhitehouse/7828718
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More info: http://news.bootswatch.com/post/29555952123/a-bookmarklet-for-bootswatch