Skip to content

Commit

Permalink
Only allow one tooltip to be open at a time.
Browse files Browse the repository at this point in the history
  • Loading branch information
KirkMcDonald committed Aug 15, 2020
1 parent 5c24fcc commit 46ed5e4
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ See the License for the specific language governing permissions and
limitations under the License.*/
"use strict"

var currentTooltip = null

function Tooltip(reference, content, target) {
if (!target) {
target = reference
Expand All @@ -31,6 +33,9 @@ Tooltip.prototype = {
if (this.isOpen) {
return
}
if (currentTooltip) {
currentTooltip.hide()
}
this.isOpen = true
if (this.node) {
this.node.style.display = ""
Expand All @@ -55,13 +60,15 @@ Tooltip.prototype = {
}
)
this.node = node
currentTooltip = this
},
hide: function() {
if (!this.isOpen) {
return
}
this.isOpen = false
this.node.style.display = "none"
currentTooltip = null
},
create: function() {
var node = document.createElement("div")
Expand Down

0 comments on commit 46ed5e4

Please sign in to comment.