Commit 824565c1 authored by Robert Knight's avatar Robert Knight

Fix some formatting inconsistencies

Run `prettier` on `frame-util.js` to fix up some minor formatting
inconsistencies.
parent 4192f106
'use strict'; 'use strict';
// Find all iframes within this iframe only // Find all iframes within this iframe only
function findFrames (container) { function findFrames(container) {
const frames = Array.from(container.getElementsByTagName('iframe')); const frames = Array.from(container.getElementsByTagName('iframe'));
return frames.filter(isValid); return frames.filter(isValid);
} }
// Check if the iframe has already been injected // Check if the iframe has already been injected
function hasHypothesis (iframe) { function hasHypothesis(iframe) {
return iframe.contentWindow.__hypothesis_frame === true; return iframe.contentWindow.__hypothesis_frame === true;
} }
// Inject embed.js into the iframe // Inject embed.js into the iframe
function injectHypothesis (iframe, scriptUrl, config) { function injectHypothesis(iframe, scriptUrl, config) {
const configElement = document.createElement('script'); const configElement = document.createElement('script');
configElement.className = 'js-hypothesis-config'; configElement.className = 'js-hypothesis-config';
configElement.type = 'application/json'; configElement.type = 'application/json';
...@@ -29,7 +29,7 @@ function injectHypothesis (iframe, scriptUrl, config) { ...@@ -29,7 +29,7 @@ function injectHypothesis (iframe, scriptUrl, config) {
} }
// Check if we can access this iframe's document // Check if we can access this iframe's document
function isAccessible (iframe) { function isAccessible(iframe) {
try { try {
return !!iframe.contentDocument; return !!iframe.contentDocument;
} catch (e) { } catch (e) {
...@@ -37,7 +37,6 @@ function isAccessible (iframe) { ...@@ -37,7 +37,6 @@ function isAccessible (iframe) {
} }
} }
/** /**
* Check if the frame elements being considered for injection have the * Check if the frame elements being considered for injection have the
* basic heuristics for content that a user might want to annotate. * basic heuristics for content that a user might want to annotate.
...@@ -48,21 +47,21 @@ function isAccessible (iframe) { ...@@ -48,21 +47,21 @@ function isAccessible (iframe) {
* @param {HTMLIFrameElement} iframe the frame being checked * @param {HTMLIFrameElement} iframe the frame being checked
* @returns {boolean} result of our validity checks * @returns {boolean} result of our validity checks
*/ */
function isValid (iframe) { function isValid(iframe) {
const isNotClientFrame = !iframe.classList.contains('h-sidebar-iframe'); const isNotClientFrame = !iframe.classList.contains('h-sidebar-iframe');
const frameRect = iframe.getBoundingClientRect(); const frameRect = iframe.getBoundingClientRect();
const MIN_WIDTH = 150; const MIN_WIDTH = 150;
const MIN_HEIGHT = 150; const MIN_HEIGHT = 150;
const hasSizableContainer = frameRect.width > MIN_WIDTH && frameRect.height > MIN_HEIGHT; const hasSizableContainer =
frameRect.width > MIN_WIDTH && frameRect.height > MIN_HEIGHT;
return isNotClientFrame && hasSizableContainer; return isNotClientFrame && hasSizableContainer;
} }
function isDocumentReady (iframe, callback) { function isDocumentReady(iframe, callback) {
if (iframe.contentDocument.readyState === 'loading') { if (iframe.contentDocument.readyState === 'loading') {
iframe.contentDocument.addEventListener('DOMContentLoaded', function () { iframe.contentDocument.addEventListener('DOMContentLoaded', function() {
callback(); callback();
}); });
} else { } else {
...@@ -70,9 +69,9 @@ function isDocumentReady (iframe, callback) { ...@@ -70,9 +69,9 @@ function isDocumentReady (iframe, callback) {
} }
} }
function isLoaded (iframe, callback) { function isLoaded(iframe, callback) {
if (iframe.contentDocument.readyState !== 'complete') { if (iframe.contentDocument.readyState !== 'complete') {
iframe.addEventListener('load', function () { iframe.addEventListener('load', function() {
callback(); callback();
}); });
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment