Files
NetNewsWire/Mac/MainWindow/Detail/main_mac.js
T

49 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
function scrollDetection() {
window.onscroll = function(event) {
window.webkit.messageHandlers.windowDidScroll.postMessage(window.scrollY);
}
}
function linkHover() {
window.onmouseover = function(event) {
var closestAnchor = event.target.closest('a')
if (closestAnchor) {
window.webkit.messageHandlers.mouseDidEnter.postMessage(closestAnchor.href);
}
}
window.onmouseout = function(event) {
var closestAnchor = event.target.closest('a')
if (closestAnchor) {
window.webkit.messageHandlers.mouseDidExit.postMessage(closestAnchor.href);
}
}
}
// The selection as an HTML fragment — links, bold, and so on included.
function selectedHTML() {
var selection = window.getSelection();
var container = document.createElement("div");
for (var i = 0; i < selection.rangeCount; i++) {
container.appendChild(selection.getRangeAt(i).cloneContents());
}
// Relative URLs would break outside this page.
container.querySelectorAll("a[href]").forEach(function(anchor) {
anchor.setAttribute("href", anchor.href);
});
// Images served from the timeline’s copy would break outside this page.
container.querySelectorAll("img[data-nnw-src]").forEach(function(image) {
image.setAttribute("src", image.getAttribute("data-nnw-src"));
image.removeAttribute("data-nnw-src");
});
// A single-paragraph selection doesn't need its <p> wrapper.
if (container.childNodes.length === 1 && container.firstChild.nodeName === "P") {
return container.firstChild.innerHTML;
}
return container.innerHTML;
}
function postRenderProcessing() {
scrollDetection();
linkHover();
}