From 497e554f49b71960f38934b5aed862cd51cbe82a Mon Sep 17 00:00:00 2001 From: 8n-tech <8n-tech@users.noreply.github.com> Date: Thu, 16 Apr 2015 07:02:17 +1000 Subject: [PATCH] "Load more" button and functionality. Signed-off-by: 8n-tech <8n-tech@users.noreply.github.com> --- board-search.php | 1 + boards.php | 2 ++ js/board-directory.js | 58 ++++++++++++++++++++++++++---- stylesheets/style.css | 17 +++++++-- templates/8chan/boards-search.html | 27 ++++++++------ 5 files changed, 86 insertions(+), 19 deletions(-) diff --git a/board-search.php b/board-search.php index 7e088c05..931a0d53 100644 --- a/board-search.php +++ b/board-search.php @@ -199,6 +199,7 @@ array_multisort( $boardLimit = $search['index'] ? 50 : 100; $response['omitted'] = count( $response['boards'] ) - $boardLimit; +$response['omitted'] = $response['omitted'] < 0 ? 0 : $response['omitted']; $response['boards'] = array_splice( $response['boards'], $search['page'], $boardLimit ); $response['order'] = array_keys( $response['boards'] ); diff --git a/boards.php b/boards.php index 5dd5fa97..39876d68 100644 --- a/boards.php +++ b/boards.php @@ -70,6 +70,8 @@ $tagsHTML = Element("8chan/boards-tags.html", array( $searchHTML = Element("8chan/boards-search.html", array( "config" => $config, + "boards" => $boards, + "tags" => $tags, "search" => $searchJson['search'], "boards_total" => $boards_total, diff --git a/js/board-directory.js b/js/board-directory.js index f22b686b..1b3ad830 100644 --- a/js/board-directory.js +++ b/js/board-directory.js @@ -15,6 +15,7 @@ 'board-head' : ".board-list-head", 'board-body' : ".board-list-tbody", 'board-loading' : ".board-list-loading", + 'board-omitted' : ".board-list-omitted", 'search' : "#search-form", 'search-lang' : "#search-lang-input", @@ -23,7 +24,12 @@ 'search-title' : "#search-title-input", 'search-submit' : "#search-submit", - 'tag-link' : ".tag-link" + 'tag-link' : ".tag-link", + + 'footer-page' : ".board-page-num", + 'footer-count' : ".board-page-count", + 'footer-total' : ".board-page-total", + 'footer-more' : ".board-page-loadmore" }, // HTML Templates for dynamic construction @@ -78,6 +84,8 @@ if ($search.length > 0) { // Bind form events. boardlist.$boardlist + // Load more + .on( 'click', selectors['board-omitted'], searchForms, boardlist.events.loadMore ) // Tag click .on( 'click', selectors['tag-link'], searchForms, boardlist.events.tagClick ) // Form Submission @@ -94,18 +102,19 @@ boardlist : function(data) { boardlist.build.boards(data['boards'], data['order']); boardlist.build.lastSearch(data['search']); + boardlist.build.footer(data); boardlist.build.tags(data['tags']); }, - boards : function(data, order) { + boards : function(boards, order) { // Find our head, columns, and body. var $head = $( boardlist.options.selector['board-head'], boardlist.$boardlist ), $cols = $("[data-column]", $head ), $body = $( boardlist.options.selector['board-body'], boardlist.$boardlist ); $.each( order, function( index, uri ) { - var row = data[uri]; + var row = boards[uri]; $row = $( boardlist.options.template['board-row'] ); $cols.each( function( index, col ) { @@ -114,6 +123,7 @@ $row.appendTo( $body ); } ); + }, board : function(row, col) { var $col = $(col), @@ -192,14 +202,46 @@ }; }, + footer : function(data) { + var selector = boardlist.options.selector, + $page = $( selector['footer-page'], boardlist.$boardlist ), + $count = $( selector['footer-count'], boardlist.$boardlist ), + $total = $( selector['footer-total'], boardlist.$boardlist ), + $more = $( selector['footer-more'], boardlist.$boardlist ); + + var boards = Object.keys(data['boards']).length, + omitted = data['omitted'] - data['search']['page']; + + if (omitted < 0) { + omitted = 0; + } + + var total = boards + omitted + data['search']['page']; + + //$page.text( data['search']['page'] ); + $count.text( data['search']['page'] + boards ); + $total.text( total ); + $more.toggle( omitted != 0 ); + }, + tags : function(data) { } }, events : { + loadMore : function(event) { + var parameters = $.extend( {}, boardlist.lastSearch ); + + parameters.page = $( boardlist.options.selector['board-body'], boardlist.$boardlist ).children().length; + + boardlist.submit( parameters ); + }, + searchSubmit : function(event) { event.preventDefault(); + $( boardlist.options.selector['board-body'], boardlist.$boardlist ).html(""); + boardlist.submit( { 'lang' : event.data.searchLang.val(), 'tags' : event.data.searchTag.val(), @@ -227,17 +269,19 @@ submit : function( parameters ) { var $boardlist = boardlist.$boardlist, - $boardbody = $( boardlist.options.selector['board-body'], $boardlist ), - $boardload = $( boardlist.options.selector['board-loading'], $boardlist ); + $boardload = $( boardlist.options.selector['board-loading'], $boardlist ), + $searchSubmit = $( boardlist.options.selector['search-submit'] ); - $boardbody.html(""); + $searchSubmit.prop( 'disabled', true ); $boardload.show(); - $.get( + return $.get( "/board-search.php", parameters, function(data) { + $searchSubmit.prop( 'disabled', false ); $boardload.hide(); + boardlist.build.boardlist( $.parseJSON(data) ); } ); diff --git a/stylesheets/style.css b/stylesheets/style.css index 04cba240..022cc319 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -1356,6 +1356,7 @@ div.boardlist a { table.board-list-table { display: table; margin: -2px; + margin-bottom: 10px; overflow: hidden; table-layout: fixed; } @@ -1404,14 +1405,26 @@ table.board-list-table div.board-cell { overflow: hidden; } -tfoot.board-list-loading { +tbody.board-list-loading { display: none; } -tfoot.board-list-loading .loading { +tbody.board-list-loading .loading { height: 80px; } +tbody.board-list-omitted td { + background: #98E; + border-top: 1px solid #000333; + padding: 8px; + font-size: 125%; + text-align: center; +} +tbody.board-list-omitted .board-page-loadmore { + display: none; +} + aside.search-container { + margin-bottom: 12px; } aside.search-container .box { margin-right: 12px; diff --git a/templates/8chan/boards-search.html b/templates/8chan/boards-search.html index b4d17d65..7d02cbd4 100644 --- a/templates/8chan/boards-search.html +++ b/templates/8chan/boards-search.html @@ -83,19 +83,26 @@
{{html_boards}} - {% if boards_omitted > 0 %} - -