Make the back and forward buttons kinda-sorta work

This commit is contained in:
Zixaphir 2014-01-08 12:15:41 -07:00
parent c28d455225
commit 57742dd397
3 changed files with 45 additions and 10 deletions

View File

@ -12597,11 +12597,12 @@
break; break;
} }
try { try {
return localStorage.getItem('4chan-settings'); localStorage.getItem('4chan-settings');
} catch (_error) { } catch (_error) {
err = _error; err = _error;
return new Notice('warning', 'Cookies need to be enabled on 4chan for 4chan X to operate properly.', 30); new Notice('warning', 'Cookies need to be enabled on 4chan for 4chan X to operate properly.', 30);
} }
return $.on(window, 'popstate', Main.popstate);
}, },
initThread: function(threadRoot) { initThread: function(threadRoot) {
var err, errors, post, postRoot, posts, thread, _i, _len, _ref; var err, errors, post, postRoot, posts, thread, _i, _len, _ref;
@ -12783,8 +12784,12 @@
if (view === 'catalog') { if (view === 'catalog') {
return; return;
} }
e.preventDefault(); if (e) {
history.pushState(null, '', this.pathname); e.preventDefault();
}
if (this.id !== 'popState') {
history.pushState(null, '', this.pathname);
}
view = threadID ? 'thread' : view || 'index'; view = threadID ? 'thread' : view || 'index';
if (view === g.VIEW) { if (view === g.VIEW) {
if (view === 'index') { if (view === 'index') {
@ -12818,6 +12823,14 @@
} }
return Header.setBoardList(); return Header.setBoardList();
}, },
popstate: function() {
var a;
a = $.el('a', {
href: window.location,
id: 'popState'
});
return Main.navigate.call(a);
},
updateBoard: function(boardID) { updateBoard: function(boardID) {
var onload, req; var onload, req;
g.BOARD = new Board(boardID); g.BOARD = new Board(boardID);

View File

@ -12571,11 +12571,12 @@
Main.initThread(threadRoot); Main.initThread(threadRoot);
} }
try { try {
return localStorage.getItem('4chan-settings'); localStorage.getItem('4chan-settings');
} catch (_error) { } catch (_error) {
err = _error; err = _error;
return new Notice('warning', 'Cookies need to be enabled on 4chan for 4chan X to operate properly.', 30); new Notice('warning', 'Cookies need to be enabled on 4chan for 4chan X to operate properly.', 30);
} }
return $.on(window, 'popstate', Main.popstate);
}, },
initThread: function(threadRoot) { initThread: function(threadRoot) {
var err, errors, post, postRoot, posts, thread, _i, _len, _ref; var err, errors, post, postRoot, posts, thread, _i, _len, _ref;
@ -12757,8 +12758,12 @@
if (view === 'catalog') { if (view === 'catalog') {
return; return;
} }
e.preventDefault(); if (e) {
history.pushState(null, '', this.pathname); e.preventDefault();
}
if (this.id !== 'popState') {
history.pushState(null, '', this.pathname);
}
view = threadID ? 'thread' : view || 'index'; view = threadID ? 'thread' : view || 'index';
if (view === g.VIEW) { if (view === g.VIEW) {
if (view === 'index') { if (view === 'index') {
@ -12792,6 +12797,14 @@
} }
return Header.setBoardList(); return Header.setBoardList();
}, },
popstate: function() {
var a;
a = $.el('a', {
href: window.location,
id: 'popState'
});
return Main.navigate.call(a);
},
updateBoard: function(boardID) { updateBoard: function(boardID) {
var onload, req; var onload, req;
g.BOARD = new Board(boardID); g.BOARD = new Board(boardID);

View File

@ -144,6 +144,8 @@ Main =
catch err catch err
new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30 new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30
$.on window, 'popstate', Main.popstate
initThread: (threadRoot) -> initThread: (threadRoot) ->
thread = new Thread +threadRoot.id[1..], g.BOARD thread = new Thread +threadRoot.id[1..], g.BOARD
posts = [] posts = []
@ -358,8 +360,8 @@ Main =
return if view is 'catalog' return if view is 'catalog'
e.preventDefault() e.preventDefault() if e
history.pushState null, '', @pathname history.pushState null, '', @pathname unless @id is 'popState'
view = if threadID view = if threadID
'thread' 'thread'
@ -390,6 +392,13 @@ Main =
Header.setBoardList() Header.setBoardList()
popstate: ->
a = $.el 'a',
href: window.location
id: 'popState'
Main.navigate.call a
updateBoard: (boardID) -> updateBoard: (boardID) ->
g.BOARD = new Board boardID g.BOARD = new Board boardID