]> iEval git - gruntmaster-page.git/commitdiff
Add a function for making a DOM element from HTML
authorMarius Gavrilescu <marius@ieval.ro>
Fri, 17 Apr 2015 16:03:35 +0000 (19:03 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Fri, 17 Apr 2015 16:03:35 +0000 (19:03 +0300)
MANIFEST
js/05-makedom.js [new file with mode: 0644]
js/90-themes.js
js/90-tracker.js

index 2830c6294484cf8c7c3bbcee4da66414f8ec32e0..4f04f2a33e45e69e54a552aea6426503ceeec8ef 100644 (file)
--- 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 (file)
index 0000000..68026a1
--- /dev/null
@@ -0,0 +1,5 @@
+function m(html) {
+       var div = document.createElement("div");
+       div.innerHTML = html;
+       return div.firstChild;
+}
index a61b4c0c0089983ff69f06341667ceb9f6d57e15..c280266f466e6ac7506ce355df3d4c8767bcdceb 100644 (file)
@@ -6,21 +6,13 @@ function set_style(name){
        localStorage.setItem("theme", name);
 }
 
-var theme_ul;
-
-function add_themelink(theme, text) {
-       theme_ul.innerHTML += '<li><a role="button" data-theme="' + theme +  '">' + text + '</a>'
-}
-
 $(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 = '<ul class="list-inline" id="themes">' +
+               '<li><a role="button" data-theme="cyborg">Black</a>' +
+               '<li><a role="button" data-theme="slate">Grey</a>' +
+               '<li><a role="button" data-theme="readable">White</a></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);
        });
index 0db54590532bd215b1437926e58850bd3fdce21b..42ee1f78c16bf602f2884d86737ce91fc032646e 100644 (file)
@@ -111,10 +111,7 @@ function stop_tracking(){
 }
 
 $(function(){
-       tracker = document.createElement('div');
-       tracker.id = 'tracker';
-       tracker.className = 'hidden';
-       tracker.innerHTML = 'Tracking <a id="tracker_userlink"></a>.<br><a id="tracker_stop" role="button">Stop tracking</a><br><a id="tracker_log">Job log</a><dl class="dl-horizontal"><dt>Solved</dt>    <dd id="tracker_solved">?</dd><dt>Attempted</dt> <dd id="tracker_attempted">?</dd><dt>Contests</dt>  <dd id="tracker_contests">?</dd></dl>';
+       tracker = m('<div id="tracker" class="hidden">Tracking <a id="tracker_userlink"></a>.<br><a id="tracker_stop" role="button">Stop tracking</a><br><a id="tracker_log">Job log</a><dl class="dl-horizontal"><dt>Solved</dt>    <dd id="tracker_solved">?</dd><dt>Attempted</dt> <dd id="tracker_attempted">?</dd><dt>Contests</dt>  <dd id="tracker_contests">?</dd></dl></div>');
        var sidebar = $('#sidebar')[0];
        sidebar.insertBefore(tracker, sidebar.firstChild);
        $('#tracker_stop').on('click', stop_tracking);
This page took 0.029077 seconds and 4 git commands to generate.