aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArthur <arthur@hoa.ro>2015-07-12 11:01:24 +0200
committerArthur <arthur@hoa.ro>2015-07-12 11:01:24 +0200
commit7bd3542b1b030070fa3412a2769f9632bd4e6d1b (patch)
treee2b0bfffec3063025e1872025c805626f3027dc5
parentbba021defce15184c986d5e3db138bdbdd4df5d5 (diff)
parent781e8aadea7590dc87b61915b6e65ec52f7d250e (diff)
downloadShaarli-7bd3542b1b030070fa3412a2769f9632bd4e6d1b.tar.gz
Shaarli-7bd3542b1b030070fa3412a2769f9632bd4e6d1b.tar.zst
Shaarli-7bd3542b1b030070fa3412a2769f9632bd4e6d1b.zip
Merge pull request #262 from ArthurHoaro/dup-tags
Avoid tag duplicates
-rw-r--r--index.php1
-rw-r--r--tpl/editlink.html24
2 files changed, 24 insertions, 1 deletions
diff --git a/index.php b/index.php
index d8fb3007..5f173f4d 100644
--- a/index.php
+++ b/index.php
@@ -1380,6 +1380,7 @@ function renderPage()
1380 { 1380 {
1381 if (!tokenOk($_POST['token'])) die('Wrong token.'); // Go away! 1381 if (!tokenOk($_POST['token'])) die('Wrong token.'); // Go away!
1382 $tags = trim(preg_replace('/\s\s+/',' ', $_POST['lf_tags'])); // Remove multiple spaces. 1382 $tags = trim(preg_replace('/\s\s+/',' ', $_POST['lf_tags'])); // Remove multiple spaces.
1383 $tags = implode(' ', array_unique(explode(' ', $tags))); // Remove duplicates.
1383 $linkdate=$_POST['lf_linkdate']; 1384 $linkdate=$_POST['lf_linkdate'];
1384 $url = trim($_POST['lf_url']); 1385 $url = trim($_POST['lf_url']);
1385 if (!startsWith($url,'http:') && !startsWith($url,'https:') && !startsWith($url,'ftp:') && !startsWith($url,'magnet:') && !startsWith($url,'?') && !startsWith($url,'javascript:')) 1386 if (!startsWith($url,'http:') && !startsWith($url,'https:') && !startsWith($url,'ftp:') && !startsWith($url,'magnet:') && !startsWith($url,'?') && !startsWith($url,'javascript:'))
diff --git a/tpl/editlink.html b/tpl/editlink.html
index a32748ab..3733ca21 100644
--- a/tpl/editlink.html
+++ b/tpl/editlink.html
@@ -42,7 +42,7 @@
42{if="($GLOBALS['config']['OPEN_SHAARLI'] || isLoggedIn())"} 42{if="($GLOBALS['config']['OPEN_SHAARLI'] || isLoggedIn())"}
43<script> 43<script>
44 $ = Awesomplete.$; 44 $ = Awesomplete.$;
45 new Awesomplete($('input[data-multiple]'), { 45 awesomplete = new Awesomplete($('input[data-multiple]'), {
46 filter: function(text, input) { 46 filter: function(text, input) {
47 return Awesomplete.FILTER_CONTAINS(text, input.match(/[^ ]*$/)[0]); 47 return Awesomplete.FILTER_CONTAINS(text, input.match(/[^ ]*$/)[0]);
48 }, 48 },
@@ -52,6 +52,28 @@
52 }, 52 },
53 minChars: 1 53 minChars: 1
54 }); 54 });
55
56 /**
57 * Remove already selected items from autocompletion list.
58 * HTML list is never updated, so removing a tag will add it back to awesomplete.
59 *
60 * FIXME: This a workaround waiting for awesomplete to handle this.
61 * https://github.com/LeaVerou/awesomplete/issues/16749
62 */
63 var input = document.querySelector('#lf_tags');
64 input.addEventListener('input', function()
65 {
66 proposedTags = input.getAttribute('data-list').replace(/,/g, '').split(' ');
67 reg = /(\w+) /g;
68 while((match = reg.exec(input.value)) !== null) {
69 id = proposedTags.indexOf(match[1]);
70 if(id != -1 ) {
71 proposedTags.splice(id, 1);
72 }
73 }
74
75 awesomplete.list = proposedTags;
76 });
55</script> 77</script>
56{/if} 78{/if}
57</body> 79</body>