Skip to content

Commit

Permalink
use history.pushState and onpopstate in the opening trainer
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jan 9, 2015
1 parent 7144956 commit c69300b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
12 changes: 11 additions & 1 deletion ui/opening/src/ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = function(cfg, router, i18n) {

var chess, init;

var initialize = function() {
initialize = function() {
chess = new Chess(this.data.opening.fen);
init = {
dests: chess.dests(),
Expand Down Expand Up @@ -54,6 +54,16 @@ module.exports = function(cfg, router, i18n) {
}
}.bind(this);

this.pushState = function(cfg) {
if (window.history.pushState)
window.history.pushState(cfg, null, '/training/opening/' + cfg.opening.id);
}.bind(this);

window.onpopstate = function(cfg) {
if (cfg.state) this.reload(cfg.state);
m.redraw();
}.bind(this);

var onMove = function(orig, dest, meta) {
$.sound.move();
submitMove(orig + dest);
Expand Down
1 change: 1 addition & 0 deletions ui/opening/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = function(element, config, router, i18n) {
controller: function () { return controller; },
view: view
});
controller.pushState(config);
};

// lol, that's for the rest of lichess to access mithril
Expand Down
5 changes: 4 additions & 1 deletion ui/opening/src/xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ module.exports = {
method: 'GET',
url: uncache('/training/opening'),
config: xhrConfig
}).then(ctrl.reload);
}).then(function(cfg) {
ctrl.reload(cfg);
ctrl.pushState(cfg);
});
}
};
2 changes: 1 addition & 1 deletion ui/puzzle/src/ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ module.exports = function(cfg, router, i18n) {

window.onpopstate = function(cfg) {
if (cfg.state) this.reload(cfg.state);
return true;
m.redraw();
}.bind(this);

this.playOpponentMove = function(move) {
Expand Down

0 comments on commit c69300b

Please sign in to comment.