2012-02-06 22:00:24 +00:00
|
|
|
/*
|
Add ID codes for positive user identification, and minor fixups.
Users can specify an identification code when they connect (8-100 characters), only if they are using HTTPS. This code is combined with their nickname and a server-side secret, hashed with SHA-256, and condensed down to 64 bits by XORing every 8th byte with each other, and finally converted to base64 (with the trailing = removed). This code is displayed in a tooltip when hovering over the user's chat (TODO: mobile way to view it).
Sigils have been added to be displayed before the user's name in the chat. Admins get @, users with an ID code get +, and normal users get nothing. The IS_ADMIN field is now deprecated, as this can be determined from the user's sigil. It will be removed eventually, but is still being included in events even though the official client should not be using it anymore.
Kicks and bans are now always displayed to all users, even if the server isn't transmitting quit events normally.
2018-03-03 01:24:58 +00:00
|
|
|
* Copyright (c) 2012-2018, Andy Janata
|
2012-02-02 22:47:23 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification, are permitted
|
|
|
|
* provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice, this list of conditions
|
|
|
|
* and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice, this list of
|
|
|
|
* conditions and the following disclaimer in the documentation and/or other materials provided
|
|
|
|
* with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
|
|
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2011-12-23 02:48:20 +00:00
|
|
|
/**
|
2012-03-15 17:14:32 +00:00
|
|
|
* Main application for Pretend You're Xyzzy. This only has to handle the initial nickname
|
2012-02-06 22:00:24 +00:00
|
|
|
* registration, the chat box, the logout button, and resizing the window. It should probably be
|
|
|
|
* split up into multiple files.
|
2011-12-23 02:48:20 +00:00
|
|
|
*
|
2012-02-06 22:00:24 +00:00
|
|
|
* @author Andy Janata (ajanata@socialgamer.net)
|
2011-12-23 02:48:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
2012-12-28 03:33:27 +00:00
|
|
|
// Initialize the logger (i.e. the global chat tab) before anything needs it.
|
|
|
|
cah.log.init();
|
|
|
|
|
2011-12-25 03:37:45 +00:00
|
|
|
// see if we already exist on the server so we can resume
|
2012-01-13 04:05:39 +00:00
|
|
|
cah.Ajax.build(cah.$.AjaxOperation.FIRST_LOAD).run();
|
2011-12-25 03:37:45 +00:00
|
|
|
|
2012-10-12 05:18:40 +01:00
|
|
|
if ($.cookie("nickname")) {
|
|
|
|
$("#nickname").val($.cookie("nickname"));
|
|
|
|
}
|
2011-12-23 02:48:20 +00:00
|
|
|
$("#nicknameconfirm").click(nicknameconfirm_click);
|
Add ID codes for positive user identification, and minor fixups.
Users can specify an identification code when they connect (8-100 characters), only if they are using HTTPS. This code is combined with their nickname and a server-side secret, hashed with SHA-256, and condensed down to 64 bits by XORing every 8th byte with each other, and finally converted to base64 (with the trailing = removed). This code is displayed in a tooltip when hovering over the user's chat (TODO: mobile way to view it).
Sigils have been added to be displayed before the user's name in the chat. Admins get @, users with an ID code get +, and normal users get nothing. The IS_ADMIN field is now deprecated, as this can be determined from the user's sigil. It will be removed eventually, but is still being included in events even though the official client should not be using it anymore.
Kicks and bans are now always displayed to all users, even if the server isn't transmitting quit events normally.
2018-03-03 01:24:58 +00:00
|
|
|
$("#nickname").keyup(nickname_keyup);
|
2018-03-02 22:28:28 +00:00
|
|
|
$("#nickname").focus();
|
Add ID codes for positive user identification, and minor fixups.
Users can specify an identification code when they connect (8-100 characters), only if they are using HTTPS. This code is combined with their nickname and a server-side secret, hashed with SHA-256, and condensed down to 64 bits by XORing every 8th byte with each other, and finally converted to base64 (with the trailing = removed). This code is displayed in a tooltip when hovering over the user's chat (TODO: mobile way to view it).
Sigils have been added to be displayed before the user's name in the chat. Admins get @, users with an ID code get +, and normal users get nothing. The IS_ADMIN field is now deprecated, as this can be determined from the user's sigil. It will be removed eventually, but is still being included in events even though the official client should not be using it anymore.
Kicks and bans are now always displayed to all users, even if the server isn't transmitting quit events normally.
2018-03-03 01:24:58 +00:00
|
|
|
if (document.location.protocol == "https:" || cah.INSECURE_ID_ALLOWED) {
|
|
|
|
$("#idcode").prop("disabled", false);
|
|
|
|
// re-use existing handler
|
|
|
|
$("#idcode").keyup(nickname_keyup);
|
|
|
|
}
|
2011-12-25 03:37:45 +00:00
|
|
|
|
2013-02-25 02:47:05 +00:00
|
|
|
$(".chat", $("#tab-global")).keyup(chat_keyup($(".chat_submit", $("#tab-global"))));
|
2012-12-29 22:21:37 +00:00
|
|
|
$(".chat_submit", $("#tab-global")).click(chatsubmit_click(null, $("#tab-global")));
|
2012-01-06 23:53:04 +00:00
|
|
|
|
|
|
|
// TODO: have some sort of mechanism to alert the server that we have unloaded the page, but
|
|
|
|
// have not expressed an interest in being cleared out yet.
|
|
|
|
// $(window).bind("beforeunload", window_beforeunload);
|
|
|
|
$("#logout").click(logout_click);
|
2012-10-16 04:23:37 +01:00
|
|
|
|
2014-01-27 07:22:37 +00:00
|
|
|
cah.Preferences.load();
|
2012-01-25 08:03:41 +00:00
|
|
|
|
2012-10-16 04:23:37 +01:00
|
|
|
$("#tabs").tabs();
|
|
|
|
$("#button-global").click();
|
|
|
|
|
2012-01-25 08:03:41 +00:00
|
|
|
if ($.browser.mozilla) {
|
|
|
|
// Firefox sucks.
|
|
|
|
$("body").css("font-size", "12px");
|
|
|
|
}
|
2012-01-30 08:35:27 +00:00
|
|
|
|
|
|
|
$(window).resize(app_resize);
|
|
|
|
app_resize();
|
2011-12-23 02:48:20 +00:00
|
|
|
});
|
|
|
|
|
2013-04-28 18:11:28 +01:00
|
|
|
$(window).focus(function() {
|
|
|
|
cah.windowActive = true;
|
|
|
|
if (cah.missedGameListRefresh) {
|
|
|
|
cah.GameList.instance.update();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$(window).blur(function() {
|
|
|
|
cah.windowActive = false;
|
|
|
|
});
|
|
|
|
|
2012-02-06 22:00:24 +00:00
|
|
|
/**
|
|
|
|
* Handle a key up event in the nick box. If the key was enter, try to register with the server.
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event}
|
|
|
|
* e
|
|
|
|
*/
|
Add ID codes for positive user identification, and minor fixups.
Users can specify an identification code when they connect (8-100 characters), only if they are using HTTPS. This code is combined with their nickname and a server-side secret, hashed with SHA-256, and condensed down to 64 bits by XORing every 8th byte with each other, and finally converted to base64 (with the trailing = removed). This code is displayed in a tooltip when hovering over the user's chat (TODO: mobile way to view it).
Sigils have been added to be displayed before the user's name in the chat. Admins get @, users with an ID code get +, and normal users get nothing. The IS_ADMIN field is now deprecated, as this can be determined from the user's sigil. It will be removed eventually, but is still being included in events even though the official client should not be using it anymore.
Kicks and bans are now always displayed to all users, even if the server isn't transmitting quit events normally.
2018-03-03 01:24:58 +00:00
|
|
|
function nickname_keyup(e) {
|
2011-12-23 02:48:20 +00:00
|
|
|
if (e.which == 13) {
|
|
|
|
$("#nicknameconfirm").click();
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-06 22:00:24 +00:00
|
|
|
/**
|
|
|
|
* Handle a click event on the set nickname box. Try to register with the server.
|
|
|
|
*/
|
|
|
|
function nicknameconfirm_click() {
|
2011-12-25 03:37:45 +00:00
|
|
|
var nickname = $.trim($("#nickname").val());
|
2017-02-21 05:35:44 +00:00
|
|
|
cah.setCookie("nickname", nickname);
|
|
|
|
var builder = cah.Ajax.build(cah.$.AjaxOperation.REGISTER).withNickname(nickname);
|
Add ID codes for positive user identification, and minor fixups.
Users can specify an identification code when they connect (8-100 characters), only if they are using HTTPS. This code is combined with their nickname and a server-side secret, hashed with SHA-256, and condensed down to 64 bits by XORing every 8th byte with each other, and finally converted to base64 (with the trailing = removed). This code is displayed in a tooltip when hovering over the user's chat (TODO: mobile way to view it).
Sigils have been added to be displayed before the user's name in the chat. Admins get @, users with an ID code get +, and normal users get nothing. The IS_ADMIN field is now deprecated, as this can be determined from the user's sigil. It will be removed eventually, but is still being included in events even though the official client should not be using it anymore.
Kicks and bans are now always displayed to all users, even if the server isn't transmitting quit events normally.
2018-03-03 01:24:58 +00:00
|
|
|
var idCode = $.trim($("#idcode").val());
|
|
|
|
if (idCode) {
|
|
|
|
builder.withIdCode(idCode);
|
|
|
|
}
|
2017-02-21 05:35:44 +00:00
|
|
|
if (!cah.noPersistentId && cah.persistentId) {
|
|
|
|
builder.withPersistentId(cah.persistentId);
|
|
|
|
}
|
|
|
|
builder.run();
|
2011-12-25 03:37:45 +00:00
|
|
|
}
|
|
|
|
|
2012-02-06 22:00:24 +00:00
|
|
|
/**
|
|
|
|
* Handle a key up event in the chat box. If the key was enter, send the message to the server.
|
|
|
|
*
|
2013-02-25 02:47:05 +00:00
|
|
|
* @param {jQuery.HTMLButtonElement}
|
|
|
|
* submitButton Submit button for the chat box.
|
2012-02-06 22:00:24 +00:00
|
|
|
*/
|
2013-02-25 02:47:05 +00:00
|
|
|
function chat_keyup(submitButton) {
|
|
|
|
return function(e) {
|
|
|
|
if (e.which == 13) {
|
|
|
|
$(submitButton).click();
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
};
|
2011-12-25 03:37:45 +00:00
|
|
|
}
|
|
|
|
|
2012-02-06 22:00:24 +00:00
|
|
|
/**
|
2013-02-23 22:32:00 +00:00
|
|
|
* Generate a click handler for the chat submit button. This parses the line for any /-commands,
|
|
|
|
* then sends the request to the server.
|
|
|
|
*
|
2012-12-29 22:21:37 +00:00
|
|
|
* @param {number}
|
2013-02-23 22:32:00 +00:00
|
|
|
* game_id Game ID to use in AJAX requests, or null for global chat
|
2012-12-29 22:21:37 +00:00
|
|
|
* @param {jQuery.HTMLDivElement}
|
2013-02-23 22:32:00 +00:00
|
|
|
* parent_element Parent element, which contains one text-input-box element of class
|
2012-12-29 22:21:37 +00:00
|
|
|
* "chat", which will be used to source the data.
|
2012-02-06 22:00:24 +00:00
|
|
|
*/
|
2012-12-29 22:21:37 +00:00
|
|
|
function chatsubmit_click(game_id, parent_element) {
|
2012-12-29 21:58:19 +00:00
|
|
|
return function() {
|
2012-12-29 22:21:37 +00:00
|
|
|
var ajax = null;
|
|
|
|
|
|
|
|
var text = $.trim($(".chat", parent_element).val());
|
2012-12-29 21:58:19 +00:00
|
|
|
if (text == "") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var cmd = '';
|
|
|
|
if ('/' == text.substring(0, 1)) {
|
|
|
|
cmd = text.substring(1, text.indexOf(' ') >= 0 ? text.indexOf(' ') : undefined);
|
|
|
|
if (text.indexOf(' ') >= 0) {
|
|
|
|
text = text.substring(text.indexOf(' ') + 1);
|
|
|
|
} else {
|
|
|
|
text = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (cmd) {
|
|
|
|
// TODO support an /ignore command
|
|
|
|
case '':
|
2013-03-27 03:17:49 +00:00
|
|
|
if (game_id !== null) {
|
2013-11-30 04:54:56 +00:00
|
|
|
ajax = cah.Ajax.build(cah.$.AjaxOperation.GAME_CHAT).withGameId(game_id);
|
2013-02-25 02:47:05 +00:00
|
|
|
} else {
|
2013-11-30 04:54:56 +00:00
|
|
|
ajax = cah.Ajax.build(cah.$.AjaxOperation.CHAT);
|
2013-02-25 02:47:05 +00:00
|
|
|
}
|
2013-11-30 04:54:56 +00:00
|
|
|
ajax = ajax.withEmote(false).withMessage(text);
|
Add ID codes for positive user identification, and minor fixups.
Users can specify an identification code when they connect (8-100 characters), only if they are using HTTPS. This code is combined with their nickname and a server-side secret, hashed with SHA-256, and condensed down to 64 bits by XORing every 8th byte with each other, and finally converted to base64 (with the trailing = removed). This code is displayed in a tooltip when hovering over the user's chat (TODO: mobile way to view it).
Sigils have been added to be displayed before the user's name in the chat. Admins get @, users with an ID code get +, and normal users get nothing. The IS_ADMIN field is now deprecated, as this can be determined from the user's sigil. It will be removed eventually, but is still being included in events even though the official client should not be using it anymore.
Kicks and bans are now always displayed to all users, even if the server isn't transmitting quit events normally.
2018-03-03 01:24:58 +00:00
|
|
|
var clazz = '';
|
|
|
|
if (cah.sigil == cah.$.Sigil.ADMIN) {
|
|
|
|
clazz = 'admin';
|
|
|
|
}
|
|
|
|
cah.log.status_with_game(game_id, "<" + cah.sigil + cah.nickname + "> " + text, clazz,
|
|
|
|
false, cah.log.getTitleForIdCode(cah.idcode));
|
2012-12-29 21:58:19 +00:00
|
|
|
break;
|
2013-10-02 12:28:16 +01:00
|
|
|
case 'me':
|
2013-11-30 04:54:56 +00:00
|
|
|
if (game_id !== null) {
|
|
|
|
ajax = cah.Ajax.build(cah.$.AjaxOperation.GAME_CHAT).withGameId(game_id);
|
|
|
|
} else {
|
|
|
|
ajax = cah.Ajax.build(cah.$.AjaxOperation.CHAT);
|
|
|
|
}
|
|
|
|
ajax = ajax.withEmote(true).withMessage(text);
|
Add ID codes for positive user identification, and minor fixups.
Users can specify an identification code when they connect (8-100 characters), only if they are using HTTPS. This code is combined with their nickname and a server-side secret, hashed with SHA-256, and condensed down to 64 bits by XORing every 8th byte with each other, and finally converted to base64 (with the trailing = removed). This code is displayed in a tooltip when hovering over the user's chat (TODO: mobile way to view it).
Sigils have been added to be displayed before the user's name in the chat. Admins get @, users with an ID code get +, and normal users get nothing. The IS_ADMIN field is now deprecated, as this can be determined from the user's sigil. It will be removed eventually, but is still being included in events even though the official client should not be using it anymore.
Kicks and bans are now always displayed to all users, even if the server isn't transmitting quit events normally.
2018-03-03 01:24:58 +00:00
|
|
|
var clazz = '';
|
|
|
|
if (cah.sigil == cah.$.Sigil.ADMIN) {
|
|
|
|
clazz = 'admin';
|
|
|
|
}
|
|
|
|
cah.log.status_with_game(game_id, "* " + cah.sigil + cah.nickname + " " + text, clazz,
|
|
|
|
false, cah.log.getTitleForIdCode(cah.idcode));
|
2013-11-30 04:54:56 +00:00
|
|
|
break;
|
2013-03-27 03:17:49 +00:00
|
|
|
case 'wall':
|
|
|
|
ajax = cah.Ajax.build(cah.$.AjaxOperation.CHAT).withWall(true).withMessage(text);
|
|
|
|
break;
|
2012-12-29 21:58:19 +00:00
|
|
|
case 'kick':
|
2012-12-29 22:21:37 +00:00
|
|
|
ajax = cah.Ajax.build(cah.$.AjaxOperation.KICK).withNickname(text.split(' ')[0]);
|
2012-12-29 21:58:19 +00:00
|
|
|
break;
|
|
|
|
case 'ban':
|
|
|
|
// this could also be an IP address
|
2012-12-29 22:21:37 +00:00
|
|
|
ajax = cah.Ajax.build(cah.$.AjaxOperation.BAN).withNickname(text.split(' ')[0]);
|
2012-12-29 21:58:19 +00:00
|
|
|
break;
|
2013-11-29 03:52:19 +00:00
|
|
|
case 'sync':
|
|
|
|
if (game_id !== null) {
|
|
|
|
var game = cah.currentGames[game_id];
|
|
|
|
if (game) {
|
|
|
|
game.removeAllCards();
|
|
|
|
}
|
|
|
|
ajax = cah.Ajax.build(cah.$.AjaxOperation.GET_CARDS).withGameId(game_id);
|
|
|
|
} else {
|
|
|
|
cah.log.error("This command only works in a game.");
|
|
|
|
}
|
2013-11-30 05:04:09 +00:00
|
|
|
break;
|
2013-11-15 10:27:30 +00:00
|
|
|
case 'score':
|
2013-11-30 05:04:09 +00:00
|
|
|
ajax = cah.Ajax.build(cah.$.AjaxOperation.SCORE).withMessage(text);
|
|
|
|
if (game_id != null) {
|
|
|
|
ajax = ajax.withGameId(game_id);
|
|
|
|
}
|
2013-11-29 03:52:19 +00:00
|
|
|
break;
|
2012-12-29 21:58:19 +00:00
|
|
|
case 'names':
|
2012-12-29 22:21:37 +00:00
|
|
|
ajax = cah.Ajax.build(cah.$.AjaxOperation.NAMES);
|
2012-12-29 21:58:19 +00:00
|
|
|
break;
|
2014-08-11 06:16:15 +01:00
|
|
|
case 'addcardcast':
|
|
|
|
if (game_id !== null) {
|
|
|
|
ajax = cah.Ajax.build(cah.$.AjaxOperation.CARDCAST_ADD_CARDSET).withCardcastId(
|
|
|
|
text.split(' ')[0]).withGameId(game_id);
|
|
|
|
} else {
|
|
|
|
cah.log.error("This command only works in a game.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'removecardcast':
|
|
|
|
if (game_id !== null) {
|
|
|
|
ajax = cah.Ajax.build(cah.$.AjaxOperation.CARDCAST_REMOVE_CARDSET).withCardcastId(
|
|
|
|
text.split(' ')[0]).withGameId(game_id);
|
|
|
|
} else {
|
|
|
|
cah.log.error("This command only works in a game.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'listcardcast':
|
|
|
|
if (game_id !== null) {
|
|
|
|
ajax = cah.Ajax.build(cah.$.AjaxOperation.CARDCAST_LIST_CARDSETS).withGameId(game_id);
|
|
|
|
} else {
|
|
|
|
cah.log.error("This command only works in a game.");
|
|
|
|
}
|
|
|
|
break;
|
2018-03-06 08:15:05 +00:00
|
|
|
case 'whois':
|
|
|
|
ajax = cah.Ajax.build(cah.$.AjaxOperation.WHOIS).withNickname(text.split(' ')[0]);
|
2018-03-06 08:30:04 +00:00
|
|
|
// so we can show it in the right place; the server ignores this
|
|
|
|
if (game_id !== null) {
|
|
|
|
ajax = ajax.withGameId(game_id);
|
|
|
|
}
|
2018-03-06 08:15:05 +00:00
|
|
|
break;
|
2012-12-29 21:58:19 +00:00
|
|
|
default:
|
2013-03-27 03:17:49 +00:00
|
|
|
cah.log.error("Invalid command.");
|
2012-08-21 06:41:06 +01:00
|
|
|
}
|
|
|
|
|
2012-12-29 22:21:37 +00:00
|
|
|
if (ajax) {
|
|
|
|
ajax.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
$(".chat", parent_element).val("");
|
|
|
|
$(".chat", parent_element).focus();
|
2012-12-29 21:58:19 +00:00
|
|
|
};
|
2011-12-23 02:48:20 +00:00
|
|
|
}
|
2012-01-06 23:53:04 +00:00
|
|
|
|
2012-02-06 22:00:24 +00:00
|
|
|
/**
|
|
|
|
* Handle a click event on the log out button. Tell the server to log us out.
|
|
|
|
*/
|
|
|
|
function logout_click() {
|
2012-03-15 20:50:24 +00:00
|
|
|
if (confirm("Are you sure you wish to log out?")) {
|
|
|
|
cah.Ajax.build(cah.$.AjaxOperation.LOG_OUT).run();
|
2013-11-11 03:22:54 +00:00
|
|
|
cah.updateHash('');
|
2012-03-15 20:50:24 +00:00
|
|
|
}
|
2012-01-06 23:53:04 +00:00
|
|
|
}
|
2012-01-30 08:35:27 +00:00
|
|
|
|
2012-10-12 05:18:40 +01:00
|
|
|
/**
|
|
|
|
* Handle a click event on the preferences button. Shows the preferences modal dialog.
|
|
|
|
*/
|
|
|
|
function preferences_click() {
|
|
|
|
$("#preferences_dialog").dialog({
|
|
|
|
modal : true,
|
|
|
|
buttons : {
|
|
|
|
Ok : function() {
|
|
|
|
save_preferences();
|
|
|
|
$(this).dialog("close");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_preferences() {
|
2014-01-27 07:22:37 +00:00
|
|
|
// FIXME remove these after making sure everything calls the new way.
|
|
|
|
debugger;
|
|
|
|
cah.Preferences.load();
|
|
|
|
}
|
2012-10-12 05:18:40 +01:00
|
|
|
|
2014-01-27 07:22:37 +00:00
|
|
|
function save_preferences() {
|
|
|
|
// FIXME remove these after making sure everything calls the new way.
|
|
|
|
debugger;
|
|
|
|
cah.Preferences.save();
|
|
|
|
}
|
2012-10-12 05:18:40 +01:00
|
|
|
|
2014-01-27 07:22:37 +00:00
|
|
|
function apply_preferences() {
|
|
|
|
// FIXME remove these after making sure everything calls the new way.
|
|
|
|
debugger;
|
|
|
|
cah.Preferences.apply();
|
2012-10-12 05:18:40 +01:00
|
|
|
}
|
|
|
|
|
2014-01-27 07:22:37 +00:00
|
|
|
/**
|
|
|
|
* Add selected items from sourceList to destList, ignoring duplicates.
|
|
|
|
*/
|
|
|
|
cah.transferItems = function(sourceListId, destListId, idPrefix) {
|
|
|
|
cah.transferItems(sourceListId, destListId, idPrefix, function(a, b) {
|
|
|
|
return Number(a.value) - Number(b.value);
|
|
|
|
});
|
|
|
|
};
|
2012-10-12 05:18:40 +01:00
|
|
|
|
2014-01-27 07:22:37 +00:00
|
|
|
cah.transferItems = function(sourceListId, destListId, idPrefix, sortFunc) {
|
|
|
|
$('#' + sourceListId + ' option').filter(':selected').each(function() {
|
|
|
|
var existing = $('#' + idPrefix + '_' + this.value);
|
|
|
|
if (existing.length == 0) {
|
|
|
|
cah.addItem(destListId, this.value, this.text, idPrefix);
|
|
|
|
}
|
2012-10-12 05:18:40 +01:00
|
|
|
});
|
2014-01-27 07:22:37 +00:00
|
|
|
$('#' + destListId + ' option').sort(sortFunc).appendTo('#' + destListId);
|
2012-10-12 05:18:40 +01:00
|
|
|
|
2014-01-27 07:22:37 +00:00
|
|
|
cah.removeItems(sourceListId);
|
|
|
|
};
|
2012-10-12 05:18:40 +01:00
|
|
|
|
2014-01-27 07:22:37 +00:00
|
|
|
/**
|
|
|
|
* Add an item to a list.
|
|
|
|
*
|
|
|
|
* @param listId
|
|
|
|
* {String} Id of the select element.
|
|
|
|
* @param value
|
|
|
|
* {String} Value attribute of the item to insert into the list.
|
|
|
|
* @param text
|
|
|
|
* {String} The display text to insert into the list.
|
|
|
|
* @param idPrefix
|
|
|
|
* {String} The prefix for the id of the item to insert into the list.
|
|
|
|
*/
|
|
|
|
cah.addItem = function(listId, value, text, idPrefix) {
|
|
|
|
$('#' + listId).append(
|
|
|
|
'<option value="' + value + '" id="' + idPrefix + '_' + value + '">' + text + '</option>');
|
|
|
|
};
|
2012-10-12 05:18:40 +01:00
|
|
|
|
2014-01-27 07:22:37 +00:00
|
|
|
/**
|
|
|
|
* Remove selected items from list.
|
|
|
|
*
|
|
|
|
* @param listId
|
|
|
|
* {String} Id of the list from which to remove selected items.
|
|
|
|
*/
|
|
|
|
cah.removeItems = function(listId) {
|
|
|
|
$('#' + listId + ' option').filter(':selected').each(function() {
|
|
|
|
this.parentElement.removeChild(this);
|
2012-10-12 05:18:40 +01:00
|
|
|
});
|
2014-01-27 07:22:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a cookie.
|
|
|
|
*
|
|
|
|
* @param {String}
|
|
|
|
* name The name of the cookie.
|
|
|
|
* @param {Any}
|
|
|
|
* value The value of the cookie.
|
|
|
|
*/
|
|
|
|
cah.setCookie = function(name, value) {
|
|
|
|
return $.cookie(name, value, {
|
2017-02-21 05:35:44 +00:00
|
|
|
domain : cah.COOKIE_DOMAIN,
|
2014-01-27 07:22:37 +00:00
|
|
|
expires : 365
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a cookie.
|
|
|
|
*
|
|
|
|
* @param {String}
|
|
|
|
* name The name of the cookie.
|
|
|
|
*/
|
|
|
|
cah.removeCookie = function(name) {
|
2017-02-21 05:35:44 +00:00
|
|
|
$.removeCookie(name, {
|
|
|
|
domain : cah.COOKIE_DOMAIN
|
|
|
|
});
|
2014-01-27 07:22:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a cookie.
|
|
|
|
*
|
|
|
|
* @param {String}
|
|
|
|
* name The name of the cookie.
|
|
|
|
* @returns The value of the cookie, or {@code undefined} if the cookie is not set.
|
|
|
|
*/
|
|
|
|
cah.getCookie = function(name) {
|
|
|
|
return $.cookie(name);
|
|
|
|
};
|
2012-10-12 05:18:40 +01:00
|
|
|
|
2012-02-06 22:00:24 +00:00
|
|
|
/**
|
|
|
|
* Handle a window resize event. Resize the chat and info areas to fit vertically and horizontally.
|
|
|
|
* This was tested extensively in Chrome. It may not be pixel-perfect in other browsers.
|
|
|
|
*/
|
2012-01-30 08:35:27 +00:00
|
|
|
function app_resize() {
|
2012-12-28 03:33:27 +00:00
|
|
|
var chat = $(".chat", $("#tab-global"));
|
|
|
|
var log = cah.log.log;
|
|
|
|
|
2012-10-16 04:23:37 +01:00
|
|
|
var chatWidth = $("#canvas").width() - 257;
|
|
|
|
$("#tabs").width(chatWidth + 'px');
|
|
|
|
var bottomHeight = $(window).height() - $("#main").height() - $("#menubar").height() - 29;
|
2012-01-30 08:35:27 +00:00
|
|
|
$("#bottom").height(bottomHeight);
|
|
|
|
$("#info_area").height(bottomHeight);
|
2012-10-16 04:23:37 +01:00
|
|
|
$("#tabs").height(bottomHeight);
|
2018-03-09 18:13:46 +00:00
|
|
|
$("#tab-preferences").height(bottomHeight - 45);
|
|
|
|
$("#tab-gamelist-filters").height(bottomHeight - 45);
|
2013-02-23 22:32:00 +00:00
|
|
|
|
|
|
|
// global chat
|
|
|
|
do_app_resize(chat, log);
|
|
|
|
// per-game chats
|
|
|
|
for ( var id in cah.currentGames) {
|
|
|
|
chat = $(".chat", $("#tab-chat-game_" + id));
|
|
|
|
log = $(".log", $("#tab-chat-game_" + id));
|
|
|
|
do_app_resize(chat, log);
|
|
|
|
}
|
|
|
|
|
2012-01-30 08:35:27 +00:00
|
|
|
// this is ugly and terrible.
|
|
|
|
if ($(window).height() < 650) {
|
|
|
|
$("body").css("overflow-y", "auto");
|
|
|
|
} else {
|
|
|
|
$("body").css("overflow-y", "hidden");
|
|
|
|
}
|
|
|
|
}
|
2013-02-23 22:32:00 +00:00
|
|
|
|
|
|
|
function do_app_resize(chatElement, logElement) {
|
|
|
|
var chatWidth = $("#canvas").width() - 257;
|
|
|
|
logElement.width((chatWidth + 2) + 'px');
|
|
|
|
chatElement.width((chatWidth - 42) + 'px');
|
|
|
|
var bottomHeight = $(window).height() - $("#main").height() - $("#menubar").height() - 29;
|
|
|
|
logElement.height(bottomHeight - chatElement.height() - 40);
|
|
|
|
}
|
2018-05-30 20:19:53 +01:00
|
|
|
|
|
|
|
cah.logUserPermalinks = function(data) {
|
|
|
|
var linkMsg = "";
|
|
|
|
if (cah.$.AjaxResponse.SESSION_PERMALINK in data) {
|
|
|
|
linkMsg += "<a href='" + data[cah.$.AjaxResponse.SESSION_PERMALINK]
|
|
|
|
+ "'rel='noopener' target='_blank'>Permanent link to games you play this session.</a> ";
|
|
|
|
}
|
|
|
|
if (cah.$.AjaxResponse.USER_PERMALINK in data && !cah.noPersistentId) {
|
|
|
|
linkMsg += "<a href='"
|
|
|
|
+ data[cah.$.AjaxResponse.USER_PERMALINK]
|
|
|
|
+ "'rel='noopener' target='_blank'>Permanent link to every time you've played on this device.</a> ";
|
|
|
|
}
|
|
|
|
if ("" != linkMsg) {
|
|
|
|
cah.log.status(linkMsg, undefined, true);
|
|
|
|
}
|
|
|
|
}
|