From: Marius Gavrilescu Date: Fri, 17 Apr 2015 16:03:35 +0000 (+0300) Subject: Add a function for making a DOM element from HTML X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=81c2ef986ee0eba06af44f7830ee54be7e548bb3;p=gruntmaster-page.git Add a function for making a DOM element from HTML --- diff --git a/MANIFEST b/MANIFEST index 2830c62..4f04f2a 100644 --- a/MANIFEST +++ b/MANIFEST @@ -14,6 +14,7 @@ css/themes/cyborg.css css/themes/readable.css css/themes/slate.css js/00-strict.js +js/05-makedom.js js/05-ki.js js/10-modal.js js/80-sidebar.js diff --git a/js/05-makedom.js b/js/05-makedom.js new file mode 100644 index 0000000..68026a1 --- /dev/null +++ b/js/05-makedom.js @@ -0,0 +1,5 @@ +function m(html) { + var div = document.createElement("div"); + div.innerHTML = html; + return div.firstChild; +} diff --git a/js/90-themes.js b/js/90-themes.js index a61b4c0..c280266 100644 --- a/js/90-themes.js +++ b/js/90-themes.js @@ -6,21 +6,13 @@ function set_style(name){ localStorage.setItem("theme", name); } -var theme_ul; - -function add_themelink(theme, text) { - theme_ul.innerHTML += '
  • ' + text + '' -} - $(function() { - theme_ul = document.createElement('ul'); - theme_ul.className = 'list-inline'; - theme_ul.id = 'themes'; - add_themelink('cyborg', 'Black'); - add_themelink('slate', 'Grey'); - add_themelink('readable', 'White'); + var theme_ul = ''; var sidebar = $('#sidebar')[0]; - sidebar.insertBefore(theme_ul, sidebar.firstChild); + sidebar.insertBefore(m(theme_ul), sidebar.firstChild); $('#themes a').on('click', function(e){ set_style(this.dataset.theme); }); diff --git a/js/90-tracker.js b/js/90-tracker.js index 0db5459..42ee1f7 100644 --- a/js/90-tracker.js +++ b/js/90-tracker.js @@ -111,10 +111,7 @@ function stop_tracking(){ } $(function(){ - tracker = document.createElement('div'); - tracker.id = 'tracker'; - tracker.className = 'hidden'; - tracker.innerHTML = 'Tracking .
    Stop tracking
    Job log
    Solved
    ?
    Attempted
    ?
    Contests
    ?
    '; + tracker = m(''); var sidebar = $('#sidebar')[0]; sidebar.insertBefore(tracker, sidebar.firstChild); $('#tracker_stop').on('click', stop_tracking);