4 var ToolTip = (function () {
9 milliSecs = 500, // time to wait before displaying tooltip
14 threshold = 10, // number of pixels that mouse can move before tip is dismissed
19 my.booksModel = undefined;
24 // Set the book ID for the details pane, and then show it
25 my.displayDetails = function (newBookId) {
30 // Hide the details pane, if it is currently visible
31 my.hideDetails = function () {
32 mousePos.x = undefined;
33 mousePos.y = undefined;
35 var elem = document.getElementById('details');
37 elem.style.display = 'none';
40 my.mouseMoved = function (x, y) {
41 // Is there an active tooltip?
42 if (typeof mousePos.x === 'undefined') {
43 // No active tooltip, so nothing further to do
47 var deltaX = Math.abs(x - mousePos.x);
48 var deltaY = Math.abs(y - mousePos.y);
50 if ( (deltaX > threshold)
51 || (deltaY > threshold) )
53 my.stopTooltipTimer();
58 // Show the details pane
59 my.showDetails = function () {
61 var elem = document.getElementById('details');
62 var index = BooksModel.map[id];
63 var book = BooksModel.cache[index];
64 var html = '<div><p><b>' + book.Title + '</b></p>'
65 + '<p><i>' + ce(book.AuthorReading) + '<br/>' + ce(book.Series) + ' ' + ce(book.Volume) + '</i></p></div><div>'
66 + ce(book.Description)
69 // Remember the current mouse (x,y).
70 // If we move the mouse too far from this point, that will trigger hiding the tooltip.
71 mousePos.x = g_state.mousePos.x;
72 mousePos.y = g_state.mousePos.y;
74 elem.innerHTML = html;
76 elem.style.display = 'block'; // show, and calculate size, so that we can query it below
81 var bcr = elem.getBoundingClientRect();
83 var width = bcr.width;
84 var height = bcr.height;
86 x = Math.max(x - (width / 2), 0);
87 y = Math.max(y - (height / 2), 0);
89 elem.style.left = x + 'px';
90 elem.style.top = y + 'px';
93 my.startTooltipTimer = function (newBookId) {
94 if (typeof timer !== 'undefined') {
98 timer = setTimeout(my.showDetails, milliSecs);
101 my.stopTooltipTimer = function () {
102 if (typeof timer === 'undefined') {
113 // ce(s): "clear if empty()"
114 // return s, unless it's undefined, in which case return an empty ("clear") string
116 if (typeof s !== 'undefined') {