Reusing Plugin Init Options in further methods (Basic issue)
Hello!
I'm new to jQuery plugins, I've edited multiples but I'd like to make my own using the cleanest and most standard structure.
Is there a way to reuse the options used after the plugin initialization?(Like an instance of a class?)
I put my failing attempts to reach the value in the code.(
See orange part)
Here's my (basic) plugin code:
- (function( $ ){
- var methods = {
- init : function( options ) {
- var settings = $.extend( {
- 'location' : 'top'
- }, options);
-
- return this.each(function(){
- console.log(settings['location']);
- });
- },
- destroy : function( ) {
- },
- move : function( ) {
- //Using 'location' : 'top' to define upcoming movements
- console.log(this.settings['location']);
- console.log(this);
- }
- };
- $.fn.animatrix = function( method ) {
-
- if ( methods[method] ) {
- return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
- } else if ( typeof method === 'object' || ! method ) {
- return methods.init.apply( this, arguments );
- } else {
- $.error( 'Method ' + method + ' does not exist on jQuery.tooltip' );
- }
-
- };
- })( jQuery );
This is how it would be called:
- $('#element').animatrix();
- $('#element').animatrix('move');
Any help/tip is greatly appreciated.