Skip to content

Instantly share code, notes, and snippets.

@kovchiy
Created July 9, 2017 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kovchiy/d5090a2f44260b240fe316bef30457b2 to your computer and use it in GitHub Desktop.
Save kovchiy/d5090a2f44260b240fe316bef30457b2 to your computer and use it in GitHub Desktop.
/**
* @block Tooltip Всплывающая подсказка
* @dep Control
* @tag control
* @ext control
*/
Beast.decl({
Tooltip: {
inherits: 'Control',
mod: {
Theme: 'default',
State: 'release',
},
param: {
target: '',
},
expand: function () {
this.append(
<tail/>,
<label>{this.text()}</label>
)
},
domInit: function () {
if (this.param('target')) {
this.param('target').onDomInit(function () {
requestAnimationFrame(function () {
this.updatePosition()
this.mod('State', 'active')
}.bind(this))
}.bind(this))
}
},
onWin: {
resize: function () {
this.updatePosition()
}
},
on: {
Release: function () {
this.remove()
}
},
bindTo: function (target) {
var root = target
while (root.parentNode()) {
root = root.parentNode()
}
this.param('target', target)
.appendTo(root)
return this
},
updatePosition: function () {
var offsetParent = this.param('target').domNode()
var left = offsetParent.offsetLeft
var top = offsetParent.offsetTop
var height = offsetParent.offsetHeight
while (offsetParent = offsetParent.offsetParent) {
left += offsetParent.offsetLeft
top += offsetParent.offsetTop
}
this.css({
left: left - 2,
top: top + height - 4
})
}
},
Tooltip__label: {
inherits: 'Typo',
mod: {
text:'S',
medium:true
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment