5f253bcc1e9fe486362d1106232d40030dee82a5
[quanweb.git] / js / Main.js
1 // QuanLib:  eBook Library
2 // Copyright (C) 2017 by Christian Jaekl (cejaekl@yahoo.com)
3
4 'use strict';
5
6 // Global state information (yuck).  TODO:  refactor this to compartmentalize.
7 var g_state = {
8     mousePos: {    // Last known position of the mouse cursor
9         x: undefined,
10         y: undefined
11     }
12 };
13
14 // ==============
15 // Initialization
16
17 document.onmousemove = onMouseMove;
18
19 BooksView.init(BooksModel);
20 PagingController.init(BooksModel);
21 SearchController.init(BooksModel);
22
23 if (Modernizr.fetch) {
24     console.log('quanweb:  browser feature check:  OK');
25 }
26 else {
27     // If we cared about supporting older browsers (at this point, IE11 and Adroid 4.x's built-in browser,
28     // neither of which is due to receive security patch support for much longer), then we would insert a 
29     // shim here to implement the fetch API.  But, in this case, we don't and won't.
30     alert('Sorry, this page will not work in your browser.\nPlease use a recent version of Chrome, Edge or Firefox instead.');
31 }
32
33 // ================
34 // Global functions
35 // 
36 // TODO:  refactor this to compartmentalize more functionality.
37
38 function report(message) {
39     document.getElementById('books').innerHTML = message;
40 }
41
42 function onMouseMove(event) {
43     if (typeof event === 'undefined') {
44         return;
45     }
46     
47     var x = event.pageX;
48     var y = event.pageY;
49     
50     if (  x === g_state.mousePos.x
51        && y === g_state.mousePos.y)
52     {
53         // No change from previous known position. 
54         // Nothing to see (or do) here, move along.
55         return;
56     }
57     
58     // Remember current mouse (x,y) position
59     g_state.mousePos.x = x;
60     g_state.mousePos.y = y;
61
62     ToolTip.mouseMoved(x, y);
63 }
64
65 function onNext() {
66     if (BooksModel.last < (BooksModel.count - 1)) {
67         PagingController.adjustPos(BooksModel.first + BooksModel.pageSize);
68     }
69 }
70
71 function onPrev() {
72     if (BooksModel.first > 0) {
73         PagingController.adjustPos(BooksModel.first - BooksModel.pageSize);
74     }
75 }
76
77 function onSlide(value) {
78     PagingController.adjustPos(value);
79 }
80
81 function onSearch() {
82     SearchController.onSearch();
83 }
84