From 2e242a9f9d6ca8b8d41196d8ff29e80f8f41fab0 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sat, 11 Jan 2014 19:52:49 -0700 Subject: [PATCH 1/4] Holy, how tired was I when I did that? Damn. --- builds/4chan-X.user.js | 6 ++---- builds/crx/script.js | 6 ++---- src/General/Navigate.coffee | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 91e08a981..e1f891e25 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -11898,10 +11898,8 @@ if (g.VIEW === 'catalog' || g.BOARD.ID === 'f') { return; } - ({ - ready: function() { - return $.on(window, 'popstate', Navigate.popstate); - } + $.ready(function() { + return $.on(window, 'popstate', Navigate.popstate); }); Thread.callbacks.push({ name: 'Navigate', diff --git a/builds/crx/script.js b/builds/crx/script.js index 70499ee45..5ce34b6a2 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -11887,10 +11887,8 @@ if (g.VIEW === 'catalog' || g.BOARD.ID === 'f') { return; } - ({ - ready: function() { - return $.on(window, 'popstate', Navigate.popstate); - } + $.ready(function() { + return $.on(window, 'popstate', Navigate.popstate); }); Thread.callbacks.push({ name: 'Navigate', diff --git a/src/General/Navigate.coffee b/src/General/Navigate.coffee index 02a1c60fe..6b47aea2a 100644 --- a/src/General/Navigate.coffee +++ b/src/General/Navigate.coffee @@ -3,7 +3,7 @@ Navigate = return if g.VIEW is 'catalog' or g.BOARD.ID is 'f' # blink/webkit throw a popstate on page load. Not what we want. - ready: -> + $.ready -> $.on window, 'popstate', Navigate.popstate Thread.callbacks.push From ab3a4c66405b9e470366b1d5299ea82df24a7a60 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sat, 11 Jan 2014 20:21:25 -0700 Subject: [PATCH 2/4] Get hash navigation working with Navigate.navigate() --- builds/4chan-X.user.js | 35 +++++++++++++++++++++++++++-------- builds/crx/script.js | 35 +++++++++++++++++++++++++++-------- src/General/Navigate.coffee | 23 +++++++++++++++++------ 3 files changed, 71 insertions(+), 22 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index e1f891e25..d1ccb5d12 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -11894,6 +11894,7 @@ }; Navigate = { + path: window.location.pathname, init: function() { if (g.VIEW === 'catalog' || g.BOARD.ID === 'f') { return; @@ -11919,12 +11920,22 @@ return $.on(replyLink, 'click', Navigate.navigate); }, post: function() { - var postLink; + var hashlink, postlink, _i, _len, _ref, _results; if (g.VIEW === 'thread' && this.thread.ID === g.THREADID) { return; } - postLink = $('a[title="Highlight this post"]', this.nodes.info); - return $.on(postLink, 'click', Navigate.navigate); + postlink = $('a[title="Highlight this post"]', this.nodes.info); + $.on(postlink, 'click', Navigate.navigate); + if (!Conf['Quote Hash Navigation']) { + return; + } + _ref = $$('.hashlink', this.nodes.comment); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + hashlink = _ref[_i]; + _results.push($.on(hashlink, 'click', Navigate.navigate)); + } + return _results; }, clean: function() { var posts, threads; @@ -12094,13 +12105,12 @@ return $('.boardTitle').textContent = d.title = "/" + board + "/ - " + title; }, navigate: function(e) { - var boardID, hash, onload, pageNum, path, threadID, view; + var boardID, onload, pageNum, path, threadID, view; if (this.hostname !== 'boards.4chan.org' || window.location.hostname === 'rs.4chan.org' || (e && (e.shiftKey || (e.type === 'click' && e.button !== 0)))) { return; } $.addClass(Index.button, 'fa-spin'); path = this.pathname.split('/'); - hash = this.hash; if (path[0] === '') { path.shift(); } @@ -12108,12 +12118,17 @@ if (view === 'catalog' || ('f' === boardID || 'f' === g.BOARD.ID)) { return; } + path = this.pathname; + if (this.hash) { + path += this.hash; + } if (e) { e.preventDefault(); } if (this.id !== 'popState') { - history.pushState(null, '', this.pathname); + history.pushState(null, '', path); } + Navigate.path = this.pathname; if (threadID) { view = 'thread'; } else { @@ -12139,7 +12154,7 @@ } } else { onload = function(e) { - return Navigate.load(e, hash); + return Navigate.load(e); }; Navigate.req = $.ajax("//a.4cdn.org/" + boardID + "/res/" + threadID + ".json", { onabort: onload, @@ -12217,7 +12232,8 @@ Main.callbackNodes(Thread, [thread]); Main.callbackNodes(Post, posts); Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading']); - return Navigate.buildThread(); + Navigate.buildThread(); + return Header.hashScroll.call(window); }, buildThread: function() { var board; @@ -12232,6 +12248,9 @@ }, popstate: function() { var a; + if (window.location.pathname === Navigate.path) { + return; + } a = $.el('a', { href: window.location, id: 'popState' diff --git a/builds/crx/script.js b/builds/crx/script.js index 5ce34b6a2..f014ef368 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -11883,6 +11883,7 @@ }; Navigate = { + path: window.location.pathname, init: function() { if (g.VIEW === 'catalog' || g.BOARD.ID === 'f') { return; @@ -11908,12 +11909,22 @@ return $.on(replyLink, 'click', Navigate.navigate); }, post: function() { - var postLink; + var hashlink, postlink, _i, _len, _ref, _results; if (g.VIEW === 'thread' && this.thread.ID === g.THREADID) { return; } - postLink = $('a[title="Highlight this post"]', this.nodes.info); - return $.on(postLink, 'click', Navigate.navigate); + postlink = $('a[title="Highlight this post"]', this.nodes.info); + $.on(postlink, 'click', Navigate.navigate); + if (!Conf['Quote Hash Navigation']) { + return; + } + _ref = $$('.hashlink', this.nodes.comment); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + hashlink = _ref[_i]; + _results.push($.on(hashlink, 'click', Navigate.navigate)); + } + return _results; }, clean: function() { var posts, threads; @@ -12083,13 +12094,12 @@ return $('.boardTitle').textContent = d.title = "/" + board + "/ - " + title; }, navigate: function(e) { - var boardID, hash, onload, pageNum, path, threadID, view; + var boardID, onload, pageNum, path, threadID, view; if (this.hostname !== 'boards.4chan.org' || window.location.hostname === 'rs.4chan.org' || (e && (e.shiftKey || (e.type === 'click' && e.button !== 0)))) { return; } $.addClass(Index.button, 'fa-spin'); path = this.pathname.split('/'); - hash = this.hash; if (path[0] === '') { path.shift(); } @@ -12097,12 +12107,17 @@ if (view === 'catalog' || ('f' === boardID || 'f' === g.BOARD.ID)) { return; } + path = this.pathname; + if (this.hash) { + path += this.hash; + } if (e) { e.preventDefault(); } if (this.id !== 'popState') { - history.pushState(null, '', this.pathname); + history.pushState(null, '', path); } + Navigate.path = this.pathname; if (threadID) { view = 'thread'; } else { @@ -12128,7 +12143,7 @@ } } else { onload = function(e) { - return Navigate.load(e, hash); + return Navigate.load(e); }; Navigate.req = $.ajax("//a.4cdn.org/" + boardID + "/res/" + threadID + ".json", { onabort: onload, @@ -12206,7 +12221,8 @@ Main.callbackNodes(Thread, [thread]); Main.callbackNodes(Post, posts); Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading']); - return Navigate.buildThread(); + Navigate.buildThread(); + return Header.hashScroll.call(window); }, buildThread: function() { var board; @@ -12221,6 +12237,9 @@ }, popstate: function() { var a; + if (window.location.pathname === Navigate.path) { + return; + } a = $.el('a', { href: window.location, id: 'popState' diff --git a/src/General/Navigate.coffee b/src/General/Navigate.coffee index 6b47aea2a..8e30ae722 100644 --- a/src/General/Navigate.coffee +++ b/src/General/Navigate.coffee @@ -1,4 +1,5 @@ Navigate = + path: window.location.pathname init: -> return if g.VIEW is 'catalog' or g.BOARD.ID is 'f' @@ -22,8 +23,13 @@ Navigate = post: -> # We don't need to reload the thread inside the thread return if g.VIEW is 'thread' and @thread.ID is g.THREADID - postLink = $ 'a[title="Highlight this post"]', @nodes.info - $.on postLink, 'click', Navigate.navigate + postlink = $ 'a[title="Highlight this post"]', @nodes.info + $.on postlink, 'click', Navigate.navigate + + return unless Conf['Quote Hash Navigation'] + + for hashlink in $$ '.hashlink', @nodes.comment + $.on hashlink, 'click', Navigate.navigate clean: -> {posts, threads} = g @@ -176,14 +182,17 @@ Navigate = $.addClass Index.button, 'fa-spin' path = @pathname.split '/' - hash = @hash path.shift() if path[0] is '' [boardID, view, threadID] = path return if view is 'catalog' or 'f' in [boardID, g.BOARD.ID] + path = @pathname + path += @hash if @hash + e.preventDefault() if e - history.pushState null, '', @pathname unless @id is 'popState' + history.pushState null, '', path unless @id is 'popState' + Navigate.path = @pathname if threadID view = 'thread' @@ -210,7 +219,7 @@ Navigate = # Moving from index to thread or thread to thread else - onload = (e) -> Navigate.load e, hash + onload = (e) -> Navigate.load e Navigate.req = $.ajax "//a.4cdn.org/#{boardID}/res/#{threadID}.json", onabort: onload onloadend: onload @@ -279,6 +288,7 @@ Navigate = Navigate.ready 'Quote Threading', QuoteThreading.force, Conf['Quote Threading'] Navigate.buildThread() + Header.hashScroll.call window buildThread: -> board = $ '.board' @@ -290,7 +300,8 @@ Navigate = Unread.read() Unread.update() - popstate: -> + popstate: -> + return if window.location.pathname is Navigate.path a = $.el 'a', href: window.location id: 'popState' From 79776710af9fec4aea715a24e5c2982a42aba83b Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sat, 11 Jan 2014 20:22:45 -0700 Subject: [PATCH 3/4] return --- builds/4chan-X.user.js | 6 ++---- builds/crx/script.js | 6 ++---- src/General/Navigate.coffee | 8 +++++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index d1ccb5d12..c85bbf0c2 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -11920,7 +11920,7 @@ return $.on(replyLink, 'click', Navigate.navigate); }, post: function() { - var hashlink, postlink, _i, _len, _ref, _results; + var hashlink, postlink, _i, _len, _ref; if (g.VIEW === 'thread' && this.thread.ID === g.THREADID) { return; } @@ -11930,12 +11930,10 @@ return; } _ref = $$('.hashlink', this.nodes.comment); - _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { hashlink = _ref[_i]; - _results.push($.on(hashlink, 'click', Navigate.navigate)); + $.on(hashlink, 'click', Navigate.navigate); } - return _results; }, clean: function() { var posts, threads; diff --git a/builds/crx/script.js b/builds/crx/script.js index f014ef368..73f2c3e30 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -11909,7 +11909,7 @@ return $.on(replyLink, 'click', Navigate.navigate); }, post: function() { - var hashlink, postlink, _i, _len, _ref, _results; + var hashlink, postlink, _i, _len, _ref; if (g.VIEW === 'thread' && this.thread.ID === g.THREADID) { return; } @@ -11919,12 +11919,10 @@ return; } _ref = $$('.hashlink', this.nodes.comment); - _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { hashlink = _ref[_i]; - _results.push($.on(hashlink, 'click', Navigate.navigate)); + $.on(hashlink, 'click', Navigate.navigate); } - return _results; }, clean: function() { var posts, threads; diff --git a/src/General/Navigate.coffee b/src/General/Navigate.coffee index 8e30ae722..16c8bda60 100644 --- a/src/General/Navigate.coffee +++ b/src/General/Navigate.coffee @@ -2,7 +2,7 @@ Navigate = path: window.location.pathname init: -> return if g.VIEW is 'catalog' or g.BOARD.ID is 'f' - + # blink/webkit throw a popstate on page load. Not what we want. $.ready -> $.on window, 'popstate', Navigate.popstate @@ -31,6 +31,8 @@ Navigate = for hashlink in $$ '.hashlink', @nodes.comment $.on hashlink, 'click', Navigate.navigate + return + clean: -> {posts, threads} = g @@ -133,7 +135,7 @@ Navigate = error: err ] return false - + return unless board Navigate.updateTitle board @@ -147,7 +149,7 @@ Navigate = ['ws', 'Yotsuba B New'] else ['nws', 'Yotsuba New'] - + $.globalEval "var style_group = '#{style[1]}'" mainStyleSheet = $ 'link[title=switch]', d.head From 43bcc6468198890f4bc5cad1c4dcc322158a91d2 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sat, 11 Jan 2014 21:02:56 -0700 Subject: [PATCH 4/4] Let Index.update handle its own page functions --- builds/4chan-X.user.js | 6 +----- builds/crx/script.js | 6 +----- src/General/Navigate.coffee | 5 +---- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index c85bbf0c2..292826a6d 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -12145,11 +12145,7 @@ } else { Navigate.updateBoard(boardID); } - if (Conf['Index Mode'] === 'paged' && pageNum) { - return Index.update(pageNum); - } else { - return Index.update(); - } + return Index.update(pageNum); } else { onload = function(e) { return Navigate.load(e); diff --git a/builds/crx/script.js b/builds/crx/script.js index 73f2c3e30..cd066205c 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -12134,11 +12134,7 @@ } else { Navigate.updateBoard(boardID); } - if (Conf['Index Mode'] === 'paged' && pageNum) { - return Index.update(pageNum); - } else { - return Index.update(); - } + return Index.update(pageNum); } else { onload = function(e) { return Navigate.load(e); diff --git a/src/General/Navigate.coffee b/src/General/Navigate.coffee index 16c8bda60..b284b4973 100644 --- a/src/General/Navigate.coffee +++ b/src/General/Navigate.coffee @@ -214,10 +214,7 @@ Navigate = else Navigate.updateBoard boardID - if Conf['Index Mode'] is 'paged' and pageNum - Index.update pageNum - else - Index.update() + Index.update pageNum # Moving from index to thread or thread to thread else