From 3e9b5b029e765aefeff4716f2fe37363bebafee0 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 8 Jun 2012 10:23:25 +0200 Subject: [PATCH] Use the "input" event as much as possible. This event fires when a text input element's value changes, always when it changes, only when it changes. It fires on keyup, keydown, paste, cut, with the keyboard, with shortcuts, with the context menu, etc... It works on Chrome, Firefox 12+ and Opera. --- 4chan_x.user.js | 22 +++++++++++----------- script.coffee | 23 ++++++++++++----------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 2d69d00bd..05c2d754c 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1938,7 +1938,7 @@ return new QR.reply().select(); }); $.on($('form', QR.el), 'submit', QR.submit); - $.on($('textarea', QR.el), 'keyup', function() { + $.on($('textarea', QR.el), 'input', function() { return QR.selected.el.lastChild.textContent = this.value; }); $.on(fileInput, 'change', QR.fileInput); @@ -1955,7 +1955,7 @@ _ref1 = ['name', 'email', 'sub', 'com']; for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { name = _ref1[_j]; - $.on($("[name=" + name + "]", QR.el), 'input keyup change paste', function() { + $.on($("[name=" + name + "]", QR.el), 'input', function() { var _ref2; QR.selected[this.name] = this.value; if (QR.cooldown.auto && QR.selected === QR.replies[0] && (0 < (_ref2 = QR.cooldown.seconds) && _ref2 < 6)) { @@ -2315,12 +2315,12 @@ (back = $('[name=backlink]', dialog)).value = $.get('backlink', Conf['backlink']); (time = $('[name=time]', dialog)).value = $.get('time', Conf['time']); (fileInfo = $('[name=fileInfo]', dialog)).value = $.get('fileInfo', Conf['fileInfo']); - $.on(back, 'keyup', $.cb.value); - $.on(back, 'keyup', Options.backlink); - $.on(time, 'keyup', $.cb.value); - $.on(time, 'keyup', Options.time); - $.on(fileInfo, 'keyup', $.cb.value); - $.on(fileInfo, 'keyup', Options.fileInfo); + $.on(back, 'input', $.cb.value); + $.on(back, 'input', Options.backlink); + $.on(time, 'input', $.cb.value); + $.on(time, 'input', Options.time); + $.on(fileInfo, 'input', $.cb.value); + $.on(fileInfo, 'input', Options.fileInfo); favicon = $('select', dialog); favicon.value = $.get('favicon', Conf['favicon']); $.on(favicon, 'change', $.cb.value); @@ -2447,10 +2447,10 @@ Conf[input.name] = input.checked; } } else if (input.name === 'Interval') { - $.on(input, 'change', function() { - return Conf['Interval'] = this.value = parseInt(this.value, 10) || Conf['Interval']; + $.on(input, 'input', function() { + this.value = parseInt(this.value, 10) || Conf['Interval']; + return $.cb.value.call(this); }); - $.on(input, 'change', $.cb.value); } else if (input.type === 'button') { $.on(input, 'click', this.update); } diff --git a/script.coffee b/script.coffee index f07e424ee..a24ebc1e3 100644 --- a/script.coffee +++ b/script.coffee @@ -1444,7 +1444,7 @@ QR = $.on $('#dump', QR.el), 'click', -> QR.el.classList.toggle 'dump' $.on $('#addReply', QR.el), 'click', -> new QR.reply().select() $.on $('form', QR.el), 'submit', QR.submit - $.on $('textarea', QR.el), 'keyup', -> QR.selected.el.lastChild.textContent = @value + $.on $('textarea', QR.el), 'input', -> QR.selected.el.lastChild.textContent = @value $.on fileInput, 'change', QR.fileInput $.on fileInput, 'click', (e) -> if e.shiftKey then QR.selected.rmFile() or e.preventDefault() $.on spoiler.firstChild, 'change', -> $('input', QR.selected.el).click() @@ -1454,8 +1454,8 @@ QR = # save selected reply's data for name in ['name', 'email', 'sub', 'com'] # The input event replaces keyup, change and paste events. - # XXX Opera? - $.on $("[name=#{name}]", QR.el), 'input keyup change paste', -> + # XXX Does Opera support the `input` event? + $.on $("[name=#{name}]", QR.el), 'input', -> QR.selected[@name] = @value # Disable auto-posting if you're typing in the first reply # during the last 5 seconds of the cooldown. @@ -1790,12 +1790,12 @@ Options = (back = $ '[name=backlink]', dialog).value = $.get 'backlink', Conf['backlink'] (time = $ '[name=time]', dialog).value = $.get 'time', Conf['time'] (fileInfo = $ '[name=fileInfo]', dialog).value = $.get 'fileInfo', Conf['fileInfo'] - $.on back, 'keyup', $.cb.value - $.on back, 'keyup', Options.backlink - $.on time, 'keyup', $.cb.value - $.on time, 'keyup', Options.time - $.on fileInfo, 'keyup', $.cb.value - $.on fileInfo, 'keyup', Options.fileInfo + $.on back, 'input', $.cb.value + $.on back, 'input', Options.backlink + $.on time, 'input', $.cb.value + $.on time, 'input', Options.time + $.on fileInfo, 'input', $.cb.value + $.on fileInfo, 'input', Options.fileInfo favicon = $ 'select', dialog favicon.value = $.get 'favicon', Conf['favicon'] $.on favicon, 'change', $.cb.value @@ -1907,8 +1907,9 @@ Updater = # Required for the QR's update after posting. Conf[input.name] = input.checked else if input.name is 'Interval' - $.on input, 'change', -> Conf['Interval'] = @value = parseInt(@value, 10) or Conf['Interval'] - $.on input, 'change', $.cb.value + $.on input, 'input', -> + @value = parseInt(@value, 10) or Conf['Interval'] + $.cb.value.call @ else if input.type is 'button' $.on input, 'click', @update