Skip to content

Instantly share code, notes, and snippets.

@omo
Last active August 29, 2015 14:17
Show Gist options
  • Save omo/647295fa5839d336f09a to your computer and use it in GitHub Desktop.
Save omo/647295fa5839d336f09a to your computer and use it in GitHub Desktop.
Title Dialog
// Bootstrap:
// window.fetch("https://gist.githubusercontent.com/xxx").then(function(r) { r.text().then(function(j) { eval(j); }); }).catch(function(e) { console.log(e); });
(function() {
function wrapWithDiv(efn, cls) {
var div = document.createElement("div");
div.appendChild(efn());
if (null !== cls)
div.className = cls;
return div;
}
var dialog = document.createElement("dialog");
dialog.tabIndex = 0;
var ds = dialog.createShadowRoot();
ds.appendChild(wrapWithDiv(function() {
var span = document.createElement("span");
span.textContent = document.title;
return span;
}, "title"));
ds.appendChild(wrapWithDiv(function() {
var a = document.createElement("a");
a.textContent = document.location.toString();
a.href = document.location.toString();
return a;
}, "link"));
var style = document.createElement("style");
style.textContent = `
:host {
z-index: 100;
font-size: medium;
}
* {
font-family: verdana;
font-size: medium;
}
div {
font-weight: normal;
}
div.title {
font-weight: bold;
}
a {
color: blue;
}
`;
ds.appendChild(style);
document.body.insertBefore(dialog, document.body.firstChild);
dialog.show();
dialog.focus();
window.getSelection().selectAllChildren(ds);
window.setTimeout(function() {
document.body.removeChild(dialog);
}, 3000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment