Fix links to PS rooms

Clicking links to PS rooms can be pretty unreliable in terms of whether
and where they open. This commit uses a global click handler, to make
sure that any and every link to PS rooms, including links in the News,
will open in the current PS window.

You can always right-click and Open in New Tab, of course.
This commit is contained in:
Guangcong Luo
2015-01-25 01:45:12 -05:00
parent 6a3b9e06e1
commit f82c73dd3b

View File

@@ -2,16 +2,31 @@
if (window.nodewebkit) {
window.gui = require('nw.gui');
$('body').on('click', 'a', function(e) {
if (this.target === '_blank') {
gui.Shell.openExternal(this.href);
window.nwWindow = gui.Window.get();
}
$(document).on('click', 'a', function(e) {
if (this.href && this.className !== 'closebutton' && (this.href.substr(0, 32) === 'http://play.pokemonshowdown.com/' || this.href.substr(0, 33) === 'https://play.pokemonshowdown.com/')) {
var target;
if (this.href.charAt(4) === ':') {
target = this.href.substr(32);
} else {
target = this.href.substr(33);
}
if (target.indexOf('/') < 0 && target.indexOf('.') < 0) {
window.app.tryJoinRoom(target);
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
return;
}
});
window.nwWindow = gui.Window.get();
}
}
if (window.nodewebkit && this.target === '_blank') {
gui.Shell.openExternal(this.href);
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
}
});
Config.version = '0.9.2';
Config.origindomain = 'play.pokemonshowdown.com';