diff options
author | 2017-07-17 16:52:28 +0300 | |
---|---|---|
committer | 2017-07-17 16:52:28 +0300 | |
commit | 37afaeffc31c4dd5f79a5984aa654fe46b75d50e (patch) | |
tree | 9a3d701a6771284d2734bff1bbdf8b7266f33443 /juick-www/src/main/static | |
parent | 6d6dbcb55a6090920e6b056bcfc68297b8efea10 (diff) |
www: js cleanup
Diffstat (limited to 'juick-www/src/main/static')
-rw-r--r-- | juick-www/src/main/static/scripts.js | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/juick-www/src/main/static/scripts.js b/juick-www/src/main/static/scripts.js index c24448ff..4f2586ee 100644 --- a/juick-www/src/main/static/scripts.js +++ b/juick-www/src/main/static/scripts.js @@ -1,25 +1,7 @@ -var autosize = function(t) { - var offset = !window.opera ? (t.offsetHeight - t.clientHeight) - : (t.offsetHeight + parseInt(window.getComputedStyle(t, null).getPropertyValue('border-top-width'))); - - var resize = function(t) { - t.style.height = 'auto'; - t.style.height = (t.scrollHeight + offset ) + 'px'; - }; - - t.addEventListener && t.addEventListener('input', function(event) { - resize(t); - }); - - t['attachEvent'] && t.attachEvent('onkeyup', function() { - resize(t); - }); -}; - require('whatwg-fetch'); require('element-closest'); require('classlist.js'); -var killy = require('killy'); +let killy = require('killy'); if (!('remove' in Element.prototype)) { // Firefox <23 Element.prototype.remove = function() { @@ -32,6 +14,38 @@ if (!('remove' in Element.prototype)) { // Firefox <23 NodeList.prototype.forEach = Array.prototype.forEach; HTMLCollection.prototype.forEach = Array.prototype.forEach; +Element.prototype.selectText = function () { + let d = document; + if (d.body.createTextRange) { + let range = d.body.createTextRange(); + range.moveToElementText(this); + range.select(); + } else if (window.getSelection) { + let selection = window.getSelection(); + let rangeSel = d.createRange(); + rangeSel.selectNodeContents(this); + selection.removeAllRanges(); + selection.addRange(rangeSel); + } +}; + +function autosize(el) { + let offset = (!window.opera) + ? (el.offsetHeight - el.clientHeight) + : (el.offsetHeight + parseInt(window.getComputedStyle(el, null).getPropertyValue('border-top-width'))); + + let resize = function(el) { + el.style.height = 'auto'; + el.style.height = (el.scrollHeight + offset) + 'px'; + }; + + if (el.addEventListener) { + el.addEventListener('input', () => resize(el)); + } else if (el.attachEvent) { + el.attachEvent('onkeyup', () => resize(el)); + } +} + /* eslint-disable only-ascii/only-ascii */ const translations = { 'en': { @@ -583,21 +597,6 @@ function setPrivacy(e, mid) { } /******************************************************************************/ -Element.prototype.selectText = function () { - var d = document; - if (d.body.createTextRange) { - var range = d.body.createTextRange(); - range.moveToElementText(this); - range.select(); - } else if (window.getSelection) { - var selection = window.getSelection(); - var rangeSel = d.createRange(); - rangeSel.selectNodeContents(this); - selection.removeAllRanges(); - selection.addRange(rangeSel); - } -}; - function ready(fn) { if (document.readyState != 'loading') { fn(); |