inject notes and game id to chat plugin

This commit is contained in:
Thibault Duplessis 2014-12-09 09:32:00 +01:00
parent 3016153b38
commit ea87554cad

View file

@ -767,7 +767,9 @@ var storage = {
function startRound(element, cfg) { function startRound(element, cfg) {
var data = cfg.data; var data = cfg.data;
if (data.chat) $('#chat').chat({ if (data.chat) $('#chat').chat({
messages: data.chat messages: data.chat,
initialNote: data.note,
gameId: data.game.id
}); });
var $watchers = $('#site_header div.watchers').watchers(); var $watchers = $('#site_header div.watchers').watchers();
var round; var round;
@ -925,7 +927,9 @@ var storage = {
$.widget("lichess.chat", { $.widget("lichess.chat", {
_create: function() { _create: function() {
this.options = $.extend({ this.options = $.extend({
messages: [] messages: [],
initialNote: '',
gameId: null
}, this.options); }, this.options);
var self = this; var self = this;
self.$msgs = self.element.find('.messages'); self.$msgs = self.element.find('.messages');
@ -977,16 +981,13 @@ var storage = {
}).find('a:first').click(); }).find('a:first').click();
$notes = self.element.find('.notes textarea'); $notes = self.element.find('.notes textarea');
if (self.options.gameId && $notes.length) {
var data = lichess.analyse ? lichess.analyse.data : (lichess.round ? lichess.round.data : false);
if (data) {
$notes.on('change keyup paste', $.fp.debounce(function() { $notes.on('change keyup paste', $.fp.debounce(function() {
$.post('/' + data.game.id + '/note', { $.post('/' + self.options.gameId + '/note', {
text: $notes.val() text: $notes.val()
}); });
}, 1000)); }, 1000));
$notes.val(data.note || ''); $notes.val(self.options.initialNote || '');
} }
}, },
append: function(msg) { append: function(msg) {
@ -2003,7 +2004,9 @@ var storage = {
function startAnalyse(element, cfg) { function startAnalyse(element, cfg) {
var data = cfg.data; var data = cfg.data;
if (data.chat) $('#chat').chat({ if (data.chat) $('#chat').chat({
messages: data.chat messages: data.chat,
initialNote: data.note,
gameId: data.game.id
}); });
var $watchers = $('#site_header div.watchers').watchers(); var $watchers = $('#site_header div.watchers').watchers();
var analyse, $panels; var analyse, $panels;