Add board-mode and board-sort to custom board navigation.

This commit is contained in:
Mayhem 2014-02-14 21:43:44 +01:00
parent 9eda01601c
commit fe5f19d705
6 changed files with 83 additions and 37 deletions

View File

@ -1,5 +1,7 @@
- Added `Image Size` setting for the catalog.
- Added `Open threads in a new tab` setting for the catalog.
- Added `board-mode:"type"` and `board-sort:"type"` parameters to custom board navigation.
- Added OP name/date tooltip in the catalog.
- Added a keybind to cycle through index sort types, `Ctrl+x` by default.
- Added keybindings for index modes, `Ctrl+{1,2,3}` by default.

View File

@ -497,7 +497,7 @@ a[href="javascript:;"] {
}
.thread-info {
position: fixed;
background: inherit;
background-color: inherit;
padding: 2px;
border-radius: 2px;
box-shadow: 0 0 5px rgba(0, 0, 0, .25);

View File

@ -10,5 +10,5 @@
</a>
</div>
<div class="pages cataloglink">
<a href="./">Catalog</a>
<a href="./" data-index-mode="catalog">Catalog</a>
</div>

View File

@ -8,6 +8,9 @@
<div>Board link (Replace with title when on that board): <code>board-replace</code></div>
<div>Full text link: <code>board-full</code></div>
<div>Custom text link: <code>board-text:"VIP Board"</code></div>
<div>Index mode: <code>board-mode:"type"</code> where type is <code>paged</code>, <code>all threads</code> or <code>catalog</code></div>
<div>Index sort: <code>board-sort:"type"</code> where type is <code>bump order</code>, <code>last reply</code>, <code>creation date</code>, <code>reply count</code> or <code>file count</code></div>
<div>Combinations are possible: <code>board-text:"VIP Catalog"-mode:"catalog"-sort:"creation date"</code></div>
<div>Full board list toggle: <code>toggle-all</code></div>
</fieldset>

View File

@ -112,10 +112,12 @@ Header =
list = $ '#custom-board-list', Header.bar
$.rmAll list
return unless text
as = $$ '#full-board-list a[title]', Header.bar
nodes = text.match(/[\w@]+(-(all|title|replace|full|archive|text:"[^"]+"))*|[^\w@]+/g).map (t) ->
as = $$ '.boardList a[title]', Header.bar
re = /[\w@]+(-(all|title|replace|full|archive|(mode|sort|text):"[^"]+"))*|[^\w@]+/g
nodes = text.match(re).map (t) ->
if /^[^\w@]/.test t
return $.tn t
if /^toggle-all/.test t
a = $.el 'a',
className: 'show-board-list-button'
@ -123,32 +125,47 @@ Header =
href: 'javascript:;'
$.on a, 'click', Header.toggleBoardList
return a
boardID = if /^current/.test t
g.BOARD.ID
boardID = t.split('-')[0]
boardID = g.BOARD.ID if boardID is 'current'
for a in as when a.textContent is boardID
a = a.cloneNode()
break
return $.tn boardID if a.parentNode # Not a clone.
if /-archive/.test t
if href = Redirect.to 'board', {boardID}
a.href = href
else
return a.firstChild # Its text node.
a.textContent = if /-title/.test(t) or /-replace/.test(t) and boardID is g.BOARD.ID
a.title
else if /-full/.test t
"/#{boardID}/ - #{a.title}"
else if m = t.match /-text:"([^"]+)"/
m[1]
else
t.match(/^[^-]+/)[0]
for a in as
if a.textContent is boardID
a = a.cloneNode true
boardID
a.textContent = if /-title/.test(t) or /-replace/.test(t) and $.hasClass a, 'current'
a.title
else if /-full/.test t
"/#{boardID}/ - #{a.title}"
else if m = t.match /-text:"(.+)"/
m[1]
else
a.textContent
if m = t.match /-mode:"([^"]+)"/
type = m[1].toLowerCase()
a.dataset.indexMode = switch type
when 'all threads' then 'all pages'
when 'paged', 'catalog' then type
else 'paged'
if m = t.match /-sort:"([^"]+)"/
type = m[1].toLowerCase()
a.dataset.indexSort = switch type
when 'bump order' then 'bump'
when 'last reply' then 'lastreply'
when 'creation date' then 'birth'
when 'reply count' then 'replycount'
when 'file count' then 'filecount'
else 'bump'
if /-archive/.test t
if href = Redirect.to 'board', {boardID}
a.href = href
else
return $.tn a.textContent
$.addClass a, 'navSmall' if boardID is '@'
return a
$.tn t
$.addClass a, 'navSmall' if boardID is '@'
a
$.add list, nodes
toggleBoardList: ->

View File

@ -95,6 +95,7 @@ Index =
@currentPage = @getCurrentPage()
$.on window, 'popstate', @cb.popstate
$.on @pagelist, 'click', @cb.pageNav
$.on $('#custom-board-list', Header.bar), 'click', @cb.headerNav
@cb.toggleCatalogMode()
@ -260,10 +261,10 @@ Index =
'Show'
Index.sort()
Index.buildIndex()
mode: ->
mode: (e) ->
Index.cb.toggleCatalogMode()
Index.togglePagelist()
Index.buildIndex()
Index.buildIndex() if e
mode = Conf['Index Mode']
if mode not in ['catalog', Conf['Previous Index Mode']]
Conf['Previous Index Mode'] = mode
@ -273,9 +274,9 @@ Index =
QR.hide()
else
QR.unhide()
sort: ->
sort: (e) ->
Index.sort()
Index.buildIndex()
Index.buildIndex() if e
size: (e) ->
if Conf['Index Mode'] isnt 'catalog'
$.rmClass Index.root, 'catalog-small'
@ -316,13 +317,36 @@ Index =
else
return
e.preventDefault()
if a.textContent is 'Catalog'
$.set 'Index Mode', 'catalog'
Conf['Index Mode'] = 'catalog'
Index.selectMode.value = 'catalog'
Index.cb.mode()
Index.scrollToIndex()
return if Index.cb.indexNav a, true
Index.userPageNav +a.pathname.split('/')[2]
headerNav: (e) ->
a = e.target
return if e.button isnt 0 or a.nodeName isnt 'A' or a.hostname isnt 'boards.4chan.org'
# Save settings
onSameBoard = a.pathname.split('/')[1] is g.BOARD.ID
Index.cb.indexNav a, onSameBoard
# Do nav if this isn't a simple click, or different board.
return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or !onSameBoard
e.preventDefault()
indexNav: (a, onSameBoard) ->
{indexMode, indexSort} = a.dataset
if indexMode
$.set 'Index Mode', indexMode
Conf['Index Mode'] = indexMode
if g.VIEW is 'index' and onSameBoard
Index.selectMode.value = indexMode
Index.cb.mode()
if indexSort
$.set 'Index Sort', indexSort
Conf['Index Sort'] = indexSort
if g.VIEW is 'index' and onSameBoard
Index.selectSort.value = indexSort
Index.cb.sort()
if g.VIEW is 'index' and onSameBoard and (indexMode or indexSort)
Index.buildIndex()
Index.scrollToIndex()
return true
false
scrollToIndex: ->
Header.scrollToIfNeeded Index.navLinks