Merge branch 'v3'

Conflicts:
	builds/appchan-x.user.js
	builds/crx/script.js
	src/General/Header.coffee
This commit is contained in:
Zixaphir 2014-01-13 19:36:02 -07:00
commit 750ac760bb
6 changed files with 61 additions and 50 deletions

View File

@ -135,6 +135,7 @@
Config = { Config = {
main: { main: {
'Miscellaneous': { 'Miscellaneous': {
'JSON Navigation': [true, 'Use JSON for loading the Board Index and Threads. Also allows searching and sorting the board index and infinite scolling.'],
'Catalog Links': [true, 'Add toggle link in header menu to turn Navigation links into links to each board\'s catalog.'], 'Catalog Links': [true, 'Add toggle link in header menu to turn Navigation links into links to each board\'s catalog.'],
'External Catalog': [false, 'Link to external catalog instead of the internal one.'], 'External Catalog': [false, 'Link to external catalog instead of the internal one.'],
'Announcement Hiding': [true, 'Add button to hide 4chan announcements.'], 'Announcement Hiding': [true, 'Add button to hide 4chan announcements.'],
@ -4119,6 +4120,8 @@
var a, footer, _i, _len, _ref, _results; var a, footer, _i, _len, _ref, _results;
if (a = $("a[href*='/" + g.BOARD + "/']", footer = $.id('boardNavDesktopFoot'))) { if (a = $("a[href*='/" + g.BOARD + "/']", footer = $.id('boardNavDesktopFoot'))) {
a.className = 'current'; a.className = 'current';
}
if (Conf['JSON Navigation']) {
_ref = $$('a', footer); _ref = $$('a', footer);
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@ -4161,7 +4164,9 @@
_ref = $$('a', boardList); _ref = $$('a', boardList);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
a = _ref[_i]; a = _ref[_i];
$.on(a, 'click', Navigate.navigate); if (Conf['JSON Navigation']) {
$.on(a, 'click', Navigate.navigate);
}
if (a.pathname.split('/')[1] === g.BOARD.ID) { if (a.pathname.split('/')[1] === g.BOARD.ID) {
a.className = 'current'; a.className = 'current';
} }
@ -4217,7 +4222,9 @@
a = as[_i]; a = as[_i];
if (a.textContent === board) { if (a.textContent === board) {
a = a.cloneNode(true); a = a.cloneNode(true);
$.on(a, 'click', Navigate.navigate); if (Conf['JSON Navigation']) {
$.on(a, 'click', Navigate.navigate);
}
a.textContent = /-title/.test(t) || /-replace/.test(t) && $.hasClass(a, 'current') ? a.title : /-full/.test(t) ? "/" + board + "/ - " + a.title : (m = t.match(/-text:"(.+)"/)) ? m[1] : a.textContent; a.textContent = /-title/.test(t) || /-replace/.test(t) && $.hasClass(a, 'current') ? a.title : /-full/.test(t) ? "/" + board + "/ - " + a.title : (m = t.match(/-text:"(.+)"/)) ? m[1] : a.textContent;
if (m = t.match(/-(index|catalog)/)) { if (m = t.match(/-(index|catalog)/)) {
a.dataset.only = m[1]; a.dataset.only = m[1];
@ -4445,7 +4452,7 @@
Index = { Index = {
init: function() { init: function() {
var anchorEntry, input, label, modeEntry, name, refNavEntry, repliesEntry, sortEntry, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2; var anchorEntry, input, label, modeEntry, name, refNavEntry, repliesEntry, sortEntry, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
if (g.BOARD.ID === 'f' || g.VIEW === 'catalog') { if (g.BOARD.ID === 'f' || g.VIEW === 'catalog' || !Conf['JSON Navigation']) {
return; return;
} }
this.button = $.el('a', { this.button = $.el('a', {
@ -4619,18 +4626,20 @@
if (Index.req || Conf['Index Mode'] !== 'infinite' || (doc.scrollTop <= doc.scrollHeight - (300 + window.innerHeight)) || g.VIEW === 'thread') { if (Index.req || Conf['Index Mode'] !== 'infinite' || (doc.scrollTop <= doc.scrollHeight - (300 + window.innerHeight)) || g.VIEW === 'thread') {
return; return;
} }
pageNum = Index.getCurrentPage() + 1; if (Index.pageNum == null) {
Index.pageNum = Index.getCurrentPage();
}
pageNum = Index.pageNum++;
if (pageNum >= Index.pagesNum) { if (pageNum >= Index.pagesNum) {
return Index.endNotice(); return Index.endNotice();
} }
nodesPerPage = Index.threadsNumPerPage * 2; nodesPerPage = Index.threadsNumPerPage * 2;
history.pushState(null, '', "/" + g.BOARD + "/" + pageNum);
nodes = Index.sortedNodes.slice(nodesPerPage * pageNum, nodesPerPage * (pageNum + 1)); nodes = Index.sortedNodes.slice(nodesPerPage * pageNum, nodesPerPage * (pageNum + 1));
if (Conf['Show Replies']) { if (Conf['Show Replies']) {
Index.buildReplies(nodes); Index.buildReplies(nodes);
} }
$.add(Index.root, nodes); $.add(Index.root, nodes);
return Index.setPage(); return Index.setPage(pageNum);
}), }),
endNotice: (function() { endNotice: (function() {
var notify, reset; var notify, reset;
@ -4675,14 +4684,6 @@
} }
e.preventDefault(); e.preventDefault();
return Index.userPageNav(+a.pathname.split('/')[2]); return Index.userPageNav(+a.pathname.split('/')[2]);
},
link: function(e) {
if (g.VIEW !== 'index' || /catalog/.test(this.href)) {
return;
}
e.preventDefault();
history.pushState(null, '', this.pathname);
return Index.update();
} }
}, },
scrollToIndex: function() { scrollToIndex: function() {
@ -4745,9 +4746,9 @@
} }
return Index.togglePagelist(); return Index.togglePagelist();
}, },
setPage: function() { setPage: function(pageNum) {
var a, href, maxPageNum, next, pageNum, pagesRoot, prev, strong; var a, href, maxPageNum, next, pagesRoot, prev, strong;
pageNum = Index.getCurrentPage(); pageNum || (pageNum = Index.getCurrentPage());
maxPageNum = Index.getMaxPageNum(); maxPageNum = Index.getMaxPageNum();
pagesRoot = $('.pages', Index.pagelist); pagesRoot = $('.pages', Index.pagelist);
prev = pagesRoot.previousSibling.firstChild; prev = pagesRoot.previousSibling.firstChild;
@ -4784,6 +4785,7 @@
if (!(d.readyState === 'loading' || Index.root.parentElement)) { if (!(d.readyState === 'loading' || Index.root.parentElement)) {
$.replace($('.board'), Index.root); $.replace($('.board'), Index.root);
} }
delete Index.pageNum;
if ((_ref = Index.req) != null) { if ((_ref = Index.req) != null) {
_ref.abort(); _ref.abort();
} }
@ -15614,7 +15616,7 @@
Navigate = { Navigate = {
path: window.location.pathname, path: window.location.pathname,
init: function() { init: function() {
if (g.VIEW === 'catalog' || g.BOARD.ID === 'f') { if (g.VIEW === 'catalog' || g.BOARD.ID === 'f' || !Conf['JSON Navigation']) {
return; return;
} }
$.ready(function() { $.ready(function() {
@ -15833,6 +15835,7 @@
if (e) { if (e) {
e.preventDefault(); e.preventDefault();
} }
delete Index.pageNum;
path = this.pathname; path = this.pathname;
if (this.hash) { if (this.hash) {
path += this.hash; path += this.hash;

View File

@ -113,6 +113,7 @@
Config = { Config = {
main: { main: {
'Miscellaneous': { 'Miscellaneous': {
'JSON Navigation': [true, 'Use JSON for loading the Board Index and Threads. Also allows searching and sorting the board index and infinite scolling.'],
'Catalog Links': [true, 'Add toggle link in header menu to turn Navigation links into links to each board\'s catalog.'], 'Catalog Links': [true, 'Add toggle link in header menu to turn Navigation links into links to each board\'s catalog.'],
'External Catalog': [false, 'Link to external catalog instead of the internal one.'], 'External Catalog': [false, 'Link to external catalog instead of the internal one.'],
'Announcement Hiding': [true, 'Add button to hide 4chan announcements.'], 'Announcement Hiding': [true, 'Add button to hide 4chan announcements.'],
@ -4129,6 +4130,8 @@
var a, footer, _i, _len, _ref, _results; var a, footer, _i, _len, _ref, _results;
if (a = $("a[href*='/" + g.BOARD + "/']", footer = $.id('boardNavDesktopFoot'))) { if (a = $("a[href*='/" + g.BOARD + "/']", footer = $.id('boardNavDesktopFoot'))) {
a.className = 'current'; a.className = 'current';
}
if (Conf['JSON Navigation']) {
_ref = $$('a', footer); _ref = $$('a', footer);
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@ -4171,7 +4174,9 @@
_ref = $$('a', boardList); _ref = $$('a', boardList);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
a = _ref[_i]; a = _ref[_i];
$.on(a, 'click', Navigate.navigate); if (Conf['JSON Navigation']) {
$.on(a, 'click', Navigate.navigate);
}
if (a.pathname.split('/')[1] === g.BOARD.ID) { if (a.pathname.split('/')[1] === g.BOARD.ID) {
a.className = 'current'; a.className = 'current';
} }
@ -4227,7 +4232,9 @@
a = as[_i]; a = as[_i];
if (a.textContent === board) { if (a.textContent === board) {
a = a.cloneNode(true); a = a.cloneNode(true);
$.on(a, 'click', Navigate.navigate); if (Conf['JSON Navigation']) {
$.on(a, 'click', Navigate.navigate);
}
a.textContent = /-title/.test(t) || /-replace/.test(t) && $.hasClass(a, 'current') ? a.title : /-full/.test(t) ? "/" + board + "/ - " + a.title : (m = t.match(/-text:"(.+)"/)) ? m[1] : a.textContent; a.textContent = /-title/.test(t) || /-replace/.test(t) && $.hasClass(a, 'current') ? a.title : /-full/.test(t) ? "/" + board + "/ - " + a.title : (m = t.match(/-text:"(.+)"/)) ? m[1] : a.textContent;
if (m = t.match(/-(index|catalog)/)) { if (m = t.match(/-(index|catalog)/)) {
a.dataset.only = m[1]; a.dataset.only = m[1];
@ -4455,7 +4462,7 @@
Index = { Index = {
init: function() { init: function() {
var anchorEntry, input, label, modeEntry, name, refNavEntry, repliesEntry, sortEntry, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2; var anchorEntry, input, label, modeEntry, name, refNavEntry, repliesEntry, sortEntry, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
if (g.BOARD.ID === 'f' || g.VIEW === 'catalog') { if (g.BOARD.ID === 'f' || g.VIEW === 'catalog' || !Conf['JSON Navigation']) {
return; return;
} }
this.button = $.el('a', { this.button = $.el('a', {
@ -4629,18 +4636,20 @@
if (Index.req || Conf['Index Mode'] !== 'infinite' || (doc.scrollTop <= doc.scrollHeight - (300 + window.innerHeight)) || g.VIEW === 'thread') { if (Index.req || Conf['Index Mode'] !== 'infinite' || (doc.scrollTop <= doc.scrollHeight - (300 + window.innerHeight)) || g.VIEW === 'thread') {
return; return;
} }
pageNum = Index.getCurrentPage() + 1; if (Index.pageNum == null) {
Index.pageNum = Index.getCurrentPage();
}
pageNum = Index.pageNum++;
if (pageNum >= Index.pagesNum) { if (pageNum >= Index.pagesNum) {
return Index.endNotice(); return Index.endNotice();
} }
nodesPerPage = Index.threadsNumPerPage * 2; nodesPerPage = Index.threadsNumPerPage * 2;
history.pushState(null, '', "/" + g.BOARD + "/" + pageNum);
nodes = Index.sortedNodes.slice(nodesPerPage * pageNum, nodesPerPage * (pageNum + 1)); nodes = Index.sortedNodes.slice(nodesPerPage * pageNum, nodesPerPage * (pageNum + 1));
if (Conf['Show Replies']) { if (Conf['Show Replies']) {
Index.buildReplies(nodes); Index.buildReplies(nodes);
} }
$.add(Index.root, nodes); $.add(Index.root, nodes);
return Index.setPage(); return Index.setPage(pageNum);
}), }),
endNotice: (function() { endNotice: (function() {
var notify, reset; var notify, reset;
@ -4685,14 +4694,6 @@
} }
e.preventDefault(); e.preventDefault();
return Index.userPageNav(+a.pathname.split('/')[2]); return Index.userPageNav(+a.pathname.split('/')[2]);
},
link: function(e) {
if (g.VIEW !== 'index' || /catalog/.test(this.href)) {
return;
}
e.preventDefault();
history.pushState(null, '', this.pathname);
return Index.update();
} }
}, },
scrollToIndex: function() { scrollToIndex: function() {
@ -4755,9 +4756,9 @@
} }
return Index.togglePagelist(); return Index.togglePagelist();
}, },
setPage: function() { setPage: function(pageNum) {
var a, href, maxPageNum, next, pageNum, pagesRoot, prev, strong; var a, href, maxPageNum, next, pagesRoot, prev, strong;
pageNum = Index.getCurrentPage(); pageNum || (pageNum = Index.getCurrentPage());
maxPageNum = Index.getMaxPageNum(); maxPageNum = Index.getMaxPageNum();
pagesRoot = $('.pages', Index.pagelist); pagesRoot = $('.pages', Index.pagelist);
prev = pagesRoot.previousSibling.firstChild; prev = pagesRoot.previousSibling.firstChild;
@ -4794,6 +4795,7 @@
if (!(d.readyState === 'loading' || Index.root.parentElement)) { if (!(d.readyState === 'loading' || Index.root.parentElement)) {
$.replace($('.board'), Index.root); $.replace($('.board'), Index.root);
} }
delete Index.pageNum;
if ((_ref = Index.req) != null) { if ((_ref = Index.req) != null) {
_ref.abort(); _ref.abort();
} }
@ -15609,7 +15611,7 @@
Navigate = { Navigate = {
path: window.location.pathname, path: window.location.pathname,
init: function() { init: function() {
if (g.VIEW === 'catalog' || g.BOARD.ID === 'f') { if (g.VIEW === 'catalog' || g.BOARD.ID === 'f' || !Conf['JSON Navigation']) {
return; return;
} }
$.ready(function() { $.ready(function() {
@ -15828,6 +15830,7 @@
if (e) { if (e) {
e.preventDefault(); e.preventDefault();
} }
delete Index.pageNum;
path = this.pathname; path = this.pathname;
if (this.hash) { if (this.hash) {
path += this.hash; path += this.hash;

View File

@ -1,6 +1,10 @@
Config = Config =
main: main:
'Miscellaneous': 'Miscellaneous':
'JSON Navigation' : [
true
'Use JSON for loading the Board Index and Threads. Also allows searching and sorting the board index and infinite scolling.'
]
'Catalog Links': [ 'Catalog Links': [
true true
'Add toggle link in header menu to turn Navigation links into links to each board\'s catalog.' 'Add toggle link in header menu to turn Navigation links into links to each board\'s catalog.'

View File

@ -83,6 +83,7 @@ Header =
$.ready => $.ready =>
if a = $ "a[href*='/#{g.BOARD}/']", footer = $.id 'boardNavDesktopFoot' if a = $ "a[href*='/#{g.BOARD}/']", footer = $.id 'boardNavDesktopFoot'
a.className = 'current' a.className = 'current'
if Conf['JSON Navigation']
$.on a, 'click', Navigate.navigate for a in $$ 'a', footer $.on a, 'click', Navigate.navigate for a in $$ 'a', footer
bar: $.el 'div', bar: $.el 'div',
@ -113,7 +114,8 @@ Header =
id: 'board-list' id: 'board-list'
innerHTML: "<span id=custom-board-list></span><span id=full-board-list hidden><span class='hide-board-list-container brackets-wrap'><a href=javascript:; class='hide-board-list-button'>&nbsp;-&nbsp;</a></span> #{fourchannav.innerHTML}</span>" innerHTML: "<span id=custom-board-list></span><span id=full-board-list hidden><span class='hide-board-list-container brackets-wrap'><a href=javascript:; class='hide-board-list-button'>&nbsp;-&nbsp;</a></span> #{fourchannav.innerHTML}</span>"
for a in $$ 'a', boardList for a in $$ 'a', boardList
$.on a, 'click', Navigate.navigate if Conf['JSON Navigation']
$.on a, 'click', Navigate.navigate
if a.pathname.split('/')[1] is g.BOARD.ID if a.pathname.split('/')[1] is g.BOARD.ID
a.className = 'current' a.className = 'current'
fullBoardList = $ '#full-board-list', boardList fullBoardList = $ '#full-board-list', boardList
@ -167,7 +169,8 @@ Header =
if a.textContent is board if a.textContent is board
a = a.cloneNode true a = a.cloneNode true
$.on a, 'click', Navigate.navigate if Conf['JSON Navigation']
$.on a, 'click', Navigate.navigate
a.textContent = if /-title/.test(t) or /-replace/.test(t) and $.hasClass a, 'current' a.textContent = if /-title/.test(t) or /-replace/.test(t) and $.hasClass a, 'current'
a.title a.title

View File

@ -1,6 +1,6 @@
Index = Index =
init: -> init: ->
return if g.BOARD.ID is 'f' or g.VIEW is 'catalog' return if g.BOARD.ID is 'f' or g.VIEW is 'catalog' or !Conf['JSON Navigation']
@button = $.el 'a', @button = $.el 'a',
className: 'index-refresh-shortcut fa' className: 'index-refresh-shortcut fa'
@ -112,14 +112,14 @@ Index =
scroll: $.debounce 100, -> scroll: $.debounce 100, ->
return if Index.req or Conf['Index Mode'] isnt 'infinite' or (doc.scrollTop <= doc.scrollHeight - (300 + window.innerHeight)) or g.VIEW is 'thread' return if Index.req or Conf['Index Mode'] isnt 'infinite' or (doc.scrollTop <= doc.scrollHeight - (300 + window.innerHeight)) or g.VIEW is 'thread'
pageNum = Index.getCurrentPage() + 1 Index.pageNum = Index.getCurrentPage() unless Index.pageNum? # Avoid having to pushState to keep track of the current page
pageNum = Index.pageNum++
return Index.endNotice() if pageNum >= Index.pagesNum return Index.endNotice() if pageNum >= Index.pagesNum
nodesPerPage = Index.threadsNumPerPage * 2 nodesPerPage = Index.threadsNumPerPage * 2
history.pushState null, '', "/#{g.BOARD}/#{pageNum}"
nodes = Index.sortedNodes[nodesPerPage * pageNum ... nodesPerPage * (pageNum + 1)] nodes = Index.sortedNodes[nodesPerPage * pageNum ... nodesPerPage * (pageNum + 1)]
Index.buildReplies nodes if Conf['Show Replies'] Index.buildReplies nodes if Conf['Show Replies']
$.add Index.root, nodes $.add Index.root, nodes
Index.setPage() Index.setPage pageNum
endNotice: do -> endNotice: do ->
notify = false notify = false
@ -148,11 +148,6 @@ Index =
return if a.textContent is 'Catalog' return if a.textContent is 'Catalog'
e.preventDefault() e.preventDefault()
Index.userPageNav +a.pathname.split('/')[2] Index.userPageNav +a.pathname.split('/')[2]
link: (e) ->
return if g.VIEW isnt 'index' or /catalog/.test @href
e.preventDefault()
history.pushState null, '', @pathname
Index.update()
scrollToIndex: -> scrollToIndex: ->
Header.scrollToIfNeeded Index.root Header.scrollToIfNeeded Index.root
@ -197,8 +192,8 @@ Index =
$.rmAll pagesRoot $.rmAll pagesRoot
$.add pagesRoot, nodes $.add pagesRoot, nodes
Index.togglePagelist() Index.togglePagelist()
setPage: -> setPage: (pageNum) ->
pageNum = Index.getCurrentPage() pageNum or= Index.getCurrentPage()
maxPageNum = Index.getMaxPageNum() maxPageNum = Index.getMaxPageNum()
pagesRoot = $ '.pages', Index.pagelist pagesRoot = $ '.pages', Index.pagelist
# Previous/Next buttons # Previous/Next buttons
@ -227,6 +222,7 @@ Index =
return return
unless d.readyState is 'loading' or Index.root.parentElement unless d.readyState is 'loading' or Index.root.parentElement
$.replace $('.board'), Index.root $.replace $('.board'), Index.root
delete Index.pageNum
Index.req?.abort() Index.req?.abort()
Index.notice?.close() Index.notice?.close()

View File

@ -1,7 +1,7 @@
Navigate = Navigate =
path: window.location.pathname path: window.location.pathname
init: -> init: ->
return if g.VIEW is 'catalog' or g.BOARD.ID is 'f' return if g.VIEW is 'catalog' or g.BOARD.ID is 'f' or !Conf['JSON Navigation']
# blink/webkit throw a popstate on page load. Not what we want. # blink/webkit throw a popstate on page load. Not what we want.
$.ready -> $.on window, 'popstate', Navigate.popstate $.ready -> $.on window, 'popstate', Navigate.popstate
@ -174,6 +174,8 @@ Navigate =
return if view is 'catalog' or 'f' in [boardID, g.BOARD.ID] return if view is 'catalog' or 'f' in [boardID, g.BOARD.ID]
e.preventDefault() if e e.preventDefault() if e
delete Index.pageNum
path = @pathname path = @pathname
path += @hash if @hash path += @hash if @hash