From cf1a4c1cc440c5e63ef68389f92fedf349849992 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sat, 8 Mar 2014 16:14:16 -0700 Subject: [PATCH] Phase out vanilla catalog --- LICENSE | 2 +- builds/4chan-X.user.js | 49 ++++++++++++++++++++----------------- builds/crx/script.js | 49 ++++++++++++++++++++----------------- src/General/Index.coffee | 28 ++++++++++----------- src/General/Main.coffee | 3 +-- src/General/Navigate.coffee | 4 +-- 6 files changed, 70 insertions(+), 65 deletions(-) diff --git a/LICENSE b/LICENSE index 435306a3e..bda0ddf5a 100755 --- a/LICENSE +++ b/LICENSE @@ -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. * https://github.com/Spittie/4chan-x/blob/master/LICENSE diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 2fdd6e9ec..507debdeb 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -24,7 +24,7 @@ // ==/UserScript== /* -* 4chan X - Version 1.4.1 - 2014-03-07 +* 4chan X - Version 1.4.1 - 2014-03-08 * * Licensed under the MIT license. * https://github.com/Spittie/4chan-x/blob/master/LICENSE @@ -2639,6 +2639,7 @@ innerHTML: "Return Bottom  " }); this.searchInput = $('#index-search', this.navLinks); + this.searchTest(); this.hideLabel = $('#hidden-label', this.navLinks); this.selectMode = $('#index-mode', this.navLinks); this.selectSort = $('#index-sort', this.navLinks); @@ -2655,12 +2656,9 @@ $.on(this.selectMode, 'change', this.cb.mode); $.on(this.selectSort, 'change', this.cb.sort); $.on(this.selectSize, 'change', this.cb.size); - this.searchInput = $('#index-search', this.navLinks); this.currentPage = this.getCurrentPage(); $.on(d, 'scroll', Index.scroll); $.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); if (g.VIEW === 'index') { this.update(); @@ -2844,18 +2842,22 @@ types[(i + 1) % types.length].selected = true; return $.event('change', null, Index.selectSort); }, - addCatalogSwitch: function() { - var a; - a = $.el('a', { - href: 'javascript:;', - textContent: 'Switch to 4chan X\'s catalog', - className: 'btn-wrap' - }); - $.on(a, 'click', function() { - $.set('Index Mode', 'catalog'); - return window.location = './'; - }); - return $.add($.id('info'), a); + catalogSwitch: function() { + var hash; + $.set('Index Mode', 'catalog'); + hash = window.location.hash; + return window.location = './' + hash; + }, + searchTest: function() { + var hash, match; + if (!(hash = window.location.hash)) { + return; + } + if (!(match = hash.match(/s=([\w]+)/))) { + return; + } + this.searchInput.value = match[1]; + return $.on(d, '4chanXInitFinished', this.onSearchInput); }, setupNavLinks: function() { var el, _i, _len, _ref; @@ -3105,7 +3107,9 @@ } else { strong = $.el('strong'); } - a = pagesRoot.children[pageNum]; + if (!(a = pagesRoot.children[pageNum])) { + return; + } $.before(a, strong); return $.add(strong, a); }, @@ -12763,9 +12767,6 @@ return; } $.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]; if ('f' === boardID || 'f' === g.BOARD.ID) { return; @@ -12773,6 +12774,9 @@ if (e) { e.preventDefault(); } + if (Index.isSearching) { + Index.clearSearch(); + } Navigate.title = function() {}; delete Index.pageNum; $.rmAll(Header.hover); @@ -12783,7 +12787,7 @@ view = 'index'; } path = this.pathname; - if (this.hash) { + if (this.hash && view === 'thread') { path += this.hash; } if (this.id !== 'popState') { @@ -13534,8 +13538,7 @@ } })(); if (g.VIEW === 'catalog') { - $.ready(Index.addCatalogSwitch); - return; + return $.ready(Index.catalogSwitch); } if (g.VIEW === 'thread') { g.THREADID = +pathname[3]; diff --git a/builds/crx/script.js b/builds/crx/script.js index 4e829fb90..56cbe17c2 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // 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. * https://github.com/Spittie/4chan-x/blob/master/LICENSE @@ -2698,6 +2698,7 @@ innerHTML: "Return Bottom  " }); this.searchInput = $('#index-search', this.navLinks); + this.searchTest(); this.hideLabel = $('#hidden-label', this.navLinks); this.selectMode = $('#index-mode', this.navLinks); this.selectSort = $('#index-sort', this.navLinks); @@ -2714,12 +2715,9 @@ $.on(this.selectMode, 'change', this.cb.mode); $.on(this.selectSort, 'change', this.cb.sort); $.on(this.selectSize, 'change', this.cb.size); - this.searchInput = $('#index-search', this.navLinks); this.currentPage = this.getCurrentPage(); $.on(d, 'scroll', Index.scroll); $.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); if (g.VIEW === 'index') { this.update(); @@ -2903,18 +2901,22 @@ types[(i + 1) % types.length].selected = true; return $.event('change', null, Index.selectSort); }, - addCatalogSwitch: function() { - var a; - a = $.el('a', { - href: 'javascript:;', - textContent: 'Switch to 4chan X\'s catalog', - className: 'btn-wrap' - }); - $.on(a, 'click', function() { - $.set('Index Mode', 'catalog'); - return window.location = './'; - }); - return $.add($.id('info'), a); + catalogSwitch: function() { + var hash; + $.set('Index Mode', 'catalog'); + hash = window.location.hash; + return window.location = './' + hash; + }, + searchTest: function() { + var hash, match; + if (!(hash = window.location.hash)) { + return; + } + if (!(match = hash.match(/s=([\w]+)/))) { + return; + } + this.searchInput.value = match[1]; + return $.on(d, '4chanXInitFinished', this.onSearchInput); }, setupNavLinks: function() { var el, _i, _len, _ref; @@ -3164,7 +3166,9 @@ } else { strong = $.el('strong'); } - a = pagesRoot.children[pageNum]; + if (!(a = pagesRoot.children[pageNum])) { + return; + } $.before(a, strong); return $.add(strong, a); }, @@ -12777,9 +12781,6 @@ return; } $.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]; if ('f' === boardID || 'f' === g.BOARD.ID) { return; @@ -12787,6 +12788,9 @@ if (e) { e.preventDefault(); } + if (Index.isSearching) { + Index.clearSearch(); + } Navigate.title = function() {}; delete Index.pageNum; $.rmAll(Header.hover); @@ -12797,7 +12801,7 @@ view = 'index'; } path = this.pathname; - if (this.hash) { + if (this.hash && view === 'thread') { path += this.hash; } if (this.id !== 'popState') { @@ -13546,8 +13550,7 @@ } })(); if (g.VIEW === 'catalog') { - $.ready(Index.addCatalogSwitch); - return; + return $.ready(Index.catalogSwitch); } if (g.VIEW === 'thread') { g.THREADID = +pathname[3]; diff --git a/src/General/Index.coffee b/src/General/Index.coffee index bafe731dc..26e6d182e 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -95,6 +95,9 @@ Index = innerHTML: <%= importHTML('Features/Index-navlinks') %> @searchInput = $ '#index-search', @navLinks + + @searchTest() + @hideLabel = $ '#hidden-label', @navLinks @selectMode = $ '#index-mode', @navLinks @selectSort = $ '#index-sort', @navLinks @@ -109,14 +112,10 @@ Index = $.on @selectSort, 'change', @cb.sort $.on @selectSize, 'change', @cb.size - @searchInput = $ '#index-search', @navLinks - @currentPage = @getCurrentPage() $.on d, 'scroll', Index.scroll $.on @pagelist, 'click', @cb.pageNav - $.on @searchInput, 'input', @onSearchInput - $.on $('#index-search-clear', @navLinks), 'click', @clearSearch $.on $('#returnlink a', @navLinks), 'click', Navigate.navigate if g.VIEW is 'index' @@ -254,15 +253,16 @@ Index = types[(i + 1) % types.length].selected = true $.event 'change', null, Index.selectSort - addCatalogSwitch: -> - a = $.el 'a', - href: 'javascript:;' - textContent: 'Switch to <%= meta.name %>\'s catalog' - className: 'btn-wrap' - $.on a, 'click', -> - $.set 'Index Mode', 'catalog' - window.location = './' - $.add $.id('info'), a + catalogSwitch: -> + $.set 'Index Mode', 'catalog' + {hash} = window.location + window.location = './' + hash + + searchTest: -> + return unless hash = window.location.hash + return unless match = hash.match /s=([\w]+)/ + @searchInput.value = match[1] + $.on d, '4chanXInitFinished', @onSearchInput setupNavLinks: -> for el in $$ '.navLinks.desktop > a' @@ -456,7 +456,7 @@ Index = $.replace strong, strong.firstChild else 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 $.add strong, a diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 20a236d9f..fa15f5450 100755 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -15,8 +15,7 @@ Main = else 'index' if g.VIEW is 'catalog' - $.ready Index.addCatalogSwitch - return + return $.ready Index.catalogSwitch if g.VIEW is 'thread' g.THREADID = +pathname[3] diff --git a/src/General/Navigate.coffee b/src/General/Navigate.coffee index 8a1c9b022..b2ae0a094 100644 --- a/src/General/Navigate.coffee +++ b/src/General/Navigate.coffee @@ -165,12 +165,12 @@ Navigate = return $.addClass Index.button, 'fa-spin' - Index.clearSearch() if Index.isSearching [_, boardID, view, threadID] = @pathname.split '/' return if 'f' in [boardID, g.BOARD.ID] e.preventDefault() if e + Index.clearSearch() if Index.isSearching Navigate.title = -> return delete Index.pageNum @@ -183,7 +183,7 @@ Navigate = view = 'index' # path is "/boardID/". See the problem? path = @pathname - path += @hash if @hash + path += @hash if @hash and view is 'thread' history.pushState null, '', path unless @id is 'popState' Navigate.path = @pathname