caching link content for link preview
This commit is contained in:
@@ -50,6 +50,8 @@
|
||||
var tooltipWrapper = document.getElementById('tooltip-wrapper')
|
||||
var tooltipContent = document.getElementById('tooltip-content')
|
||||
|
||||
var linkHistories = {};
|
||||
|
||||
function hideTooltip() {
|
||||
opacityTimeout = setTimeout(function() {
|
||||
tooltipWrapper.style.opacity = 0;
|
||||
@@ -66,20 +68,30 @@
|
||||
var top = window.pageYOffset || document.documentElement.scrollTop
|
||||
|
||||
if (event.target.host === window.location.host) {
|
||||
iframe.src = event.target.href
|
||||
iframe.onload = function() {
|
||||
tooltipContentHtml = ''
|
||||
tooltipContentHtml += '<div style="font-weight: bold;">' + iframe.contentWindow.document.querySelector('h1').innerHTML + '</div>'
|
||||
tooltipContentHtml += iframe.contentWindow.document.querySelector('content').innerHTML
|
||||
if (!linkHistories[event.target.href]) {
|
||||
iframe.src = event.target.href
|
||||
iframe.onload = function() {
|
||||
tooltipContentHtml = ''
|
||||
tooltipContentHtml += '<div style="font-weight: bold;">' + iframe.contentWindow.document.querySelector('h1').innerHTML + '</div>'
|
||||
tooltipContentHtml += iframe.contentWindow.document.querySelector('content').innerHTML
|
||||
|
||||
tooltipContent.innerHTML = tooltipContentHtml
|
||||
tooltipContent.innerHTML = tooltipContentHtml
|
||||
linkHistories[event.target.href] = tooltipContentHtml
|
||||
|
||||
tooltipWrapper.style.display = 'block';
|
||||
setTimeout(function() {
|
||||
tooltipWrapper.style.opacity = 1;
|
||||
}, 1)
|
||||
}
|
||||
} else {
|
||||
tooltipContent.innerHTML = linkHistories[event.target.href]
|
||||
tooltipWrapper.style.display = 'block';
|
||||
setTimeout(function() {
|
||||
tooltipWrapper.style.opacity = 1;
|
||||
}, 1)
|
||||
}
|
||||
|
||||
|
||||
tooltipWrapper.style.left = elem_props.left - (tooltipWrapper.offsetWidth / 2) + (elem_props.width / 2) + "px";
|
||||
if ((window.innerHeight - elem_props.top) < (tooltipWrapper.offsetHeight)) {
|
||||
tooltipWrapper.style.top = elem_props.top + top - tooltipWrapper.offsetHeight - 10 + "px";
|
||||
|
||||
Reference in New Issue
Block a user