forked from scala/scala-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTooltip.scala
40 lines (36 loc) · 1 KB
/
Tooltip.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package org.scalalang
import org.querki.jquery._
import org.scalajs.dom.Element
import scala.scalajs.js
/**
* This renders tooltips for any .masterTooltip class element
*/
object Tooltip {
def apply(): Unit = {
$(".masterTooltip")
.hover(
(tooltip: Element) => {
// make sure we have a title
$(tooltip).attr("title").toOption.foreach((title: String) => {
// create our tooltip and place it on the body
$("<p class=\"tooltip\"></p>")
.text(title)
.appendTo("body")
.fadeIn("slow")
})
},
() => {
// remove our tooltip when we mouse off
$(".tooltip").remove()
}
)
.mousemove((e: JQueryEventObject) => {
val mouseX: Int = e.pageX + 20 //Get X coordinates
val mouseY: Int = e.pageY + 10 //Get Y coordinates
$(".tooltip").css(js.Dictionary[js.Any](
"left" -> mouseX,
"top" -> mouseY
))
})
}
}