-
Notifications
You must be signed in to change notification settings - Fork 0
Asynchronized Usage with RequireJS
Alican Çubukçuoğlu edited this page Feb 2, 2015
·
4 revisions
Since MLLEmbed is a named module, you won't be able to load it using it's path.
MLLEmbed also won't automatically run when it's called as an AMD module so you have to call mllembed.run()
manually.
//Wrong:
require(['path/to/mllembed.min.js'], function (mllembed) {
//mllembed is undefined!
});
//Correct:
require.config({
paths: {
'mll.embed': 'path/to/mllembed.min.js'
}
});
require(['jquery', 'mll.embed'], function ($, mllembed) {
//Configure
mllembed.config('clientId', 'SomeCompany');
mllembed.config('something', 'else');
mllembed.ready(function () {
//Convert existing iframes on the page
mllembed.run();
//Add a new iframe
$('<iframe width="640" height="360" src="https://www.youtube.com/embed/zf_cb_Nw5zY?rel=0&controls=0&showinfo=0" frameborder="0" allowfullscreen></iframe>')
.appendTo('body');
//Run the automatic converter manually so it finds the iframe above
mllembed.run();
//Add another iframe
var iframe = $('<iframe width="640" height="360" src="https://www.youtube-nocookie.com/embed/_cLvpJY2deo?showinfo=0" frameborder="0" allowfullscreen></iframe>')
.appendTo('body');
//Ask mllembed to convert the inserted iframe
mllembed.convert(iframe[0]);
});
});