-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme-changer.js
98 lines (83 loc) · 2.48 KB
/
theme-changer.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
var ThemeChanger = {};
ThemeChanger.Init = function() {
ThemeChanger.themes = [];
ThemeChanger.currentTheme = 0;
ThemeChanger.Cache();
ThemeChanger.BindListeners();
ThemeChanger.PopulateCategories();
ThemeChanger.PopulateThemes();
};
ThemeChanger.Cache = function() {
ThemeChanger.dom = {};
ThemeChanger.dom.doc = $(document);
};
ThemeChanger.BindListeners = function(){
ThemeChanger.dom.doc.on('keydown', function(e){
if( e.ctrlKey || e.metaKey ){
if( e.which == 39 ){
ThemeChanger.NextTheme();
return false;
}
if( e.which == 37 ){
ThemeChanger.PrevTheme();
return false;
}
if( e.which == 35 ){
ThemeChanger.RemoveTheme();
return false;
}
}
});
};
ThemeChanger.PopulateCategories = function() {
};
ThemeChanger.PopulateThemes = function() {
var params = {category: 'default'};
if( location.href.indexOf('facebook.com') >= 0 ){
params.category = 'facebook';
}
else if( location.href.indexOf('twitter.com') >= 0 ){
params.category = 'twitter';
}
else if( $('link[href*=bootstrap]').length > 0 ){
params.category = 'bootstrap';
}
$.getJSON('//common.greaterthanten.com/css/themes/list.php', params, function(data){
ThemeChanger.themes = data;
});
};
ThemeChanger.NextTheme = function() {
ThemeChanger.currentTheme++;
ThemeChanger.currentTheme = ThemeChanger.currentTheme % ThemeChanger.themes.length;
ThemeChanger.LoadTheme();
};
ThemeChanger.PrevTheme = function() {
ThemeChanger.currentTheme = (ThemeChanger.currentTheme < 1) ? (ThemeChanger.themes.length - 1) : (ThemeChanger.currentTheme - 1);
ThemeChanger.LoadTheme();
};
ThemeChanger.LoadTheme = function() {
var css = $('link.theme-changer');
if( css.length < 1 ){
ThemeChanger.saved = $('link[href*=bootstrap]').not('[href*=responsive]').detach();
css = $('<link class="theme-changer">');
$('head').prepend(css);
}
css.attr({
rel : 'stylesheet',
type : 'text/css',
href : '//common.greaterthanten.com/css/themes/' + ThemeChanger.themes[ThemeChanger.currentTheme]
});
var $div = $('#theme-changer-label');
if( $div.length < 1 ){
$div = $('<div id="theme-changer-label" />');
$div.css('position', 'fixed').css('top', '0px').css('left', '0px').css('color', 'black').css('background-color', 'white');
}
$div.text(ThemeChanger.themes[ThemeChanger.currentTheme]);
$('body').append($div);
};
ThemeChanger.RemoveTheme = function() {
$('link.theme-changer').remove();
$('#theme-changer-label').remove();
$('head').prepend(ThemeChanger.saved);
};
ThemeChanger.Init();