open file dialog when file button clicked on chrom

This commit is contained in:
James Campos 2011-09-25 19:52:03 -07:00
parent 1b6e77be81
commit 3f4b01dd8b
2 changed files with 58 additions and 22 deletions

View File

@ -1324,18 +1324,17 @@
}); });
} }
}, },
attach: function() { attach: function(file) {
var box, file, files; var box, files;
files = $('#files', QR.qr); files = $('#files', QR.qr);
box = $.el('li', { box = $.el('li', {
innerHTML: "<img><input type=file name=upfile accept='" + QR.accept + "'><a class=x>X</a>" innerHTML: "<img><a class=x>X</a>"
}); });
file = $('input', box);
$.bind(file, 'change', QR.change);
$.bind($('.x', box), 'click', QR.rmThumb); $.bind($('.x', box), 'click', QR.rmThumb);
$.add(box, file);
$.add(files, box); $.add(files, box);
file.click(); QR.stats();
return QR.stats(); return QR.foo();
}, },
rmThumb: function() { rmThumb: function() {
$.rm(this.parentNode); $.rm(this.parentNode);
@ -1392,15 +1391,16 @@
return window.location = 'javascript:Recaptcha.reload()'; return window.location = 'javascript:Recaptcha.reload()';
}, },
change: function(e) { change: function(e) {
var file, fr, img, qr; var file, fr, img;
file = this.files[0]; file = this.files[0];
if (file.size > QR.MAX_FILE_SIZE) { if (file.size > QR.MAX_FILE_SIZE) {
alert('Error: File too large.'); alert('Error: File too large.');
$.rm(this.parentNode); QR.foo(this);
QR.attach();
return; return;
} }
qr = QR.qr; if (this.previousSibling.nodeName === 'BUTTON') {
QR.attach(this);
}
fr = new FileReader(); fr = new FileReader();
img = $('img', this.parentNode); img = $('img', this.parentNode);
fr.onload = function(e) { fr.onload = function(e) {
@ -1437,6 +1437,20 @@
} }
} }
}, },
foo: function(old) {
var input;
input = $.el('input', {
type: 'file',
name: 'upfile',
accept: QR.accept
});
$.bind(input, 'change', QR.change);
if (old) {
return $.replace(old, file);
} else {
return $.after($('button', QR.qr), input);
}
},
dialog: function(text, tid) { dialog: function(text, tid) {
var c, l, m, qr, ta; var c, l, m, qr, ta;
if (text == null) { if (text == null) {
@ -1452,7 +1466,10 @@
if (conf['Cooldown']) { if (conf['Cooldown']) {
QR.cooldown(); QR.cooldown();
} }
$.bind($('button', qr), 'click', QR.attach); QR.foo();
$.bind($('button', qr), 'click', function() {
return this.nextSibling.click();
});
$.bind($('.close', qr), 'click', QR.close); $.bind($('.close', qr), 'click', QR.close);
$.bind($('form', qr), 'submit', QR.submit); $.bind($('form', qr), 'submit', QR.submit);
$.bind($('#recaptcha_response_field', qr), 'keydown', QR.keydown); $.bind($('#recaptcha_response_field', qr), 'keydown', QR.keydown);
@ -3261,6 +3278,11 @@
#qr input[name=resto] {\ #qr input[name=resto] {\
width: 80px;\ width: 80px;\
}\ }\
#qr button + input {\
position: absolute;\
opacity: 0;\
pointer-events: none;\
}\
' '
}; };
if (d.body) { if (d.body) {

View File

@ -976,17 +976,15 @@ QR =
$('#autohide', QR.qr).checked = true $('#autohide', QR.qr).checked = true
if conf['Cooldown'] if conf['Cooldown']
$.bind window, 'storage', (e) -> QR.cooldown() if e.key is "#{NAMESPACE}cooldown/#{g.BOARD}" $.bind window, 'storage', (e) -> QR.cooldown() if e.key is "#{NAMESPACE}cooldown/#{g.BOARD}"
attach: -> attach: (file) ->
#$('#autopost', QR.qr).checked = true
files = $ '#files', QR.qr files = $ '#files', QR.qr
box = $.el 'li', box = $.el 'li',
innerHTML: "<img><input type=file name=upfile accept='#{QR.accept}'><a class=x>X</a>" innerHTML: "<img><a class=x>X</a>"
file = $ 'input', box
$.bind file, 'change', QR.change
$.bind $('.x', box), 'click', QR.rmThumb $.bind $('.x', box), 'click', QR.rmThumb
$.add box, file
$.add files, box $.add files, box
file.click()
QR.stats() QR.stats()
QR.foo()
rmThumb: -> rmThumb: ->
$.rm @parentNode $.rm @parentNode
QR.stats() QR.stats()
@ -1029,10 +1027,10 @@ QR =
file = @files[0] file = @files[0]
if file.size > QR.MAX_FILE_SIZE if file.size > QR.MAX_FILE_SIZE
alert 'Error: File too large.' alert 'Error: File too large.'
$.rm @parentNode QR.foo @
QR.attach()
return return
{qr} = QR if @previousSibling.nodeName is 'BUTTON'
QR.attach @
fr = new FileReader() fr = new FileReader()
img = $ 'img', @parentNode img = $ 'img', @parentNode
fr.onload = (e) -> fr.onload = (e) ->
@ -1057,6 +1055,16 @@ QR =
textContent: 'Submit' textContent: 'Submit'
disabled: false disabled: false
QR.submit() if $('#autopost', QR.qr).checked QR.submit() if $('#autopost', QR.qr).checked
foo: (old) ->
input = $.el 'input',
type: 'file'
name: 'upfile'
accept: QR.accept
$.bind input, 'change', QR.change
if old
$.replace old, file
else
$.after $('button', QR.qr), input
dialog: (text='', tid) -> dialog: (text='', tid) ->
tid or= g.THREAD_ID or '' tid or= g.THREAD_ID or ''
QR.qr = qr = ui.dialog 'qr', 'top: 0; right: 0;', " QR.qr = qr = ui.dialog 'qr', 'top: 0; right: 0;', "
@ -1100,7 +1108,8 @@ QR =
$('[name=pwd]', qr).value = if m = c.match(/4chan_pass=([^;]+)/) then decodeURIComponent m[1] else $('input[name=pwd]').value $('[name=pwd]', qr).value = if m = c.match(/4chan_pass=([^;]+)/) then decodeURIComponent m[1] else $('input[name=pwd]').value
$('textarea', qr).value = text $('textarea', qr).value = text
QR.cooldown() if conf['Cooldown'] QR.cooldown() if conf['Cooldown']
$.bind $('button', qr), 'click', QR.attach QR.foo()
$.bind $('button', qr), 'click', -> @nextSibling.click()
$.bind $('.close', qr), 'click', QR.close $.bind $('.close', qr), 'click', QR.close
$.bind $('form', qr), 'submit', QR.submit $.bind $('form', qr), 'submit', QR.submit
$.bind $('#recaptcha_response_field', qr), 'keydown', QR.keydown $.bind $('#recaptcha_response_field', qr), 'keydown', QR.keydown
@ -2522,6 +2531,11 @@ Main =
#qr input[name=resto] { #qr input[name=resto] {
width: 80px; width: 80px;
} }
#qr button + input {
position: absolute;
opacity: 0;
pointer-events: none;
}
' '
if d.body if d.body