0

I am trying to include Dailymotion in my web app. I have one javascript file (for Dailymotion) and an inline javascript.I am trying to get the recomemmended videos from DM, for which I have a function ready.

Dailymotion.js looks something like this

login();
function login(){
  getScreenname();
}
function getScreename(){
  // print some name
}
function getRecoVideos(callback){
  callback(result);
}

Inline.js

getRecoVideos(function(result){
  console.log(result);
});

In the inline.js file, the call to getRecoVideos doesn't work because, the login is not finished. How can I synchronize the calls?

Andrew Templeton
  • 1,656
  • 10
  • 13
kosta
  • 4,302
  • 10
  • 50
  • 104

1 Answers1

1

Per this documentation DM takes a response function that you can use to then call the getRecoVideos() function.

UPDATE:

To make it so you can receive the event from anywhere you could do the following:

DM.login(function() {
    $(document).trigger("dm-logged-in");
});

And then to receive the event:

$(document).on("dm-logged-in", function() {
    // Do what you want here...
});

This is using jQuery. If you don't use jQuery see this for more data on how to dispatch events in Java Script: How to trigger event in JavaScript?

Community
  • 1
  • 1
ced-b
  • 3,957
  • 1
  • 27
  • 39
  • Thanks for the reply. I have managed to get the recommended videos, but only if call the function from the same js file(Dailymotion.js). I want to call the function from a inline js. How can i signal if the login is complete using Javascript(not referring to the API docs) – kosta Mar 05 '14 at 04:47