Jquery plugin with api -
how can retrieve api variables plugin. per jquery authoring documentation, here plugin structure:
(function( $ ){ var methods = { init : function( options ) { return this.each(function() { var settings = { 'height' : 10, 'width' : 10 }; if ( options ) { $.extend( settings, options ); } $('<div>', { css : { height : settings.height, width : settings.width, } }).appendto(this); }); } }; $.fn.myplugin = 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 + ' not exist on jquery.element' ); } }; })( jquery ); i able following :
var element = $('div').myplugin(); console.log(element.properties); in properties, have function returns height , width of div. how go creating properties variable in design ?
thanks
you rid of...
return this.each(function() { ... }); ...and have plugin return such as...
return { 'properties': { 'width': calculatedwidth, 'height': calculatedheight } } however, doing mean can not chain method.
Comments
Post a Comment