forked from DevExpress/bootstrap-themes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
58 lines (53 loc) · 2.16 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var dx = dx || {};
(function(){
var themes = {};
themes["purple"] = { folder: "purple", title: "Purple" };
themes["office-white"] = { folder: "office-white", title: "Office White" };
$('body').scrollspy({ target: '#scrollspy', offset: 90 });
$('[data-toggle="popover"]').popover();
$('[data-toggle="tooltip"]').tooltip();
$('[data-toggle="indeterminate-checkbox"]').prop("indeterminate", true);
$("a[href='#']").click(function(e) {
e.preventDefault();
});
function getCurrentThemeName() {
var url = window.location.href;
var regex = new RegExp('[?&]theme(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
var result = (!results || !results[2]) ? null : results[2];
return result || "purple";
}
function updateThemesList() {
var listHtml = "";
for(var themeName in themes) {
listHtml += "<a class='dropdown-item' href='javascript:;' onclick='dx.setTheme("" + themeName + "")'>" + themes[themeName].title + "</a>";
};
$("#themesList").html(listHtml);
}
function updateCurrentTheme() {
var themeName = getCurrentThemeName();
var theme = themes[themeName];
if(theme) {
var minCssUrl = "dist/" + theme.folder + "/bootstrap.min.css";
var cssUrl = "dist/" + theme.folder + "/bootstrap.css";
$("#styleLink").attr("href", minCssUrl);
$("#downloadCss").attr("href", cssUrl);
$("#downloadMinCss").attr("href", minCssUrl);
$("#themeCaption").html(theme.title);
$("#downloadTheme").html(theme.title);
}
}
dx.setTheme = function(themeName) {
var anchor = document.location.href.split("#")[1];
window.history.pushState({ themeName: themeName }, window.title, "?theme=" + themeName + (anchor ? "#" + anchor : ""));
updateCurrentTheme();
}
$(document).ready(function(){
updateThemesList();
updateCurrentTheme();
});
$(window).on('popstate', function() {
updateThemesList();
updateCurrentTheme();
});
})();