OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 |
| 6 /** |
| 7 * A function-object for displaying a tooltip. |
| 8 * usage: |
| 9 * |
| 10 * hover("hi there!"); |
| 11 * hover.set(100,250); |
| 12 * hover.stop(); |
| 13 */ |
| 14 var hover = (function () { |
| 15 "use strict"; |
| 16 |
| 17 // Make a div to hold our tooltip. |
| 18 // There will only be one globally, so we can close over |
| 19 // a single one. |
| 20 var hoverElement = document.createElement('div'); |
| 21 document.querySelector('body').appendChild(hoverElement); |
| 22 |
| 23 // The visible style is what we will see when the hover is applied. |
| 24 var visibleStyle = "position:absolute; display: block; padding:10px; " + |
| 25 "border: 1px solid black; background: white; " + |
| 26 "padding-top: 3px; padding-bottom: 3px;"; |
| 27 |
| 28 // Set the text for the tooltip |
| 29 var hover = function (text) { |
| 30 hoverElement.setAttribute('style', visibleStyle); |
| 31 removeChildren(hoverElement); |
| 32 hoverElement.appendChild(document.createTextNode(text)); |
| 33 }; |
| 34 |
| 35 // Make the tooltip disapear |
| 36 hover.stop = function () { |
| 37 hoverElement.setAttribute('style', "display:none;"); |
| 38 }; |
| 39 |
| 40 // Set the position of the tooltip |
| 41 hover.set = function (x, y) { |
| 42 x += 15; |
| 43 y -= 20; |
| 44 hoverElement.setAttribute('style', visibleStyle + |
| 45 " left: " + x + "px; top: " + y + ";"); |
| 46 }; |
| 47 |
| 48 return hover; |
| 49 }()); |
OLD | NEW |