-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run embed script after DOMContentLoaded
- Loading branch information
Showing
4 changed files
with
41 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,57 @@ | ||
(function() { | ||
document.addEventListener("DOMContentLoaded", function() { | ||
|
||
var caniuse_embeds = document.getElementsByClassName("ciu_embed"); | ||
var caniuse_embeds = document.getElementsByClassName("ciu_embed"); | ||
|
||
for (var i = 0; i < caniuse_embeds.length; i++) { | ||
for (var i = 0; i < caniuse_embeds.length; i++) { | ||
|
||
var embed = caniuse_embeds[i]; | ||
var feature = embed.getAttribute('data-feature'); | ||
var periods = embed.getAttribute('data-periods'); | ||
var accessibleColours = embed.getAttribute('data-accessible-colours') || 'false'; | ||
var embed = caniuse_embeds[i]; | ||
var feature = embed.getAttribute('data-feature'); | ||
var periods = embed.getAttribute('data-periods'); | ||
var accessibleColours = embed.getAttribute('data-accessible-colours') || 'false'; | ||
|
||
if (feature) { | ||
if (feature) { | ||
|
||
var url = 'https://caniuse.bitsofco.de/embed/index.html'; | ||
//var url = 'http://localhost:8000/embed/index.html' | ||
var url = 'https://caniuse.bitsofco.de/embed/index.html'; | ||
//var url = 'http://localhost:8000/embed/index.html' | ||
|
||
var iframe = '<iframe src="'+url+'?feat='+feature+'&periods='+periods+'&accessible-colours='+accessibleColours+'" frameborder="0" width="100%" height="400px"></iframe>'; | ||
var iframe = '<iframe src="'+url+'?feat='+feature+'&periods='+periods+'&accessible-colours='+accessibleColours+'" frameborder="0" width="100%" height="400px"></iframe>'; | ||
|
||
embed.innerHTML = iframe; | ||
embed.innerHTML = iframe; | ||
|
||
} else { | ||
} else { | ||
|
||
embed.innerHTML = "A feature was not included. Go to <a href='https://caniuse.bitsofco.de/#how-to-use'>https://caniuse.bitsofco.de/#how-to-use</a> to generate an embed."; | ||
} | ||
} | ||
embed.innerHTML = "A feature was not included. Go to <a href='https://caniuse.bitsofco.de/#how-to-use'>https://caniuse.bitsofco.de/#how-to-use</a> to generate an embed."; | ||
} | ||
} | ||
|
||
|
||
// GET RESPONSIVE HEIGHT PASSED FROM IFRAME | ||
|
||
// GET RESPONSIVE HEIGHT PASSED FROM IFRAME | ||
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent"; | ||
var eventer = window[eventMethod]; | ||
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message"; | ||
|
||
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent"; | ||
var eventer = window[eventMethod]; | ||
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message"; | ||
eventer(messageEvent,function(e) { | ||
var data = e.data; | ||
if ( (typeof data === 'string') && (data.indexOf('ciu_embed') > -1) ) { | ||
|
||
eventer(messageEvent,function(e) { | ||
var data = e.data; | ||
if ( (typeof data === 'string') && (data.indexOf('ciu_embed') > -1) ) { | ||
var featureID = data.split(':')[1]; | ||
var height = data.split(':')[2]; | ||
|
||
var featureID = data.split(':')[1]; | ||
var height = data.split(':')[2]; | ||
for (var i = 0; i < caniuse_embeds.length; i++) { | ||
|
||
for (var i = 0; i < caniuse_embeds.length; i++) { | ||
var embed = caniuse_embeds[i]; | ||
|
||
if ( embed.getAttribute('data-feature') === featureID ) { | ||
var iframeHeight = parseInt(height) + 30; | ||
embed.childNodes[0].height = iframeHeight + 'px'; | ||
break; | ||
} | ||
} | ||
} | ||
},false); | ||
|
||
var embed = caniuse_embeds[i]; | ||
|
||
if ( embed.getAttribute('data-feature') === featureID ) { | ||
var iframeHeight = parseInt(height) + 30; | ||
embed.childNodes[0].height = iframeHeight + 'px'; | ||
break; | ||
} | ||
} | ||
} | ||
},false); | ||
}); // end DOMContentLoaded | ||
|
||
|
||
}).call(this); | ||
}()); |