From 57742dd397c639dad0306bbe80c74bff0aeadef1 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Wed, 8 Jan 2014 12:15:41 -0700 Subject: [PATCH] Make the back and forward buttons kinda-sorta work --- builds/4chan-X.user.js | 21 +++++++++++++++++---- builds/crx/script.js | 21 +++++++++++++++++---- src/General/Main.coffee | 13 +++++++++++-- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index b66b530f7..9d441d65d 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -12597,11 +12597,12 @@ break; } try { - return localStorage.getItem('4chan-settings'); + localStorage.getItem('4chan-settings'); } catch (_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) { var err, errors, post, postRoot, posts, thread, _i, _len, _ref; @@ -12783,8 +12784,12 @@ if (view === 'catalog') { return; } - e.preventDefault(); - history.pushState(null, '', this.pathname); + if (e) { + e.preventDefault(); + } + if (this.id !== 'popState') { + history.pushState(null, '', this.pathname); + } view = threadID ? 'thread' : view || 'index'; if (view === g.VIEW) { if (view === 'index') { @@ -12818,6 +12823,14 @@ } return Header.setBoardList(); }, + popstate: function() { + var a; + a = $.el('a', { + href: window.location, + id: 'popState' + }); + return Main.navigate.call(a); + }, updateBoard: function(boardID) { var onload, req; g.BOARD = new Board(boardID); diff --git a/builds/crx/script.js b/builds/crx/script.js index c2a9a092b..de7fb944f 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -12571,11 +12571,12 @@ Main.initThread(threadRoot); } try { - return localStorage.getItem('4chan-settings'); + localStorage.getItem('4chan-settings'); } catch (_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) { var err, errors, post, postRoot, posts, thread, _i, _len, _ref; @@ -12757,8 +12758,12 @@ if (view === 'catalog') { return; } - e.preventDefault(); - history.pushState(null, '', this.pathname); + if (e) { + e.preventDefault(); + } + if (this.id !== 'popState') { + history.pushState(null, '', this.pathname); + } view = threadID ? 'thread' : view || 'index'; if (view === g.VIEW) { if (view === 'index') { @@ -12792,6 +12797,14 @@ } return Header.setBoardList(); }, + popstate: function() { + var a; + a = $.el('a', { + href: window.location, + id: 'popState' + }); + return Main.navigate.call(a); + }, updateBoard: function(boardID) { var onload, req; g.BOARD = new Board(boardID); diff --git a/src/General/Main.coffee b/src/General/Main.coffee index eb1094a1d..cb54cfaf8 100755 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -144,6 +144,8 @@ Main = catch err new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30 + $.on window, 'popstate', Main.popstate + initThread: (threadRoot) -> thread = new Thread +threadRoot.id[1..], g.BOARD posts = [] @@ -358,8 +360,8 @@ Main = return if view is 'catalog' - e.preventDefault() - history.pushState null, '', @pathname + e.preventDefault() if e + history.pushState null, '', @pathname unless @id is 'popState' view = if threadID 'thread' @@ -390,6 +392,13 @@ Main = Header.setBoardList() + popstate: -> + a = $.el 'a', + href: window.location + id: 'popState' + + Main.navigate.call a + updateBoard: (boardID) -> g.BOARD = new Board boardID