1 | /** |
||
2 | * Extends the functionality of jQuery to include Mivhak |
||
3 | * |
||
4 | * @param {Function|Object} methodOrOptions |
||
5 | * @returns {jQuery} |
||
6 | */ |
||
7 | $.fn.mivhak = function( methodOrOptions ) { |
||
8 | |||
9 | // Store arguments for use with methods |
||
10 | var args = arguments.length > 1 ? Array.apply(null, arguments).slice(1) : null; |
||
11 | |||
12 | return this.each(function(){ |
||
13 | |||
14 | // If this is an options object, set or update the options |
||
15 | if( typeof methodOrOptions === 'object' || !methodOrOptions ) |
||
16 | { |
||
17 | // If this is the initial call for this element, instantiate a new Mivhak object |
||
18 | if( typeof $(this).data( 'mivhak' ) === 'undefined' ) { |
||
19 | var plugin = new Mivhak( this, methodOrOptions ); |
||
0 ignored issues
–
show
|
|||
20 | $(this).data( 'mivhak', plugin ); |
||
21 | } |
||
22 | // Otherwise update existing settings (consequent calls will update, rather than recreate Mivhak) |
||
23 | else |
||
24 | { |
||
25 | $(this).data('mivhak').setOptions( methodOrOptions ); |
||
26 | $(this).data('mivhak').applyOptions(); |
||
27 | } |
||
28 | } |
||
29 | |||
30 | // If this is a method call, run the method (if it exists) |
||
31 | else if( Mivhak.methodExists( methodOrOptions ) ) |
||
32 | { |
||
33 | Mivhak.methods[methodOrOptions].apply($(this).data('mivhak'), args); |
||
34 | } |
||
35 | }); |
||
36 | }; |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.