summaryrefslogtreecommitdiff
path: root/pastepy/static/js/theme.js
diff options
context:
space:
mode:
Diffstat (limited to 'pastepy/static/js/theme.js')
-rw-r--r--pastepy/static/js/theme.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/pastepy/static/js/theme.js b/pastepy/static/js/theme.js
new file mode 100644
index 0000000..d13c120
--- /dev/null
+++ b/pastepy/static/js/theme.js
@@ -0,0 +1,41 @@
+function set_theme(name) {
+ var themes = {
+ default: {
+ bootstrap: '/static/css/bootstrap.flatly.min.css',
+ pygments: '/highlight_stylesheet',
+ pastepy: '/static/css/paste.css',
+ },
+ dark: {
+ bootstrap: '/static/css/bootstrap.darkly.min.css',
+ pygments: '/highlight_stylesheet/paraiso-dark',
+ pastepy: '/static/css/paste.dark.css',
+ }
+ };
+ var bootstrap_css = document.getElementById('bootstrap-css');
+ var pygments_css = document.getElementById('pygments-css');
+ var pastepy_css = document.getElementById('pastepy-css');
+ var theme = themes[name];
+ bootstrap_css.href = theme.bootstrap;
+ if (pygments_css) {
+ pygments_css.href = theme.pygments;
+ }
+ if (pastepy_css) {
+ pastepy_css.href = theme.pastepy;
+ }
+ var theme = localStorage.setItem('theme', name);
+}
+function switch_theme(event) {
+ if (event && event.type !== 'load') {
+ event.preventDefault();
+ }
+ var bootstrap_css = document.getElementById('bootstrap-css');
+ var pygments_css = document.getElementById('pygments-css');
+ var theme = localStorage.getItem('theme');
+ set_theme(theme === 'dark' ? 'default' : 'dark');
+}
+window.addEventListener('load', function() {
+ var theme = localStorage.getItem('theme');
+ if (theme) {
+ set_theme(theme);
+ }
+});