From fa070e8e63fb25dabddc97a6c1c6b72c2b46b66f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 4 Feb 2018 22:42:15 +0300 Subject: www: addTag on post form --- juick-www/src/main/static/scripts.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'juick-www/src/main/static') diff --git a/juick-www/src/main/static/scripts.js b/juick-www/src/main/static/scripts.js index dc7745a9..22a75fac 100644 --- a/juick-www/src/main/static/scripts.js +++ b/juick-www/src/main/static/scripts.js @@ -1,6 +1,7 @@ require('whatwg-fetch'); require('element-closest'); require('classlist.js'); +require('url-search-params-polyfill'); let killy = require('killy'); let Awesomplete = require('awesomplete'); @@ -15,6 +16,9 @@ if (!('remove' in Element.prototype)) { // Firefox <23 NodeList.prototype.forEach = Array.prototype.forEach; HTMLCollection.prototype.forEach = Array.prototype.forEach; +NodeList.prototype.filter = Array.prototype.filter; +HTMLCollection.prototype.filter = Array.prototype.filter; + Element.prototype.selectText = function () { let d = document; if (d.body.createTextRange) { @@ -615,6 +619,11 @@ function getTags() { return false; } +function addTag(tag) { + document.forms['postmsg'].body.value='*'+tag+' '+document.forms['postmsg'].body.value; + return false; +} + /******************************************************************************/ function ready(fn) { @@ -677,6 +686,19 @@ ready(function () { } } + var postmsg = document.getElementById('postmsg'); + if (postmsg) { + document.querySelectorAll('a').filter(t => t.href.indexOf('?') >=0).forEach(t => { + t.addEventListener('click', e => { + let params = new URLSearchParams(t.href.slice(t.href.indexOf('?') + 1)); + if (params.has('tag')) { + addTag(params.get('tag')); + e.preventDefault(); + } + }); + }); + } + document.querySelectorAll('.msg-menu').forEach(function (el) { el.addEventListener('click', function (e) { var reply = e.target.closest('li'); -- cgit v1.2.3