Last active
December 16, 2015 18:49
-
-
Save skopp/5480511 to your computer and use it in GitHub Desktop.
bootswatcherizr vanilla javascript and a bonus coffeescript flavour (converted to coffee with js2coffee) version. Project is currently alpha [not meant for serious use]
This file contains hidden or 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
(function(e, a, g, h, f, c, b, d) { | |
if (!(f = e.jQuery) || g > f.fn.jquery || h(f)) { | |
c = a.createElement("script"); | |
c.type = "text/javascript"; | |
c.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + g + "/jquery.min.js"; | |
c.onload = c.onreadystatechange = function() { | |
if (!b && (!(d = this.readyState) || d === "loaded" || d === "complete")) { | |
h((f = e.jQuery).noConflict(1), b = 1); | |
return f(c).remove(); | |
} | |
}; | |
return a.documentElement.childNodes[0].appendChild(c); | |
} | |
})(window, document, "1.3.2", function($, L) { | |
var $e, l, r; | |
$e = void 0; | |
l = void 0; | |
r = void 0; | |
$e = void 0; | |
l = void 0; | |
r = void 0; | |
if ($(".bootswatcher")[0]) { | |
return $(".bootswatcher").remove(); | |
} else { | |
$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>"); | |
l = 1 + Math.floor(Math.random() * $e.children().length); | |
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() { | |
return $(this).css("opacity", "1"); | |
}, function() { | |
return $(this).css("opacity", "0.5"); | |
}).change(function() { | |
if (!$("link.bootswatcher")[0]) { | |
$("head").append("<link rel=\"stylesheet\" class=\"bootswatcher\">" + r); | |
} | |
return $("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"); | |
return $("body").append($e); | |
} | |
}); |
This file contains hidden or 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
((e, a, g, h, f, c, b, d) -> | |
if not (f = e.jQuery) or g > f.fn.jquery or h(f) | |
c = a.createElement("script") | |
c.type = "text/javascript" | |
c.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + g + "/jquery.min.js" | |
c.onload = c.onreadystatechange = -> | |
if not b and (not (d = @readyState) or d is "loaded" or d is "complete") | |
h (f = e.jQuery).noConflict(1), b = 1 | |
f(c).remove() | |
a.documentElement.childNodes[0].appendChild c | |
) window, document, "1.3.2", ($, L) -> | |
$e = undefined | |
l = undefined | |
r = undefined | |
$e = undefined | |
l = undefined | |
r = undefined | |
$e = undefined | |
l = undefined | |
r = undefined | |
if $(".bootswatcher")[0] | |
$(".bootswatcher").remove() | |
else | |
$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>") | |
l = 1 + Math.floor(Math.random() * $e.children().length) | |
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(-> | |
$(this).css "opacity", "1" | |
, -> | |
$(this).css "opacity", "0.5" | |
).change(-> | |
$("head").append "<link rel=\"stylesheet\" class=\"bootswatcher\">" + r unless $("link.bootswatcher")[0] | |
$("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