|
|
|
@ -1,3 +1,4 @@ |
|
|
|
|
/* global Element */ |
|
|
|
|
var yo = require('yo-yo') |
|
|
|
|
var css = require('./styles/tooltip-styles') |
|
|
|
|
var modal = require('./modal-dialog-custom') |
|
|
|
@ -24,33 +25,44 @@ class Toaster { |
|
|
|
|
} |
|
|
|
|
render (tooltipText, action, opts) { |
|
|
|
|
opts = defaultOptions(opts) |
|
|
|
|
|
|
|
|
|
if (typeof tooltipText === 'object') { |
|
|
|
|
if (tooltipText.message) { |
|
|
|
|
tooltipText = tooltipText.message |
|
|
|
|
} else { |
|
|
|
|
try { |
|
|
|
|
tooltipText = JSON.stringify(tooltipText) |
|
|
|
|
} catch (e) { |
|
|
|
|
let canShorten = true |
|
|
|
|
if (tooltipText instanceof Element) { |
|
|
|
|
canShorten = false |
|
|
|
|
} else { |
|
|
|
|
if (typeof tooltipText === 'object') { |
|
|
|
|
if (tooltipText.message) { |
|
|
|
|
tooltipText = tooltipText.message |
|
|
|
|
} else { |
|
|
|
|
try { |
|
|
|
|
tooltipText = JSON.stringify(tooltipText) |
|
|
|
|
} catch (e) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
const shortTooltipText = tooltipText.length > 201 ? tooltipText.substring(0, 200) + '...' : tooltipText |
|
|
|
|
const shortTooltipText = (canShorten && tooltipText.length > 201) ? tooltipText.substring(0, 200) + '...' : tooltipText |
|
|
|
|
|
|
|
|
|
let button = tooltipText.length > 201 ? yo` |
|
|
|
|
<button class="btn btn-secondary btn-sm" onclick=${() => { modal.alert(tooltipText) }}>show full message</button> |
|
|
|
|
<button class="btn btn-secondary btn-sm mx-3" style="white-space: nowrap;" onclick=${() => { modal.alert(tooltipText) }}>Show full message</button> |
|
|
|
|
` : `` |
|
|
|
|
|
|
|
|
|
this.tooltip = yo` |
|
|
|
|
<div class="${css.tooltip} alert alert-info" onmouseenter=${() => { over() }} onmouseleave=${() => { out() }}> |
|
|
|
|
<span> |
|
|
|
|
${shortTooltipText} |
|
|
|
|
${button} |
|
|
|
|
</span> |
|
|
|
|
${action} |
|
|
|
|
</div>` |
|
|
|
|
<div class="${css.tooltip} alert alert-info p-2" onmouseenter=${() => { over() }} onmouseleave=${() => { out() }}> |
|
|
|
|
<span class="px-2"> |
|
|
|
|
${shortTooltipText} |
|
|
|
|
${button} |
|
|
|
|
${action} |
|
|
|
|
</span> |
|
|
|
|
<span style="align-self: baseline;"> |
|
|
|
|
<button class="fas fa-times btn-info mx-1 p-0" onclick=${() => { |
|
|
|
|
this.hide() |
|
|
|
|
over() |
|
|
|
|
resolve() |
|
|
|
|
}}></button> |
|
|
|
|
</span> |
|
|
|
|
</div>` |
|
|
|
|
let timeOut = () => { |
|
|
|
|
return setTimeout(() => { |
|
|
|
|
if (this.id) { |
|
|
|
|