fe-jquery-plugin
v0.0.10
Published
base class for a jquery plugin
Downloads
6
Readme
Jquery Plugin Base Class
Simple base class that sets up :
- plugin name
- instance reference as data attr on element
- plugin method exec from element via string
- destruction life cycle.
Usage
Creating a plugin
...
plugin = require 'fe-jquery-plugin'
class Foo extends plugin
@defaults:
activeClass: 'active'
initialize: (@options)->
super(@options)
# rest of your per instance initialisation here
bar: ->
@destroy()
@element.remove()
Foo.register()
...
Using it
Attach it to an element as per usual jquery shenanigans.
...
$('#foo').Foo({activeClass: 'buwahaha' });
...
But now:
...
$('#foo').Foo('destroy');
...
Also, the plugin instance is available on the object:
...
var instance = $('#foo').data('Foo');
console.log(instance);
// => Foo
Testing
tests are outlined, and require fullfilling.
- https://gist.github.com/robballou/9ee108758dc5e0e2d028
- http://bloggemdano.blogspot.com.au/2012/01/testing-jquery-plugin-with-expectthat.html