Browse Source

Add JS catalog navigation.

pull/9/head
Ned Zimmerman 7 years ago
parent
commit
be069ba272
No known key found for this signature in database
GPG Key ID: FF56334A013120CA
  1. 3
      package.json
  2. 3
      resources/assets/scripts/main.js
  3. 1
      resources/assets/scripts/routes/common.js
  4. 31
      resources/assets/scripts/routes/home.js
  5. 10
      resources/views/partials/front-page-catalog.blade.php
  6. 88
      yarn.lock

3
package.json

@ -128,6 +128,7 @@
}, },
"dependencies": { "dependencies": {
"jquery": "1.12.4 - 3", "jquery": "1.12.4 - 3",
"tachyons-sass": "~4.7" "tachyons-sass": "~4.7",
"wpapi": "^1.1.2"
} }
} }

3
resources/assets/scripts/main.js

@ -1,9 +1,6 @@
// import external dependencies // import external dependencies
import 'jquery'; import 'jquery';
// Import everything from autoload
import "./autoload/**/*"
// import local dependencies // import local dependencies
import Router from './util/Router'; import Router from './util/Router';
import common from './routes/common'; import common from './routes/common';

1
resources/assets/scripts/routes/common.js

@ -1,6 +1,7 @@
export default { export default {
init() { init() {
// JavaScript to be fired on all pages // JavaScript to be fired on all pages
$('body').removeClass('no-js').addClass('js');
$('.toggle-menu').click((event) => { $('.toggle-menu').click((event) => {
event.preventDefault(); event.preventDefault();
$(event.currentTarget).toggleClass('is-active'); $(event.currentTarget).toggleClass('is-active');

31
resources/assets/scripts/routes/home.js

@ -1,6 +1,37 @@
const WPAPI = require( 'wpapi' );
export default { export default {
init() { init() {
// JavaScript to be fired on the home page // JavaScript to be fired on the home page
let pb = new WPAPI({ endpoint: 'http://pressbooks.dev/wp-json' });
pb.books = pb.registerRoute( 'pressbooks/v2', '/books/' );
const total = parseInt($('.navigation').attr('data-total'));
$('.latest-books .navigation .next, .latest-books .navigation .previous').live('click', (event) => {
event.preventDefault();
const page = parseInt($(event.currentTarget).attr('data-page'));
pb.books().perPage(3).page(page).then(function(data) {
let books = '', nav = '';
data.forEach((book) => {
books = books + `<div class="book">
<a class="subject" href="">Fiction</a>
<a class="title" href="${book.link}">${book.metadata.name}</a>
<a class="read-more" href="${book.link}">About this book &rarr;</a>
</div>`;
});
$('.books').html(books);
if (page > 1 && page < total) {
nav = nav + `<a class="previous f1" data-page="${page - 1}" href="/page/${page - 1}/">&larr;</a>
<a class="next f1" data-page="${page + 1}" href="/page/${page + 1}/">&rarr;</a>`;
} else if (page > 1 && page === total) {
nav = nav + `<a class="previous f1" data-page="${page - 1}" href="/page/${page - 1}/">&larr;</a>`;
} else {
nav = nav + `<a class="next f1" data-page="${page + 1}" href="/page/${page + 1}/">&rarr;</a>`;
}
$('.latest-books .navigation').html(nav);
}).catch(function(err) {
console.error(err); // eslint-disable-line
});
});
}, },
finalize() { finalize() {
// JavaScript to be fired on the home page, after the init JS // JavaScript to be fired on the home page, after the init JS

10
resources/views/partials/front-page-catalog.blade.php

@ -4,19 +4,19 @@
<div class="books"> <div class="books">
@foreach( FrontPage::latestBooks( $current_page ) as $book ) @foreach( FrontPage::latestBooks( $current_page ) as $book )
<div class="book"> <div class="book">
<a class="subject" href="">TK</a> <a class="subject" href="">Fiction</a>
<a class="title" href="{{ $book['link'] }}">{{ $book['metadata']['name'] }}</a> <a class="title" href="{{ $book['link'] }}">{{ $book['metadata']['name'] }}</a>
<a class="read-more" href="{{ $book['link'] }}">{{ __('About this book &rarr;', 'aldine') }}</a> <a class="read-more" href="{{ $book['link'] }}">{{ __('About this book &rarr;', 'aldine') }}</a>
</div> </div>
@endforeach @endforeach
</div> </div>
<div class="navigation mt2"> <nav class="navigation mt2" data-total="{{ $total_pages }}">
@if($previous_page) @if($previous_page)
<a class="previous f1" href="{{ network_home_url("/page/$previous_page/") }}">&larr;</a> <a class="previous f1" data-page="{{ $previous_page }}" href="{{ network_home_url("/page/$previous_page/") }}">&larr;</a>
@endif @endif
@if($next_page) @if($next_page)
<a class="next f1" href="{{ network_home_url("/page/$next_page/") }}">&rarr;</a> <a class="next f1" data-page="{{ $next_page }}" href="{{ network_home_url("/page/$next_page/") }}">&rarr;</a>
@endif @endif
</div> </nav>
</div> </div>
</div> </div>

88
yarn.lock

@ -980,7 +980,7 @@ component-emitter@1.1.2:
version "1.1.2" version "1.1.2"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.1.2.tgz#296594f2753daa63996d2af08d15a95116c9aec3" resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.1.2.tgz#296594f2753daa63996d2af08d15a95116c9aec3"
component-emitter@1.2.1: component-emitter@1.2.1, component-emitter@^1.2.0:
version "1.2.1" version "1.2.1"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6" resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6"
@ -1055,6 +1055,10 @@ cookie@0.3.1:
version "0.3.1" version "0.3.1"
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb" resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb"
cookiejar@^2.1.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/cookiejar/-/cookiejar-2.1.1.tgz#41ad57b1b555951ec171412a81942b1e8200d34a"
copy-globs-webpack-plugin@^0.2.0: copy-globs-webpack-plugin@^0.2.0:
version "0.2.0" version "0.2.0"
resolved "https://registry.yarnpkg.com/copy-globs-webpack-plugin/-/copy-globs-webpack-plugin-0.2.0.tgz#f946cd0ec2e0d366baa1e66a6062f261c2cc87a9" resolved "https://registry.yarnpkg.com/copy-globs-webpack-plugin/-/copy-globs-webpack-plugin-0.2.0.tgz#f946cd0ec2e0d366baa1e66a6062f261c2cc87a9"
@ -1800,6 +1804,10 @@ es6-map@^0.1.3:
es6-symbol "~3.1.1" es6-symbol "~3.1.1"
event-emitter "~0.3.5" event-emitter "~0.3.5"
es6-promise@^3.2.1:
version "3.3.1"
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-3.3.1.tgz#a08cdde84ccdbf34d027a1451bc91d4bcd28a613"
es6-set@~0.1.5: es6-set@~0.1.5:
version "0.1.5" version "0.1.5"
resolved "https://registry.yarnpkg.com/es6-set/-/es6-set-0.1.5.tgz#d2b3ec5d4d800ced818db538d28974db0a73ccb1" resolved "https://registry.yarnpkg.com/es6-set/-/es6-set-0.1.5.tgz#d2b3ec5d4d800ced818db538d28974db0a73ccb1"
@ -2244,10 +2252,6 @@ flatten@^1.0.2:
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782" resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782"
font-awesome@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/font-awesome/-/font-awesome-4.7.0.tgz#8fa8cf0411a1a31afd07b06d2902bb9fc815a133"
for-in@^0.1.3: for-in@^0.1.3:
version "0.1.8" version "0.1.8"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-0.1.8.tgz#d8773908e31256109952b1fdb9b3fa867d2775e1" resolved "https://registry.yarnpkg.com/for-in/-/for-in-0.1.8.tgz#d8773908e31256109952b1fdb9b3fa867d2775e1"
@ -2272,6 +2276,14 @@ forever-agent@~0.6.1:
version "0.6.1" version "0.6.1"
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
form-data@^2.1.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.1.tgz#6fb94fbd71885306d73d15cc497fe4cc4ecd44bf"
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.5"
mime-types "^2.1.12"
form-data@~2.1.1: form-data@~2.1.1:
version "2.1.4" version "2.1.4"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.1.4.tgz#33c183acf193276ecaa98143a69e94bfee1750d1" resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.1.4.tgz#33c183acf193276ecaa98143a69e94bfee1750d1"
@ -2284,6 +2296,10 @@ formidable@1.0.x:
version "1.0.17" version "1.0.17"
resolved "https://registry.yarnpkg.com/formidable/-/formidable-1.0.17.tgz#ef5491490f9433b705faa77249c99029ae348559" resolved "https://registry.yarnpkg.com/formidable/-/formidable-1.0.17.tgz#ef5491490f9433b705faa77249c99029ae348559"
formidable@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/formidable/-/formidable-1.1.1.tgz#96b8886f7c3c3508b932d6bd70c4d3a88f35f1a9"
fresh@0.5.0: fresh@0.5.0:
version "0.5.0" version "0.5.0"
resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.0.tgz#f474ca5e6a9246d6fd8e0953cfa9b9c805afa78e" resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.0.tgz#f474ca5e6a9246d6fd8e0953cfa9b9c805afa78e"
@ -3167,6 +3183,10 @@ is-zip@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/is-zip/-/is-zip-1.0.0.tgz#47b0a8ff4d38a76431ccfd99a8e15a4c86ba2325" resolved "https://registry.yarnpkg.com/is-zip/-/is-zip-1.0.0.tgz#47b0a8ff4d38a76431ccfd99a8e15a4c86ba2325"
is@^3.1.0:
version "3.2.1"
resolved "https://registry.yarnpkg.com/is/-/is-3.2.1.tgz#d0ac2ad55eb7b0bec926a5266f6c662aaa83dca5"
isarray@0.0.1: isarray@0.0.1:
version "0.0.1" version "0.0.1"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf"
@ -3382,6 +3402,10 @@ levn@^0.3.0, levn@~0.3.0:
prelude-ls "~1.1.2" prelude-ls "~1.1.2"
type-check "~0.3.2" type-check "~0.3.2"
li@^1.0.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/li/-/li-1.2.1.tgz#37bd3d8d6f4ad520fa5e3c118106591093c2fb2b"
limiter@^1.0.5: limiter@^1.0.5:
version "1.1.2" version "1.1.2"
resolved "https://registry.yarnpkg.com/limiter/-/limiter-1.1.2.tgz#229d8055891c8b11af9e0ee5200e8e09bb3dcbeb" resolved "https://registry.yarnpkg.com/limiter/-/limiter-1.1.2.tgz#229d8055891c8b11af9e0ee5200e8e09bb3dcbeb"
@ -3634,7 +3658,7 @@ lodash.templatesettings@^3.0.0:
lodash._reinterpolate "^3.0.0" lodash._reinterpolate "^3.0.0"
lodash.escape "^3.0.0" lodash.escape "^3.0.0"
lodash.uniq@^4.5.0: lodash.uniq@^4.3.0, lodash.uniq@^4.5.0:
version "4.5.0" version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
@ -3752,6 +3776,10 @@ merge-stream@^1.0.0:
dependencies: dependencies:
readable-stream "^2.0.1" readable-stream "^2.0.1"
methods@^1.1.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
micromatch@2.3.11, micromatch@^2.1.5, micromatch@^2.3.11, micromatch@^2.3.7: micromatch@2.3.11, micromatch@^2.1.5, micromatch@^2.3.11, micromatch@^2.3.7:
version "2.3.11" version "2.3.11"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565"
@ -3795,7 +3823,7 @@ mime@1.3.4:
version "1.3.4" version "1.3.4"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.4.tgz#115f9e3b6b3daf2959983cb38f149a2d40eb5d53" resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.4.tgz#115f9e3b6b3daf2959983cb38f149a2d40eb5d53"
mime@1.3.x, "mime@>= 0.0.1", mime@^1.3.4: mime@1.3.x, "mime@>= 0.0.1", mime@^1.3.4, mime@^1.3.6:
version "1.3.6" version "1.3.6"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.6.tgz#591d84d3653a6b0b4a3b9df8de5aa8108e72e5e0" resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.6.tgz#591d84d3653a6b0b4a3b9df8de5aa8108e72e5e0"
@ -3988,6 +4016,12 @@ node-status-codes@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/node-status-codes/-/node-status-codes-1.0.0.tgz#5ae5541d024645d32a58fcddc9ceecea7ae3ac2f" resolved "https://registry.yarnpkg.com/node-status-codes/-/node-status-codes-1.0.0.tgz#5ae5541d024645d32a58fcddc9ceecea7ae3ac2f"
node.extend@^1.1.5:
version "1.1.6"
resolved "https://registry.yarnpkg.com/node.extend/-/node.extend-1.1.6.tgz#a7b882c82d6c93a4863a5504bd5de8ec86258b96"
dependencies:
is "^3.1.0"
"nopt@2 || 3", nopt@3.0.x: "nopt@2 || 3", nopt@3.0.x:
version "3.0.6" version "3.0.6"
resolved "https://registry.yarnpkg.com/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9" resolved "https://registry.yarnpkg.com/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9"
@ -4250,6 +4284,12 @@ parse-json@^2.1.0, parse-json@^2.2.0:
dependencies: dependencies:
error-ex "^1.2.0" error-ex "^1.2.0"
parse-link-header@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/parse-link-header/-/parse-link-header-0.4.1.tgz#f6bd615dc6713fd40935ce97945e4d3f522edf14"
dependencies:
xtend "~4.0.0"
parse5@^1.4.2: parse5@^1.4.2:
version "1.5.1" version "1.5.1"
resolved "https://registry.yarnpkg.com/parse5/-/parse5-1.5.1.tgz#9b7f3b0de32be78dc2401b17573ccaf0f6f59d94" resolved "https://registry.yarnpkg.com/parse5/-/parse5-1.5.1.tgz#9b7f3b0de32be78dc2401b17573ccaf0f6f59d94"
@ -5008,7 +5048,7 @@ qs@6.2.1:
version "6.2.1" version "6.2.1"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.2.1.tgz#ce03c5ff0935bc1d9d69a9f14cbd18e568d67625" resolved "https://registry.yarnpkg.com/qs/-/qs-6.2.1.tgz#ce03c5ff0935bc1d9d69a9f14cbd18e568d67625"
"qs@>= 0.4.0": "qs@>= 0.4.0", qs@^6.2.0, qs@^6.4.0:
version "6.5.0" version "6.5.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.0.tgz#8d04954d364def3efc55b5a0793e1e2c8b1e6e49" resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.0.tgz#8d04954d364def3efc55b5a0793e1e2c8b1e6e49"
@ -5374,6 +5414,10 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
hash-base "^2.0.0" hash-base "^2.0.0"
inherits "^2.0.1" inherits "^2.0.1"
route-parser@0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/route-parser/-/route-parser-0.0.4.tgz#eb873c7cc460d1124220479ed909af312e86149c"
run-async@^2.2.0: run-async@^2.2.0:
version "2.3.0" version "2.3.0"
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0" resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0"
@ -6021,6 +6065,21 @@ sum-up@^1.0.1:
dependencies: dependencies:
chalk "^1.0.0" chalk "^1.0.0"
superagent@^3.3.1:
version "3.6.0"
resolved "https://registry.yarnpkg.com/superagent/-/superagent-3.6.0.tgz#eb679651057c3462199c7b902b696c25350e1b87"
dependencies:
component-emitter "^1.2.0"
cookiejar "^2.1.0"
debug "^2.6.0"
extend "^3.0.0"
form-data "^2.1.1"
formidable "^1.1.1"
methods "^1.1.1"
mime "^1.3.6"
qs "^6.4.0"
readable-stream "^2.0.5"
supports-color@^2.0.0: supports-color@^2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
@ -6653,6 +6712,19 @@ wordwrap@~1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
wpapi@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/wpapi/-/wpapi-1.1.2.tgz#c633651d3990a5ab63a7704b39573a1e8d4c2f1e"
dependencies:
es6-promise "^3.2.1"
li "^1.0.1"
lodash.uniq "^4.3.0"
node.extend "^1.1.5"
parse-link-header "^0.4.1"
qs "^6.2.0"
route-parser "0.0.4"
superagent "^3.3.1"
wrap-ansi@^2.0.0: wrap-ansi@^2.0.0:
version "2.1.0" version "2.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"

Loading…
Cancel
Save