Last active
October 20, 2015 13:50
-
-
Save khusamov/7cc94f5e285c415947b1 to your computer and use it in GitHub Desktop.
Переключатель темы Bootswatch for Twitter Bootstrap
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
/** | |
* Переключатель темы Bootswatch for Twitter Bootstrap. | |
* http://jsbin.com/momonupayu/1/edit?html,js,output | |
* http://bootswatch.com/help/ | |
* | |
* Цепляется к событию change элемента select#themeswitch. | |
* Меняет link содержащий bootswatch в аттрибуте href. | |
*/ | |
$(function() { | |
$.getJSON("https://bootswatch.com/api/3.json", function (data) { | |
var themes = data.themes; | |
var select = $("select#themeswitch"); | |
select.show(); | |
themes.push({ | |
css: "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css", | |
name: "Default" | |
}); | |
themes.forEach(function(value, index){ | |
select.append($("<option />") | |
.val(index) | |
.text(value.name)); | |
}); | |
var link = $("link[href*='bootswatch']"); | |
themes.forEach(function(theme, index) { | |
if (link.attr("href") == theme.css) { | |
select.val(index); | |
} | |
}); | |
select.change(function(){ | |
var theme = themes[$(this).val()]; | |
link.attr("href", theme.css); | |
}); | |
}, "json").fail(function(){ | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment