Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return Instance of DropKick #285

Closed
Szeremeta opened this issue Apr 13, 2015 · 3 comments
Closed

Return Instance of DropKick #285

Szeremeta opened this issue Apr 13, 2015 · 3 comments

Comments

@Szeremeta
Copy link

Robdel12,
In case I'm missing something, all of the useful dk methods are only applicable to instances of dropkick, would it not be sensible to return an instance reference to dk upon instantiation?

This is useful for single page apps etc.

At the moment we're getting around it like so:

var nationsDropkickInstance;
...
$("[name=nationality]").dropkick({
  mobile: true,
  initialize: function() {
    this.model.set({"nationality":this.value});
    $('.dk-selected', this.data.elem).after([
      '<div class="line"></div>'
    ]);
    nationsDropkickInstance = this;
  }
});
...
nationsDropkickInstance.refresh();

I see this pattern in so many plugins, so would be interested in the best approach!

thanks!

@Robdel12
Copy link
Owner

I don't quite know how to do it with the jQuery plugin (CC: @wwilsman) but with the normal DK constructor you can do:

var nationsDropkickInstance;
...
nationsDropkickInstance = new Dropkick("#nationality", {
  mobile: true,
  initialize: function() {
    this.model.set({"nationality":this.value});
    $('.dk-selected', this.data.elem).after([
      '<div class="line"></div>'
    ]);
  }
});
...
nationsDropkickInstance.refresh();

@Szeremeta
Copy link
Author

Thanks Rob...like your solution!

@Robdel12
Copy link
Owner

No problem! I'm going to close this for now. If you need anything else let me know and we'll reopen :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants