Projet

Général

Profil

Révision 503b3f7b

Ajouté par Assos Assos il y a environ 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/jquery_update/replace/ui/ui/jquery.ui.dialog.js
1
/*
2
 * jQuery UI Dialog 1.8.11
1
/*!
2
 * jQuery UI Dialog 1.10.2
3
 * http://jqueryui.com
3 4
 *
4
 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
5
 * Dual licensed under the MIT or GPL Version 2 licenses.
5
 * Copyright 2013 jQuery Foundation and other contributors
6
 * Released under the MIT license.
6 7
 * http://jquery.org/license
7 8
 *
8
 * http://docs.jquery.com/UI/Dialog
9
 * http://api.jqueryui.com/dialog/
9 10
 *
10 11
 * Depends:
11 12
 *	jquery.ui.core.js
......
18 19
 */
19 20
(function( $, undefined ) {
20 21

  
21
var uiDialogClasses =
22
		'ui-dialog ' +
23
		'ui-widget ' +
24
		'ui-widget-content ' +
25
		'ui-corner-all ',
26
	sizeRelatedOptions = {
22
var sizeRelatedOptions = {
27 23
		buttons: true,
28 24
		height: true,
29 25
		maxHeight: true,
......
39 35
		minWidth: true
40 36
	};
41 37

  
42
$.widget("ui.dialog", {
38
$.widget( "ui.dialog", {
39
	version: "1.10.2",
43 40
	options: {
41
		appendTo: "body",
44 42
		autoOpen: true,
45
		buttons: {},
43
		buttons: [],
46 44
		closeOnEscape: true,
47
		closeText: 'close',
48
		dialogClass: '',
45
		closeText: "close",
46
		dialogClass: "",
49 47
		draggable: true,
50 48
		hide: null,
51
		height: 'auto',
52
		maxHeight: false,
53
		maxWidth: false,
49
		height: "auto",
50
		maxHeight: null,
51
		maxWidth: null,
54 52
		minHeight: 150,
55 53
		minWidth: 150,
56 54
		modal: false,
57 55
		position: {
58
			my: 'center',
59
			at: 'center',
60
			collision: 'fit',
61
			// ensure that the titlebar is never outside the document
62
			using: function(pos) {
63
				var topOffset = $(this).css(pos).offset().top;
64
				if (topOffset < 0) {
65
					$(this).css('top', pos.top - topOffset);
56
			my: "center",
57
			at: "center",
58
			of: window,
59
			collision: "fit",
60
			// Ensure the titlebar is always visible
61
			using: function( pos ) {
62
				var topOffset = $( this ).css( pos ).offset().top;
63
				if ( topOffset < 0 ) {
64
					$( this ).css( "top", pos.top - topOffset );
66 65
				}
67 66
			}
68 67
		},
69 68
		resizable: true,
70 69
		show: null,
71
		stack: true,
72
		title: '',
70
		title: null,
73 71
		width: 300,
74
		zIndex: 1000
72

  
73
		// callbacks
74
		beforeClose: null,
75
		close: null,
76
		drag: null,
77
		dragStart: null,
78
		dragStop: null,
79
		focus: null,
80
		open: null,
81
		resize: null,
82
		resizeStart: null,
83
		resizeStop: null
75 84
	},
76 85

  
77 86
	_create: function() {
78
		this.originalTitle = this.element.attr('title');
79
		// #5742 - .attr() might return a DOMElement
80
		if ( typeof this.originalTitle !== "string" ) {
81
			this.originalTitle = "";
82
		}
83

  
87
		this.originalCss = {
88
			display: this.element[0].style.display,
89
			width: this.element[0].style.width,
90
			minHeight: this.element[0].style.minHeight,
91
			maxHeight: this.element[0].style.maxHeight,
92
			height: this.element[0].style.height
93
		};
94
		this.originalPosition = {
95
			parent: this.element.parent(),
96
			index: this.element.parent().children().index( this.element )
97
		};
98
		this.originalTitle = this.element.attr("title");
84 99
		this.options.title = this.options.title || this.originalTitle;
85
		var self = this,
86
			options = self.options,
87

  
88
			title = options.title || '&#160;',
89
			titleId = $.ui.dialog.getTitleId(self.element),
90 100

  
91
			uiDialog = (self.uiDialog = $('<div></div>'))
92
				.appendTo(document.body)
93
				.hide()
94
				.addClass(uiDialogClasses + options.dialogClass)
95
				.css({
96
					zIndex: options.zIndex
97
				})
98
				// setting tabIndex makes the div focusable
99
				// setting outline to 0 prevents a border on focus in Mozilla
100
				.attr('tabIndex', -1).css('outline', 0).keydown(function(event) {
101
					if (options.closeOnEscape && event.keyCode &&
102
						event.keyCode === $.ui.keyCode.ESCAPE) {
103
						
104
						self.close(event);
105
						event.preventDefault();
106
					}
107
				})
108
				.attr({
109
					role: 'dialog',
110
					'aria-labelledby': titleId
111
				})
112
				.mousedown(function(event) {
113
					self.moveToTop(false, event);
114
				}),
115

  
116
			uiDialogContent = self.element
117
				.show()
118
				.removeAttr('title')
119
				.addClass(
120
					'ui-dialog-content ' +
121
					'ui-widget-content')
122
				.appendTo(uiDialog),
123

  
124
			uiDialogTitlebar = (self.uiDialogTitlebar = $('<div></div>'))
125
				.addClass(
126
					'ui-dialog-titlebar ' +
127
					'ui-widget-header ' +
128
					'ui-corner-all ' +
129
					'ui-helper-clearfix'
130
				)
131
				.prependTo(uiDialog),
132

  
133
			uiDialogTitlebarClose = $('<a href="#"></a>')
134
				.addClass(
135
					'ui-dialog-titlebar-close ' +
136
					'ui-corner-all'
137
				)
138
				.attr('role', 'button')
139
				.hover(
140
					function() {
141
						uiDialogTitlebarClose.addClass('ui-state-hover');
142
					},
143
					function() {
144
						uiDialogTitlebarClose.removeClass('ui-state-hover');
145
					}
146
				)
147
				.focus(function() {
148
					uiDialogTitlebarClose.addClass('ui-state-focus');
149
				})
150
				.blur(function() {
151
					uiDialogTitlebarClose.removeClass('ui-state-focus');
152
				})
153
				.click(function(event) {
154
					self.close(event);
155
					return false;
156
				})
157
				.appendTo(uiDialogTitlebar),
101
		this._createWrapper();
158 102

  
159
			uiDialogTitlebarCloseText = (self.uiDialogTitlebarCloseText = $('<span></span>'))
160
				.addClass(
161
					'ui-icon ' +
162
					'ui-icon-closethick'
163
				)
164
				.text(options.closeText)
165
				.appendTo(uiDialogTitlebarClose),
103
		this.element
104
			.show()
105
			.removeAttr("title")
106
			.addClass("ui-dialog-content ui-widget-content")
107
			.appendTo( this.uiDialog );
166 108

  
167
			uiDialogTitle = $('<span></span>')
168
				.addClass('ui-dialog-title')
169
				.attr('id', titleId)
170
				.html(title)
171
				.prependTo(uiDialogTitlebar);
109
		this._createTitlebar();
110
		this._createButtonPane();
172 111

  
173
		//handling of deprecated beforeclose (vs beforeClose) option
174
		//Ticket #4669 http://dev.jqueryui.com/ticket/4669
175
		//TODO: remove in 1.9pre
176
		if ($.isFunction(options.beforeclose) && !$.isFunction(options.beforeClose)) {
177
			options.beforeClose = options.beforeclose;
112
		if ( this.options.draggable && $.fn.draggable ) {
113
			this._makeDraggable();
178 114
		}
179

  
180
		uiDialogTitlebar.find("*").add(uiDialogTitlebar).disableSelection();
181

  
182
		if (options.draggable && $.fn.draggable) {
183
			self._makeDraggable();
184
		}
185
		if (options.resizable && $.fn.resizable) {
186
			self._makeResizable();
115
		if ( this.options.resizable && $.fn.resizable ) {
116
			this._makeResizable();
187 117
		}
188 118

  
189
		self._createButtons(options.buttons);
190
		self._isOpen = false;
191

  
192
		if ($.fn.bgiframe) {
193
			uiDialog.bgiframe();
194
		}
119
		this._isOpen = false;
195 120
	},
196 121

  
197 122
	_init: function() {
......
200 125
		}
201 126
	},
202 127

  
203
	destroy: function() {
204
		var self = this;
205
		
206
		if (self.overlay) {
207
			self.overlay.destroy();
128
	_appendTo: function() {
129
		var element = this.options.appendTo;
130
		if ( element && (element.jquery || element.nodeType) ) {
131
			return $( element );
208 132
		}
209
		self.uiDialog.hide();
210
		self.element
211
			.unbind('.dialog')
212
			.removeData('dialog')
213
			.removeClass('ui-dialog-content ui-widget-content')
214
			.hide().appendTo('body');
215
		self.uiDialog.remove();
133
		return this.document.find( element || "body" ).eq( 0 );
134
	},
216 135

  
217
		if (self.originalTitle) {
218
			self.element.attr('title', self.originalTitle);
136
	_destroy: function() {
137
		var next,
138
			originalPosition = this.originalPosition;
139

  
140
		this._destroyOverlay();
141

  
142
		this.element
143
			.removeUniqueId()
144
			.removeClass("ui-dialog-content ui-widget-content")
145
			.css( this.originalCss )
146
			// Without detaching first, the following becomes really slow
147
			.detach();
148

  
149
		this.uiDialog.stop( true, true ).remove();
150

  
151
		if ( this.originalTitle ) {
152
			this.element.attr( "title", this.originalTitle );
219 153
		}
220 154

  
221
		return self;
155
		next = originalPosition.parent.children().eq( originalPosition.index );
156
		// Don't try to place the dialog next to itself (#8613)
157
		if ( next.length && next[0] !== this.element[0] ) {
158
			next.before( this.element );
159
		} else {
160
			originalPosition.parent.append( this.element );
161
		}
222 162
	},
223 163

  
224 164
	widget: function() {
225 165
		return this.uiDialog;
226 166
	},
227 167

  
228
	close: function(event) {
229
		var self = this,
230
			maxZ, thisZ;
231
		
232
		if (false === self._trigger('beforeClose', event)) {
233
			return;
234
		}
235

  
236
		if (self.overlay) {
237
			self.overlay.destroy();
238
		}
239
		self.uiDialog.unbind('keypress.ui-dialog');
168
	disable: $.noop,
169
	enable: $.noop,
240 170

  
241
		self._isOpen = false;
171
	close: function( event ) {
172
		var that = this;
242 173

  
243
		if (self.options.hide) {
244
			self.uiDialog.hide(self.options.hide, function() {
245
				self._trigger('close', event);
246
			});
247
		} else {
248
			self.uiDialog.hide();
249
			self._trigger('close', event);
174
		if ( !this._isOpen || this._trigger( "beforeClose", event ) === false ) {
175
			return;
250 176
		}
251 177

  
252
		$.ui.dialog.overlay.resize();
178
		this._isOpen = false;
179
		this._destroyOverlay();
253 180

  
254
		// adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
255
		if (self.options.modal) {
256
			maxZ = 0;
257
			$('.ui-dialog').each(function() {
258
				if (this !== self.uiDialog[0]) {
259
					thisZ = $(this).css('z-index');
260
					if(!isNaN(thisZ)) {
261
						maxZ = Math.max(maxZ, thisZ);
262
					}
263
				}
264
			});
265
			$.ui.dialog.maxZ = maxZ;
181
		if ( !this.opener.filter(":focusable").focus().length ) {
182
			// Hiding a focused element doesn't trigger blur in WebKit
183
			// so in case we have nothing to focus on, explicitly blur the active element
184
			// https://bugs.webkit.org/show_bug.cgi?id=47182
185
			$( this.document[0].activeElement ).blur();
266 186
		}
267 187

  
268
		return self;
188
		this._hide( this.uiDialog, this.options.hide, function() {
189
			that._trigger( "close", event );
190
		});
269 191
	},
270 192

  
271 193
	isOpen: function() {
272 194
		return this._isOpen;
273 195
	},
274 196

  
275
	// the force parameter allows us to move modal dialogs to their correct
276
	// position on open
277
	moveToTop: function(force, event) {
278
		var self = this,
279
			options = self.options,
280
			saveScroll;
197
	moveToTop: function() {
198
		this._moveToTop();
199
	},
281 200

  
282
		if ((options.modal && !force) ||
283
			(!options.stack && !options.modal)) {
284
			return self._trigger('focus', event);
201
	_moveToTop: function( event, silent ) {
202
		var moved = !!this.uiDialog.nextAll(":visible").insertBefore( this.uiDialog ).length;
203
		if ( moved && !silent ) {
204
			this._trigger( "focus", event );
285 205
		}
206
		return moved;
207
	},
286 208

  
287
		if (options.zIndex > $.ui.dialog.maxZ) {
288
			$.ui.dialog.maxZ = options.zIndex;
289
		}
290
		if (self.overlay) {
291
			$.ui.dialog.maxZ += 1;
292
			self.overlay.$el.css('z-index', $.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ);
209
	open: function() {
210
		var that = this;
211
		if ( this._isOpen ) {
212
			if ( this._moveToTop() ) {
213
				this._focusTabbable();
214
			}
215
			return;
293 216
		}
294 217

  
295
		//Save and then restore scroll since Opera 9.5+ resets when parent z-Index is changed.
296
		//  http://ui.jquery.com/bugs/ticket/3193
297
		saveScroll = { scrollTop: self.element.attr('scrollTop'), scrollLeft: self.element.attr('scrollLeft') };
298
		$.ui.dialog.maxZ += 1;
299
		self.uiDialog.css('z-index', $.ui.dialog.maxZ);
300
		self.element.attr(saveScroll);
301
		self._trigger('focus', event);
218
		this._isOpen = true;
219
		this.opener = $( this.document[0].activeElement );
220

  
221
		this._size();
222
		this._position();
223
		this._createOverlay();
224
		this._moveToTop( null, true );
225
		this._show( this.uiDialog, this.options.show, function() {
226
			that._focusTabbable();
227
			that._trigger("focus");
228
		});
302 229

  
303
		return self;
230
		this._trigger("open");
304 231
	},
305 232

  
306
	open: function() {
307
		if (this._isOpen) { return; }
308

  
309
		var self = this,
310
			options = self.options,
311
			uiDialog = self.uiDialog;
312

  
313
		self.overlay = options.modal ? new $.ui.dialog.overlay(self) : null;
314
		self._size();
315
		self._position(options.position);
316
		uiDialog.show(options.show);
317
		self.moveToTop(true);
318

  
319
		// prevent tabbing out of modal dialogs
320
		if (options.modal) {
321
			uiDialog.bind('keypress.ui-dialog', function(event) {
322
				if (event.keyCode !== $.ui.keyCode.TAB) {
233
	_focusTabbable: function() {
234
		// Set focus to the first match:
235
		// 1. First element inside the dialog matching [autofocus]
236
		// 2. Tabbable element inside the content element
237
		// 3. Tabbable element inside the buttonpane
238
		// 4. The close button
239
		// 5. The dialog itself
240
		var hasFocus = this.element.find("[autofocus]");
241
		if ( !hasFocus.length ) {
242
			hasFocus = this.element.find(":tabbable");
243
		}
244
		if ( !hasFocus.length ) {
245
			hasFocus = this.uiDialogButtonPane.find(":tabbable");
246
		}
247
		if ( !hasFocus.length ) {
248
			hasFocus = this.uiDialogTitlebarClose.filter(":tabbable");
249
		}
250
		if ( !hasFocus.length ) {
251
			hasFocus = this.uiDialog;
252
		}
253
		hasFocus.eq( 0 ).focus();
254
	},
255

  
256
	_keepFocus: function( event ) {
257
		function checkFocus() {
258
			var activeElement = this.document[0].activeElement,
259
				isActive = this.uiDialog[0] === activeElement ||
260
					$.contains( this.uiDialog[0], activeElement );
261
			if ( !isActive ) {
262
				this._focusTabbable();
263
			}
264
		}
265
		event.preventDefault();
266
		checkFocus.call( this );
267
		// support: IE
268
		// IE <= 8 doesn't prevent moving focus even with event.preventDefault()
269
		// so we check again later
270
		this._delay( checkFocus );
271
	},
272

  
273
	_createWrapper: function() {
274
		this.uiDialog = $("<div>")
275
			.addClass( "ui-dialog ui-widget ui-widget-content ui-corner-all ui-front " +
276
				this.options.dialogClass )
277
			.hide()
278
			.attr({
279
				// Setting tabIndex makes the div focusable
280
				tabIndex: -1,
281
				role: "dialog"
282
			})
283
			.appendTo( this._appendTo() );
284

  
285
		this._on( this.uiDialog, {
286
			keydown: function( event ) {
287
				if ( this.options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
288
						event.keyCode === $.ui.keyCode.ESCAPE ) {
289
					event.preventDefault();
290
					this.close( event );
323 291
					return;
324 292
				}
325 293

  
326
				var tabbables = $(':tabbable', this),
327
					first = tabbables.filter(':first'),
328
					last  = tabbables.filter(':last');
294
				// prevent tabbing out of dialogs
295
				if ( event.keyCode !== $.ui.keyCode.TAB ) {
296
					return;
297
				}
298
				var tabbables = this.uiDialog.find(":tabbable"),
299
					first = tabbables.filter(":first"),
300
					last  = tabbables.filter(":last");
329 301

  
330
				if (event.target === last[0] && !event.shiftKey) {
331
					first.focus(1);
332
					return false;
333
				} else if (event.target === first[0] && event.shiftKey) {
334
					last.focus(1);
335
					return false;
302
				if ( ( event.target === last[0] || event.target === this.uiDialog[0] ) && !event.shiftKey ) {
303
					first.focus( 1 );
304
					event.preventDefault();
305
				} else if ( ( event.target === first[0] || event.target === this.uiDialog[0] ) && event.shiftKey ) {
306
					last.focus( 1 );
307
					event.preventDefault();
336 308
				}
309
			},
310
			mousedown: function( event ) {
311
				if ( this._moveToTop( event ) ) {
312
					this._focusTabbable();
313
				}
314
			}
315
		});
316

  
317
		// We assume that any existing aria-describedby attribute means
318
		// that the dialog content is marked up properly
319
		// otherwise we brute force the content as the description
320
		if ( !this.element.find("[aria-describedby]").length ) {
321
			this.uiDialog.attr({
322
				"aria-describedby": this.element.uniqueId().attr("id")
337 323
			});
338 324
		}
325
	},
339 326

  
340
		// set focus to the first tabbable element in the content area or the first button
341
		// if there are no tabbable elements, set focus on the dialog itself
342
		$(self.element.find(':tabbable').get().concat(
343
			uiDialog.find('.ui-dialog-buttonpane :tabbable').get().concat(
344
				uiDialog.get()))).eq(0).focus();
327
	_createTitlebar: function() {
328
		var uiDialogTitle;
329

  
330
		this.uiDialogTitlebar = $("<div>")
331
			.addClass("ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix")
332
			.prependTo( this.uiDialog );
333
		this._on( this.uiDialogTitlebar, {
334
			mousedown: function( event ) {
335
				// Don't prevent click on close button (#8838)
336
				// Focusing a dialog that is partially scrolled out of view
337
				// causes the browser to scroll it into view, preventing the click event
338
				if ( !$( event.target ).closest(".ui-dialog-titlebar-close") ) {
339
					// Dialog isn't getting focus when dragging (#8063)
340
					this.uiDialog.focus();
341
				}
342
			}
343
		});
345 344

  
346
		self._isOpen = true;
347
		self._trigger('open');
345
		this.uiDialogTitlebarClose = $("<button></button>")
346
			.button({
347
				label: this.options.closeText,
348
				icons: {
349
					primary: "ui-icon-closethick"
350
				},
351
				text: false
352
			})
353
			.addClass("ui-dialog-titlebar-close")
354
			.appendTo( this.uiDialogTitlebar );
355
		this._on( this.uiDialogTitlebarClose, {
356
			click: function( event ) {
357
				event.preventDefault();
358
				this.close( event );
359
			}
360
		});
348 361

  
349
		return self;
362
		uiDialogTitle = $("<span>")
363
			.uniqueId()
364
			.addClass("ui-dialog-title")
365
			.prependTo( this.uiDialogTitlebar );
366
		this._title( uiDialogTitle );
367

  
368
		this.uiDialog.attr({
369
			"aria-labelledby": uiDialogTitle.attr("id")
370
		});
371
	},
372

  
373
	_title: function( title ) {
374
		if ( !this.options.title ) {
375
			title.html("&#160;");
376
		}
377
		title.text( this.options.title );
378
	},
379

  
380
	_createButtonPane: function() {
381
		this.uiDialogButtonPane = $("<div>")
382
			.addClass("ui-dialog-buttonpane ui-widget-content ui-helper-clearfix");
383

  
384
		this.uiButtonSet = $("<div>")
385
			.addClass("ui-dialog-buttonset")
386
			.appendTo( this.uiDialogButtonPane );
387

  
388
		this._createButtons();
350 389
	},
351 390

  
352
	_createButtons: function(buttons) {
353
		var self = this,
354
			hasButtons = false,
355
			uiDialogButtonPane = $('<div></div>')
356
				.addClass(
357
					'ui-dialog-buttonpane ' +
358
					'ui-widget-content ' +
359
					'ui-helper-clearfix'
360
				),
361
			uiButtonSet = $( "<div></div>" )
362
				.addClass( "ui-dialog-buttonset" )
363
				.appendTo( uiDialogButtonPane );
391
	_createButtons: function() {
392
		var that = this,
393
			buttons = this.options.buttons;
364 394

  
365 395
		// if we already have a button pane, remove it
366
		self.uiDialog.find('.ui-dialog-buttonpane').remove();
396
		this.uiDialogButtonPane.remove();
397
		this.uiButtonSet.empty();
367 398

  
368
		if (typeof buttons === 'object' && buttons !== null) {
369
			$.each(buttons, function() {
370
				return !(hasButtons = true);
371
			});
372
		}
373
		if (hasButtons) {
374
			$.each(buttons, function(name, props) {
375
				props = $.isFunction( props ) ?
376
					{ click: props, text: name } :
377
					props;
378
				var button = $('<button type="button"></button>')
379
					.attr( props, true )
380
					.unbind('click')
381
					.click(function() {
382
						props.click.apply(self.element[0], arguments);
383
					})
384
					.appendTo(uiButtonSet);
385
				if ($.fn.button) {
386
					button.button();
387
				}
388
			});
389
			uiDialogButtonPane.appendTo(self.uiDialog);
399
		if ( $.isEmptyObject( buttons ) || ($.isArray( buttons ) && !buttons.length) ) {
400
			this.uiDialog.removeClass("ui-dialog-buttons");
401
			return;
390 402
		}
403

  
404
		$.each( buttons, function( name, props ) {
405
			var click, buttonOptions;
406
			props = $.isFunction( props ) ?
407
				{ click: props, text: name } :
408
				props;
409
			// Default to a non-submitting button
410
			props = $.extend( { type: "button" }, props );
411
			// Change the context for the click callback to be the main element
412
			click = props.click;
413
			props.click = function() {
414
				click.apply( that.element[0], arguments );
415
			};
416
			buttonOptions = {
417
				icons: props.icons,
418
				text: props.showText
419
			};
420
			delete props.icons;
421
			delete props.showText;
422
			$( "<button></button>", props )
423
				.button( buttonOptions )
424
				.appendTo( that.uiButtonSet );
425
		});
426
		this.uiDialog.addClass("ui-dialog-buttons");
427
		this.uiDialogButtonPane.appendTo( this.uiDialog );
391 428
	},
392 429

  
393 430
	_makeDraggable: function() {
394
		var self = this,
395
			options = self.options,
396
			doc = $(document),
397
			heightBeforeDrag;
431
		var that = this,
432
			options = this.options;
398 433

  
399
		function filteredUi(ui) {
434
		function filteredUi( ui ) {
400 435
			return {
401 436
				position: ui.position,
402 437
				offset: ui.offset
403 438
			};
404 439
		}
405 440

  
406
		self.uiDialog.draggable({
407
			cancel: '.ui-dialog-content, .ui-dialog-titlebar-close',
408
			handle: '.ui-dialog-titlebar',
409
			containment: 'document',
410
			start: function(event, ui) {
411
				heightBeforeDrag = options.height === "auto" ? "auto" : $(this).height();
412
				$(this).height($(this).height()).addClass("ui-dialog-dragging");
413
				self._trigger('dragStart', event, filteredUi(ui));
441
		this.uiDialog.draggable({
442
			cancel: ".ui-dialog-content, .ui-dialog-titlebar-close",
443
			handle: ".ui-dialog-titlebar",
444
			containment: "document",
445
			start: function( event, ui ) {
446
				$( this ).addClass("ui-dialog-dragging");
447
				that._blockFrames();
448
				that._trigger( "dragStart", event, filteredUi( ui ) );
414 449
			},
415
			drag: function(event, ui) {
416
				self._trigger('drag', event, filteredUi(ui));
450
			drag: function( event, ui ) {
451
				that._trigger( "drag", event, filteredUi( ui ) );
417 452
			},
418
			stop: function(event, ui) {
419
				options.position = [ui.position.left - doc.scrollLeft(),
420
					ui.position.top - doc.scrollTop()];
421
				$(this).removeClass("ui-dialog-dragging").height(heightBeforeDrag);
422
				self._trigger('dragStop', event, filteredUi(ui));
423
				$.ui.dialog.overlay.resize();
453
			stop: function( event, ui ) {
454
				options.position = [
455
					ui.position.left - that.document.scrollLeft(),
456
					ui.position.top - that.document.scrollTop()
457
				];
458
				$( this ).removeClass("ui-dialog-dragging");
459
				that._unblockFrames();
460
				that._trigger( "dragStop", event, filteredUi( ui ) );
424 461
			}
425 462
		});
426 463
	},
427 464

  
428
	_makeResizable: function(handles) {
429
		handles = (handles === undefined ? this.options.resizable : handles);
430
		var self = this,
431
			options = self.options,
465
	_makeResizable: function() {
466
		var that = this,
467
			options = this.options,
468
			handles = options.resizable,
432 469
			// .ui-resizable has position: relative defined in the stylesheet
433 470
			// but dialogs have to use absolute or fixed positioning
434
			position = self.uiDialog.css('position'),
435
			resizeHandles = (typeof handles === 'string' ?
471
			position = this.uiDialog.css("position"),
472
			resizeHandles = typeof handles === "string" ?
436 473
				handles	:
437
				'n,e,s,w,se,sw,ne,nw'
438
			);
474
				"n,e,s,w,se,sw,ne,nw";
439 475

  
440
		function filteredUi(ui) {
476
		function filteredUi( ui ) {
441 477
			return {
442 478
				originalPosition: ui.originalPosition,
443 479
				originalSize: ui.originalSize,
......
446 482
			};
447 483
		}
448 484

  
449
		self.uiDialog.resizable({
450
			cancel: '.ui-dialog-content',
451
			containment: 'document',
452
			alsoResize: self.element,
485
		this.uiDialog.resizable({
486
			cancel: ".ui-dialog-content",
487
			containment: "document",
488
			alsoResize: this.element,
453 489
			maxWidth: options.maxWidth,
454 490
			maxHeight: options.maxHeight,
455 491
			minWidth: options.minWidth,
456
			minHeight: self._minHeight(),
492
			minHeight: this._minHeight(),
457 493
			handles: resizeHandles,
458
			start: function(event, ui) {
459
				$(this).addClass("ui-dialog-resizing");
460
				self._trigger('resizeStart', event, filteredUi(ui));
494
			start: function( event, ui ) {
495
				$( this ).addClass("ui-dialog-resizing");
496
				that._blockFrames();
497
				that._trigger( "resizeStart", event, filteredUi( ui ) );
461 498
			},
462
			resize: function(event, ui) {
463
				self._trigger('resize', event, filteredUi(ui));
499
			resize: function( event, ui ) {
500
				that._trigger( "resize", event, filteredUi( ui ) );
464 501
			},
465
			stop: function(event, ui) {
466
				$(this).removeClass("ui-dialog-resizing");
467
				options.height = $(this).height();
468
				options.width = $(this).width();
469
				self._trigger('resizeStop', event, filteredUi(ui));
470
				$.ui.dialog.overlay.resize();
502
			stop: function( event, ui ) {
503
				options.height = $( this ).height();
504
				options.width = $( this ).width();
505
				$( this ).removeClass("ui-dialog-resizing");
506
				that._unblockFrames();
507
				that._trigger( "resizeStop", event, filteredUi( ui ) );
471 508
			}
472 509
		})
473
		.css('position', position)
474
		.find('.ui-resizable-se').addClass('ui-icon ui-icon-grip-diagonal-se');
510
		.css( "position", position );
475 511
	},
476 512

  
477 513
	_minHeight: function() {
478 514
		var options = this.options;
479 515

  
480
		if (options.height === 'auto') {
481
			return options.minHeight;
482
		} else {
483
			return Math.min(options.minHeight, options.height);
484
		}
516
		return options.height === "auto" ?
517
			options.minHeight :
518
			Math.min( options.minHeight, options.height );
485 519
	},
486 520

  
487
	_position: function(position) {
488
		var myAt = [],
489
			offset = [0, 0],
490
			isVisible;
491

  
492
		if (position) {
493
			// deep extending converts arrays to objects in jQuery <= 1.3.2 :-(
494
	//		if (typeof position == 'string' || $.isArray(position)) {
495
	//			myAt = $.isArray(position) ? position : position.split(' ');
496

  
497
			if (typeof position === 'string' || (typeof position === 'object' && '0' in position)) {
498
				myAt = position.split ? position.split(' ') : [position[0], position[1]];
499
				if (myAt.length === 1) {
500
					myAt[1] = myAt[0];
501
				}
502

  
503
				$.each(['left', 'top'], function(i, offsetPosition) {
504
					if (+myAt[i] === myAt[i]) {
505
						offset[i] = myAt[i];
506
						myAt[i] = offsetPosition;
507
					}
508
				});
509

  
510
				position = {
511
					my: myAt.join(" "),
512
					at: myAt.join(" "),
513
					offset: offset.join(" ")
514
				};
515
			} 
516

  
517
			position = $.extend({}, $.ui.dialog.prototype.options.position, position);
518
		} else {
519
			position = $.ui.dialog.prototype.options.position;
520
		}
521

  
522
		// need to show the dialog to get the actual offset in the position plugin
523
		isVisible = this.uiDialog.is(':visible');
524
		if (!isVisible) {
521
	_position: function() {
522
		// Need to show the dialog to get the actual offset in the position plugin
523
		var isVisible = this.uiDialog.is(":visible");
524
		if ( !isVisible ) {
525 525
			this.uiDialog.show();
526 526
		}
527
		this.uiDialog
528
			// workaround for jQuery bug #5781 http://dev.jquery.com/ticket/5781
529
			.css({ top: 0, left: 0 })
530
			.position($.extend({ of: window }, position));
531
		if (!isVisible) {
527
		this.uiDialog.position( this.options.position );
528
		if ( !isVisible ) {
532 529
			this.uiDialog.hide();
533 530
		}
534 531
	},
535 532

  
536 533
	_setOptions: function( options ) {
537
		var self = this,
538
			resizableOptions = {},
539
			resize = false;
534
		var that = this,
535
			resize = false,
536
			resizableOptions = {};
540 537

  
541 538
		$.each( options, function( key, value ) {
542
			self._setOption( key, value );
543
			
539
			that._setOption( key, value );
540

  
544 541
			if ( key in sizeRelatedOptions ) {
545 542
				resize = true;
546 543
			}
......
551 548

  
552 549
		if ( resize ) {
553 550
			this._size();
551
			this._position();
554 552
		}
555
		if ( this.uiDialog.is( ":data(resizable)" ) ) {
553
		if ( this.uiDialog.is(":data(ui-resizable)") ) {
556 554
			this.uiDialog.resizable( "option", resizableOptions );
557 555
		}
558 556
	},
559 557

  
560
	_setOption: function(key, value){
561
		var self = this,
562
			uiDialog = self.uiDialog;
563

  
564
		switch (key) {
565
			//handling of deprecated beforeclose (vs beforeClose) option
566
			//Ticket #4669 http://dev.jqueryui.com/ticket/4669
567
			//TODO: remove in 1.9pre
568
			case "beforeclose":
569
				key = "beforeClose";
570
				break;
571
			case "buttons":
572
				self._createButtons(value);
573
				break;
574
			case "closeText":
575
				// ensure that we always pass a string
576
				self.uiDialogTitlebarCloseText.text("" + value);
577
				break;
578
			case "dialogClass":
579
				uiDialog
580
					.removeClass(self.options.dialogClass)
581
					.addClass(uiDialogClasses + value);
582
				break;
583
			case "disabled":
584
				if (value) {
585
					uiDialog.addClass('ui-dialog-disabled');
586
				} else {
587
					uiDialog.removeClass('ui-dialog-disabled');
588
				}
589
				break;
590
			case "draggable":
591
				var isDraggable = uiDialog.is( ":data(draggable)" );
592
				if ( isDraggable && !value ) {
593
					uiDialog.draggable( "destroy" );
594
				}
595
				
596
				if ( !isDraggable && value ) {
597
					self._makeDraggable();
598
				}
599
				break;
600
			case "position":
601
				self._position(value);
602
				break;
603
			case "resizable":
604
				// currently resizable, becoming non-resizable
605
				var isResizable = uiDialog.is( ":data(resizable)" );
606
				if (isResizable && !value) {
607
					uiDialog.resizable('destroy');
608
				}
558
	_setOption: function( key, value ) {
559
		/*jshint maxcomplexity:15*/
560
		var isDraggable, isResizable,
561
			uiDialog = this.uiDialog;
609 562

  
610
				// currently resizable, changing handles
611
				if (isResizable && typeof value === 'string') {
612
					uiDialog.resizable('option', 'handles', value);
613
				}
563
		if ( key === "dialogClass" ) {
564
			uiDialog
565
				.removeClass( this.options.dialogClass )
566
				.addClass( value );
567
		}
614 568

  
615
				// currently non-resizable, becoming resizable
616
				if (!isResizable && value !== false) {
617
					self._makeResizable(value);
618
				}
619
				break;
620
			case "title":
621
				// convert whatever was passed in o a string, for html() to not throw up
622
				$(".ui-dialog-title", self.uiDialogTitlebar).html("" + (value || '&#160;'));
623
				break;
569
		if ( key === "disabled" ) {
570
			return;
571
		}
572

  
573
		this._super( key, value );
574

  
575
		if ( key === "appendTo" ) {
576
			this.uiDialog.appendTo( this._appendTo() );
577
		}
578

  
579
		if ( key === "buttons" ) {
580
			this._createButtons();
581
		}
582

  
583
		if ( key === "closeText" ) {
584
			this.uiDialogTitlebarClose.button({
585
				// Ensure that we always pass a string
586
				label: "" + value
587
			});
624 588
		}
625 589

  
626
		$.Widget.prototype._setOption.apply(self, arguments);
590
		if ( key === "draggable" ) {
591
			isDraggable = uiDialog.is(":data(ui-draggable)");
592
			if ( isDraggable && !value ) {
593
				uiDialog.draggable("destroy");
594
			}
595

  
596
			if ( !isDraggable && value ) {
597
				this._makeDraggable();
598
			}
599
		}
600

  
601
		if ( key === "position" ) {
602
			this._position();
603
		}
604

  
605
		if ( key === "resizable" ) {
606
			// currently resizable, becoming non-resizable
607
			isResizable = uiDialog.is(":data(ui-resizable)");
608
			if ( isResizable && !value ) {
609
				uiDialog.resizable("destroy");
610
			}
611

  
612
			// currently resizable, changing handles
613
			if ( isResizable && typeof value === "string" ) {
614
				uiDialog.resizable( "option", "handles", value );
615
			}
616

  
617
			// currently non-resizable, becoming resizable
618
			if ( !isResizable && value !== false ) {
619
				this._makeResizable();
620
			}
621
		}
622

  
623
		if ( key === "title" ) {
624
			this._title( this.uiDialogTitlebar.find(".ui-dialog-title") );
625
		}
627 626
	},
628 627

  
629 628
	_size: function() {
630
		/* If the user has resized the dialog, the .ui-dialog and .ui-dialog-content
631
		 * divs will both have width and height set, so we need to reset them
632
		 */
633
		var options = this.options,
634
			nonContentHeight,
635
			minContentHeight,
636
			isVisible = this.uiDialog.is( ":visible" );
637

  
638
		// reset content sizing
629
		// If the user has resized the dialog, the .ui-dialog and .ui-dialog-content
630
		// divs will both have width and height set, so we need to reset them
631
		var nonContentHeight, minContentHeight, maxContentHeight,
632
			options = this.options;
633

  
634
		// Reset content sizing
639 635
		this.element.show().css({
640
			width: 'auto',
636
			width: "auto",
641 637
			minHeight: 0,
638
			maxHeight: "none",
642 639
			height: 0
643 640
		});
644 641

  
645
		if (options.minWidth > options.width) {
642
		if ( options.minWidth > options.width ) {
646 643
			options.width = options.minWidth;
647 644
		}
648 645

  
649 646
		// reset wrapper sizing
650 647
		// determine the height of all the non-content elements
651 648
		nonContentHeight = this.uiDialog.css({
652
				height: 'auto',
649
				height: "auto",
653 650
				width: options.width
654 651
			})
655
			.height();
652
			.outerHeight();
656 653
		minContentHeight = Math.max( 0, options.minHeight - nonContentHeight );
657
		
654
		maxContentHeight = typeof options.maxHeight === "number" ?
655
			Math.max( 0, options.maxHeight - nonContentHeight ) :
656
			"none";
657

  
658 658
		if ( options.height === "auto" ) {
659
			// only needed for IE6 support
660
			if ( $.support.minHeight ) {
661
				this.element.css({
662
					minHeight: minContentHeight,
663
					height: "auto"
664
				});
665
			} else {
666
				this.uiDialog.show();
667
				var autoHeight = this.element.css( "height", "auto" ).height();
668
				if ( !isVisible ) {
669
					this.uiDialog.hide();
670
				}
671
				this.element.height( Math.max( autoHeight, minContentHeight ) );
672
			}
659
			this.element.css({
660
				minHeight: minContentHeight,
661
				maxHeight: maxContentHeight,
662
				height: "auto"
663
			});
673 664
		} else {
674
			this.element.height( Math.max( options.height - nonContentHeight, 0 ) );
665
			this.element.height( Math.max( 0, options.height - nonContentHeight ) );
675 666
		}
676 667

  
677
		if (this.uiDialog.is(':data(resizable)')) {
678
			this.uiDialog.resizable('option', 'minHeight', this._minHeight());
668
		if (this.uiDialog.is(":data(ui-resizable)") ) {
669
			this.uiDialog.resizable( "option", "minHeight", this._minHeight() );
679 670
		}
680
	}
681
});
671
	},
682 672

  
683
$.extend($.ui.dialog, {
684
	version: "1.8.11",
673
	_blockFrames: function() {
674
		this.iframeBlocks = this.document.find( "iframe" ).map(function() {
675
			var iframe = $( this );
685 676

  
686
	uuid: 0,
687
	maxZ: 0,
677
			return $( "<div>" )
678
				.css({
679
					position: "absolute",
680
					width: iframe.outerWidth(),
681
					height: iframe.outerHeight()
682
				})
683
				.appendTo( iframe.parent() )
684
				.offset( iframe.offset() )[0];
685
		});
686
	},
688 687

  
689
	getTitleId: function($el) {
690
		var id = $el.attr('id');
691
		if (!id) {
692
			this.uuid += 1;
693
			id = this.uuid;
688
	_unblockFrames: function() {
689
		if ( this.iframeBlocks ) {
690
			this.iframeBlocks.remove();
691
			delete this.iframeBlocks;
694 692
		}
695
		return 'ui-dialog-title-' + id;
696 693
	},
697 694

  
698
	overlay: function(dialog) {
699
		this.$el = $.ui.dialog.overlay.create(dialog);
700
	}
701
});
695
	_allowInteraction: function( event ) {
696
		if ( $( event.target ).closest(".ui-dialog").length ) {
697
			return true;
698
		}
702 699

  
703
$.extend($.ui.dialog.overlay, {
704
	instances: [],
705
	// reuse old instances due to IE memory leak with alpha transparency (see #5185)
706
	oldInstances: [],
707
	maxZ: 0,
708
	events: $.map('focus,mousedown,mouseup,keydown,keypress,click'.split(','),
709
		function(event) { return event + '.dialog-overlay'; }).join(' '),
710
	create: function(dialog) {
711
		if (this.instances.length === 0) {
712
			// prevent use of anchors and inputs
713
			// we use a setTimeout in case the overlay is created from an
714
			// event that we're going to be cancelling (see #2804)
715
			setTimeout(function() {
716
				// handle $(el).dialog().dialog('close') (see #4065)
717
				if ($.ui.dialog.overlay.instances.length) {
718
					$(document).bind($.ui.dialog.overlay.events, function(event) {
719
						// stop events if the z-index of the target is < the z-index of the overlay
720
						// we cannot return true when we don't want to cancel the event (#3523)
721
						if ($(event.target).zIndex() < $.ui.dialog.overlay.maxZ) {
722
							return false;
700
		// TODO: Remove hack when datepicker implements
701
		// the .ui-front logic (#8989)
702
		return !!$( event.target ).closest(".ui-datepicker").length;
703
	},
704

  
705
	_createOverlay: function() {
706
		if ( !this.options.modal ) {
707
			return;
708
		}
709

  
710
		var that = this,
711
			widgetFullName = this.widgetFullName;
712
		if ( !$.ui.dialog.overlayInstances ) {
713
			// Prevent use of anchors and inputs.
714
			// We use a delay in case the overlay is created from an
715
			// event that we're going to be cancelling. (#2804)
716
			this._delay(function() {
717
				// Handle .dialog().dialog("close") (#4065)
718
				if ( $.ui.dialog.overlayInstances ) {
719
					this.document.bind( "focusin.dialog", function( event ) {
720
						if ( !that._allowInteraction( event ) ) {
721
							event.preventDefault();
722
							$(".ui-dialog:visible:last .ui-dialog-content")
723
								.data( widgetFullName )._focusTabbable();
723 724
						}
724 725
					});
725 726
				}
726
			}, 1);
727

  
728
			// allow closing by pressing the escape key
729
			$(document).bind('keydown.dialog-overlay', function(event) {
730
				if (dialog.options.closeOnEscape && event.keyCode &&
731
					event.keyCode === $.ui.keyCode.ESCAPE) {
732
					
733
					dialog.close(event);
734
					event.preventDefault();
735
				}
736 727
			});
737

  
738
			// handle window resize
739
			$(window).bind('resize.dialog-overlay', $.ui.dialog.overlay.resize);
740 728
		}
741 729

  
742
		var $el = (this.oldInstances.pop() || $('<div></div>').addClass('ui-widget-overlay'))
743
			.appendTo(document.body)
744
			.css({
745
				width: this.width(),
746
				height: this.height()
747
			});
730
		this.overlay = $("<div>")
731
			.addClass("ui-widget-overlay ui-front")
732
			.appendTo( this._appendTo() );
733
		this._on( this.overlay, {
734
			mousedown: "_keepFocus"
735
		});
736
		$.ui.dialog.overlayInstances++;
737
	},
748 738

  
749
		if ($.fn.bgiframe) {
750
			$el.bgiframe();
739
	_destroyOverlay: function() {
740
		if ( !this.options.modal ) {
741
			return;
751 742
		}
752 743

  
753
		this.instances.push($el);
754
		return $el;
755
	},
744
		if ( this.overlay ) {
745
			$.ui.dialog.overlayInstances--;
756 746

  
757
	destroy: function($el) {
758
		var indexOf = $.inArray($el, this.instances);
759
		if (indexOf != -1){
760
			this.oldInstances.push(this.instances.splice(indexOf, 1)[0]);
747
			if ( !$.ui.dialog.overlayInstances ) {
748
				this.document.unbind( "focusin.dialog" );
749
			}
750
			this.overlay.remove();
751
			this.overlay = null;
761 752
		}
753
	}
754
});
762 755

  
763
		if (this.instances.length === 0) {
764
			$([document, window]).unbind('.dialog-overlay');
765
		}
756
$.ui.dialog.overlayInstances = 0;
757

  
758
// DEPRECATED
759
if ( $.uiBackCompat !== false ) {
760
	// position option with array notation
761
	// just override with old implementation
762
	$.widget( "ui.dialog", $.ui.dialog, {
763
		_position: function() {
764
			var position = this.options.position,
765
				myAt = [],
766
				offset = [ 0, 0 ],
767
				isVisible;
768

  
769
			if ( position ) {
770
				if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) {
771
					myAt = position.split ? position.split(" ") : [ position[0], position[1] ];
772
					if ( myAt.length === 1 ) {
773
						myAt[1] = myAt[0];
774
					}
766 775

  
767
		$el.remove();
768
		
769
		// adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
770
		var maxZ = 0;
771
		$.each(this.instances, function() {
772
			maxZ = Math.max(maxZ, this.css('z-index'));
773
		});
774
		this.maxZ = maxZ;
775
	},
776
					$.each( [ "left", "top" ], function( i, offsetPosition ) {
777
						if ( +myAt[ i ] === myAt[ i ] ) {
778
							offset[ i ] = myAt[ i ];
779
							myAt[ i ] = offsetPosition;
780
						}
781
					});
782

  
783
					position = {
784
						my: myAt[0] + (offset[0] < 0 ? offset[0] : "+" + offset[0]) + " " +
785
							myAt[1] + (offset[1] < 0 ? offset[1] : "+" + offset[1]),
786
						at: myAt.join(" ")
787
					};
788
				}
776 789

  
777
	height: function() {
778
		var scrollHeight,
779
			offsetHeight;
780
		// handle IE 6
781
		if ($.browser.msie && $.browser.version < 7) {
782
			scrollHeight = Math.max(
783
				document.documentElement.scrollHeight,
784
				document.body.scrollHeight
785
			);
786
			offsetHeight = Math.max(
787
				document.documentElement.offsetHeight,
788
				document.body.offsetHeight
789
			);
790

  
791
			if (scrollHeight < offsetHeight) {
792
				return $(window).height() + 'px';
790
				position = $.extend( {}, $.ui.dialog.prototype.options.position, position );
793 791
			} else {
794
				return scrollHeight + 'px';
792
				position = $.ui.dialog.prototype.options.position;
795 793
			}
796
		// handle "good" browsers
797
		} else {
798
			return $(document).height() + 'px';
799
		}
800
	},
801 794

  
802
	width: function() {
803
		var scrollWidth,
804
			offsetWidth;
805
		// handle IE 6
806
		if ($.browser.msie && $.browser.version < 7) {
807
			scrollWidth = Math.max(
808
				document.documentElement.scrollWidth,
809
				document.body.scrollWidth
810
			);
811
			offsetWidth = Math.max(
812
				document.documentElement.offsetWidth,
813
				document.body.offsetWidth
814
			);
815

  
816
			if (scrollWidth < offsetWidth) {
817
				return $(window).width() + 'px';
818
			} else {
819
				return scrollWidth + 'px';
795
			// need to show the dialog to get the actual offset in the position plugin
796
			isVisible = this.uiDialog.is(":visible");
797
			if ( !isVisible ) {
798
				this.uiDialog.show();
799
			}
800
			this.uiDialog.position( position );
801
			if ( !isVisible ) {
802
				this.uiDialog.hide();
820 803
			}
821
		// handle "good" browsers
822
		} else {
823
			return $(document).width() + 'px';
824 804
		}
825
	},
826

  
827
	resize: function() {
828
		/* If the dialog is draggable and the user drags it past the
829
		 * right edge of the window, the document becomes wider so we
830
		 * need to stretch the overlay. If the user then drags the
831
		 * dialog back to the left, the document will become narrower,
832
		 * so we need to shrink the overlay to the appropriate size.
833
		 * This is handled by shrinking the overlay before setting it
834
		 * to the full document size.
835
		 */
836
		var $overlays = $([]);
837
		$.each($.ui.dialog.overlay.instances, function() {
838
			$overlays = $overlays.add(this);
839
		});
840

  
841
		$overlays.css({
842
			width: 0,
843
			height: 0
844
		}).css({
845
			width: $.ui.dialog.overlay.width(),
846
			height: $.ui.dialog.overlay.height()
847
		});
848
	}
849
});
850

  
851
$.extend($.ui.dialog.overlay.prototype, {
852
	destroy: function() {
853
		$.ui.dialog.overlay.destroy(this.$el);
854
	}
855
});
805
	});
806
}
856 807

  
857
}(jQuery));
808
}( jQuery ) );

Formats disponibles : Unified diff