Skip to content

Commit

Permalink
Deploying to gh-pages from @ 9460fdd 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
johnman committed Jun 19, 2024
1 parent 406c651 commit 21ee72e
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"applications": [
{
"appId": "custom-tab",
"name": "custom-tab",
"title": "Custom Tab",
"description": "A custom tab app that lets you preview a url and navigate to it if it can be loaded. A tool to quickly test a url before adding it as an app.",
"categories": ["view", "tool"],
"version": "1.0.0",
"tooltip": "Add a custom tab to preview urls.",
"lang": "en-US",
"icons": [
{
"src": "https://built-on-openfin.github.io/web-starter/web/vnext/web-interop-support-context-and-intents/favicon.ico"
}
],
"screenshots": [
{
"src": "https://built-on-openfin.github.io/web-starter/web/vnext/web-interop-support-context-and-intents/images/previews/preview-app-custom-tab.jpeg"
}
],
"contactEmail": "[email protected]",
"supportEmail": "[email protected]",
"publisher": "OpenFin",
"type": "web",
"details": {
"url": "https://built-on-openfin.github.io/web-starter/web/vnext/web-interop-support-context-and-intents/platform/custom-tab/custom-tab.html"
},
"interop": {}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Custom Tab</title>
<link rel="icon" type="image/x-icon" href="../../favicon.ico" />
<link rel="stylesheet" href="../../common/style/app.css" />
<script defer="defer" src="./custom-tab.js"></script>
<style>
.query-container {
padding-top: 125px;
}
.preview {
height: 100%;
padding: 0px;
}
</style>
</head>

<body class="col fill gap20">
<header class="row spread middle">
<div class="col">
<h1>Custom Tab</h1>
</div>
</header>
<main class="form fill col gap20 middle scroll-vertical">
<div id="preview" class="width-full row preview" style="display: none">
<iframe id="preview-iframe" class="width-full preview" src="about:blank"></iframe>
</div>
<div id="url-container" class="width-full row pad20 query-container">
<input id="url" type="text" class="large center full" placeholder="http://www.example.com" />
</div>
<div class="width-full row pad20 center">
<button type="submit" id="previewBtn" disabled="true">Preview</button>
<button type="submit" id="cancelBtn" style="display: none; margin-right: 10px">Cancel</button>
<button type="submit" id="actionBtn" style="display: none">Navigate</button>
</div>
</main>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const url = document.querySelector('#url');
const actionBtn = document.querySelector('#actionBtn');
const previewBtn = document.querySelector('#previewBtn');
const cancelBtn = document.querySelector('#cancelBtn');
const previewContainer = document.querySelector('#preview');
const previewFrame = document.querySelector('#preview-iframe');
const urlContainer = document.querySelector('#url-container');

/**
* Is the query text a url.
* @param value The value to test.
* @returns True if the input is a url.
*/
function isValueAUrl(value) {
return /^https?:\/\//.test(value);
}

/**
* Switch the label based on the content.
* @param e The event to get the value from.
*/
function validateValue(e) {
setPreviewEnabledState(e.target.value);
}

/**
* Sets whether the preview button is enabled.
* @param urlToValidate The url to validate.
*/
function setPreviewEnabledState(urlToValidate) {
if (isValueAUrl(urlToValidate)) {
previewBtn.disabled = false;
} else {
previewBtn.disabled = true;
}
}

/**
* Open the query or search.
*/
async function actionQuery() {
const targetUrl = url.value;
if (isValueAUrl(targetUrl)) {
location.href = url.value;
}
}

/**
* Init the content.
*/
async function init() {
url.addEventListener('input', validateValue);
url.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
actionQuery();
}
});
actionBtn.addEventListener('click', actionQuery);
previewBtn.addEventListener('click', async () => {
urlContainer.style.display = 'none';
previewContainer.style.display = 'block';
previewFrame.src = url.value;
cancelBtn.style.display = 'block';
previewBtn.style.display = 'none';
actionBtn.style.display = 'block';
});
cancelBtn.addEventListener('click', () => {
urlContainer.style.display = 'block';
previewContainer.style.display = 'none';
previewFrame.src = 'about:blank';
cancelBtn.style.display = 'none';
previewBtn.style.display = 'block';
actionBtn.style.display = 'none';
url.focus();
});
setTimeout(() => {
setPreviewEnabledState(url.value);
}, 500);
}

document.addEventListener('DOMContentLoaded', () => {
try {
init();
} catch (error) {
console.error(error);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"app": {
"directory": [
"https://built-on-openfin.github.io/web-starter/web/vnext/web-interop-support-context-and-intents/apps.json",
"https://built-on-openfin.github.io/web-starter/web/vnext/web-interop-support-context-and-intents/common/apps-tools.json",
"https://built-on-openfin.github.io/web-starter/web/vnext/web-interop-support-context-and-intents/common/apps.json",
"https://built-on-openfin.github.io/web-starter/web/vnext/web-interop-support-context-and-intents/common/apps-fdc3-2-0.json",
"https://built-on-openfin.github.io/web-starter/web/vnext/web-interop-support-context-and-intents/common/apps-interop.json",
Expand Down

0 comments on commit 21ee72e

Please sign in to comment.