From f4bf9b5413e54bdb9b7639a868bf9ec9bb4d9152 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sat, 13 Apr 2013 23:26:15 +0200 Subject: [PATCH] Add the `has-focus` class to the QR element when it has focus. @saxamaphone69 --- CHANGELOG.md | 1 + css/style.css | 2 +- src/qr.coffee | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68212e550..a58503966 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- The QR won't auto-hide when auto-hide is enabled and one of its input is focused. Doesn't work on Firefox. - Fix QR remembering the file spoiler state when it shouldn't. - Fix QR cooldown in Opera. diff --git a/css/style.css b/css/style.css index a729961c2..30d916302 100644 --- a/css/style.css +++ b/css/style.css @@ -549,7 +549,7 @@ a[href="javascript:;"] { :root.hide-original-post-form #postForm, :root.hide-original-post-form .postingMode, :root.hide-original-post-form #togglePostForm, -#qr.autohide:not(:hover) > form { +#qr.autohide:not(.has-focus):not(:hover) > form { display: none; } #qr select, #dump-button, .remove, .captcha-img { diff --git a/src/qr.coffee b/src/qr.coffee index 39f3e94ed..4323d6ce2 100644 --- a/src/qr.coffee +++ b/src/qr.coffee @@ -73,6 +73,10 @@ QR = QR.status() if !Conf['Remember Spoiler'] and QR.nodes.spoiler.checked QR.nodes.spoiler.click() + focusin: -> + $.addClass QR.nodes.el, 'has-focus' + focusout: -> + $.rmClass QR.nodes.el, 'has-focus' hide: -> d.activeElement.blur() $.addClass QR.nodes.el, 'autohide' @@ -361,6 +365,12 @@ QR = spoiler: $ 'input', el span: el.lastChild + <% if (type === 'userscript') { %> + # XXX Firefox lacks focusin/focusout support. + for elm in $$ '*', el + $.on elm, 'blur', QR.focusout + $.on elm, 'focus', QR.focusin + <% } %> $.on el, 'click', @select.bind @ $.on @nodes.rm, 'click', (e) => e.stopPropagation(); @rm() $.on @nodes.label, 'click', (e) => e.stopPropagation() @@ -619,6 +629,12 @@ QR = # start with an uncached captcha @reload() + <% if (type === 'userscript') { %> + # XXX Firefox lacks focusin/focusout support. + $.on input, 'blur', QR.focusout + $.on input, 'focus', QR.focusin + <% } %> + $.addClass QR.nodes.el, 'has-captcha' $.after QR.nodes.com.parentNode, [imgContainer, input] sync: (@captchas) -> @@ -791,6 +807,14 @@ QR = textContent: "Thread No.#{thread}" $.after nodes.autohide, nodes.thread + <% if (type === 'userscript') { %> + # XXX Firefox lacks focusin/focusout support. + for elm in $$ '*', QR.nodes.el + $.on elm, 'blur', QR.focusout + $.on elm, 'focus', QR.focusin + <% } %> + $.on QR.nodes.el, 'focusin', QR.focusin + $.on QR.nodes.el, 'focusout', QR.focusout for node in [nodes.fileButton, nodes.filename.parentNode] $.on node, 'click', QR.openFileInput $.on nodes.autohide, 'change', QR.toggleHide