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 )
57 // Show the details pane
58 my.showDetails = function () {
60 var elem = document.getElementById('details');
61 var index = BooksModel.map[id];
62 var book = BooksModel.cache[index];
63 var html = '<div><p><b>' + book.Title + '</b></p>'
64 + '<p><i>' + ce(book.AuthorReading) + '<br/>' + ce(book.Series) + ' ' + ce(book.Volume) + '</i></p></div><div>'
65 + ce(book.Description)
68 // Remember the current mouse (x,y).
69 // If we move the mouse too far from this point, that will trigger hiding the tooltip.
70 mousePos.x = g_state.mousePos.x;
71 mousePos.y = g_state.mousePos.y;
73 elem.innerHTML = html;
75 elem.style.display = 'block'; // show, and calculate size, so that we can query it below
80 var bcr = elem.getBoundingClientRect();
82 var width = bcr.width;
83 var height = bcr.height;
85 x = Math.max(x - (width / 2), 0);
86 y = Math.max(y - (height / 2), 0);
88 elem.style.left = x + 'px';
89 elem.style.top = y + 'px';
92 my.startTooltipTimer = function (newBookId) {
93 if (typeof timer !== 'undefined') {
97 timer = setTimeout(my.showDetails, milliSecs);
100 my.stopTooltipTimer = function () {
101 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') {