My apologies, JEFHQ12951, but last night I didn't have a lot of options for diverse testing. Testing the setInterval() versions, now, I am also seeing an inconsistency in its loading success.
The issue isn't even with the dataset attributes being blacklisted. Though that is troublesome, it's an issue that has been solved 100%. At this point, the problem is with Canvas' dynamic content loading. Sadly, there really isn't any better way to deal with it than setInterval(), as far as I'm aware. Though I try to help with JavaScript solutions, I'm no expert at the language and do it mostly to gain experience with the language. ^^'
Now, regarding the latest of identified issues with making Amara work, I've traced it down to the recognition of the load event. Inside of the setInterval(), the event isn't recognized while it is recognized from without. This appears to be caused by the script file being loaded while the main script still has additional code to execute.
After bouncing some ideas around with some friends that are MUCH better at JavaScript than I, we came up with a few ideas that I've trying out all day. The most promising one, in theory, was dynamically generating IFRAMEs to replace the DIVs with an HTML page built perfectly to run Amara, but no matter how I went about this, only using a third-party host could I get it to work. The concept being that you supply the video dataset to the third-party host as part of the URL of the IFRAME and it renders the page using server-side languages so that the content is fully built before it ever reaches the browser. Any other attempt produced errors where Amara wouldn't recognize the targetOrigin.
Several more ideas failed for the same reasons, the Amara script wasn't designed to allow such abstract usage.
I did find a "solution" that has worked for me, however, it is also incorrect (you'll get an error). The idea is to trick the browser into re-executing the window.onload function AFTER the Amara JavaScript file has been linked and it has been consistently successful while testing in Google Chrome 50, Mozilla Firefox 46, and Internet Explorer 11 on Windows 7 and Safari 9 on OS X.
I'm not particularly familiar with the Amara embedder, but general appearance/functionality appears to cooperate with this modification.
I had to, once again, expand the snippets to accommodate functionality (such as ensuring the dataset isn't broken by the window.onload function being ran twice). Included in the additional functionality is a prototype I wrote for retrieving a list of DOM elements by TagName, AttributeName, and AttributeValue. It's only used to keep from linking the Amara JavaScript file twice, but I didn't see any reason to write the detection into the script when I already had the prototype.
There's only a JavaScript version of this one. I haven't had the time to write a jQuery equivalent (had a niece born a little earlier today), but if you can confirm that this version works for you, I'll make a jQuery equivalent a priority for tomorrow.
JavaScript
Node.prototype.getElementsByTagNameAndAttribute = function(tag, attribute, value) {
var dom = this.all || this.getElementsByTagName(tag);
var match = new Array();
for(var i = 0; i < dom.length; i++) {
if((typeof dom[i]) === 'object') {
if((attribute !== undefined && (value !== undefined && dom[i].getAttribute(attribute) === value) || (value === undefined && dom[i].hasAttribute(attribute))) || (attribute === undefined && value === undefined)) {
match.push(dom[i]);
}
}
}
return match;
};
function loadFile(fileURL, type) {
switch(type) {
case 'js':
var link = document.createElement('script');
link.setAttribute('type', 'text/javascript');
link.setAttribute('src', fileURL);
document.getElementsByTagName('body')[0].appendChild(link);
break;
case 'css':
var link = document.createElement('style');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('type', 'text/css');
link.setAttribute('href', fileURL);
document.getElementsByTagName('head')[0].appendChild(link);
break;
}
}
function embedAmara(amara) {
for(var i = 0; i < amara.length; i++) {
if(amara[i].hasAttribute('style')) {
amara[i].dataset.height = amara[i].style.height;
amara[i].dataset.width = amara[i].style.width;
amara[i].removeAttribute('style');
}
if(amara[i].hasAttribute('role')) {
var dataVal = (amara[i].hasAttribute('role')) ? amara[i].getAttribute('role').split('**|**') : '';
if(dataVal.length >= 1) {
amara[i].dataset.url = dataVal[0];
}
if(dataVal.length >= 2 && dataVal[1] != '') {
amara[i].dataset.hideOrder = dataVal[1];
}
if(dataVal.length >= 3 && dataVal[2] != '') {
amara[i].dataset.initialLanguage = dataVal[2];
}
if(dataVal.length >= 4 && dataVal[3] != '') {
amara[i].dataset.showSubtitlesDefault = dataVal[3];
}
if(dataVal.length >= 5 && dataVal[4] != '') {
amara[i].dataset.showTranscriptDefault = dataVal[4];
}
amara[i].removeAttribute('role');
}
}
var amaraURL = 'https://amara.org/embedder-iframe';
if(document.getElementsByTagNameAndAttribute('script', 'src', amaraURL).length == 0) {
loadFile(amaraURL, 'js');
}
}
window.onload = (function() {
var i = 0, timeout = 30, interval = 500;
var wait = setInterval(function() {
var amara = document.getElementsByClassName('amara-embed');
if(amara.length != 0) {
embedAmara(amara);
onload();
clearInterval(wait);
} else if(i == timeout) {
clearInterval(wait);
}
i++;
}, interval);
})();