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/package-lock.json | 5 +++++ juick-www/package.json | 1 + juick-www/src/main/static/scripts.js | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/juick-www/package-lock.json b/juick-www/package-lock.json index 1511195a..37f7e493 100644 --- a/juick-www/package-lock.json +++ b/juick-www/package-lock.json @@ -10057,6 +10057,11 @@ "schema-utils": "0.3.0" } }, + "url-search-params-polyfill": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/url-search-params-polyfill/-/url-search-params-polyfill-2.0.2.tgz", + "integrity": "sha512-zFN1r66KeSpxM2qrbHPf4u6nbIIGLOCNdO3JXdV5mEqeoBPev7VwuCv5goL69TQmfAQdVyTHI8lmzCIRPEW4Bg==" + }, "util": { "version": "0.10.3", "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", diff --git a/juick-www/package.json b/juick-www/package.json index fa3ce1a3..e77e6a32 100644 --- a/juick-www/package.json +++ b/juick-www/package.json @@ -39,6 +39,7 @@ "element-closest": "^2.0.2", "evil-icons": "^1.9.0", "killy": "file:src/main/js/killy", + "url-search-params-polyfill": "^2.0.2", "whatwg-fetch": "^2.0.3" } } 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