Commented javascript code

This commit is contained in:
Maurice Parker 2019-09-21 16:11:09 -05:00
parent 2db839db98
commit c7166cf7c9

View File

@ -1,11 +1,20 @@
// These mouse functions are used by NetNewsWire for Mac to display link previews
function mouseDidEnterLink(anchor) { function mouseDidEnterLink(anchor) {
window.webkit.messageHandlers.mouseDidEnter.postMessage(anchor.href); window.webkit.messageHandlers.mouseDidEnter.postMessage(anchor.href);
} }
function mouseDidExitLink(anchor) { function mouseDidExitLink(anchor) {
window.webkit.messageHandlers.mouseDidExit.postMessage(anchor.href); window.webkit.messageHandlers.mouseDidExit.postMessage(anchor.href);
} }
// Add the mouse listeners for the above functions
function linkHover() {
document.querySelectorAll("a").forEach(element => {
element.addEventListener("mouseenter", function() { mouseDidEnterLink(this) });
element.addEventListener("mouseleave", function() { mouseDidExitLink(this) });
});
}
// Here we are making iframes responsive. Particularly useful for inline Youtube videos.
function wrapFrames() { function wrapFrames() {
document.querySelectorAll("iframe").forEach(element => { document.querySelectorAll("iframe").forEach(element => {
var wrapper = document.createElement("div"); var wrapper = document.createElement("div");
@ -15,19 +24,15 @@ function wrapFrames() {
}); });
} }
// Strip out all styling so that we have better control over layout
function stripStyles() { function stripStyles() {
document.getElementsByTagName("body")[0].querySelectorAll("style, link[rel=stylesheet]").forEach(element => element.remove()); document.getElementsByTagName("body")[0].querySelectorAll("style, link[rel=stylesheet]").forEach(element => element.remove());
document.getElementsByTagName("body")[0].querySelectorAll("[style]").forEach(element => element.removeAttribute("style")); document.getElementsByTagName("body")[0].querySelectorAll("[style]").forEach(element => element.removeAttribute("style"));
} }
function linkHover() { // Add the playsinline attribute to any HTML5 videos that don't have it.
var anchors = document.getElementsByTagName("a"); // Without this attribute videos may autoplay and take over the whole screen
for (var i = 0; i < anchors.length; i++) { // on an iphone when viewing an article.
anchors[i].addEventListener("mouseenter", function() { mouseDidEnterLink(this) });
anchors[i].addEventListener("mouseleave", function() { mouseDidExitLink(this) });
}
}
function inlineVideos() { function inlineVideos() {
document.querySelectorAll("video").forEach(element => { document.querySelectorAll("video").forEach(element => {
element.setAttribute("playsinline", true) element.setAttribute("playsinline", true)
@ -41,6 +46,7 @@ function error() {
function render(data) { function render(data) {
document.getElementsByTagName("style")[0].innerHTML = data.style; document.getElementsByTagName("style")[0].innerHTML = data.style;
document.body.innerHTML = data.body; document.body.innerHTML = data.body;
window.scrollTo(0, 0); window.scrollTo(0, 0);
wrapFrames() wrapFrames()