Skip to content

Commit

Permalink
Add preview HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
gigamaster committed Jul 15, 2024
1 parent f7cafd3 commit 64800ad
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
10 changes: 5 additions & 5 deletions app/asset/app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/*! */

/*! instant.page v5.2.0 - (C) 2019-2023 Alexandre Dieulot - https://instant.page/license */
let t,e,n,o,i,a=null,s=65,c=new Set;const r=1111;function d(t){o=performance.now();const e=t.target.closest("a");m(e)&&p(e.href,"high")}function u(t){if(performance.now()-o<r)return;if(!("closest"in t.target))return;const e=t.target.closest("a");m(e)&&(e.addEventListener("mouseout",f,{passive:!0}),i=setTimeout(()=>{p(e.href,"high"),i=void 0},s))}function l(t){const e=t.target.closest("a");m(e)&&p(e.href,"high")}function f(t){t.relatedTarget&&t.target.closest("a")==t.relatedTarget.closest("a")||i&&(clearTimeout(i),i=void 0)}function h(t){if(performance.now()-o<r)return;const e=t.target.closest("a");if(t.which>1||t.metaKey||t.ctrlKey)return;if(!e)return;e.addEventListener("click",function(t){1337!=t.detail&&t.preventDefault()},{capture:!0,passive:!1,once:!0});const n=new MouseEvent("click",{view:window,bubbles:!0,cancelable:!1,detail:1337});e.dispatchEvent(n)}function m(o){if(o&&o.href&&(!n||"instant"in o.dataset)){if(o.origin!=location.origin){if(!(e||"instant"in o.dataset)||!a)return}if(["http:","https:"].includes(o.protocol)&&("http:"!=o.protocol||"https:"!=location.protocol)&&(t||!o.search||"instant"in o.dataset)&&!(o.hash&&o.pathname+o.search==location.pathname+location.search||"noInstant"in o.dataset))return!0}}function p(t,e="auto"){if(c.has(t))return;const n=document.createElement("link");n.rel="prefetch",n.href=t,n.fetchPriority=e,n.as="document",document.head.appendChild(n),c.add(t)}!function(){if(!document.createElement("link").relList.supports("prefetch"))return;const o="instantVaryAccept"in document.body.dataset||"Shopify"in window,i=navigator.userAgent.indexOf("Chrome/");i>-1&&(a=parseInt(navigator.userAgent.substring(i+"Chrome/".length)));if(o&&a&&a<110)return;const c="instantMousedownShortcut"in document.body.dataset;t="instantAllowQueryString"in document.body.dataset,e="instantAllowExternalLinks"in document.body.dataset,n="instantWhitelist"in document.body.dataset;const r={capture:!0,passive:!0};let f=!1,v=!1,g=!1;if("instantIntensity"in document.body.dataset){const t=document.body.dataset.instantIntensity;if(t.startsWith("mousedown"))f=!0,"mousedown-only"==t&&(v=!0);else if(t.startsWith("viewport")){const e=navigator.connection&&navigator.connection.saveData,n=navigator.connection&&navigator.connection.effectiveType&&navigator.connection.effectiveType.includes("2g");e||n||("viewport"==t?document.documentElement.clientWidth*document.documentElement.clientHeight<45e4&&(g=!0):"viewport-all"==t&&(g=!0))}else{const e=parseInt(t);isNaN(e)||(s=e)}}v||document.addEventListener("touchstart",d,r);f?c||document.addEventListener("mousedown",l,r):document.addEventListener("mouseover",u,r);c&&document.addEventListener("mousedown",h,r);if(g){let t=window.requestIdleCallback;t||(t=(t=>{t()})),t(function(){const t=new IntersectionObserver(e=>{e.forEach(e=>{if(e.isIntersecting){const n=e.target;t.unobserve(n),p(n.href)}})});document.querySelectorAll("a").forEach(e=>{m(e)&&t.observe(e)})},{timeout:1500})}}();
/*! */
/* global LinkPreviewer */
/* global LinkPreviewer */
const linkPreviewer = new LinkPreviewer();
linkPreviewer.attach('td a.preview');

Expand Down Expand Up @@ -161,4 +158,7 @@ function openWithSelfMain(url, title, w, h) {
if (window.focus) {
newWindow.focus();
}
}
}
/*! fetch */
var _htmlToElements=function(e){var t=document.createElement("template");t.innerHTML=e;const n=t.content.childNodes,o=[],a=[];for(var d in n)1==n[d].nodeType&&("SCRIPT"===n[d].nodeName?a.push(n[d]):o.push(n[d]));return o.concat(a)},_loadContent=function(e,t,n,o){if(0!==t||o||(document.querySelector(n).innerHTML=""),!(t<=e.length))return!0;var a=e[t];if(void 0!==a&&"SCRIPT"===a.nodeName){var d=document.createElement("script");a.type&&(d.type=a.type),Array.prototype.forEach.call(a.attributes,(function(e){d.setAttribute(e.nodeName,e.nodeValue)})),""!=a.src?(d.src=a.src,d.onload=function(){_loadContent(e,t+1,n)},document.head.appendChild(d)):(d.text=a.text,document.body.appendChild(d),_loadContent(e,t+1,n))}else void 0!==a&&document.querySelector(n).appendChild(a),_loadContent(e,t+1,n)},loadData=async function(e,t,n=!1){return _loadContent(_htmlToElements(e),0,t,n)};

41 changes: 33 additions & 8 deletions app/asset/lib/link-previewer.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@

let stylesContainer = document.head.querySelectorAll(`style.${styleClass}`);
let activeRenderer;

// ratio 16:9 400x225, 384x216, 368x207, 352x198
if (stylesContainer.length === 0) {
stylesContainer = document.createElement('style');
stylesContainer.className = styleClass;
stylesContainer.textContent = `
.${componentClass}-container {
position:absolute;
z-index:10000;
width:400px;
min-height:200px;
width:368px;
height:207px;
border: 1px solid rgba(0,0,0,.2);
border-radius: 6px;
outline: 0;
overflow: clip;
box-shadow: 0 3px 7px rgba(0,0,0,.2);
background: #212527;
background-clip: padding-box;
Expand Down Expand Up @@ -50,13 +51,19 @@
.${componentClass}-drawing {
}
.${componentClass}-text {
min-height:190px;
max-height:300px;
width:368px;
min-height:207px;
overflow:hidden;
padding:10px;
}
.${componentClass}-html {
padding:10px;
width:368px;
min-height:207px;
padding:1px;
overflow:hidden;
border: none;
transform: scale(0.995);
transform-origin: 0 0;
}
.${componentClass}-video {
width:100%;
Expand Down Expand Up @@ -124,7 +131,18 @@
function renderVideo(url) {
contentVideo.src = url;
}

function renderHTML(url){
//contentHtml.src = url;
let iframeHTML = document.createElement("iframe");
iframeHTML.setAttribute("width", "366");
iframeHTML.setAttribute("height", "205");
iframeHTML.setAttribute("scrolling", "no");
iframeHTML.setAttribute('frameborder', "0");
iframeHTML.style.cssText = 'width:366px;height:205px;border: none;";overflow:hidden;';
iframeHTML.src = url;
contentHtml.appendChild(iframeHTML);
showContent(contentHtml);
}
function renderText(url) {
fetch(url, {
signal,
Expand Down Expand Up @@ -197,6 +215,8 @@
window.pdfjsLib
) {
renderPdf(url);
} else if (contentType.indexOf('text/html') != -1) {
renderHTML(url);
} else if (
(contentType.indexOf('text/') != -1) ||
// (contentType.indexOf('text/css') != -1) ||
Expand Down Expand Up @@ -233,7 +253,7 @@
});
window.setTimeout(function() {
controller.abort();
}, 5000);
}, 3000);
}
}

Expand Down Expand Up @@ -310,6 +330,11 @@
findRenderer(this.src, 'unknown');
};

const contentHtml = previewerOverlay.querySelector(`div.${componentClass}-html`);
contentHtml.onload = function() {
showContent(contentHtml);
};

const contentText = previewerOverlay.querySelector(`pre.${componentClass}-text`);
// const contentHtml = previewerOverlay.querySelector(`div.${componentClass}-html`);
const contentDrawing = previewerOverlay.querySelector(`div.${componentClass}-drawing`);
Expand Down

0 comments on commit 64800ad

Please sign in to comment.