Subversion Repositories Sites.obs-saisons.fr

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
40 aurelien 1
/*!
2
 * jQuery UI Widget 1.8.5
3
 *
4
 * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
5
 * Dual licensed under the MIT or GPL Version 2 licenses.
6
 * http://jquery.org/license
7
 *
8
 * http://docs.jquery.com/UI/Widget
9
 */
10
(function( $, undefined ) {
11
 
12
// jQuery 1.4+
13
if ( $.cleanData ) {
14
	var _cleanData = $.cleanData;
15
	$.cleanData = function( elems ) {
16
		for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
17
			$( elem ).triggerHandler( "remove" );
18
		}
19
		_cleanData( elems );
20
	};
21
} else {
22
	var _remove = $.fn.remove;
23
	$.fn.remove = function( selector, keepData ) {
24
		return this.each(function() {
25
			if ( !keepData ) {
26
				if ( !selector || $.filter( selector, [ this ] ).length ) {
27
					$( "*", this ).add( [ this ] ).each(function() {
28
						$( this ).triggerHandler( "remove" );
29
					});
30
				}
31
			}
32
			return _remove.call( $(this), selector, keepData );
33
		});
34
	};
35
}
36
 
37
$.widget = function( name, base, prototype ) {
38
	var namespace = name.split( "." )[ 0 ],
39
		fullName;
40
	name = name.split( "." )[ 1 ];
41
	fullName = namespace + "-" + name;
42
 
43
	if ( !prototype ) {
44
		prototype = base;
45
		base = $.Widget;
46
	}
47
 
48
	// create selector for plugin
49
	$.expr[ ":" ][ fullName ] = function( elem ) {
50
		return !!$.data( elem, name );
51
	};
52
 
53
	$[ namespace ] = $[ namespace ] || {};
54
	$[ namespace ][ name ] = function( options, element ) {
55
		// allow instantiation without initializing for simple inheritance
56
		if ( arguments.length ) {
57
			this._createWidget( options, element );
58
		}
59
	};
60
 
61
	var basePrototype = new base();
62
	// we need to make the options hash a property directly on the new instance
63
	// otherwise we'll modify the options hash on the prototype that we're
64
	// inheriting from
65
//	$.each( basePrototype, function( key, val ) {
66
//		if ( $.isPlainObject(val) ) {
67
//			basePrototype[ key ] = $.extend( {}, val );
68
//		}
69
//	});
70
	basePrototype.options = $.extend( true, {}, basePrototype.options );
71
	$[ namespace ][ name ].prototype = $.extend( true, basePrototype, {
72
		namespace: namespace,
73
		widgetName: name,
74
		widgetEventPrefix: $[ namespace ][ name ].prototype.widgetEventPrefix || name,
75
		widgetBaseClass: fullName
76
	}, prototype );
77
 
78
	$.widget.bridge( name, $[ namespace ][ name ] );
79
};
80
 
81
$.widget.bridge = function( name, object ) {
82
	$.fn[ name ] = function( options ) {
83
		var isMethodCall = typeof options === "string",
84
			args = Array.prototype.slice.call( arguments, 1 ),
85
			returnValue = this;
86
 
87
		// allow multiple hashes to be passed on init
88
		options = !isMethodCall && args.length ?
89
			$.extend.apply( null, [ true, options ].concat(args) ) :
90
			options;
91
 
92
		// prevent calls to internal methods
93
		if ( isMethodCall && options.substring( 0, 1 ) === "_" ) {
94
			return returnValue;
95
		}
96
 
97
		if ( isMethodCall ) {
98
			this.each(function() {
99
				var instance = $.data( this, name );
100
				if ( !instance ) {
101
					throw "cannot call methods on " + name + " prior to initialization; " +
102
						"attempted to call method '" + options + "'";
103
				}
104
				if ( !$.isFunction( instance[options] ) ) {
105
					throw "no such method '" + options + "' for " + name + " widget instance";
106
				}
107
				var methodValue = instance[ options ].apply( instance, args );
108
				if ( methodValue !== instance && methodValue !== undefined ) {
109
					returnValue = methodValue;
110
					return false;
111
				}
112
			});
113
		} else {
114
			this.each(function() {
115
				var instance = $.data( this, name );
116
				if ( instance ) {
117
					instance.option( options || {} )._init();
118
				} else {
119
					$.data( this, name, new object( options, this ) );
120
				}
121
			});
122
		}
123
 
124
		return returnValue;
125
	};
126
};
127
 
128
$.Widget = function( options, element ) {
129
	// allow instantiation without initializing for simple inheritance
130
	if ( arguments.length ) {
131
		this._createWidget( options, element );
132
	}
133
};
134
 
135
$.Widget.prototype = {
136
	widgetName: "widget",
137
	widgetEventPrefix: "",
138
	options: {
139
		disabled: false
140
	},
141
	_createWidget: function( options, element ) {
142
		// $.widget.bridge stores the plugin instance, but we do it anyway
143
		// so that it's stored even before the _create function runs
144
		$.data( element, this.widgetName, this );
145
		this.element = $( element );
146
		this.options = $.extend( true, {},
147
			this.options,
148
			$.metadata && $.metadata.get( element )[ this.widgetName ],
149
			options );
150
 
151
		var self = this;
152
		this.element.bind( "remove." + this.widgetName, function() {
153
			self.destroy();
154
		});
155
 
156
		this._create();
157
		this._init();
158
	},
159
	_create: function() {},
160
	_init: function() {},
161
 
162
	destroy: function() {
163
		this.element
164
			.unbind( "." + this.widgetName )
165
			.removeData( this.widgetName );
166
		this.widget()
167
			.unbind( "." + this.widgetName )
168
			.removeAttr( "aria-disabled" )
169
			.removeClass(
170
				this.widgetBaseClass + "-disabled " +
171
				"ui-state-disabled" );
172
	},
173
 
174
	widget: function() {
175
		return this.element;
176
	},
177
 
178
	option: function( key, value ) {
179
		var options = key,
180
			self = this;
181
 
182
		if ( arguments.length === 0 ) {
183
			// don't return a reference to the internal hash
184
			return $.extend( {}, self.options );
185
		}
186
 
187
		if  (typeof key === "string" ) {
188
			if ( value === undefined ) {
189
				return this.options[ key ];
190
			}
191
			options = {};
192
			options[ key ] = value;
193
		}
194
 
195
		$.each( options, function( key, value ) {
196
			self._setOption( key, value );
197
		});
198
 
199
		return self;
200
	},
201
	_setOption: function( key, value ) {
202
		this.options[ key ] = value;
203
 
204
		if ( key === "disabled" ) {
205
			this.widget()
206
				[ value ? "addClass" : "removeClass"](
207
					this.widgetBaseClass + "-disabled" + " " +
208
					"ui-state-disabled" )
209
				.attr( "aria-disabled", value );
210
		}
211
 
212
		return this;
213
	},
214
 
215
	enable: function() {
216
		return this._setOption( "disabled", false );
217
	},
218
	disable: function() {
219
		return this._setOption( "disabled", true );
220
	},
221
 
222
	_trigger: function( type, event, data ) {
223
		var callback = this.options[ type ];
224
 
225
		event = $.Event( event );
226
		event.type = ( type === this.widgetEventPrefix ?
227
			type :
228
			this.widgetEventPrefix + type ).toLowerCase();
229
		data = data || {};
230
 
231
		// copy original event properties over to the new event
232
		// this would happen if we could call $.event.fix instead of $.Event
233
		// but we don't have a way to force an event to be fixed multiple times
234
		if ( event.originalEvent ) {
235
			for ( var i = $.event.props.length, prop; i; ) {
236
				prop = $.event.props[ --i ];
237
				event[ prop ] = event.originalEvent[ prop ];
238
			}
239
		}
240
 
241
		this.element.trigger( event, data );
242
 
243
		return !( $.isFunction(callback) &&
244
			callback.call( this.element[0], event, data ) === false ||
245
			event.isDefaultPrevented() );
246
	}
247
};
248
 
249
})( jQuery );