tweak history raw HTML loading

This commit is contained in:
Thibault Duplessis 2014-09-30 00:22:53 +02:00
parent 7961c49061
commit 7994c226e2
2 changed files with 10 additions and 9 deletions

View file

@ -85,8 +85,6 @@ module.exports = function(cfg, router, i18n) {
this.initiate = function() {
if (this.data.mode != 'view')
setTimeout(partial(this.playInitialMove, this.data.puzzle.id), 1000);
if (this.data.user)
$.get(this.router.Puzzle.history().url, this.setHistoryHtml);
}.bind(this);
this.reload = function(cfg) {
@ -123,12 +121,6 @@ module.exports = function(cfg, router, i18n) {
this.data.startedAt = new Date();
}.bind(this);
this.setHistoryHtml = function(html) {
m.startComputation();
this.data.historyHtml = html;
m.endComputation();
}.bind(this);
this.jump = function(to) {
chessground.anim(puzzle.jump, this.chessground.data)(this.data, to);
}.bind(this);

View file

@ -273,7 +273,16 @@ function renderFooter(ctrl) {
}
function renderHistory(ctrl) {
return m('div.history', ctrl.data.historyHtml ? m.trust(ctrl.data.historyHtml) : null);
return m('div.history', {
config: function(el, isUpdate, context) {
var hash = ctrl.data.user.history.join('');
if (hash == context.hash) return;
context.hash = hash;
$.get(ctrl.router.Puzzle.history().url, function(html) {
el.innerHTML = html;
});
}
});
}
module.exports = function(ctrl) {