Get qr keybinds almost done; blur the focused element when closing the qr; open the qr on error.

This commit is contained in:
Nicolas Stepien 2012-01-01 20:30:30 +01:00
parent b2f7f556e7
commit 3ea6e04348
2 changed files with 40 additions and 21 deletions

View File

@ -875,12 +875,11 @@
return $.on(d, 'keydown', keybinds.keydown); return $.on(d, 'keydown', keybinds.keydown);
}, },
keydown: function(e) { keydown: function(e) {
var o, range, selEnd, selStart, ta, thread, valEnd, valMid, valStart, value, _ref, _ref2, _ref3; var o, range, selEnd, selStart, ta, thread, valEnd, valMid, valStart, value, _ref, _ref2;
updater.focus = true; updater.focus = true;
if (((_ref = e.target.nodeName) === 'TEXTAREA' || _ref === 'INPUT') && !e.altKey && !e.ctrlKey && !(e.keyCode === 27)) { if (!(key = keybinds.keyCode(e)) || /TEXTAREA|INPUT/.test(e.target.nodeName) && !(e.altKey || e.ctrlKey || e.keyCode === 27)) {
return; return;
} }
if (!(key = keybinds.keyCode(e))) return;
thread = nav.getThread(); thread = nav.getThread();
switch (key) { switch (key) {
case conf.openOptions: case conf.openOptions:
@ -910,6 +909,10 @@
window.location = "/" + g.BOARD + "/0#0"; window.location = "/" + g.BOARD + "/0#0";
break; break;
case conf.openEmptyQR: case conf.openEmptyQR:
keybinds.qr(thread);
break;
case conf.openQR:
keybinds.qr(thread, true);
break; break;
case conf.nextReply: case conf.nextReply:
keybinds.hl.next(thread); keybinds.hl.next(thread);
@ -926,8 +929,6 @@
case conf.expandThread: case conf.expandThread:
expandThread.toggle(thread); expandThread.toggle(thread);
break; break;
case conf.openQR:
break;
case conf.expandImages: case conf.expandImages:
keybinds.img(thread); keybinds.img(thread);
break; break;
@ -950,12 +951,13 @@
threadHiding.toggle(thread); threadHiding.toggle(thread);
break; break;
case conf.nextPage: case conf.nextPage:
if ((_ref2 = $('input[value=Next]')) != null) _ref2.click(); if ((_ref = $('input[value=Next]')) != null) _ref.click();
break; break;
case conf.previousPage: case conf.previousPage:
if ((_ref3 = $('input[value=Previous]')) != null) _ref3.click(); if ((_ref2 = $('input[value=Previous]')) != null) _ref2.click();
break; break;
case conf.submit: case conf.submit:
if (qr.el) qr.submit();
break; break;
case conf.unreadCountTo0: case conf.unreadCountTo0:
unread.replies = []; unread.replies = [];
@ -1037,15 +1039,22 @@
return key; return key;
}, },
img: function(thread, all) { img: function(thread, all) {
var root, thumb; var thumb;
if (all) { if (all) {
return $("#imageExpand").click(); return $("#imageExpand").click();
} else { } else {
root = $('td.replyhl', thread) || thread; thumb = $('img[md5]', $('.replyhl', thread) || thread);
thumb = $('img[md5]', root);
return imgExpand.toggle(thumb.parentNode); return imgExpand.toggle(thumb.parentNode);
} }
}, },
qr: function(thread, quote) {
if (quote) {
qr.quote.call($('.quotejs + .quotejs', $('.replyhl', thread) || thread));
} else {
qr.open();
}
return $('textarea', qr.el).focus();
},
open: function(thread, tab) { open: function(thread, tab) {
var id, url; var id, url;
id = thread.firstChild.id; id = thread.firstChild.id;
@ -1139,7 +1148,7 @@
threads: [], threads: [],
getThread: function(full) { getThread: function(full) {
var bottom, i, rect, thread, _len, _ref; var bottom, i, rect, thread, _len, _ref;
nav.threads = $$('div.thread:not([hidden])'); nav.threads = $$('.thread:not([hidden])');
_ref = nav.threads; _ref = nav.threads;
for (i = 0, _len = _ref.length; i < _len; i++) { for (i = 0, _len = _ref.length; i < _len; i++) {
thread = _ref[i]; thread = _ref[i];
@ -1209,7 +1218,8 @@
} }
}, },
close: function() { close: function() {
return qr.el.hidden = true; qr.el.hidden = true;
return d.activeElement.blur();
}, },
hide: function() { hide: function() {
if ($.id('autohide').checked) { if ($.id('autohide').checked) {
@ -1220,6 +1230,7 @@
}, },
error: function(err) { error: function(err) {
$('.error', qr.el).textContent = err; $('.error', qr.el).textContent = err;
qr.open();
return alert(err); return alert(err);
}, },
cleanError: function() { cleanError: function() {

View File

@ -640,8 +640,8 @@ keybinds =
keydown: (e) -> keydown: (e) ->
updater.focus = true updater.focus = true
return if e.target.nodeName in ['TEXTAREA', 'INPUT'] and not e.altKey and not e.ctrlKey and not (e.keyCode is 27) if not (key = keybinds.keyCode(e)) or /TEXTAREA|INPUT/.test(e.target.nodeName) and not (e.altKey or e.ctrlKey or e.keyCode is 27)
return unless key = keybinds.keyCode e return
thread = nav.getThread() thread = nav.getThread()
switch key switch key
@ -670,7 +670,9 @@ keybinds =
when conf.zero when conf.zero
window.location = "/#{g.BOARD}/0#0" window.location = "/#{g.BOARD}/0#0"
when conf.openEmptyQR when conf.openEmptyQR
;# QR keybinds.qr thread
when conf.openQR
keybinds.qr thread, true
when conf.nextReply when conf.nextReply
keybinds.hl.next thread keybinds.hl.next thread
when conf.previousReply when conf.previousReply
@ -681,8 +683,6 @@ keybinds =
keybinds.open thread keybinds.open thread
when conf.expandThread when conf.expandThread
expandThread.toggle thread expandThread.toggle thread
when conf.openQR
;# QR
when conf.expandImages when conf.expandImages
keybinds.img thread keybinds.img thread
when conf.nextThread when conf.nextThread
@ -702,7 +702,7 @@ keybinds =
when conf.previousPage when conf.previousPage
$('input[value=Previous]')?.click() $('input[value=Previous]')?.click()
when conf.submit when conf.submit
;# QR qr.submit() if qr.el
when conf.unreadCountTo0 when conf.unreadCountTo0
unread.replies = [] unread.replies = []
unread.updateTitle() unread.updateTitle()
@ -739,10 +739,16 @@ keybinds =
if all if all
$("#imageExpand").click() $("#imageExpand").click()
else else
root = $('td.replyhl', thread) or thread thumb = $ 'img[md5]', $('.replyhl', thread) or thread
thumb = $ 'img[md5]', root
imgExpand.toggle thumb.parentNode imgExpand.toggle thumb.parentNode
qr: (thread, quote) ->
if quote
qr.quote.call $ '.quotejs + .quotejs', $('.replyhl', thread) or thread
else
qr.open()
$('textarea', qr.el).focus()
open: (thread, tab) -> open: (thread, tab) ->
id = thread.firstChild.id id = thread.firstChild.id
url = "http://boards.4chan.org/#{g.BOARD}/res/#{id}" url = "http://boards.4chan.org/#{g.BOARD}/res/#{id}"
@ -818,7 +824,7 @@ nav =
threads: [] threads: []
getThread: (full) -> getThread: (full) ->
nav.threads = $$ 'div.thread:not([hidden])' nav.threads = $$ '.thread:not([hidden])'
for thread, i in nav.threads for thread, i in nav.threads
rect = thread.getBoundingClientRect() rect = thread.getBoundingClientRect()
{bottom} = rect {bottom} = rect
@ -881,6 +887,7 @@ qr =
qr.dialog() qr.dialog()
close: -> close: ->
qr.el.hidden = true qr.el.hidden = true
d.activeElement.blur()
hide: -> hide: ->
if $.id('autohide').checked if $.id('autohide').checked
$.addClass qr.el, 'autohide' $.addClass qr.el, 'autohide'
@ -889,6 +896,7 @@ qr =
error: (err) -> error: (err) ->
$('.error', qr.el).textContent = err $('.error', qr.el).textContent = err
qr.open()
alert err alert err
cleanError: -> cleanError: ->
$('.error', qr.el).textContent = null $('.error', qr.el).textContent = null