Init more features asynchronously.

This commit is contained in:
Nicolas Stepien 2012-03-08 01:47:30 +01:00
parent 6bc5f5d9be
commit 29617d64ef
2 changed files with 70 additions and 40 deletions

View File

@ -1258,8 +1258,12 @@
qr = {
init: function() {
var form, iframe, link, loadChecking;
if (!$.id('recaptcha_challenge_field_holder')) return;
g.callbacks.push(this.node);
return setTimeout(this.asyncInit);
},
asyncInit: function() {
var form, iframe, link, loadChecking, script;
if (conf['Hide Original Post Form']) {
link = $.el('h1', {
innerHTML: "<a href=javascript:;>" + (g.REPLY ? 'Quick Reply' : 'New Thread') + "</a>"
@ -1271,7 +1275,6 @@
form = d.forms[0];
$.before(form, link);
}
g.callbacks.push(this.node);
if (/chrome/i.test(navigator.userAgent)) {
qr.status({
ready: true
@ -1299,19 +1302,14 @@
});
$.add(d.head, iframe);
}
setTimeout(function() {
var script;
script = $.el('script', {
textContent: 'Recaptcha.focus_response_field=function(){}'
});
$.add(d.head, script);
return $.rm(script);
script = $.el('script', {
textContent: 'Recaptcha.focus_response_field=function(){}'
});
$.add(d.head, script);
$.rm(script);
if (conf['Persistent QR']) {
setTimeout(function() {
qr.dialog();
if (conf['Auto Hide QR']) return qr.hide();
});
qr.dialog();
if (conf['Auto Hide QR']) qr.hide();
}
$.on(d, 'dragover', qr.dragOver);
$.on(d, 'drop', qr.dropFile);
@ -3948,19 +3946,51 @@
Favicon.init();
if (conf['Quick Reply']) qr.init();
if (conf['Image Expansion']) ImageExpand.init();
if (conf['Thread Watcher']) Watcher.init();
if (conf['Keybinds']) Keybinds.init();
if (conf['Thread Watcher']) {
setTimeout(function() {
return Watcher.init();
});
}
if (conf['Keybinds']) {
setTimeout(function() {
return Keybinds.init();
});
}
if (g.REPLY) {
if (conf['Thread Updater']) Updater.init();
if (conf['Thread Updater']) {
setTimeout(function() {
return Updater.init();
});
}
if (conf['Thread Stats']) ThreadStats.init();
if (conf['Reply Navigation']) Nav.init();
if (conf['Reply Navigation']) {
setTimeout(function() {
return Nav.init();
});
}
if (conf['Post in Title']) TitlePost.init();
if (conf['Unread Count'] || conf['Unread Favicon']) Unread.init();
} else {
if (conf['Thread Hiding']) ThreadHiding.init();
if (conf['Thread Expansion']) ExpandThread.init();
if (conf['Comment Expansion']) ExpandComment.init();
if (conf['Index Navigation']) Nav.init();
if (conf['Thread Hiding']) {
setTimeout(function() {
return ThreadHiding.init();
});
}
if (conf['Thread Expansion']) {
setTimeout(function() {
return ExpandThread.init();
});
}
if (conf['Comment Expansion']) {
setTimeout(function() {
return ExpandComment.init();
});
}
if (conf['Index Navigation']) {
setTimeout(function() {
return Nav.init();
});
}
}
nodes = [];
_ref2 = $$('.op, a + table', form);

View File

@ -1031,6 +1031,10 @@ Nav =
qr =
init: ->
return unless $.id 'recaptcha_challenge_field_holder'
g.callbacks.push @node
setTimeout @asyncInit
asyncInit: ->
if conf['Hide Original Post Form']
link = $.el 'h1', innerHTML: "<a href=javascript:;>#{if g.REPLY then 'Quick Reply' else 'New Thread'}</a>"
$.on $('a', link), 'click', ->
@ -1038,7 +1042,6 @@ qr =
$('textarea', qr.el).focus()
form = d.forms[0]
$.before form, link
g.callbacks.push @node
# CORS is ignored for content script on Chrome, but not Safari/Oprah/Firefox.
if /chrome/i.test navigator.userAgent
@ -1056,17 +1059,14 @@ qr =
$.on iframe, 'load', -> if @src isnt 'about:blank' then setTimeout loadChecking, 500, @
$.add d.head, iframe
# This is extemely slow, execute is asynchronously.
setTimeout ->
# Prevent original captcha input from being focused on reload.
script = $.el 'script', textContent: 'Recaptcha.focus_response_field=function(){}'
$.add d.head, script
$.rm script
# Prevent original captcha input from being focused on reload.
script = $.el 'script', textContent: 'Recaptcha.focus_response_field=function(){}'
$.add d.head, script
$.rm script
if conf['Persistent QR']
setTimeout ->
qr.dialog()
qr.hide() if conf['Auto Hide QR']
qr.dialog()
qr.hide() if conf['Auto Hide QR']
$.on d, 'dragover', qr.dragOver
$.on d, 'drop', qr.dropFile
$.on d, 'dragstart', qr.drag
@ -2054,7 +2054,7 @@ ThreadHiding =
hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {}
for thread in $$ '.thread'
op = thread.firstChild
a = $.el 'a',
a = $.el 'a',
textContent: '[ - ]'
href: 'javascript:;'
$.on a, 'click', ThreadHiding.cb.hide
@ -3266,20 +3266,20 @@ Main =
ImageExpand.init()
if conf['Thread Watcher']
Watcher.init()
setTimeout -> Watcher.init()
if conf['Keybinds']
Keybinds.init()
setTimeout -> Keybinds.init()
if g.REPLY
if conf['Thread Updater']
Updater.init()
setTimeout -> Updater.init()
if conf['Thread Stats']
ThreadStats.init()
if conf['Reply Navigation']
Nav.init()
setTimeout -> Nav.init()
if conf['Post in Title']
TitlePost.init()
@ -3289,16 +3289,16 @@ Main =
else #not reply
if conf['Thread Hiding']
ThreadHiding.init()
setTimeout -> ThreadHiding.init()
if conf['Thread Expansion']
ExpandThread.init()
setTimeout -> ExpandThread.init()
if conf['Comment Expansion']
ExpandComment.init()
setTimeout -> ExpandComment.init()
if conf['Index Navigation']
Nav.init()
setTimeout -> Nav.init()
nodes = []
for node in $$ '.op, a + table', form