Refactor search into its own controller.
[quanweb.git] / js / Main.js
1 //QuanLib:  eBook Library
2 //(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 // ================
24 // Global functions
25 // 
26 // TODO:  refactor this to compartmentalize more functionality.
27
28 function report(message) {
29     document.getElementById('books').innerHTML = message;
30 }
31
32 function onMouseMove(event) {
33     if (typeof event === 'undefined') {
34         return;
35     }
36     
37     var x = event.pageX;
38     var y = event.pageY;
39     
40     if (  x === g_state.mousePos.x
41        && y === g_state.mousePos.y)
42     {
43         // No change from previous known position. 
44         // Nothing to see (or do) here, move along.
45         return;
46     }
47     
48     // Remember current mouse (x,y) position
49     g_state.mousePos.x = x;
50     g_state.mousePos.y = y;
51
52     ToolTip.mouseMoved(x, y);
53 }
54
55 function onNext() {
56     if (BooksModel.last < (BooksModel.count - 1)) {
57         PagingController.adjustPos(BooksModel.first + BooksModel.pageSize);
58     }
59 }
60
61 function onPrev() {
62     if (BooksModel.first > 0) {
63         PagingController.adjustPos(BooksModel.first - BooksModel.pageSize);
64     }
65 }
66
67 function onSlide(value) {
68     PagingController.adjustPos(value);
69 }
70
71 function onSearch() {
72     SearchController.onSearch();
73 }
74