Get hash navigation working with Navigate.navigate()

This commit is contained in:
Zixaphir 2014-01-11 20:21:25 -07:00
parent 2e242a9f9d
commit ab3a4c6640
3 changed files with 71 additions and 22 deletions

View File

@ -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'

View File

@ -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'

View File

@ -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'