Fix $.open. #932

This commit is contained in:
Nicolas Stepien 2013-03-03 17:31:07 +01:00
parent c8e2b23faf
commit 68761aac28
5 changed files with 38 additions and 19 deletions

View File

@ -842,9 +842,21 @@
detail: detail detail: detail
})); }));
}, },
open: function(url) { open: (function() {
return (window.GM_openInTab || window.open)(url, '_blank'); if (typeof GM_openInTab !== "undefined" && GM_openInTab !== null) {
}, return function(URL) {
var a;
a = $.el('a', {
href: URL
});
return GM_openInTab(a.href, '_blank');
};
} else {
return function(URL) {
return window.open(URL, '_blank');
};
}
})(),
debounce: function(wait, fn) { debounce: function(wait, fn) {
var args, exec, that, timeout; var args, exec, that, timeout;
timeout = null; timeout = null;
@ -2907,7 +2919,7 @@
if (g.VIEW !== 'index') { if (g.VIEW !== 'index') {
return; return;
} }
url = "//boards.4chan.org/" + thread.board + "/res/" + thread; url = "/" + thread.board + "/res/" + thread;
if (tab) { if (tab) {
return $.open(url); return $.open(url);
} else { } else {
@ -4533,6 +4545,9 @@
completeExpand: function(post) { completeExpand: function(post) {
var rect, root, thumb; var rect, root, thumb;
thumb = post.file.thumb; thumb = post.file.thumb;
if (!$.hasClass(thumb, 'expanding')) {
return;
}
rect = post.nodes.root.getBoundingClientRect(); rect = post.nodes.root.getBoundingClientRect();
$.addClass(post.nodes.root, 'expanded-image'); $.addClass(post.nodes.root, 'expanded-image');
$.rmClass(post.file.thumb, 'expanding'); $.rmClass(post.file.thumb, 'expanding');
@ -6808,9 +6823,9 @@
isReply: !!threadID isReply: !!threadID
}); });
if (threadID === postID) { if (threadID === postID) {
$.open("//boards.4chan.org/" + g.BOARD + "/res/" + threadID); $.open("/" + g.BOARD + "/res/" + threadID);
} else if (g.VIEW === 'index' && !QR.cooldown.auto) { } else if (g.VIEW === 'index' && !QR.cooldown.auto) {
$.open("//boards.4chan.org/" + g.BOARD + "/res/" + threadID + "#p" + postID); $.open("/" + g.BOARD + "/res/" + threadID + "#p" + postID);
} }
if (!(Conf['Persistent QR'] || QR.cooldown.auto)) { if (!(Conf['Persistent QR'] || QR.cooldown.auto)) {
QR.close(); QR.close();
@ -7243,7 +7258,6 @@
return; return;
} }
initFeature = function(name, module) { initFeature = function(name, module) {
console.time("" + name + " initialization");
try { try {
return module.init(); return module.init();
} catch (err) { } catch (err) {
@ -7252,10 +7266,9 @@
error: err error: err
}); });
} finally { } finally {
console.timeEnd("" + name + " initialization");
} }
}; };
console.time('All initializations');
initFeature('Polyfill', Polyfill); initFeature('Polyfill', Polyfill);
initFeature('Header', Header); initFeature('Header', Header);
initFeature('Settings', Settings); initFeature('Settings', Settings);
@ -7301,7 +7314,6 @@
initFeature('Thread Watcher', ThreadWatcher); initFeature('Thread Watcher', ThreadWatcher);
initFeature('Index Navigation', Nav); initFeature('Index Navigation', Nav);
initFeature('Keybinds', Keybinds); initFeature('Keybinds', Keybinds);
console.timeEnd('All initializations');
$.on(d, 'AddCallback', Main.addCallback); $.on(d, 'AddCallback', Main.addCallback);
$.on(d, '4chanMainInit', Main.initStyle); $.on(d, '4chanMainInit', Main.initStyle);
return $.ready(Main.initReady); return $.ready(Main.initReady);

View File

@ -138,8 +138,14 @@ $.extend $,
return return
event: (event, detail, root=d) -> event: (event, detail, root=d) ->
root.dispatchEvent new CustomEvent event, {bubbles: true, detail} root.dispatchEvent new CustomEvent event, {bubbles: true, detail}
open: (url) -> open: do ->
(window.GM_openInTab or window.open) url, '_blank' if GM_openInTab?
(URL) ->
# XXX fix GM opening file://// for protocol-less URLs.
a = $.el 'a', href: URL
GM_openInTab a.href, '_blank'
else
(URL) -> window.open URL, '_blank'
debounce: (wait, fn) -> debounce: (wait, fn) ->
timeout = null timeout = null
that = null that = null

View File

@ -1616,7 +1616,7 @@ Keybinds =
open: (thread, tab) -> open: (thread, tab) ->
return if g.VIEW isnt 'index' return if g.VIEW isnt 'index'
url = "//boards.4chan.org/#{thread.board}/res/#{thread}" url = "/#{thread.board}/res/#{thread}"
if tab if tab
$.open url $.open url
else else
@ -3023,6 +3023,7 @@ ImageExpand =
completeExpand: (post) -> completeExpand: (post) ->
{thumb} = post.file {thumb} = post.file
return unless $.hasClass thumb, 'expanding' # contracted before the image loaded
rect = post.nodes.root.getBoundingClientRect() rect = post.nodes.root.getBoundingClientRect()
$.addClass post.nodes.root, 'expanded-image' $.addClass post.nodes.root, 'expanded-image'
$.rmClass post.file.thumb, 'expanding' $.rmClass post.file.thumb, 'expanding'

View File

@ -300,7 +300,7 @@ Main =
return return
initFeature = (name, module) -> initFeature = (name, module) ->
console.time "#{name} initialization" # console.time "#{name} initialization"
try try
module.init() module.init()
catch err catch err
@ -308,9 +308,9 @@ Main =
message: "\"#{name}\" initialization crashed." message: "\"#{name}\" initialization crashed."
error: err error: err
finally finally
console.timeEnd "#{name} initialization" # console.timeEnd "#{name} initialization"
console.time 'All initializations' # console.time 'All initializations'
initFeature 'Polyfill', Polyfill initFeature 'Polyfill', Polyfill
initFeature 'Header', Header initFeature 'Header', Header
initFeature 'Settings', Settings initFeature 'Settings', Settings
@ -356,7 +356,7 @@ Main =
initFeature 'Thread Watcher', ThreadWatcher initFeature 'Thread Watcher', ThreadWatcher
initFeature 'Index Navigation', Nav initFeature 'Index Navigation', Nav
initFeature 'Keybinds', Keybinds initFeature 'Keybinds', Keybinds
console.timeEnd 'All initializations' # console.timeEnd 'All initializations'
$.on d, 'AddCallback', Main.addCallback $.on d, 'AddCallback', Main.addCallback
$.on d, '4chanMainInit', Main.initStyle $.on d, '4chanMainInit', Main.initStyle

View File

@ -981,9 +981,9 @@ QR =
isReply: !!threadID isReply: !!threadID
if threadID is postID # new thread if threadID is postID # new thread
$.open "//boards.4chan.org/#{g.BOARD}/res/#{threadID}" $.open "/#{g.BOARD}/res/#{threadID}"
else if g.VIEW is 'index' and !QR.cooldown.auto # posting from the index else if g.VIEW is 'index' and !QR.cooldown.auto # posting from the index
$.open "//boards.4chan.org/#{g.BOARD}/res/#{threadID}#p#{postID}" $.open "/#{g.BOARD}/res/#{threadID}#p#{postID}"
unless Conf['Persistent QR'] or QR.cooldown.auto unless Conf['Persistent QR'] or QR.cooldown.auto
QR.close() QR.close()