]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Fixes #360 - Auto-complete more than one tag in tag filter field 377/head
authorArthurHoaro <arthur@hoa.ro>
Fri, 13 Nov 2015 19:24:12 +0000 (20:24 +0100)
committerArthurHoaro <arthur@hoa.ro>
Tue, 17 Nov 2015 19:03:21 +0000 (20:03 +0100)
  * Group awesomplete for multi data in a single JS file.
  * Use it in editlink and linklist.
  * Move awesomplete JS lib at the end of page in editlink.

inc/awesomplete-multiple-tags.js [new file with mode: 0644]
tpl/editlink.html
tpl/linklist.html

diff --git a/inc/awesomplete-multiple-tags.js b/inc/awesomplete-multiple-tags.js
new file mode 100644 (file)
index 0000000..e0f889b
--- /dev/null
@@ -0,0 +1,35 @@
+$ = Awesomplete.$;
+awesomplete = new Awesomplete($('input[data-multiple]'), {
+    filter: function(text, input) {
+        return Awesomplete.FILTER_CONTAINS(text, input.match(/[^ ]*$/)[0]);
+    },
+    replace: function(text) {
+        var before = this.input.value.match(/^.+ \s*|/)[0];
+        this.input.value = before + text + " ";
+    },
+    minChars: 1
+});
+
+/**
+ * Remove already selected items from autocompletion list.
+ * HTML list is never updated, so removing a tag will add it back to awesomplete.
+ *
+ * FIXME: This a workaround waiting for awesomplete to handle this.
+ *  https://github.com/LeaVerou/awesomplete/issues/16749
+ */
+function awesompleteUniqueTag(selector) {
+    var input = document.querySelector(selector);
+    input.addEventListener('input', function()
+    {
+        proposedTags = input.getAttribute('data-list').replace(/,/g, '').split(' ');
+        reg = /(\w+) /g;
+        while((match = reg.exec(input.value)) !== null) {
+            id = proposedTags.indexOf(match[1]);
+            if(id != -1 ) {
+                proposedTags.splice(id, 1);
+            }
+        }
+
+        awesomplete.list = proposedTags;
+    });
+}
index 889d913d9126a664c43f669efdcce636eca2a774..14a2e6c80f7ad99f1554a31a023001765088dde6 100644 (file)
@@ -2,7 +2,6 @@
 <html>
 <head>{include="includes"}
     <link type="text/css" rel="stylesheet" href="../inc/awesomplete.css" />
-    <script src="inc/awesomplete.min.js#"></script>
 </head>
 <body
 {if="$link.title==''"}onload="document.linkform.lf_title.focus();"
 {include="page.footer"}
 {/if}
 {if="($GLOBALS['config']['OPEN_SHAARLI'] || isLoggedIn())"}
+<script src="inc/awesomplete.min.js#"></script>
+<script src="inc/awesomplete-multiple-tags.js#"></script>
 <script>
-    $ = Awesomplete.$;
-    awesomplete = new Awesomplete($('input[data-multiple]'), {
-        filter: function(text, input) {
-            return Awesomplete.FILTER_CONTAINS(text, input.match(/[^ ]*$/)[0]);
-        },
-        replace: function(text) {
-            var before = this.input.value.match(/^.+ \s*|/)[0];
-            this.input.value = before + text + " ";
-        },
-        minChars: 1
-    });
-
-    /**
-     * Remove already selected items from autocompletion list.
-     * HTML list is never updated, so removing a tag will add it back to awesomplete.
-     *
-     * FIXME: This a workaround waiting for awesomplete to handle this.
-     *  https://github.com/LeaVerou/awesomplete/issues/16749
-     */
-    var input = document.querySelector('#lf_tags');
-    input.addEventListener('input', function()
-    {
-        proposedTags = input.getAttribute('data-list').replace(/,/g, '').split(' ');
-        reg = /(\w+) /g;
-        while((match = reg.exec(input.value)) !== null) {
-            id = proposedTags.indexOf(match[1]);
-            if(id != -1 ) {
-                proposedTags.splice(id, 1);
-            }
-        }
-
-        awesomplete.list = proposedTags;
-    });
+    awesompleteUniqueTag('#lf_tags');
 </script>
 {/if}
 </body>
index 9ed28853a10a96e6744464bccf41603f5e0b8819..f6e9e82b6a42eaf39690129dd99717abbb505524 100644 (file)
@@ -9,12 +9,13 @@
     {include="page.header"}
     <div id="headerform" class="search">
         <form method="GET" class="searchform" name="searchform">
-            <input type="text" tabindex="1" id="searchform_value" name="searchterm" placeholder="Search text" value=""> <input type="submit" value="Search" class="bigbutton"></form>
+            <input type="text" tabindex="1" id="searchform_value" name="searchterm" placeholder="Search text" value="">
+            <input type="submit" value="Search" class="bigbutton">
+        </form>
         <form method="GET" class="tagfilter" name="tagfilter">
-            <input type="text" tabindex="2" name="searchtags" id="tagfilter_value" placeholder="Filter by tag" value="" list="tagsList" autocomplete="off" class="awesomplete" data-minChars="1">
-            <datalist id="tagsList">
-                {loop="$tags"}<option>{$key}</option>{/loop}
-            </datalist>
+            <input type="text" tabindex="2" name="searchtags" id="tagfilter_value" placeholder="Filter by tag" value=""
+                   autocomplete="off" class="awesomplete" data-multiple data-minChars="1"
+                   data-list="{loop="$tags"}{$key}, {/loop}">
             <input type="submit" value="Search" class="bigbutton">
         </form>
         {loop="$plugins_header.fields_toolbar"}
@@ -42,7 +43,9 @@
         {if="$search_type=='tags'"}
             <div id="searchcriteria">{$result_count} results for tags <i>
             {loop="search_crits"}
-                <span class="linktag" title="Remove tag"><a href="?removetag={$value}">{$value} <span class="remove">x</span></a></span>
+                <span class="linktag" title="Remove tag">
+                    <a href="?removetag={$value}">{$value} <span class="remove">x</span></a>
+                </span>
             {/loop}</i></div>
         {/if}
     {/if}
             <div class="linkcontainer">
                 {if="isLoggedIn()"}
                     <div class="linkeditbuttons">
-                        <form method="GET" class="buttoneditform"><input type="hidden" name="edit_link" value="{$value.linkdate}"><input type="image" alt="Edit" src="images/edit_icon.png#" title="Edit" class="button_edit"></form><br>
-                        <form method="POST" class="buttoneditform"><input type="hidden" name="lf_linkdate" value="{$value.linkdate}">
-                        <input type="hidden" name="token" value="{$token}"><input type="hidden" name="delete_link"><input type="image" alt="Delete" src="images/delete_icon.png#" title="Delete" class="button_delete" onClick="return confirmDeleteLink();"></form>
+                        <form method="GET" class="buttoneditform">
+                            <input type="hidden" name="edit_link" value="{$value.linkdate}">
+                            <input type="image" alt="Edit" src="images/edit_icon.png#" title="Edit" class="button_edit">
+                        </form><br>
+                        <form method="POST" class="buttoneditform">
+                            <input type="hidden" name="lf_linkdate" value="{$value.linkdate}">
+                            <input type="hidden" name="token" value="{$token}">
+                            <input type="hidden" name="delete_link">
+                            <input type="image" alt="Delete" src="images/delete_icon.png#" title="Delete"
+                                   class="button_delete" onClick="return confirmDeleteLink();">
+                        </form>
                     </div>
                 {/if}
                 <span class="linktitle"><a href="{$redirector}{$value.url}">{$value.title}</a></span>
     {include="page.footer"}
 
 <script src="inc/awesomplete.min.js#"></script>
+<script src="inc/awesomplete-multiple-tags.js#"></script>
+<script>
+    awesompleteUniqueTag('#tagfilter_value');
+</script>
 </body>
 </html>