Reputation: 25542
I have the following (simple) CoffeeScript jQuery Plugin:
$ = jQuery
$.fn.extend
schoolSelect: (options) ->
settings =
apiUrl: '/api/v1'
debug: false
settings = $.extend settings, options
log = (msg) ->
console?.log msg if settings.debug
return @each ->
@.dropkick
change: (val, label) ->
log val
log label
And I call it in another CoffeeScript file like so:
$('.school_select').schoolSelect
debug: true
But for some reason I keep getting the following error:
Uncaught TypeError: Object #<HTMLSelectElement> has no method 'dropkick'
I am using the DropKick
jQuery plugin for my HTML selects: http://jamielottering.github.com/DropKick/
How can I access the DropKick plugin within my CoffeeScript jQuery plugin?
Upvotes: 1
Views: 266
Reputation: 141638
This line:
return @each ->
@.dropkick
Needs to be
return @each ->
$(@).dropkick
In the context of a jQuery callback for each, this
gives you back a raw DOM element (hence the warning about HTMLSelectElement), not a jQuery object.
If your plugin is calling another plugin, you need to ensure the setup for the DropKick plugin is done before you extend jQuery.
Upvotes: 2