parent
38567b15f5
commit
34142874e3
@ -0,0 +1,3 @@ |
||||
Template.main.onCreated(function() { |
||||
RocketChat.tooltip.init(); |
||||
}); |
@ -0,0 +1,3 @@ |
||||
RocketChat.theme.addPackageAsset(function() { |
||||
return Assets.getText('tooltip.less'); |
||||
}); |
@ -0,0 +1,24 @@ |
||||
Package.describe({ |
||||
name: 'rocketchat:tooltip', |
||||
version: '0.0.1', |
||||
summary: '', |
||||
git: '', |
||||
documentation: 'README.md' |
||||
}); |
||||
|
||||
Package.onUse(function(api) { |
||||
api.versionsFrom('1.2.1'); |
||||
api.use('ecmascript'); |
||||
api.use('templating', 'client'); |
||||
api.use('rocketchat:lib'); |
||||
api.use('rocketchat:theme'); |
||||
api.use('rocketchat:ui-master'); |
||||
|
||||
api.addAssets('tooltip.less', 'server'); |
||||
api.addFiles('loadStylesheet.js', 'server'); |
||||
|
||||
api.addFiles('rocketchat-tooltip.html', 'client'); |
||||
api.addFiles('rocketchat-tooltip.js', 'client'); |
||||
|
||||
api.addFiles('init.js', 'client'); |
||||
}); |
@ -0,0 +1,6 @@ |
||||
<template name="rocketchatTooltip"> |
||||
<div class="tooltip"> |
||||
<div class="content"> |
||||
</div> |
||||
</div> |
||||
</template> |
@ -0,0 +1,64 @@ |
||||
/* globals Blaze, RocketChat */ |
||||
RocketChat.tooltip = { |
||||
source: null, |
||||
initiated: false, |
||||
opened: false, |
||||
init() { |
||||
if (this.initiated) { |
||||
return; |
||||
} |
||||
this.initiated = true; |
||||
|
||||
Blaze.render(Template.rocketchatTooltip, document.body); |
||||
}, |
||||
showElement(source, element) { |
||||
if (this.opened) { |
||||
return; |
||||
} |
||||
|
||||
if (this.timeout) { |
||||
clearTimeout(this.timeout); |
||||
} |
||||
|
||||
this.timeout = setTimeout(() => { |
||||
this.timeout = null; |
||||
this.source = source; |
||||
|
||||
$('.tooltip').empty().append($(element).clone().show()); |
||||
|
||||
this.setPosition().addClass('show'); |
||||
|
||||
this.opened = true; |
||||
}, 300); |
||||
|
||||
}, |
||||
hide() { |
||||
if (this.timeout) { |
||||
clearTimeout(this.timeout); |
||||
} |
||||
|
||||
if (this.opened) { |
||||
$('.tooltip').removeClass('show').empty(); |
||||
this.opened = false; |
||||
} |
||||
}, |
||||
setPosition() { |
||||
let sourcePos = $(this.source).offset(); |
||||
|
||||
let sourceWidth = $(this.source).outerWidth(); |
||||
|
||||
let top = sourcePos.top - $('.tooltip').outerHeight() - 5; |
||||
let left = sourcePos.left; |
||||
|
||||
left = left + (sourceWidth / 2) - ($('.tooltip').outerWidth() / 2); |
||||
|
||||
if (left < 0) { |
||||
left = 0; |
||||
} |
||||
return $('.tooltip') |
||||
.css({ |
||||
top: top + 'px', |
||||
left: left + 'px' |
||||
}); |
||||
}, |
||||
}; |
@ -0,0 +1,31 @@ |
||||
.tooltip { |
||||
position: absolute; |
||||
visibility: hidden; |
||||
background: black; |
||||
border-radius: 5px; |
||||
z-index: 300; |
||||
color: white; |
||||
padding: 4px; |
||||
font-size: 0.8rem; |
||||
opacity: 0; |
||||
|
||||
.transition(opacity 0.3s ease); |
||||
|
||||
&.show { |
||||
visibility: visible; |
||||
opacity: 0.9; |
||||
} |
||||
|
||||
&:after { |
||||
content: ''; |
||||
position: absolute; |
||||
top: 100%; |
||||
left: 50%; |
||||
margin-left: -5px; |
||||
width: 0; |
||||
height: 0; |
||||
border-top: 5px solid #000000; |
||||
border-right: 5px solid transparent; |
||||
border-left: 5px solid transparent; |
||||
} |
||||
} |
Loading…
Reference in new issue