Created
January 18, 2018 19:44
-
-
Save wvuwebgist/37ae4fc284de7507001d34e987e125e9 to your computer and use it in GitHub Desktop.
Add a `title` Attribute to Wufoo's <iframe> and remove superflous presentational attributes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --- Add a `title` Attribute to Wufoo's <iframe> and remove --- | |
// --- superflous presentational attributes --- | |
// We have to wait until the <iframe> is built to add stuff to it; | |
// hence, the reason for using the MutationObserver API. It listens | |
// for when the node is finished building, then we can add & remove stuff. | |
var wufooOptions = { | |
wufooId: 'wufoo-xilwg7v0n5ncc2', // The id of the <div> Wufoo gives you for their JS form embed | |
titleContent: 'Cast your vote by selecting a hat.' // The content for your title attribute | |
}; | |
var observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation, index) { | |
if (index > 0){ | |
// stops further observing of changes | |
observer.disconnect(); | |
} else { | |
var wufooIframeId = mutation.addedNodes[0].id; | |
var wufooIframe = document.getElementById(wufooIframeId); | |
wufooIframe.setAttribute('title', wufooOptions.titleContent); | |
// Remove attributes listed in the following array: | |
var removeTheseAttributes = ['frameborder','style','scrolling','allowtransparency']; | |
removeTheseAttributes.forEach(function(attr,index){ | |
wufooIframe.removeAttribute(attr); | |
}); | |
} | |
}); | |
observer.disconnect(); | |
}); | |
// Listen to all changes to the child node of the <div> supplied by Wufoo | |
var targetNode = document.getElementById(wufooOptions.wufooId); | |
observer.observe(targetNode, { childList: true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment