changeset 16:64272f2105da

Show four tag input elements by default
author Guido Berhoerster <guido+booket@berhoerster.name>
date Sun, 21 Sep 2014 19:22:09 +0200
parents fb5fb3b38c0d
children 8445c729ba97
files booket.js
diffstat 1 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/booket.js	Thu Sep 18 20:36:21 2014 +0200
+++ b/booket.js	Sun Sep 21 19:22:09 2014 +0200
@@ -1043,6 +1043,7 @@
     var importFormElement;
     var exportFormElement;
     var newNode;
+    var i;
 
     ObservableMixin.call(this);
 
@@ -1083,7 +1084,10 @@
 
     this.editTagListElement =
         this.editorFormElement.querySelector('ul.tag-input-list');
-    this.editTagListElement.appendChild(this.createTagInputElement(''));
+    // add four tag input elements for convenience
+    for (i = 0; i < 4; i++) {
+        this.editTagListElement.appendChild(this.createTagInputElement(''));
+    }
 
     saveFormElement.parentNode.insertBefore(newNode,
         saveFormElement.nextSibling);
@@ -1107,6 +1111,7 @@
     var parsedData;
     var tags = [];
     var i;
+    var tagInputElements;
 
     switch (e.type) {
     case 'error':
@@ -1201,12 +1206,12 @@
             e.target.querySelector('img.bookmark-favicon').src =
                 this.missingFaviconUri;
 
-            // remove all but one tag input element
-            while (this.editTagListElement.firstChild !== null) {
-                this.editTagListElement.removeChild(
-                    this.editTagListElement.firstChild);
+            // remove all but the first four tag input elements
+            tagInputElements =
+                this.editTagListElement.querySelectorAll('li:nth-child(n+5)');
+            for (i = 0; i < tagInputElements.length; i++) {
+                this.editTagListElement.removeChild(tagInputElements[i]);
             }
-            this.editTagListElement.appendChild(this.createTagInputElement(''));
         }
         break;
     }