From 37afaeffc31c4dd5f79a5984aa654fe46b75d50e Mon Sep 17 00:00:00 2001 From: KillyMXI Date: Mon, 17 Jul 2017 16:52:28 +0300 Subject: www: js cleanup --- juick-www/src/main/static/scripts.js | 67 ++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 34 deletions(-) (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 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(); -- cgit v1.2.3