diff options
| author | Michael Foster <savetheinternet@tinyboard.org> | 2013-07-23 01:35:56 -0400 |
|---|---|---|
| committer | Michael Foster <savetheinternet@tinyboard.org> | 2013-07-23 01:35:56 -0400 |
| commit | ab0c5ee48152818bc923a1d093f3151da42eb88e (patch) | |
| tree | 87b41b2879278f73f1ac1d0d0b2418a3aa43fc82 /templates | |
| parent | f0aee74523158e9c7504502bb54100681fffe0d5 (diff) | |
Option to make stylesheet selections board-specific
Diffstat (limited to 'templates')
| -rw-r--r-- | templates/main.js | 61 |
1 files changed, 50 insertions, 11 deletions
diff --git a/templates/main.js b/templates/main.js index 9ec0025f..b3219b3c 100644 --- a/templates/main.js +++ b/templates/main.js @@ -9,9 +9,19 @@ var styles = { {% for stylesheet in stylesheets %}{% raw %}'{% endraw %}{{ stylesheet.name|addslashes }}{% raw %}' : '{% endraw %}{{ stylesheet.uri|addslashes }}{% raw %}',
{% endraw %}{% endfor %}{% raw %}
};
+var board_name = false; -function changeStyle(styleName, link) {
- localStorage.stylesheet = styleName;
+function changeStyle(styleName, link) { + {% endraw %} + {% if config.stylesheets_board %}{% raw %} + if (board_name) { + stylesheet_choices[board_name] = styleName; + localStorage.board_stylesheets = JSON.stringify(stylesheet_choices); + } + {% endraw %}{% else %} + localStorage.stylesheet = styleName; + {% endif %} + {% raw %}
if (!document.getElementById('stylesheet')) {
var s = document.createElement('link');
@@ -27,7 +37,7 @@ function changeStyle(styleName, link) { if (document.getElementsByClassName('styles').length != 0) {
var styleLinks = document.getElementsByClassName('styles')[0].childNodes;
- for (i = 0; i < styleLinks.length; i++) {
+ for (var i = 0; i < styleLinks.length; i++) {
styleLinks[i].className = '';
}
}
@@ -36,15 +46,44 @@ function changeStyle(styleName, link) { link.className = 'selected';
}
}
-
-if (localStorage.stylesheet) {
- for (styleName in styles) {
- if (styleName == localStorage.stylesheet) {
- changeStyle(styleName);
- break;
+ + +{% endraw %} +{% if config.stylesheets_board %} + {# This is such an unacceptable mess. There needs to be an easier way. #} + var matches = document.URL.match(/\/(\w+)\/($|{{ config.dir.res|replace({'/': '\\/'}) }}{{ config.file_page|replace({'%d': '\\d+', '.': '\\.'}) }}|{{ config.file_index|replace({'.': '\\.'}) }}|{{ config.file_page|replace({'%d': '\\d+', '.': '\\.'}) }})/); + {% raw %} + if (matches) { + board_name = matches[1]; + } + + if (!localStorage.board_stylesheets) { + localStorage.board_stylesheets = '{}'; + } + + var stylesheet_choices = JSON.parse(localStorage.board_stylesheets); + if (board_name && stylesheet_choices[board_name]) { + for (var styleName in styles) { + if (styleName == stylesheet_choices[board_name]) { + changeStyle(styleName); + break; + } + } + } + {% endraw%} +{% else %} + {% raw %} + if (localStorage.stylesheet) {
+ for (var styleName in styles) {
+ if (styleName == localStorage.stylesheet) {
+ changeStyle(styleName);
+ break;
+ }
}
- }
-}
+ } + {% endraw %}
+{% endif %} +{% raw %} function init_stylechooser() {
var newElement = document.createElement('div');
|
