aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/static/scripts.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-08-30 15:04:30 +0300
committerGravatar Vitaly Takmazov2017-08-30 15:04:30 +0300
commitfeea15b5878edd01935c2bde8d8e472441489dd4 (patch)
tree3fcc7fdde270adc798301bdf3faecfda74ec5ea5 /juick-www/src/main/static/scripts.js
parentde6fda08ea1dfe5583916947ded216dea9cfd056 (diff)
www: autocomplete tags in message form
Diffstat (limited to 'juick-www/src/main/static/scripts.js')
-rw-r--r--juick-www/src/main/static/scripts.js20
1 files changed, 19 insertions, 1 deletions
diff --git a/juick-www/src/main/static/scripts.js b/juick-www/src/main/static/scripts.js
index 4001dbb6..6b4d3f08 100644
--- a/juick-www/src/main/static/scripts.js
+++ b/juick-www/src/main/static/scripts.js
@@ -2,6 +2,7 @@ require('whatwg-fetch');
require('element-closest');
require('classlist.js');
let killy = require('killy');
+let Awesomplete = require('awesomplete');
if (!('remove' in Element.prototype)) { // Firefox <23
Element.prototype.remove = function() {
@@ -504,7 +505,7 @@ function openPostDialog() {
<div>
<input class="img" name="img" placeholder="${i18n('postForm.imageLink')} (${i18n('postForm.imageFormats')})"/>
${i18n('postForm.or')} <a href="#">${i18n('postForm.upload')}</a><br/>
- <input class="tags" name="tags" placeholder="${i18n('postForm.tags')}"/><br/>
+ <input id="tags_input" class="tags" name="tags" placeholder="${i18n('postForm.tags')}"/><br/>
<input type="submit" class="subm" value="${i18n('postForm.submit')}"/>
</div>
</form>
@@ -620,6 +621,22 @@ function setPrivacy(e, mid) {
});
return false;
}
+
+function getTags() {
+ fetch('//api.juick.com/tags?hash=' + document.getElementById('body').getAttribute('data-hash'), {
+ credentials: 'same-origin'
+ })
+ .then(response => {
+ return response.json()
+ })
+ .then(json => {
+ let tags = json.map(t => t.tag);
+ let input = document.getElementById('tags_input');
+ new Awesomplete(input, {list : tags});
+ });
+ return false;
+}
+
/******************************************************************************/
function ready(fn) {
@@ -798,6 +815,7 @@ ready(function () {
var post = document.getElementById('post');
post.addEventListener('click', (e) => {
openPostDialog();
+ getTags();
var newMessageBlock = document.getElementById('newmessage');
if (newMessageBlock) {
var form = newMessageBlock.parentNode;