-//QuanLib: eBook Library
-//(C) 2017 by Christian Jaekl (cejaekl@yahoo.com)
+// QuanLib: eBook Library
+// Copyright (C) 2017 by Christian Jaekl (cejaekl@yahoo.com)
'use strict';
// ==============
// Initialization
-document.onmousemove = onMouseMove;
+Browser.setOnMouseMove(onMouseMove);
BooksView.init(BooksModel);
PagingController.init(BooksModel);
+SearchController.init(BooksModel);
+
+if (Modernizr.promises) {
+ console.log('quanweb: browser feature check: OK');
+}
+else {
+ // If we cared about supporting older browsers (at this point, IE11 and Adroid 4.x's built-in browser,
+ // neither of which is due to receive security patch support for much longer), then we would insert a
+ // shim here to implement promises. But, in this case, we don't and won't.
+ alert('Sorry, this page will not work in your browser.\nPlease use a recent version of Chrome, Edge, Firefox or Safari instead.');
+}
// ================
// Global functions
// TODO: refactor this to compartmentalize more functionality.
function report(message) {
- document.getElementById('books').innerHTML = message;
-}
-
-function constructSearchUrl() {
- var url = window.location.protocol + '//' + window.location.host + '/search/';
-
- var firstTime = true;
- var terms = ['aut', 'tit', 'ser'];
-
- for (var idx in terms) {
- var term = terms[idx];
- var elem = document.getElementById(term);
- if (null === elem) {
- console.log('Error: could not find form element for search term "' + term + '".');
- continue;
- }
-
- var value = elem.value;
- if (value.length > 0) {
- if (firstTime) {
- url += '?';
- firstTime = false;
- }
- else {
- url += '&';
- }
- url += term + '=' + encodeURIComponent('%' + value + '%');
- }
- }
-
- return url;
+ Browser.getElementById('books').innerHTML = message;
}
function onMouseMove(event) {
}
function onSearch() {
- var url = constructSearchUrl();
-
- fetch(url, {method:'GET', cache:'default'})
- .then(response => response.json())
- .then((jsonValue) => {
- // console.log('JSON response: ', jsonValue);
- BooksModel.ids = jsonValue;
- BooksModel.count = BooksModel.ids.length;
- BooksModel.first = (-1);
-
- var elem = document.getElementById('slider');
- elem.max = BooksModel.count;
-
- PagingController.adjustPos(0);
- })
- .catch(err => {
- var msg = 'Error fetching JSON from URL: ' + url + ': ' + err + ':' + err.stack;
- console.log(msg);
- report(msg);
- });
+ SearchController.onSearch();
}