Phase out vanilla catalog

This commit is contained in:
Zixaphir 2014-03-08 16:14:16 -07:00
parent e4c8bd7ee6
commit cf1a4c1cc4
6 changed files with 70 additions and 65 deletions

View File

@ -1,5 +1,5 @@
/* /*
* 4chan X - Version 1.4.1 - 2014-03-07 * 4chan X - Version 1.4.1 - 2014-03-08
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE * https://github.com/Spittie/4chan-x/blob/master/LICENSE

View File

@ -24,7 +24,7 @@
// ==/UserScript== // ==/UserScript==
/* /*
* 4chan X - Version 1.4.1 - 2014-03-07 * 4chan X - Version 1.4.1 - 2014-03-08
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE * https://github.com/Spittie/4chan-x/blob/master/LICENSE
@ -2639,6 +2639,7 @@
innerHTML: "<span class=brackets-wrap id=returnlink><a href=.././>Return</a></span> <span class=brackets-wrap id=bottomlink><a href=\"#bottom\">Bottom</a></span> <span id=\"index-menu\"><input type=\"search\" id=\"index-search\" class=\"field\" placeholder=\"Search\"><a id=\"index-search-clear\" class=\"fa fa-times-circle\" href=\"javascript:;\"></a>&nbsp;<time id=\"index-last-refresh\" title=\"Last index refresh\">...</time><span id=\"hidden-label\" hidden>&nbsp;&mdash; <span id=\"hidden-count\"></span> <span id=\"hidden-toggle\">[<a href=\"javascript:;\">Show</a>]</span></span><select id=\"index-mode\" name=\"Index Mode\"><option disabled>Index Mode</option><option value=\"paged\">Paged</option><option value=\"infinite\">Infinite Scrolling</option><option value=\"all pages\">All threads</option><option value=\"catalog\">Catalog</option></select><select id=\"index-sort\" name=\"Index Sort\"><option disabled>Index Sort</option><option value=\"bump\">Bump order</option><option value=\"lastreply\">Last reply</option><option value=\"birth\">Creation date</option><option value=\"replycount\">Reply count</option><option value=\"filecount\">File count</option></select><select id=\"index-size\" name=\"Index Size\"><option disabled>Image Size</option><option value=\"small\">Small</option><option value=\"large\">Large</option></select></span>" innerHTML: "<span class=brackets-wrap id=returnlink><a href=.././>Return</a></span> <span class=brackets-wrap id=bottomlink><a href=\"#bottom\">Bottom</a></span> <span id=\"index-menu\"><input type=\"search\" id=\"index-search\" class=\"field\" placeholder=\"Search\"><a id=\"index-search-clear\" class=\"fa fa-times-circle\" href=\"javascript:;\"></a>&nbsp;<time id=\"index-last-refresh\" title=\"Last index refresh\">...</time><span id=\"hidden-label\" hidden>&nbsp;&mdash; <span id=\"hidden-count\"></span> <span id=\"hidden-toggle\">[<a href=\"javascript:;\">Show</a>]</span></span><select id=\"index-mode\" name=\"Index Mode\"><option disabled>Index Mode</option><option value=\"paged\">Paged</option><option value=\"infinite\">Infinite Scrolling</option><option value=\"all pages\">All threads</option><option value=\"catalog\">Catalog</option></select><select id=\"index-sort\" name=\"Index Sort\"><option disabled>Index Sort</option><option value=\"bump\">Bump order</option><option value=\"lastreply\">Last reply</option><option value=\"birth\">Creation date</option><option value=\"replycount\">Reply count</option><option value=\"filecount\">File count</option></select><select id=\"index-size\" name=\"Index Size\"><option disabled>Image Size</option><option value=\"small\">Small</option><option value=\"large\">Large</option></select></span>"
}); });
this.searchInput = $('#index-search', this.navLinks); this.searchInput = $('#index-search', this.navLinks);
this.searchTest();
this.hideLabel = $('#hidden-label', this.navLinks); this.hideLabel = $('#hidden-label', this.navLinks);
this.selectMode = $('#index-mode', this.navLinks); this.selectMode = $('#index-mode', this.navLinks);
this.selectSort = $('#index-sort', this.navLinks); this.selectSort = $('#index-sort', this.navLinks);
@ -2655,12 +2656,9 @@
$.on(this.selectMode, 'change', this.cb.mode); $.on(this.selectMode, 'change', this.cb.mode);
$.on(this.selectSort, 'change', this.cb.sort); $.on(this.selectSort, 'change', this.cb.sort);
$.on(this.selectSize, 'change', this.cb.size); $.on(this.selectSize, 'change', this.cb.size);
this.searchInput = $('#index-search', this.navLinks);
this.currentPage = this.getCurrentPage(); this.currentPage = this.getCurrentPage();
$.on(d, 'scroll', Index.scroll); $.on(d, 'scroll', Index.scroll);
$.on(this.pagelist, 'click', this.cb.pageNav); $.on(this.pagelist, 'click', this.cb.pageNav);
$.on(this.searchInput, 'input', this.onSearchInput);
$.on($('#index-search-clear', this.navLinks), 'click', this.clearSearch);
$.on($('#returnlink a', this.navLinks), 'click', Navigate.navigate); $.on($('#returnlink a', this.navLinks), 'click', Navigate.navigate);
if (g.VIEW === 'index') { if (g.VIEW === 'index') {
this.update(); this.update();
@ -2844,18 +2842,22 @@
types[(i + 1) % types.length].selected = true; types[(i + 1) % types.length].selected = true;
return $.event('change', null, Index.selectSort); return $.event('change', null, Index.selectSort);
}, },
addCatalogSwitch: function() { catalogSwitch: function() {
var a; var hash;
a = $.el('a', { $.set('Index Mode', 'catalog');
href: 'javascript:;', hash = window.location.hash;
textContent: 'Switch to 4chan X\'s catalog', return window.location = './' + hash;
className: 'btn-wrap' },
}); searchTest: function() {
$.on(a, 'click', function() { var hash, match;
$.set('Index Mode', 'catalog'); if (!(hash = window.location.hash)) {
return window.location = './'; return;
}); }
return $.add($.id('info'), a); if (!(match = hash.match(/s=([\w]+)/))) {
return;
}
this.searchInput.value = match[1];
return $.on(d, '4chanXInitFinished', this.onSearchInput);
}, },
setupNavLinks: function() { setupNavLinks: function() {
var el, _i, _len, _ref; var el, _i, _len, _ref;
@ -3105,7 +3107,9 @@
} else { } else {
strong = $.el('strong'); strong = $.el('strong');
} }
a = pagesRoot.children[pageNum]; if (!(a = pagesRoot.children[pageNum])) {
return;
}
$.before(a, strong); $.before(a, strong);
return $.add(strong, a); return $.add(strong, a);
}, },
@ -12763,9 +12767,6 @@
return; return;
} }
$.addClass(Index.button, 'fa-spin'); $.addClass(Index.button, 'fa-spin');
if (Index.isSearching) {
Index.clearSearch();
}
_ref = this.pathname.split('/'), _ = _ref[0], boardID = _ref[1], view = _ref[2], threadID = _ref[3]; _ref = this.pathname.split('/'), _ = _ref[0], boardID = _ref[1], view = _ref[2], threadID = _ref[3];
if ('f' === boardID || 'f' === g.BOARD.ID) { if ('f' === boardID || 'f' === g.BOARD.ID) {
return; return;
@ -12773,6 +12774,9 @@
if (e) { if (e) {
e.preventDefault(); e.preventDefault();
} }
if (Index.isSearching) {
Index.clearSearch();
}
Navigate.title = function() {}; Navigate.title = function() {};
delete Index.pageNum; delete Index.pageNum;
$.rmAll(Header.hover); $.rmAll(Header.hover);
@ -12783,7 +12787,7 @@
view = 'index'; view = 'index';
} }
path = this.pathname; path = this.pathname;
if (this.hash) { if (this.hash && view === 'thread') {
path += this.hash; path += this.hash;
} }
if (this.id !== 'popState') { if (this.id !== 'popState') {
@ -13534,8 +13538,7 @@
} }
})(); })();
if (g.VIEW === 'catalog') { if (g.VIEW === 'catalog') {
$.ready(Index.addCatalogSwitch); return $.ready(Index.catalogSwitch);
return;
} }
if (g.VIEW === 'thread') { if (g.VIEW === 'thread') {
g.THREADID = +pathname[3]; g.THREADID = +pathname[3];

View File

@ -1,6 +1,6 @@
// Generated by CoffeeScript // Generated by CoffeeScript
/* /*
* 4chan X - Version 1.4.1 - 2014-03-07 * 4chan X - Version 1.4.1 - 2014-03-08
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE * https://github.com/Spittie/4chan-x/blob/master/LICENSE
@ -2698,6 +2698,7 @@
innerHTML: "<span class=brackets-wrap id=returnlink><a href=.././>Return</a></span> <span class=brackets-wrap id=bottomlink><a href=\"#bottom\">Bottom</a></span> <span id=\"index-menu\"><input type=\"search\" id=\"index-search\" class=\"field\" placeholder=\"Search\"><a id=\"index-search-clear\" class=\"fa fa-times-circle\" href=\"javascript:;\"></a>&nbsp;<time id=\"index-last-refresh\" title=\"Last index refresh\">...</time><span id=\"hidden-label\" hidden>&nbsp;&mdash; <span id=\"hidden-count\"></span> <span id=\"hidden-toggle\">[<a href=\"javascript:;\">Show</a>]</span></span><select id=\"index-mode\" name=\"Index Mode\"><option disabled>Index Mode</option><option value=\"paged\">Paged</option><option value=\"infinite\">Infinite Scrolling</option><option value=\"all pages\">All threads</option><option value=\"catalog\">Catalog</option></select><select id=\"index-sort\" name=\"Index Sort\"><option disabled>Index Sort</option><option value=\"bump\">Bump order</option><option value=\"lastreply\">Last reply</option><option value=\"birth\">Creation date</option><option value=\"replycount\">Reply count</option><option value=\"filecount\">File count</option></select><select id=\"index-size\" name=\"Index Size\"><option disabled>Image Size</option><option value=\"small\">Small</option><option value=\"large\">Large</option></select></span>" innerHTML: "<span class=brackets-wrap id=returnlink><a href=.././>Return</a></span> <span class=brackets-wrap id=bottomlink><a href=\"#bottom\">Bottom</a></span> <span id=\"index-menu\"><input type=\"search\" id=\"index-search\" class=\"field\" placeholder=\"Search\"><a id=\"index-search-clear\" class=\"fa fa-times-circle\" href=\"javascript:;\"></a>&nbsp;<time id=\"index-last-refresh\" title=\"Last index refresh\">...</time><span id=\"hidden-label\" hidden>&nbsp;&mdash; <span id=\"hidden-count\"></span> <span id=\"hidden-toggle\">[<a href=\"javascript:;\">Show</a>]</span></span><select id=\"index-mode\" name=\"Index Mode\"><option disabled>Index Mode</option><option value=\"paged\">Paged</option><option value=\"infinite\">Infinite Scrolling</option><option value=\"all pages\">All threads</option><option value=\"catalog\">Catalog</option></select><select id=\"index-sort\" name=\"Index Sort\"><option disabled>Index Sort</option><option value=\"bump\">Bump order</option><option value=\"lastreply\">Last reply</option><option value=\"birth\">Creation date</option><option value=\"replycount\">Reply count</option><option value=\"filecount\">File count</option></select><select id=\"index-size\" name=\"Index Size\"><option disabled>Image Size</option><option value=\"small\">Small</option><option value=\"large\">Large</option></select></span>"
}); });
this.searchInput = $('#index-search', this.navLinks); this.searchInput = $('#index-search', this.navLinks);
this.searchTest();
this.hideLabel = $('#hidden-label', this.navLinks); this.hideLabel = $('#hidden-label', this.navLinks);
this.selectMode = $('#index-mode', this.navLinks); this.selectMode = $('#index-mode', this.navLinks);
this.selectSort = $('#index-sort', this.navLinks); this.selectSort = $('#index-sort', this.navLinks);
@ -2714,12 +2715,9 @@
$.on(this.selectMode, 'change', this.cb.mode); $.on(this.selectMode, 'change', this.cb.mode);
$.on(this.selectSort, 'change', this.cb.sort); $.on(this.selectSort, 'change', this.cb.sort);
$.on(this.selectSize, 'change', this.cb.size); $.on(this.selectSize, 'change', this.cb.size);
this.searchInput = $('#index-search', this.navLinks);
this.currentPage = this.getCurrentPage(); this.currentPage = this.getCurrentPage();
$.on(d, 'scroll', Index.scroll); $.on(d, 'scroll', Index.scroll);
$.on(this.pagelist, 'click', this.cb.pageNav); $.on(this.pagelist, 'click', this.cb.pageNav);
$.on(this.searchInput, 'input', this.onSearchInput);
$.on($('#index-search-clear', this.navLinks), 'click', this.clearSearch);
$.on($('#returnlink a', this.navLinks), 'click', Navigate.navigate); $.on($('#returnlink a', this.navLinks), 'click', Navigate.navigate);
if (g.VIEW === 'index') { if (g.VIEW === 'index') {
this.update(); this.update();
@ -2903,18 +2901,22 @@
types[(i + 1) % types.length].selected = true; types[(i + 1) % types.length].selected = true;
return $.event('change', null, Index.selectSort); return $.event('change', null, Index.selectSort);
}, },
addCatalogSwitch: function() { catalogSwitch: function() {
var a; var hash;
a = $.el('a', { $.set('Index Mode', 'catalog');
href: 'javascript:;', hash = window.location.hash;
textContent: 'Switch to 4chan X\'s catalog', return window.location = './' + hash;
className: 'btn-wrap' },
}); searchTest: function() {
$.on(a, 'click', function() { var hash, match;
$.set('Index Mode', 'catalog'); if (!(hash = window.location.hash)) {
return window.location = './'; return;
}); }
return $.add($.id('info'), a); if (!(match = hash.match(/s=([\w]+)/))) {
return;
}
this.searchInput.value = match[1];
return $.on(d, '4chanXInitFinished', this.onSearchInput);
}, },
setupNavLinks: function() { setupNavLinks: function() {
var el, _i, _len, _ref; var el, _i, _len, _ref;
@ -3164,7 +3166,9 @@
} else { } else {
strong = $.el('strong'); strong = $.el('strong');
} }
a = pagesRoot.children[pageNum]; if (!(a = pagesRoot.children[pageNum])) {
return;
}
$.before(a, strong); $.before(a, strong);
return $.add(strong, a); return $.add(strong, a);
}, },
@ -12777,9 +12781,6 @@
return; return;
} }
$.addClass(Index.button, 'fa-spin'); $.addClass(Index.button, 'fa-spin');
if (Index.isSearching) {
Index.clearSearch();
}
_ref = this.pathname.split('/'), _ = _ref[0], boardID = _ref[1], view = _ref[2], threadID = _ref[3]; _ref = this.pathname.split('/'), _ = _ref[0], boardID = _ref[1], view = _ref[2], threadID = _ref[3];
if ('f' === boardID || 'f' === g.BOARD.ID) { if ('f' === boardID || 'f' === g.BOARD.ID) {
return; return;
@ -12787,6 +12788,9 @@
if (e) { if (e) {
e.preventDefault(); e.preventDefault();
} }
if (Index.isSearching) {
Index.clearSearch();
}
Navigate.title = function() {}; Navigate.title = function() {};
delete Index.pageNum; delete Index.pageNum;
$.rmAll(Header.hover); $.rmAll(Header.hover);
@ -12797,7 +12801,7 @@
view = 'index'; view = 'index';
} }
path = this.pathname; path = this.pathname;
if (this.hash) { if (this.hash && view === 'thread') {
path += this.hash; path += this.hash;
} }
if (this.id !== 'popState') { if (this.id !== 'popState') {
@ -13546,8 +13550,7 @@
} }
})(); })();
if (g.VIEW === 'catalog') { if (g.VIEW === 'catalog') {
$.ready(Index.addCatalogSwitch); return $.ready(Index.catalogSwitch);
return;
} }
if (g.VIEW === 'thread') { if (g.VIEW === 'thread') {
g.THREADID = +pathname[3]; g.THREADID = +pathname[3];

View File

@ -95,6 +95,9 @@ Index =
innerHTML: <%= importHTML('Features/Index-navlinks') %> innerHTML: <%= importHTML('Features/Index-navlinks') %>
@searchInput = $ '#index-search', @navLinks @searchInput = $ '#index-search', @navLinks
@searchTest()
@hideLabel = $ '#hidden-label', @navLinks @hideLabel = $ '#hidden-label', @navLinks
@selectMode = $ '#index-mode', @navLinks @selectMode = $ '#index-mode', @navLinks
@selectSort = $ '#index-sort', @navLinks @selectSort = $ '#index-sort', @navLinks
@ -109,14 +112,10 @@ Index =
$.on @selectSort, 'change', @cb.sort $.on @selectSort, 'change', @cb.sort
$.on @selectSize, 'change', @cb.size $.on @selectSize, 'change', @cb.size
@searchInput = $ '#index-search', @navLinks
@currentPage = @getCurrentPage() @currentPage = @getCurrentPage()
$.on d, 'scroll', Index.scroll $.on d, 'scroll', Index.scroll
$.on @pagelist, 'click', @cb.pageNav $.on @pagelist, 'click', @cb.pageNav
$.on @searchInput, 'input', @onSearchInput
$.on $('#index-search-clear', @navLinks), 'click', @clearSearch
$.on $('#returnlink a', @navLinks), 'click', Navigate.navigate $.on $('#returnlink a', @navLinks), 'click', Navigate.navigate
if g.VIEW is 'index' if g.VIEW is 'index'
@ -254,15 +253,16 @@ Index =
types[(i + 1) % types.length].selected = true types[(i + 1) % types.length].selected = true
$.event 'change', null, Index.selectSort $.event 'change', null, Index.selectSort
addCatalogSwitch: -> catalogSwitch: ->
a = $.el 'a', $.set 'Index Mode', 'catalog'
href: 'javascript:;' {hash} = window.location
textContent: 'Switch to <%= meta.name %>\'s catalog' window.location = './' + hash
className: 'btn-wrap'
$.on a, 'click', -> searchTest: ->
$.set 'Index Mode', 'catalog' return unless hash = window.location.hash
window.location = './' return unless match = hash.match /s=([\w]+)/
$.add $.id('info'), a @searchInput.value = match[1]
$.on d, '4chanXInitFinished', @onSearchInput
setupNavLinks: -> setupNavLinks: ->
for el in $$ '.navLinks.desktop > a' for el in $$ '.navLinks.desktop > a'
@ -456,7 +456,7 @@ Index =
$.replace strong, strong.firstChild $.replace strong, strong.firstChild
else else
strong = $.el 'strong' strong = $.el 'strong'
a = pagesRoot.children[pageNum] return unless a = pagesRoot.children[pageNum] # If coming in from a Navigate.navigate, this could break.
$.before a, strong $.before a, strong
$.add strong, a $.add strong, a

View File

@ -15,8 +15,7 @@ Main =
else else
'index' 'index'
if g.VIEW is 'catalog' if g.VIEW is 'catalog'
$.ready Index.addCatalogSwitch return $.ready Index.catalogSwitch
return
if g.VIEW is 'thread' if g.VIEW is 'thread'
g.THREADID = +pathname[3] g.THREADID = +pathname[3]

View File

@ -165,12 +165,12 @@ Navigate =
return return
$.addClass Index.button, 'fa-spin' $.addClass Index.button, 'fa-spin'
Index.clearSearch() if Index.isSearching
[_, boardID, view, threadID] = @pathname.split '/' [_, boardID, view, threadID] = @pathname.split '/'
return if 'f' in [boardID, g.BOARD.ID] return if 'f' in [boardID, g.BOARD.ID]
e.preventDefault() if e e.preventDefault() if e
Index.clearSearch() if Index.isSearching
Navigate.title = -> return Navigate.title = -> return
delete Index.pageNum delete Index.pageNum
@ -183,7 +183,7 @@ Navigate =
view = 'index' # path is "/boardID/". See the problem? view = 'index' # path is "/boardID/". See the problem?
path = @pathname path = @pathname
path += @hash if @hash path += @hash if @hash and view is 'thread'
history.pushState null, '', path unless @id is 'popState' history.pushState null, '', path unless @id is 'popState'
Navigate.path = @pathname Navigate.path = @pathname