remember position of column titles
authorAndrew Lorimer <andrew@lorimer.id.au>
Sat, 17 Aug 2019 01:34:04 +0000 (11:34 +1000)
committerAndrew Lorimer <andrew@lorimer.id.au>
Sat, 17 Aug 2019 01:34:04 +0000 (11:34 +1000)
admin.js
index 157c99091aa716c9d3093eb3da6a9ee42e29728a..ddc08c5e2aff6cd442b4ffbbb12e082c62e5e5f0 100644 (file)
--- a/admin.js
+++ b/admin.js
@@ -3,25 +3,23 @@ var rmspan = ["<span class='remove' id='delete-", "'>–</span>"]
 document.addEventListener("DOMContentLoaded", function() {
   chrome.storage.sync.get(
     {"lists": [
-      [
+      ["General",
         ["Github", "https://github.com"],
         ["Wikipedia", "https://en.wikipedia.org"],
         ["Gmail", "https://mail.google.com"]
       ],
-      [
+      ["Productivity",
         ["Desmos", "https://www.desmos.com/calculator"],
         ["Wolfram", "https://wolframalpha.com"],
         ["Hacker News", "https://news.ycombinator.com"]
       ],
-      [
+      ["Social",
         ["Reddit", "https://www.reddit.com"],
         ["YouTube", "https://youtube.com"],
         ["Instagram", "https://instagram.com"]
       ]
-    ],
-"l1name": "General",
-"l2name": "Productivity",
-"l3name": "Social"},
+    ]
+},
     userListsCallback);
 });
 
@@ -36,15 +34,20 @@ function columnToArray(list) {
 
 function listToArray(list) {
   var l = [];
+  console.log(list);
+  console.log(list.getElementsByClassName('title')[0].getElementsByTagName("p")[0].textContent);
+  l[0] = list.getElementsByClassName('title')[0].getElementsByTagName("p")[0].textContent;
   var elem = list.getElementsByTagName("li");
   for (var i = 0; i < elem.length; ++i) {
-    l[i] = [elem[i].getElementsByTagName("a")[0].innerText, elem[i].getElementsByTagName("a")[0].getAttribute("href")];
+    l[i+1] = [elem[i].getElementsByTagName("a")[0].innerText, elem[i].getElementsByTagName("a")[0].getAttribute("href")];
   }
   return l;
 }
 
 var userListsCallback = function(lists) {
-  mainlist = [lists["l1name"],lists["l2name"],lists["l3name"]]
+  console.log(lists);
+  console.log(lists['lists'][0][0]);
+  mainlist = [lists['lists'][0][0],lists['lists'][1][0],lists['lists'][2][0]]
   for(var i=0;i<lists["lists"].length;i++) {
     var ul = document.createElement("ul");
     ul.setAttribute("id", mainlist[i]);
@@ -71,7 +74,7 @@ var userListsCallback = function(lists) {
     title.insertAdjacentHTML("beforeend", "<span class='add' id='add-"+mainlist[i]+"'>+</span>");
 
     var list = lists["lists"][i];
-    for(var j=0;j<lists["lists"][i].length;j++) {
+    for(var j=1;j<lists["lists"][i].length;j++) {
       var li = document.createElement("li");
       li.setAttribute("id", mainlist[i]+"-"+j);
       var siteurl = list[j][1];
@@ -98,7 +101,6 @@ var userListsCallback = function(lists) {
 };
 
 function dragStart(e) {
-  console.log("Drag started for " + this);
   console.log(this);
   dragSrcEl = this;
   e.dataTransfer.effectAllowed = 'move';
@@ -106,7 +108,6 @@ function dragStart(e) {
 }
 
 function dragOver(e) {
-  console.log("Object " + this + " is ready to be placed");
   if (e.preventDefault) {
     e.preventDefault();
   }
@@ -127,11 +128,11 @@ function drop(e) {
     e.stopPropagation();
   }
   if (dragSrcEl != this) {
+    console.log(mainlist);
     dragSrcEl.innerHTML = this.innerHTML;
     this.innerHTML = e.dataTransfer.getData('text/html');
+    save();
   }
-  console.log("Saving positions");
-  save();
   return false;
 }
 
@@ -160,7 +161,6 @@ function listen(li) {
       save();
     } else {
       var ul = document.getElementById(r[1]);
-      console.log(ul);
       if (document.querySelectorAll("#"+r[1]+" .new").length > 0) {
         fields = document.querySelector("#"+r[1]+" .new .name");
         fields.focus(); 
@@ -228,6 +228,7 @@ function menu() {
 
 function save(l) {
   var set = l || JSON.parse(JSON.stringify(mainlist));
+  console.log(set);
   d = []
   d = set;
   console.log("Saving settings");