diff --git a/src/jquery.molequul-widget.js b/src/jquery.molequul-widget.js new file mode 100644 index 0000000..9abbc18 --- /dev/null +++ b/src/jquery.molequul-widget.js @@ -0,0 +1,54 @@ +(function( $, undefined ) { + + // our "Widget" object constructor + var Molequul = function( options, element ){ + this.options = options; + this.element = element; + + this._init(); + }; + + Molequul.prototype = { + + // _init fires when your instance is first created + // (from the constructor above), and when you + // attempt to initialize the widget again (by the bridge) + // after it has already been initialized. + _init: function(){ + // init code + }, + + option: function( key, value ){ + + // get/change options AFTER initialization: + // you don't have to support all these cases, + // but here's how: + + // signature: $('#foo').bar({ cool:false }); + if ( $.isPlainObject( key ) ){ + this.options = $.extend(true, this.options, key); + + // signature: $('#foo').option('cool'); - getter + } else if ( key && typeof value === "undefined" ){ + return this.options[ key ]; + + // signature: $('#foo').bar('option', 'baz', false); + } else { + this.options[ key ] = value; + } + + return this; // make sure to return the instance! + }, + + publicFn: function(){ // notice no underscore + return "public method"; + }, + + _privateFn: function(){ + return "private method"; + } + }; + + $.widget.bridge( 'molequul', Molequul ); + +})( jQuery ); \ No newline at end of file diff --git a/src/jquery.ui.widget.js b/src/jquery.ui.widget.js new file mode 100644 index 0000000..805771c --- /dev/null +++ b/src/jquery.ui.widget.js @@ -0,0 +1,61 @@ +/*! + * jQuery UI Widget 1.8.5 + * + * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Widget + */ +(function( $, undefined ) { + + $.widget = $.widget || {}; + + $.widget.bridge = $.widget.bridge || function( name, object ) { + $.fn[ name ] = function( options ) { + var isMethodCall = typeof options === "string", + args = Array.prototype.slice.call( arguments, 1 ), + returnValue = this; + + // allow multiple hashes to be passed on init + options = !isMethodCall && args.length ? + $.extend.apply( null, [ true, options ].concat(args) ) : + options; + + // prevent calls to internal methods + if ( isMethodCall && options.substring( 0, 1 ) === "_" ) { + return returnValue; + } + + if ( isMethodCall ) { + this.each(function() { + var instance = $.data( this, name ); + if ( !instance ) { + throw "cannot call methods on " + name + " prior to initialization; " + + "attempted to call method '" + options + "'"; + } + if ( !$.isFunction( instance[options] ) ) { + throw "no such method '" + options + "' for " + name + " widget instance"; + } + var methodValue = instance[ options ].apply( instance, args ); + if ( methodValue !== instance && methodValue !== undefined ) { + returnValue = methodValue; + return false; + } + }); + } else { + this.each(function() { + var instance = $.data( this, name ); + if ( instance ) { + instance.option( options || {} )._init(); + } else { + $.data( this, name, new object( options, this ) ); + } + }); + } + + return returnValue; + }; + }; + +})( jQuery ); \ No newline at end of file