I am creating a jQuery plugin from the jQuery boilerplate. I've been successful in my implementation so far.
However, I would like my plugging to to be called like this
$('selector').myplugin({data}) -- and have it return a chainable object
or
$.myplugin({data}) --and have it return something (string, object, array).
I read around about moving the this.each() ... return this
to each method, but I am getting
TypeError: undefined is not a function (evaluating '$.myplugin()')
Example:
Here's an example of what I would like to do.
<input class="textIn" type="text" />
<input class="textOut" type="text" />
<script>
var input = $('.textIn').val();
//CASE #1
// will perform method named someMethod with an arg and return a value
var output = $.myPlugin(someMethod, input);
//CASE #2
// will go through each node with class 'textOut' and perform someMethod with an arg
$('.textOut').myPlugin(someMethod, input);
//CASE #3
// will go through each node with class 'textOut' and perform someOtherMethod
$('.textOut').myPlugin(someOtherMethod);
</script>
Maybe case #1 and #2 cannot be combined and I will have to rename the method, but I'm not sure. Any help would be great!