Return Instance of DropKick
Szeremeta opened this issue · comments
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!
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();
Thanks Rob...like your solution!
No problem! I'm going to close this for now. If you need anything else let me know and we'll reopen :)