When a non-logined user clicks on a given button, I want to stop the event, collect his oauth, collect his email if i do not have it, and then execute the event.
I want to do everything in javascript because that would keep things much more simple.
This is how I am executing it, and I have 2 questions:
- Is there a more elegant way of doing multiple level callbacks?
- The way i am triggering the event at the end seems hackish. What might be a better way to do it?
jQuery("a.callbacktesting").click(function(event){ if (success==false){ event.preventDefault(); event.stopImmediatePropagation(); authentication({endevent:event,followup:afterEmail},collectEmail, failFn); } }); //1st level function function authentication(params, successFn, failFn){ if (success=true){ successFn(params,params.followup,failFn); }else{ failFn(); } } //2nd level function function collectEmail(params, successFn, failFn){ console.log("Collecting email"); if (success=true){ successFn(params); }else{ failFn(); }; } //After everything is done, you want to execute this function afterEmail(params){ jele=$(params.endevent.currentTarget) action=params.endevent.type jele.trigger(action); }