From bdaa8919598cbbd8753fd6795b34b594b1b30805 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Fri, 3 Apr 2015 11:15:51 +0300 Subject: [PATCH] Insert javascript-dependent HTML from javascript --- js/90-themes.js | 16 ++++++++++++---- js/90-tracker.js | 9 ++++++--- js/95-login.js | 2 +- tmpl/skel.en | 25 ------------------------- 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/js/90-themes.js b/js/90-themes.js index 7221dde..6afd444 100644 --- a/js/90-themes.js +++ b/js/90-themes.js @@ -6,11 +6,19 @@ localStorage.setItem("theme", name); } + var selector; + + function add_themelink(theme, text) { + var link = $('' + text + ''); + link.appendTo(selector.find('ul')).wrap('
  • ').on('click', function () { set_style(theme) }); + } + $( document ).ready(function() { - $('#theme-selector').detach().prependTo($('#sidebar')); - $('#theme_slate' ).on('click', function () { set_style("slate"); }); - $('#theme_cyborg' ).on('click', function () { set_style("cyborg"); }); - $('#theme_readable').on('click', function () { set_style("readable"); }); + selector = $('
    Themes:
      '); + add_themelink('cyborg', 'Black'); + add_themelink('slate', 'Grey'); + add_themelink('readable', 'White'); + $('#sidebar').prepend(selector); }); var theme = localStorage.getItem("theme"); diff --git a/js/90-tracker.js b/js/90-tracker.js index 50ba7d4..1fa4905 100644 --- a/js/90-tracker.js +++ b/js/90-tracker.js @@ -9,6 +9,8 @@ $('.tracker-info').removeClass('tracker-info info'); } + var tracker; + function update_tracker(){ var data = localStorage.getItem('tracker_data'); var user = localStorage.getItem('tracker_username'); @@ -74,7 +76,7 @@ function start_tracking(user){ localStorage.setItem('tracker_username', user); $('#tracker_userlink').attr('href', '/us/' + user).html(user); - $('#tracker_tracking').removeClass('hidden'); + tracker.removeClass('hidden'); update_tracker(); var lastfetch = localStorage.getItem('tracker_lastfetch'); if(Date.now() - lastfetch > 60 * 10 * 1000) @@ -100,11 +102,12 @@ localStorage.removeItem('tracker_username'); localStorage.removeItem('tracker_data'); localStorage.removeItem('tracker_lastfetch'); - $('#tracker_tracking').addClass('hidden'); + tracker.addClass('hidden'); } $( document ).ready(function(){ - $('#tracker').detach().prependTo($('#sidebar')); + tracker = $(''); + tracker.prependTo($('#sidebar')); $('#tracker_stop').on('click', stop_tracking); $('#track_user').on('click', function() { stop_tracking(); start_tracking($(this).data('user')) }); $('#submitform').on('submit', function() { localStorage.removeItem('tracker_lastfetch') }); diff --git a/js/95-login.js b/js/95-login.js index 60ede9d..7f52deb 100644 --- a/js/95-login.js +++ b/js/95-login.js @@ -2,7 +2,7 @@ 'use strict'; $( document ).ready(function(){ - $('#login').detach().prependTo($('#sidebar')).on('click', function(e) { + $('Log in').prependTo($('#sidebar')).wrap('
      ').on('click', function(e) { var xhr = new XMLHttpRequest(); xhr.open('GET', '/login'); xhr.onload = function () { diff --git a/tmpl/skel.en b/tmpl/skel.en index 6ae836a..22411f9 100644 --- a/tmpl/skel.en +++ b/tmpl/skel.en @@ -33,31 +33,6 @@
      Content goes here
      -
      - -
      -Themes: - -
      - -
      - -
      -