0

I saw this awesome post by John Resig on "Simple Class Instantiation": http://ejohn.org/blog/simple-class-instantiation/

So i started create scripts this way, but unfortunately it has caused some troubles and confusion.

I'm working on some kind of "custom dialog framework", where it should only be possible to view one dialog at a time, and if you dismiss one, the next appears. Let's call this dialog queue.

Secondly it should run proceed or cancel depending on what the users chooses. So we could use it like this:

var dialog = UIDialog();
dialog.proceed(function() {
    // Do stuff
});
dialog.cancel(function() {
    // Do stuff
});

I currently have this code: http://pastebin.com/sGyjArfA Right now the dialog queue seems to work, but I'm pretty lost on how i should make the callback thing work.

1
  • Callback thingie... can you be more specific? Do you want a callback when proceed occurs and when cancel occurs? Commented Jun 12, 2011 at 17:49

1 Answer 1

1

You need to store the callbacks in the dialog object, and then just call them at the appropriate times. E.g.,

UIDialog.prototype.proceed = function(callback) { this.cbProceed = callback; }

And then in the dialog logic that handles the proceed logic, just call the callback if it's set:

if (this.cbProceed && jQuery.isFunction(this.cbProceed))
  this.cbProceed();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.