From 7f1c8fbb4b5da87665a50f7991ed6d1dbd2b2c29 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 14 Jun 2012 21:15:48 +0200 Subject: [PATCH 1/4] Fix file input on Opera not being reset in QR.resetFileInput. --- 4chan_x.user.js | 22 +++++++++++++++++++++- script.coffee | 15 ++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index a90efaf85..68c5ef589 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1630,7 +1630,27 @@ return QR.resetFileInput(); }, resetFileInput: function() { - return $('[type=file]', QR.el).value = null; + var clone, input; + input = $('[type=file]', QR.el); + input.value = null; + if ($.engine !== 'presto') { + return; + } + clone = $.el('input', { + type: 'file', + accept: input.accept, + max: input.max, + multiple: input.multiple, + size: input.size, + title: input.title + }); + $.on(clone, 'change', QR.fileInput); + $.on(clone, 'click', function(e) { + if (e.shiftKey) { + return QR.selected.rmFile() || e.preventDefault(); + } + }); + return $.replace(input, clone); }, replies: [], reply: (function() { diff --git a/script.coffee b/script.coffee index 8de6a1cf0..1f4d78d9d 100644 --- a/script.coffee +++ b/script.coffee @@ -1207,7 +1207,20 @@ QR = $.addClass QR.el, 'dump' QR.resetFileInput() # reset input resetFileInput: -> - $('[type=file]', QR.el).value = null + input = $ '[type=file]', QR.el + input.value = null + return unless $.engine is 'presto' + # XXX Opera needs extra care to reset its file input's value + clone = $.el 'input', + type: 'file' + accept: input.accept + max: input.max + multiple: input.multiple + size: input.size + title: input.title + $.on clone, 'change', QR.fileInput + $.on clone, 'click', (e) -> if e.shiftKey then QR.selected.rmFile() or e.preventDefault() + $.replace input, clone replies: [] reply: class From 07ada393420b84558a28a5d39ccc6bc690505ae0 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 14 Jun 2012 22:04:35 +0200 Subject: [PATCH 2/4] Fix file preParsing for /f/. Close #445 --- 4chan_x.user.js | 11 ++++------- script.coffee | 13 ++++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 68c5ef589..38c52826f 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -4302,7 +4302,7 @@ } }, preParse: function(node) { - var el, fileInfo, img, post, rootClass; + var el, img, post, rootClass; rootClass = node.className; el = $('.post', node); post = { @@ -4319,12 +4319,9 @@ fileInfo: false, img: false }; - if (fileInfo = $('.fileInfo', el)) { - img = fileInfo.nextElementSibling.firstElementChild; - if (img.alt !== 'File deleted.') { - post.fileInfo = fileInfo; - post.img = img; - } + if (img = $('img[data-md5]', el)) { + post.fileInfo = img.parentNode.previousElementSibling; + post.img = img; } Main.prettify(post.blockquote); return post; diff --git a/script.coffee b/script.coffee index 1f4d78d9d..de035fa7b 100644 --- a/script.coffee +++ b/script.coffee @@ -1487,7 +1487,6 @@ QR = # save selected reply's data for name in ['name', 'email', 'sub', 'com'] # The input event replaces keyup, change and paste events. - # 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 @@ -2148,7 +2147,7 @@ Sauce = @links = [] for link in Conf['sauces'].split '\n' continue if link[0] is '#' - # .trim() is there to fix Opera reading two different line breaks. + # XXX .trim() is there to fix Opera reading two different line breaks. @links.push @createSauceLink link.trim() return unless @links.length Main.callbacks.push @node @@ -3292,11 +3291,11 @@ Main = backlinks: el.getElementsByClassName 'backlink' fileInfo: false img: false - if fileInfo = $ '.fileInfo', el - img = fileInfo.nextElementSibling.firstElementChild - if img.alt isnt 'File deleted.' - post.fileInfo = fileInfo - post.img = img + if img = $ 'img[data-md5]', el + # Make sure to not add deleted images, + # those do not have a data-md5 attribute. + post.fileInfo = img.parentNode.previousElementSibling + post.img = img Main.prettify post.blockquote post node: (nodes, notify) -> From 4f8cfa82d811dfcd61ef0566312433d2f5e8449b Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 14 Jun 2012 22:35:43 +0200 Subject: [PATCH 3/4] 'Fix' the caret position when quoting on Opera. Changelog. --- 4chan_x.user.js | 3 +++ changelog | 3 +++ script.coffee | 2 ++ 3 files changed, 8 insertions(+) diff --git a/4chan_x.user.js b/4chan_x.user.js index 38c52826f..a069e0ed6 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1570,6 +1570,9 @@ ta.value = ta.value.slice(0, caretPos) + text + ta.value.slice(ta.selectionEnd); ta.focus(); range = caretPos + text.length; + if ($.engine === 'presto') { + range++; + } ta.setSelectionRange(range, range); e = d.createEvent('Event'); e.initEvent('input', true, false); diff --git a/changelog b/changelog index ffd74a58e..80081b804 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,7 @@ master +- Mayhem + Opera fixes. + /f/ fixes. 2.32.1 - Mayhem diff --git a/script.coffee b/script.coffee index de035fa7b..3ddaadb87 100644 --- a/script.coffee +++ b/script.coffee @@ -1155,6 +1155,8 @@ QR = ta.focus() # Move the caret to the end of the new quote. range = caretPos + text.length + # XXX Opera counts newlines as double + range++ if $.engine is 'presto' ta.setSelectionRange range, range # Fire the 'input' event From 0b26a4d81715a2c51eb053fea45fd0e1a14d32c7 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 15 Jun 2012 18:05:21 +0200 Subject: [PATCH 4/4] Fine text selection to quote on Opera. --- 4chan_x.user.js | 5 ++++- script.coffee | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index a069e0ed6..90359ecd1 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1562,6 +1562,9 @@ text = ">>" + id + "\n"; sel = window.getSelection(); if ((s = sel.toString()) && id === ((_ref = $.x('ancestor-or-self::blockquote', sel.anchorNode)) != null ? _ref.id.match(/\d+$/)[0] : void 0)) { + if ($.engine === 'presto') { + s = d.getSelection(); + } s = s.replace(/\n/g, '\n>'); text += ">" + s + "\n"; } @@ -1571,7 +1574,7 @@ ta.focus(); range = caretPos + text.length; if ($.engine === 'presto') { - range++; + range += text.match(/\n/g).length; } ta.setSelectionRange(range, range); e = d.createEvent('Event'); diff --git a/script.coffee b/script.coffee index 3ddaadb87..0a69e51db 100644 --- a/script.coffee +++ b/script.coffee @@ -1145,6 +1145,8 @@ QR = sel = window.getSelection() if (s = sel.toString()) and id is $.x('ancestor-or-self::blockquote', sel.anchorNode)?.id.match(/\d+$/)[0] + # XXX Opera needs d.getSelection() to retain linebreaks from the selected text + s = d.getSelection() if $.engine is 'presto' s = s.replace /\n/g, '\n>' text += ">#{s}\n" @@ -1156,7 +1158,7 @@ QR = # Move the caret to the end of the new quote. range = caretPos + text.length # XXX Opera counts newlines as double - range++ if $.engine is 'presto' + range += text.match(/\n/g).length if $.engine is 'presto' ta.setSelectionRange range, range # Fire the 'input' event