text changes to registration mail content
[namibia] / public / js / vendor / jquery.ui.widget.js
1 /*
2  * jQuery UI Widget 1.9.1+amd
3  * https://github.com/blueimp/jQuery-File-Upload
4  *
5  * Copyright 2012 jQuery Foundation and other contributors
6  * Released under the MIT license.
7  * http://jquery.org/license
8  *
9  * http://api.jqueryui.com/jQuery.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 var uuid = 0,
23         slice = Array.prototype.slice,
24         _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
35 $.widget = function( name, base, prototype ) {
36         var fullName, existingConstructor, constructor, basePrototype,
37                 namespace = name.split( "." )[ 0 ];
38
39         name = name.split( "." )[ 1 ];
40         fullName = namespace + "-" + name;
41
42         if ( !prototype ) {
43                 prototype = base;
44                 base = $.Widget;
45         }
46
47         // create selector for plugin
48         $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
49                 return !!$.data( elem, fullName );
50         };
51
52         $[ namespace ] = $[ namespace ] || {};
53         existingConstructor = $[ namespace ][ name ];
54         constructor = $[ namespace ][ name ] = function( options, element ) {
55                 // allow instantiation without "new" keyword
56                 if ( !this._createWidget ) {
57                         return new constructor( options, element );
58                 }
59
60                 // allow instantiation without initializing for simple inheritance
61                 // must use "new" keyword (the code above always passes args)
62                 if ( arguments.length ) {
63                         this._createWidget( options, element );
64                 }
65         };
66         // extend with the existing constructor to carry over any static properties
67         $.extend( constructor, existingConstructor, {
68                 version: prototype.version,
69                 // copy the object used to create the prototype in case we need to
70                 // redefine the widget later
71                 _proto: $.extend( {}, prototype ),
72                 // track widgets that inherit from this widget in case this widget is
73                 // redefined after a widget inherits from it
74                 _childConstructors: []
75         });
76
77         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         basePrototype.options = $.widget.extend( {}, basePrototype.options );
82         $.each( prototype, function( prop, value ) {
83                 if ( $.isFunction( value ) ) {
84                         prototype[ prop ] = (function() {
85                                 var _super = function() {
86                                                 return base.prototype[ prop ].apply( this, arguments );
87                                         },
88                                         _superApply = function( args ) {
89                                                 return base.prototype[ prop ].apply( this, args );
90                                         };
91                                 return function() {
92                                         var __super = this._super,
93                                                 __superApply = this._superApply,
94                                                 returnValue;
95
96                                         this._super = _super;
97                                         this._superApply = _superApply;
98
99                                         returnValue = value.apply( this, arguments );
100
101                                         this._super = __super;
102                                         this._superApply = __superApply;
103
104                                         return returnValue;
105                                 };
106                         })();
107                 }
108         });
109         constructor.prototype = $.widget.extend( basePrototype, {
110                 // TODO: remove support for widgetEventPrefix
111                 // always use the name + a colon as the prefix, e.g., draggable:start
112                 // don't prefix for widgets that aren't DOM-based
113                 widgetEventPrefix: basePrototype.widgetEventPrefix || name
114         }, prototype, {
115                 constructor: constructor,
116                 namespace: namespace,
117                 widgetName: name,
118                 // TODO remove widgetBaseClass, see #8155
119                 widgetBaseClass: fullName,
120                 widgetFullName: fullName
121         });
122
123         // If this widget is being redefined then we need to find all widgets that
124         // are inheriting from it and redefine all of them so that they inherit from
125         // the new version of this widget. We're essentially trying to replace one
126         // level in the prototype chain.
127         if ( existingConstructor ) {
128                 $.each( existingConstructor._childConstructors, function( i, child ) {
129                         var childPrototype = child.prototype;
130
131                         // redefine the child widget using the same prototype that was
132                         // originally used, but inherit from the new version of the base
133                         $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
134                 });
135                 // remove the list of existing child constructors from the old constructor
136                 // so the old child constructors can be garbage collected
137                 delete existingConstructor._childConstructors;
138         } else {
139                 base._childConstructors.push( constructor );
140         }
141
142         $.widget.bridge( name, constructor );
143 };
144
145 $.widget.extend = function( target ) {
146         var input = slice.call( arguments, 1 ),
147                 inputIndex = 0,
148                 inputLength = input.length,
149                 key,
150                 value;
151         for ( ; inputIndex < inputLength; inputIndex++ ) {
152                 for ( key in input[ inputIndex ] ) {
153                         value = input[ inputIndex ][ key ];
154                         if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
155                                 // Clone objects
156                                 if ( $.isPlainObject( value ) ) {
157                                         target[ key ] = $.isPlainObject( target[ key ] ) ?
158                                                 $.widget.extend( {}, target[ key ], value ) :
159                                                 // Don't extend strings, arrays, etc. with objects
160                                                 $.widget.extend( {}, value );
161                                 // Copy everything else by reference
162                                 } else {
163                                         target[ key ] = value;
164                                 }
165                         }
166                 }
167         }
168         return target;
169 };
170
171 $.widget.bridge = function( name, object ) {
172         var fullName = object.prototype.widgetFullName;
173         $.fn[ name ] = function( options ) {
174                 var isMethodCall = typeof options === "string",
175                         args = slice.call( arguments, 1 ),
176                         returnValue = this;
177
178                 // allow multiple hashes to be passed on init
179                 options = !isMethodCall && args.length ?
180                         $.widget.extend.apply( null, [ options ].concat(args) ) :
181                         options;
182
183                 if ( isMethodCall ) {
184                         this.each(function() {
185                                 var methodValue,
186                                         instance = $.data( this, fullName );
187                                 if ( !instance ) {
188                                         return $.error( "cannot call methods on " + name + " prior to initialization; " +
189                                                 "attempted to call method '" + options + "'" );
190                                 }
191                                 if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
192                                         return $.error( "no such method '" + options + "' for " + name + " widget instance" );
193                                 }
194                                 methodValue = instance[ options ].apply( instance, args );
195                                 if ( methodValue !== instance && methodValue !== undefined ) {
196                                         returnValue = methodValue && methodValue.jquery ?
197                                                 returnValue.pushStack( methodValue.get() ) :
198                                                 methodValue;
199                                         return false;
200                                 }
201                         });
202                 } else {
203                         this.each(function() {
204                                 var instance = $.data( this, fullName );
205                                 if ( instance ) {
206                                         instance.option( options || {} )._init();
207                                 } else {
208                                         new object( options, this );
209                                 }
210                         });
211                 }
212
213                 return returnValue;
214         };
215 };
216
217 $.Widget = function( /* options, element */ ) {};
218 $.Widget._childConstructors = [];
219
220 $.Widget.prototype = {
221         widgetName: "widget",
222         widgetEventPrefix: "",
223         defaultElement: "<div>",
224         options: {
225                 disabled: false,
226
227                 // callbacks
228                 create: null
229         },
230         _createWidget: function( options, element ) {
231                 try {
232                 element = $( element || this.defaultElement || this )[ 0 ];
233                 this.element = $( element );
234                 this.uuid = uuid++;
235                 this.eventNamespace = "." + this.widgetName + this.uuid;
236                 this.options = $.widget.extend( {},
237                         this.options,
238                         this._getCreateOptions(),
239                         options );
240
241                 this.bindings = $();
242                 this.hoverable = $();
243                 this.focusable = $();
244
245                 if ( element !== this ) {
246                         // 1.9 BC for #7810
247                         // TODO remove dual storage
248                         $.data( element, this.widgetName, this );
249                         $.data( element, this.widgetFullName, this );
250                         this._on( this.element, {
251                                 remove: function( event ) {
252                                         if ( event.target === element ) {
253                                                 this.destroy();
254                                         }
255                                 }
256                         });
257                         this.document = $( element.style ?
258                                 // element within the document
259                                 element.ownerDocument :
260                                 // element is window or document
261                                 element.document || element );
262                         this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
263                 }
264
265                 this._create();
266                 this._trigger( "create", null, this._getCreateEventData() );
267                 this._init();
268                 } catch(e) {}
269         },
270         _getCreateOptions: $.noop,
271         _getCreateEventData: $.noop,
272         _create: $.noop,
273         _init: $.noop,
274
275         destroy: function() {
276                 this._destroy();
277                 // we can probably remove the unbind calls in 2.0
278                 // all event bindings should go through this._on()
279                 this.element
280                         .unbind( this.eventNamespace )
281                         // 1.9 BC for #7810
282                         // TODO remove dual storage
283                         .removeData( this.widgetName )
284                         .removeData( this.widgetFullName )
285                         // support: jquery <1.6.3
286                         // http://bugs.jquery.com/ticket/9413
287                         .removeData( $.camelCase( this.widgetFullName ) );
288                 this.widget()
289                         .unbind( this.eventNamespace )
290                         .removeAttr( "aria-disabled" )
291                         .removeClass(
292                                 this.widgetFullName + "-disabled " +
293                                 "ui-state-disabled" );
294
295                 // clean up events and states
296                 this.bindings.unbind( this.eventNamespace );
297                 this.hoverable.removeClass( "ui-state-hover" );
298                 this.focusable.removeClass( "ui-state-focus" );
299         },
300         _destroy: $.noop,
301
302         widget: function() {
303                 return this.element;
304         },
305
306         option: function( key, value ) {
307                 var options = key,
308                         parts,
309                         curOption,
310                         i;
311
312                 if ( arguments.length === 0 ) {
313                         // don't return a reference to the internal hash
314                         return $.widget.extend( {}, this.options );
315                 }
316
317                 if ( typeof key === "string" ) {
318                         // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
319                         options = {};
320                         parts = key.split( "." );
321                         key = parts.shift();
322                         if ( parts.length ) {
323                                 curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
324                                 for ( i = 0; i < parts.length - 1; i++ ) {
325                                         curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
326                                         curOption = curOption[ parts[ i ] ];
327                                 }
328                                 key = parts.pop();
329                                 if ( value === undefined ) {
330                                         return curOption[ key ] === undefined ? null : curOption[ key ];
331                                 }
332                                 curOption[ key ] = value;
333                         } else {
334                                 if ( value === undefined ) {
335                                         return this.options[ key ] === undefined ? null : this.options[ key ];
336                                 }
337                                 options[ key ] = value;
338                         }
339                 }
340
341                 this._setOptions( options );
342
343                 return this;
344         },
345         _setOptions: function( options ) {
346                 var key;
347
348                 for ( key in options ) {
349                         this._setOption( key, options[ key ] );
350                 }
351
352                 return this;
353         },
354         _setOption: function( key, value ) {
355                 this.options[ key ] = value;
356
357                 if ( key === "disabled" ) {
358                         this.widget()
359                                 .toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value )
360                                 .attr( "aria-disabled", value );
361                         this.hoverable.removeClass( "ui-state-hover" );
362                         this.focusable.removeClass( "ui-state-focus" );
363                 }
364
365                 return this;
366         },
367
368         enable: function() {
369                 return this._setOption( "disabled", false );
370         },
371         disable: function() {
372                 return this._setOption( "disabled", true );
373         },
374
375         _on: function( element, handlers ) {
376                 var delegateElement,
377                         instance = this;
378                 // no element argument, shuffle and use this.element
379                 if ( !handlers ) {
380                         handlers = element;
381                         element = this.element;
382                         delegateElement = this.widget();
383                 } else {
384                         // accept selectors, DOM elements
385                         element = delegateElement = $( element );
386                         this.bindings = this.bindings.add( element );
387                 }
388
389                 $.each( handlers, function( event, handler ) {
390                         function handlerProxy() {
391                                 // allow widgets to customize the disabled handling
392                                 // - disabled as an array instead of boolean
393                                 // - disabled class as method for disabling individual parts
394                                 if ( instance.options.disabled === true ||
395                                                 $( this ).hasClass( "ui-state-disabled" ) ) {
396                                         return;
397                                 }
398                                 return ( typeof handler === "string" ? instance[ handler ] : handler )
399                                         .apply( instance, arguments );
400                         }
401
402                         // copy the guid so direct unbinding works
403                         if ( typeof handler !== "string" ) {
404                                 handlerProxy.guid = handler.guid =
405                                         handler.guid || handlerProxy.guid || $.guid++;
406                         }
407
408                         var match = event.match( /^(\w+)\s*(.*)$/ ),
409                                 eventName = match[1] + instance.eventNamespace,
410                                 selector = match[2];
411                         if ( selector ) {
412                                 delegateElement.delegate( selector, eventName, handlerProxy );
413                         } else {
414                                 element.bind( eventName, handlerProxy );
415                         }
416                 });
417         },
418
419         _off: function( element, eventName ) {
420                 eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
421                 element.unbind( eventName ).undelegate( eventName );
422         },
423
424         _delay: function( handler, delay ) {
425                 function handlerProxy() {
426                         return ( typeof handler === "string" ? instance[ handler ] : handler )
427                                 .apply( instance, arguments );
428                 }
429                 var instance = this;
430                 return setTimeout( handlerProxy, delay || 0 );
431         },
432
433         _hoverable: function( element ) {
434                 this.hoverable = this.hoverable.add( element );
435                 this._on( element, {
436                         mouseenter: function( event ) {
437                                 $( event.currentTarget ).addClass( "ui-state-hover" );
438                         },
439                         mouseleave: function( event ) {
440                                 $( event.currentTarget ).removeClass( "ui-state-hover" );
441                         }
442                 });
443         },
444
445         _focusable: function( element ) {
446                 this.focusable = this.focusable.add( element );
447                 this._on( element, {
448                         focusin: function( event ) {
449                                 $( event.currentTarget ).addClass( "ui-state-focus" );
450                         },
451                         focusout: function( event ) {
452                                 $( event.currentTarget ).removeClass( "ui-state-focus" );
453                         }
454                 });
455         },
456
457         _trigger: function( type, event, data ) {
458                 var prop, orig,
459                         callback = this.options[ type ];
460
461                 data = data || {};
462                 event = $.Event( event );
463                 event.type = ( type === this.widgetEventPrefix ?
464                         type :
465                         this.widgetEventPrefix + type ).toLowerCase();
466                 // the original event may come from any element
467                 // so we need to reset the target on the new event
468                 event.target = this.element[ 0 ];
469
470                 // copy original event properties over to the new event
471                 orig = event.originalEvent;
472                 if ( orig ) {
473                         for ( prop in orig ) {
474                                 if ( !( prop in event ) ) {
475                                         event[ prop ] = orig[ prop ];
476                                 }
477                         }
478                 }
479
480                 this.element.trigger( event, data );
481                 return !( $.isFunction( callback ) &&
482                         callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
483                         event.isDefaultPrevented() );
484         }
485 };
486
487 $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
488         $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
489                 if ( typeof options === "string" ) {
490                         options = { effect: options };
491                 }
492                 var hasOptions,
493                         effectName = !options ?
494                                 method :
495                                 options === true || typeof options === "number" ?
496                                         defaultEffect :
497                                         options.effect || defaultEffect;
498                 options = options || {};
499                 if ( typeof options === "number" ) {
500                         options = { duration: options };
501                 }
502                 hasOptions = !$.isEmptyObject( options );
503                 options.complete = callback;
504                 if ( options.delay ) {
505                         element.delay( options.delay );
506                 }
507                 if ( hasOptions && $.effects && ( $.effects.effect[ effectName ] || $.uiBackCompat !== false && $.effects[ effectName ] ) ) {
508                         element[ method ]( options );
509                 } else if ( effectName !== method && element[ effectName ] ) {
510                         element[ effectName ]( options.duration, options.easing, callback );
511                 } else {
512                         element.queue(function( next ) {
513                                 $( this )[ method ]();
514                                 if ( callback ) {
515                                         callback.call( element[ 0 ] );
516                                 }
517                                 next();
518                         });
519                 }
520         };
521 });
522
523 // DEPRECATED
524 if ( $.uiBackCompat !== false ) {
525         $.Widget.prototype._getCreateOptions = function() {
526                 return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ];
527         };
528 }
529
530 }));