2 * jQuery UI Widget 1.8.18+amd
3 * https://github.com/blueimp/jQuery-File-Upload
5 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
6 * Dual licensed under the MIT or GPL Version 2 licenses.
7 * http://jquery.org/license
9 * http://docs.jquery.com/UI/Widget
13 if (typeof define === "function" && define.amd) {
14 // Register as an anonymous AMD module:
15 define(["jquery"], factory);
20 }(function( $, undefined ) {
24 var _cleanData = $.cleanData;
25 $.cleanData = function( elems ) {
26 for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
28 $( elem ).triggerHandler( "remove" );
29 // http://bugs.jquery.com/ticket/8235
35 var _remove = $.fn.remove;
36 $.fn.remove = function( selector, keepData ) {
37 return this.each(function() {
39 if ( !selector || $.filter( selector, [ this ] ).length ) {
40 $( "*", this ).add( [ this ] ).each(function() {
42 $( this ).triggerHandler( "remove" );
43 // http://bugs.jquery.com/ticket/8235
48 return _remove.call( $(this), selector, keepData );
53 $.widget = function( name, base, prototype ) {
54 var namespace = name.split( "." )[ 0 ],
56 name = name.split( "." )[ 1 ];
57 fullName = namespace + "-" + name;
64 // create selector for plugin
65 $.expr[ ":" ][ fullName ] = function( elem ) {
66 return !!$.data( elem, name );
69 $[ namespace ] = $[ namespace ] || {};
70 $[ namespace ][ name ] = function( options, element ) {
71 // allow instantiation without initializing for simple inheritance
72 if ( arguments.length ) {
73 this._createWidget( options, element );
77 var basePrototype = new base();
78 // we need to make the options hash a property directly on the new instance
79 // otherwise we'll modify the options hash on the prototype that we're
81 // $.each( basePrototype, function( key, val ) {
82 // if ( $.isPlainObject(val) ) {
83 // basePrototype[ key ] = $.extend( {}, val );
86 basePrototype.options = $.extend( true, {}, basePrototype.options );
87 $[ namespace ][ name ].prototype = $.extend( true, basePrototype, {
90 widgetEventPrefix: $[ namespace ][ name ].prototype.widgetEventPrefix || name,
91 widgetBaseClass: fullName
94 $.widget.bridge( name, $[ namespace ][ name ] );
97 $.widget.bridge = function( name, object ) {
98 $.fn[ name ] = function( options ) {
99 var isMethodCall = typeof options === "string",
100 args = Array.prototype.slice.call( arguments, 1 ),
103 // allow multiple hashes to be passed on init
104 options = !isMethodCall && args.length ?
105 $.extend.apply( null, [ true, options ].concat(args) ) :
108 // prevent calls to internal methods
109 if ( isMethodCall && options.charAt( 0 ) === "_" ) {
113 if ( isMethodCall ) {
114 this.each(function() {
115 var instance = $.data( this, name ),
116 methodValue = instance && $.isFunction( instance[options] ) ?
117 instance[ options ].apply( instance, args ) :
119 // TODO: add this back in 1.9 and use $.error() (see #5972)
120 // if ( !instance ) {
121 // throw "cannot call methods on " + name + " prior to initialization; " +
122 // "attempted to call method '" + options + "'";
124 // if ( !$.isFunction( instance[options] ) ) {
125 // throw "no such method '" + options + "' for " + name + " widget instance";
127 // var methodValue = instance[ options ].apply( instance, args );
128 if ( methodValue !== instance && methodValue !== undefined ) {
129 returnValue = methodValue;
134 this.each(function() {
135 var instance = $.data( this, name );
137 instance.option( options || {} )._init();
139 $.data( this, name, new object( options, this ) );
148 $.Widget = function( options, element ) {
149 // allow instantiation without initializing for simple inheritance
150 if ( arguments.length ) {
151 this._createWidget( options, element );
155 $.Widget.prototype = {
156 widgetName: "widget",
157 widgetEventPrefix: "",
161 _createWidget: function( options, element ) {
162 // $.widget.bridge stores the plugin instance, but we do it anyway
163 // so that it's stored even before the _create function runs
164 $.data( element, this.widgetName, this );
165 this.element = $( element );
166 this.options = $.extend( true, {},
168 this._getCreateOptions(),
172 this.element.bind( "remove." + this.widgetName, function() {
177 this._trigger( "create" );
180 _getCreateOptions: function() {
181 return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ];
183 _create: function() {},
184 _init: function() {},
186 destroy: function() {
188 .unbind( "." + this.widgetName )
189 .removeData( this.widgetName );
191 .unbind( "." + this.widgetName )
192 .removeAttr( "aria-disabled" )
194 this.widgetBaseClass + "-disabled " +
195 "ui-state-disabled" );
202 option: function( key, value ) {
205 if ( arguments.length === 0 ) {
206 // don't return a reference to the internal hash
207 return $.extend( {}, this.options );
210 if (typeof key === "string" ) {
211 if ( value === undefined ) {
212 return this.options[ key ];
215 options[ key ] = value;
218 this._setOptions( options );
222 _setOptions: function( options ) {
224 $.each( options, function( key, value ) {
225 self._setOption( key, value );
230 _setOption: function( key, value ) {
231 this.options[ key ] = value;
233 if ( key === "disabled" ) {
235 [ value ? "addClass" : "removeClass"](
236 this.widgetBaseClass + "-disabled" + " " +
237 "ui-state-disabled" )
238 .attr( "aria-disabled", value );
245 return this._setOption( "disabled", false );
247 disable: function() {
248 return this._setOption( "disabled", true );
251 _trigger: function( type, event, data ) {
253 callback = this.options[ type ];
256 event = $.Event( event );
257 event.type = ( type === this.widgetEventPrefix ?
259 this.widgetEventPrefix + type ).toLowerCase();
260 // the original event may come from any element
261 // so we need to reset the target on the new event
262 event.target = this.element[ 0 ];
264 // copy original event properties over to the new event
265 orig = event.originalEvent;
267 for ( prop in orig ) {
268 if ( !( prop in event ) ) {
269 event[ prop ] = orig[ prop ];
274 this.element.trigger( event, data );
276 return !( $.isFunction(callback) &&
277 callback.call( this.element[0], event, data ) === false ||
278 event.isDefaultPrevented() );