comparison PalanthirExplorer/libs/jquery-file-upload/js/vendor/jquery.ui.widget.js @ 45:33d67e1ab173

r
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Sep 2012 13:24:59 +0200
parents PalantirExplorer/libs/jquery-file-upload/js/vendor/jquery.ui.widget.js@3959d33612cc
children
comparison
equal deleted inserted replaced
43:9be852ad33d2 45:33d67e1ab173
1 /*
2 * jQuery UI Widget 1.8.18+amd
3 * https://github.com/blueimp/jQuery-File-Upload
4 *
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
8 *
9 * http://docs.jquery.com/UI/Widget
10 */
11
12 (function (factory) {
13 if (typeof define === "function" && define.amd) {
14 // Register as an anonymous AMD module:
15 define(["jquery"], factory);
16 } else {
17 // Browser globals:
18 factory(jQuery);
19 }
20 }(function( $, undefined ) {
21
22 // jQuery 1.4+
23 if ( $.cleanData ) {
24 var _cleanData = $.cleanData;
25 $.cleanData = function( elems ) {
26 for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
27 try {
28 $( elem ).triggerHandler( "remove" );
29 // http://bugs.jquery.com/ticket/8235
30 } catch( e ) {}
31 }
32 _cleanData( elems );
33 };
34 } else {
35 var _remove = $.fn.remove;
36 $.fn.remove = function( selector, keepData ) {
37 return this.each(function() {
38 if ( !keepData ) {
39 if ( !selector || $.filter( selector, [ this ] ).length ) {
40 $( "*", this ).add( [ this ] ).each(function() {
41 try {
42 $( this ).triggerHandler( "remove" );
43 // http://bugs.jquery.com/ticket/8235
44 } catch( e ) {}
45 });
46 }
47 }
48 return _remove.call( $(this), selector, keepData );
49 });
50 };
51 }
52
53 $.widget = function( name, base, prototype ) {
54 var namespace = name.split( "." )[ 0 ],
55 fullName;
56 name = name.split( "." )[ 1 ];
57 fullName = namespace + "-" + name;
58
59 if ( !prototype ) {
60 prototype = base;
61 base = $.Widget;
62 }
63
64 // create selector for plugin
65 $.expr[ ":" ][ fullName ] = function( elem ) {
66 return !!$.data( elem, name );
67 };
68
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 );
74 }
75 };
76
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
80 // inheriting from
81 // $.each( basePrototype, function( key, val ) {
82 // if ( $.isPlainObject(val) ) {
83 // basePrototype[ key ] = $.extend( {}, val );
84 // }
85 // });
86 basePrototype.options = $.extend( true, {}, basePrototype.options );
87 $[ namespace ][ name ].prototype = $.extend( true, basePrototype, {
88 namespace: namespace,
89 widgetName: name,
90 widgetEventPrefix: $[ namespace ][ name ].prototype.widgetEventPrefix || name,
91 widgetBaseClass: fullName
92 }, prototype );
93
94 $.widget.bridge( name, $[ namespace ][ name ] );
95 };
96
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 ),
101 returnValue = this;
102
103 // allow multiple hashes to be passed on init
104 options = !isMethodCall && args.length ?
105 $.extend.apply( null, [ true, options ].concat(args) ) :
106 options;
107
108 // prevent calls to internal methods
109 if ( isMethodCall && options.charAt( 0 ) === "_" ) {
110 return returnValue;
111 }
112
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 ) :
118 instance;
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 + "'";
123 // }
124 // if ( !$.isFunction( instance[options] ) ) {
125 // throw "no such method '" + options + "' for " + name + " widget instance";
126 // }
127 // var methodValue = instance[ options ].apply( instance, args );
128 if ( methodValue !== instance && methodValue !== undefined ) {
129 returnValue = methodValue;
130 return false;
131 }
132 });
133 } else {
134 this.each(function() {
135 var instance = $.data( this, name );
136 if ( instance ) {
137 instance.option( options || {} )._init();
138 } else {
139 $.data( this, name, new object( options, this ) );
140 }
141 });
142 }
143
144 return returnValue;
145 };
146 };
147
148 $.Widget = function( options, element ) {
149 // allow instantiation without initializing for simple inheritance
150 if ( arguments.length ) {
151 this._createWidget( options, element );
152 }
153 };
154
155 $.Widget.prototype = {
156 widgetName: "widget",
157 widgetEventPrefix: "",
158 options: {
159 disabled: false
160 },
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, {},
167 this.options,
168 this._getCreateOptions(),
169 options );
170
171 var self = this;
172 this.element.bind( "remove." + this.widgetName, function() {
173 self.destroy();
174 });
175
176 this._create();
177 this._trigger( "create" );
178 this._init();
179 },
180 _getCreateOptions: function() {
181 return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ];
182 },
183 _create: function() {},
184 _init: function() {},
185
186 destroy: function() {
187 this.element
188 .unbind( "." + this.widgetName )
189 .removeData( this.widgetName );
190 this.widget()
191 .unbind( "." + this.widgetName )
192 .removeAttr( "aria-disabled" )
193 .removeClass(
194 this.widgetBaseClass + "-disabled " +
195 "ui-state-disabled" );
196 },
197
198 widget: function() {
199 return this.element;
200 },
201
202 option: function( key, value ) {
203 var options = key;
204
205 if ( arguments.length === 0 ) {
206 // don't return a reference to the internal hash
207 return $.extend( {}, this.options );
208 }
209
210 if (typeof key === "string" ) {
211 if ( value === undefined ) {
212 return this.options[ key ];
213 }
214 options = {};
215 options[ key ] = value;
216 }
217
218 this._setOptions( options );
219
220 return this;
221 },
222 _setOptions: function( options ) {
223 var self = this;
224 $.each( options, function( key, value ) {
225 self._setOption( key, value );
226 });
227
228 return this;
229 },
230 _setOption: function( key, value ) {
231 this.options[ key ] = value;
232
233 if ( key === "disabled" ) {
234 this.widget()
235 [ value ? "addClass" : "removeClass"](
236 this.widgetBaseClass + "-disabled" + " " +
237 "ui-state-disabled" )
238 .attr( "aria-disabled", value );
239 }
240
241 return this;
242 },
243
244 enable: function() {
245 return this._setOption( "disabled", false );
246 },
247 disable: function() {
248 return this._setOption( "disabled", true );
249 },
250
251 _trigger: function( type, event, data ) {
252 var prop, orig,
253 callback = this.options[ type ];
254
255 data = data || {};
256 event = $.Event( event );
257 event.type = ( type === this.widgetEventPrefix ?
258 type :
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 ];
263
264 // copy original event properties over to the new event
265 orig = event.originalEvent;
266 if ( orig ) {
267 for ( prop in orig ) {
268 if ( !( prop in event ) ) {
269 event[ prop ] = orig[ prop ];
270 }
271 }
272 }
273
274 this.element.trigger( event, data );
275
276 return !( $.isFunction(callback) &&
277 callback.call( this.element[0], event, data ) === false ||
278 event.isDefaultPrevented() );
279 }
280 };
281
282 }));