1 | /*! |
---|
2 | * jQuery UI Dialog 1.9.0 |
---|
3 | * http://jqueryui.com |
---|
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/dialog/ |
---|
10 | * |
---|
11 | * Depends: |
---|
12 | * jquery.ui.core.js |
---|
13 | * jquery.ui.widget.js |
---|
14 | * jquery.ui.button.js |
---|
15 | * jquery.ui.draggable.js |
---|
16 | * jquery.ui.mouse.js |
---|
17 | * jquery.ui.position.js |
---|
18 | * jquery.ui.resizable.js |
---|
19 | */ |
---|
20 | (function( $, undefined ) { |
---|
21 | |
---|
22 | var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ", |
---|
23 | sizeRelatedOptions = { |
---|
24 | buttons: true, |
---|
25 | height: true, |
---|
26 | maxHeight: true, |
---|
27 | maxWidth: true, |
---|
28 | minHeight: true, |
---|
29 | minWidth: true, |
---|
30 | width: true |
---|
31 | }, |
---|
32 | resizableRelatedOptions = { |
---|
33 | maxHeight: true, |
---|
34 | maxWidth: true, |
---|
35 | minHeight: true, |
---|
36 | minWidth: true |
---|
37 | }; |
---|
38 | |
---|
39 | $.widget("ui.dialog", { |
---|
40 | version: "1.9.0", |
---|
41 | options: { |
---|
42 | autoOpen: true, |
---|
43 | buttons: {}, |
---|
44 | closeOnEscape: true, |
---|
45 | closeText: "close", |
---|
46 | dialogClass: "", |
---|
47 | draggable: true, |
---|
48 | hide: null, |
---|
49 | height: "auto", |
---|
50 | maxHeight: false, |
---|
51 | maxWidth: false, |
---|
52 | minHeight: 150, |
---|
53 | minWidth: 150, |
---|
54 | modal: false, |
---|
55 | position: { |
---|
56 | my: "center", |
---|
57 | at: "center", |
---|
58 | of: window, |
---|
59 | collision: "fit", |
---|
60 | // ensure that the titlebar is never outside the document |
---|
61 | using: function( pos ) { |
---|
62 | var topOffset = $( this ).css( pos ).offset().top; |
---|
63 | if ( topOffset < 0 ) { |
---|
64 | $( this ).css( "top", pos.top - topOffset ); |
---|
65 | } |
---|
66 | } |
---|
67 | }, |
---|
68 | resizable: true, |
---|
69 | show: null, |
---|
70 | stack: true, |
---|
71 | title: "", |
---|
72 | width: 300, |
---|
73 | zIndex: 1000 |
---|
74 | }, |
---|
75 | |
---|
76 | _create: function() { |
---|
77 | this.originalTitle = this.element.attr( "title" ); |
---|
78 | // #5742 - .attr() might return a DOMElement |
---|
79 | if ( typeof this.originalTitle !== "string" ) { |
---|
80 | this.originalTitle = ""; |
---|
81 | } |
---|
82 | this.oldPosition = { |
---|
83 | parent: this.element.parent(), |
---|
84 | index: this.element.parent().children().index( this.element ) |
---|
85 | }; |
---|
86 | this.options.title = this.options.title || this.originalTitle; |
---|
87 | var that = this, |
---|
88 | options = this.options, |
---|
89 | |
---|
90 | title = options.title || " ", |
---|
91 | |
---|
92 | uiDialog = ( this.uiDialog = $( "<div>" ) ) |
---|
93 | .addClass( uiDialogClasses + options.dialogClass ) |
---|
94 | .css({ |
---|
95 | display: "none", |
---|
96 | outline: 0, // TODO: move to stylesheet |
---|
97 | zIndex: options.zIndex |
---|
98 | }) |
---|
99 | // setting tabIndex makes the div focusable |
---|
100 | .attr( "tabIndex", -1) |
---|
101 | .keydown(function( event ) { |
---|
102 | if ( options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode && |
---|
103 | event.keyCode === $.ui.keyCode.ESCAPE ) { |
---|
104 | that.close( event ); |
---|
105 | event.preventDefault(); |
---|
106 | } |
---|
107 | }) |
---|
108 | .mousedown(function( event ) { |
---|
109 | that.moveToTop( false, event ); |
---|
110 | }) |
---|
111 | .appendTo( "body" ), |
---|
112 | |
---|
113 | uiDialogContent = this.element |
---|
114 | .show() |
---|
115 | .removeAttr( "title" ) |
---|
116 | .addClass( "ui-dialog-content ui-widget-content" ) |
---|
117 | .appendTo( uiDialog ), |
---|
118 | |
---|
119 | uiDialogTitlebar = ( this.uiDialogTitlebar = $( "<div>" ) ) |
---|
120 | .addClass( "ui-dialog-titlebar ui-widget-header " + |
---|
121 | "ui-corner-all ui-helper-clearfix" ) |
---|
122 | .prependTo( uiDialog ), |
---|
123 | |
---|
124 | uiDialogTitlebarClose = $( "<a href='#'></a>" ) |
---|
125 | .addClass( "ui-dialog-titlebar-close ui-corner-all" ) |
---|
126 | .attr( "role", "button" ) |
---|
127 | .click(function( event ) { |
---|
128 | event.preventDefault(); |
---|
129 | that.close( event ); |
---|
130 | }) |
---|
131 | .appendTo( uiDialogTitlebar ), |
---|
132 | |
---|
133 | uiDialogTitlebarCloseText = ( this.uiDialogTitlebarCloseText = $( "<span>" ) ) |
---|
134 | .addClass( "ui-icon ui-icon-closethick" ) |
---|
135 | .text( options.closeText ) |
---|
136 | .appendTo( uiDialogTitlebarClose ), |
---|
137 | |
---|
138 | uiDialogTitle = $( "<span>" ) |
---|
139 | .uniqueId() |
---|
140 | .addClass( "ui-dialog-title" ) |
---|
141 | .html( title ) |
---|
142 | .prependTo( uiDialogTitlebar ), |
---|
143 | |
---|
144 | uiDialogButtonPane = ( this.uiDialogButtonPane = $( "<div>" ) ) |
---|
145 | .addClass( "ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" ), |
---|
146 | |
---|
147 | uiButtonSet = ( this.uiButtonSet = $( "<div>" ) ) |
---|
148 | .addClass( "ui-dialog-buttonset" ) |
---|
149 | .appendTo( uiDialogButtonPane ); |
---|
150 | |
---|
151 | uiDialog.attr({ |
---|
152 | role: "dialog", |
---|
153 | "aria-labelledby": uiDialogTitle.attr( "id" ) |
---|
154 | }); |
---|
155 | |
---|
156 | uiDialogTitlebar.find( "*" ).add( uiDialogTitlebar ).disableSelection(); |
---|
157 | this._hoverable( uiDialogTitlebarClose ); |
---|
158 | this._focusable( uiDialogTitlebarClose ); |
---|
159 | |
---|
160 | if ( options.draggable && $.fn.draggable ) { |
---|
161 | this._makeDraggable(); |
---|
162 | } |
---|
163 | if ( options.resizable && $.fn.resizable ) { |
---|
164 | this._makeResizable(); |
---|
165 | } |
---|
166 | |
---|
167 | this._createButtons( options.buttons ); |
---|
168 | this._isOpen = false; |
---|
169 | |
---|
170 | if ( $.fn.bgiframe ) { |
---|
171 | uiDialog.bgiframe(); |
---|
172 | } |
---|
173 | |
---|
174 | // prevent tabbing out of modal dialogs |
---|
175 | this._on( uiDialog, { keydown: function( event ) { |
---|
176 | if ( !options.modal || event.keyCode !== $.ui.keyCode.TAB ) { |
---|
177 | return; |
---|
178 | } |
---|
179 | |
---|
180 | var tabbables = $( ":tabbable", uiDialog ), |
---|
181 | first = tabbables.filter( ":first" ), |
---|
182 | last = tabbables.filter( ":last" ); |
---|
183 | |
---|
184 | if ( event.target === last[0] && !event.shiftKey ) { |
---|
185 | first.focus( 1 ); |
---|
186 | return false; |
---|
187 | } else if ( event.target === first[0] && event.shiftKey ) { |
---|
188 | last.focus( 1 ); |
---|
189 | return false; |
---|
190 | } |
---|
191 | }}); |
---|
192 | }, |
---|
193 | |
---|
194 | _init: function() { |
---|
195 | if ( this.options.autoOpen ) { |
---|
196 | this.open(); |
---|
197 | } |
---|
198 | }, |
---|
199 | |
---|
200 | _destroy: function() { |
---|
201 | var next, |
---|
202 | oldPosition = this.oldPosition; |
---|
203 | |
---|
204 | if ( this.overlay ) { |
---|
205 | this.overlay.destroy(); |
---|
206 | } |
---|
207 | this.uiDialog.hide(); |
---|
208 | this.element |
---|
209 | .removeClass( "ui-dialog-content ui-widget-content" ) |
---|
210 | .hide() |
---|
211 | .appendTo( "body" ); |
---|
212 | this.uiDialog.remove(); |
---|
213 | |
---|
214 | if ( this.originalTitle ) { |
---|
215 | this.element.attr( "title", this.originalTitle ); |
---|
216 | } |
---|
217 | |
---|
218 | next = oldPosition.parent.children().eq( oldPosition.index ); |
---|
219 | // Don't try to place the dialog next to itself (#8613) |
---|
220 | if ( next.length && next[ 0 ] !== this.element[ 0 ] ) { |
---|
221 | next.before( this.element ); |
---|
222 | } else { |
---|
223 | oldPosition.parent.append( this.element ); |
---|
224 | } |
---|
225 | }, |
---|
226 | |
---|
227 | widget: function() { |
---|
228 | return this.uiDialog; |
---|
229 | }, |
---|
230 | |
---|
231 | close: function( event ) { |
---|
232 | var that = this, |
---|
233 | maxZ, thisZ; |
---|
234 | |
---|
235 | if ( !this._isOpen ) { |
---|
236 | return; |
---|
237 | } |
---|
238 | |
---|
239 | if ( false === this._trigger( "beforeClose", event ) ) { |
---|
240 | return; |
---|
241 | } |
---|
242 | |
---|
243 | this._isOpen = false; |
---|
244 | |
---|
245 | if ( this.overlay ) { |
---|
246 | this.overlay.destroy(); |
---|
247 | } |
---|
248 | |
---|
249 | if ( this.options.hide ) { |
---|
250 | this.uiDialog.hide( this.options.hide, function() { |
---|
251 | that._trigger( "close", event ); |
---|
252 | }); |
---|
253 | } else { |
---|
254 | this.uiDialog.hide(); |
---|
255 | this._trigger( "close", event ); |
---|
256 | } |
---|
257 | |
---|
258 | $.ui.dialog.overlay.resize(); |
---|
259 | |
---|
260 | // adjust the maxZ to allow other modal dialogs to continue to work (see #4309) |
---|
261 | if ( this.options.modal ) { |
---|
262 | maxZ = 0; |
---|
263 | $( ".ui-dialog" ).each(function() { |
---|
264 | if ( this !== that.uiDialog[0] ) { |
---|
265 | thisZ = $( this ).css( "z-index" ); |
---|
266 | if ( !isNaN( thisZ ) ) { |
---|
267 | maxZ = Math.max( maxZ, thisZ ); |
---|
268 | } |
---|
269 | } |
---|
270 | }); |
---|
271 | $.ui.dialog.maxZ = maxZ; |
---|
272 | } |
---|
273 | |
---|
274 | return this; |
---|
275 | }, |
---|
276 | |
---|
277 | isOpen: function() { |
---|
278 | return this._isOpen; |
---|
279 | }, |
---|
280 | |
---|
281 | // the force parameter allows us to move modal dialogs to their correct |
---|
282 | // position on open |
---|
283 | moveToTop: function( force, event ) { |
---|
284 | var options = this.options, |
---|
285 | saveScroll; |
---|
286 | |
---|
287 | if ( ( options.modal && !force ) || |
---|
288 | ( !options.stack && !options.modal ) ) { |
---|
289 | return this._trigger( "focus", event ); |
---|
290 | } |
---|
291 | |
---|
292 | if ( options.zIndex > $.ui.dialog.maxZ ) { |
---|
293 | $.ui.dialog.maxZ = options.zIndex; |
---|
294 | } |
---|
295 | if ( this.overlay ) { |
---|
296 | $.ui.dialog.maxZ += 1; |
---|
297 | $.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ; |
---|
298 | this.overlay.$el.css( "z-index", $.ui.dialog.overlay.maxZ ); |
---|
299 | } |
---|
300 | |
---|
301 | // Save and then restore scroll |
---|
302 | // Opera 9.5+ resets when parent z-index is changed. |
---|
303 | // http://bugs.jqueryui.com/ticket/3193 |
---|
304 | saveScroll = { |
---|
305 | scrollTop: this.element.scrollTop(), |
---|
306 | scrollLeft: this.element.scrollLeft() |
---|
307 | }; |
---|
308 | $.ui.dialog.maxZ += 1; |
---|
309 | this.uiDialog.css( "z-index", $.ui.dialog.maxZ ); |
---|
310 | this.element.attr( saveScroll ); |
---|
311 | this._trigger( "focus", event ); |
---|
312 | |
---|
313 | return this; |
---|
314 | }, |
---|
315 | |
---|
316 | open: function() { |
---|
317 | if ( this._isOpen ) { |
---|
318 | return; |
---|
319 | } |
---|
320 | |
---|
321 | var hasFocus, |
---|
322 | options = this.options, |
---|
323 | uiDialog = this.uiDialog; |
---|
324 | |
---|
325 | this._size(); |
---|
326 | this._position( options.position ); |
---|
327 | uiDialog.show( options.show ); |
---|
328 | this.overlay = options.modal ? new $.ui.dialog.overlay( this ) : null; |
---|
329 | this.moveToTop( true ); |
---|
330 | |
---|
331 | // set focus to the first tabbable element in the content area or the first button |
---|
332 | // if there are no tabbable elements, set focus on the dialog itself |
---|
333 | hasFocus = this.element.find( ":tabbable" ); |
---|
334 | if ( !hasFocus.length ) { |
---|
335 | hasFocus = this.uiDialogButtonPane.find( ":tabbable" ); |
---|
336 | if ( !hasFocus.length ) { |
---|
337 | hasFocus = uiDialog; |
---|
338 | } |
---|
339 | } |
---|
340 | hasFocus.eq( 0 ).focus(); |
---|
341 | |
---|
342 | this._isOpen = true; |
---|
343 | this._trigger( "open" ); |
---|
344 | |
---|
345 | return this; |
---|
346 | }, |
---|
347 | |
---|
348 | _createButtons: function( buttons ) { |
---|
349 | var uiDialogButtonPane, uiButtonSet, |
---|
350 | that = this, |
---|
351 | hasButtons = false; |
---|
352 | |
---|
353 | // if we already have a button pane, remove it |
---|
354 | this.uiDialogButtonPane.remove(); |
---|
355 | this.uiButtonSet.empty(); |
---|
356 | |
---|
357 | if ( typeof buttons === "object" && buttons !== null ) { |
---|
358 | $.each( buttons, function() { |
---|
359 | return !(hasButtons = true); |
---|
360 | }); |
---|
361 | } |
---|
362 | if ( hasButtons ) { |
---|
363 | $.each( buttons, function( name, props ) { |
---|
364 | props = $.isFunction( props ) ? |
---|
365 | { click: props, text: name } : |
---|
366 | props; |
---|
367 | var button = $( "<button type='button'>" ) |
---|
368 | .attr( props, true ) |
---|
369 | .unbind( "click" ) |
---|
370 | .click(function() { |
---|
371 | props.click.apply( that.element[0], arguments ); |
---|
372 | }) |
---|
373 | .appendTo( that.uiButtonSet ); |
---|
374 | if ( $.fn.button ) { |
---|
375 | button.button(); |
---|
376 | } |
---|
377 | }); |
---|
378 | this.uiDialog.addClass( "ui-dialog-buttons" ); |
---|
379 | this.uiDialogButtonPane.appendTo( this.uiDialog ); |
---|
380 | } else { |
---|
381 | this.uiDialog.removeClass( "ui-dialog-buttons" ); |
---|
382 | } |
---|
383 | }, |
---|
384 | |
---|
385 | _makeDraggable: function() { |
---|
386 | var that = this, |
---|
387 | options = this.options; |
---|
388 | |
---|
389 | function filteredUi( ui ) { |
---|
390 | return { |
---|
391 | position: ui.position, |
---|
392 | offset: ui.offset |
---|
393 | }; |
---|
394 | } |
---|
395 | |
---|
396 | this.uiDialog.draggable({ |
---|
397 | cancel: ".ui-dialog-content, .ui-dialog-titlebar-close", |
---|
398 | handle: ".ui-dialog-titlebar", |
---|
399 | containment: "document", |
---|
400 | start: function( event, ui ) { |
---|
401 | $( this ) |
---|
402 | .addClass( "ui-dialog-dragging" ); |
---|
403 | that._trigger( "dragStart", event, filteredUi( ui ) ); |
---|
404 | }, |
---|
405 | drag: function( event, ui ) { |
---|
406 | that._trigger( "drag", event, filteredUi( ui ) ); |
---|
407 | }, |
---|
408 | stop: function( event, ui ) { |
---|
409 | options.position = [ |
---|
410 | ui.position.left - that.document.scrollLeft(), |
---|
411 | ui.position.top - that.document.scrollTop() |
---|
412 | ]; |
---|
413 | $( this ) |
---|
414 | .removeClass( "ui-dialog-dragging" ); |
---|
415 | that._trigger( "dragStop", event, filteredUi( ui ) ); |
---|
416 | $.ui.dialog.overlay.resize(); |
---|
417 | } |
---|
418 | }); |
---|
419 | }, |
---|
420 | |
---|
421 | _makeResizable: function( handles ) { |
---|
422 | handles = (handles === undefined ? this.options.resizable : handles); |
---|
423 | var that = this, |
---|
424 | options = this.options, |
---|
425 | // .ui-resizable has position: relative defined in the stylesheet |
---|
426 | // but dialogs have to use absolute or fixed positioning |
---|
427 | position = this.uiDialog.css( "position" ), |
---|
428 | resizeHandles = typeof handles === 'string' ? |
---|
429 | handles : |
---|
430 | "n,e,s,w,se,sw,ne,nw"; |
---|
431 | |
---|
432 | function filteredUi( ui ) { |
---|
433 | return { |
---|
434 | originalPosition: ui.originalPosition, |
---|
435 | originalSize: ui.originalSize, |
---|
436 | position: ui.position, |
---|
437 | size: ui.size |
---|
438 | }; |
---|
439 | } |
---|
440 | |
---|
441 | this.uiDialog.resizable({ |
---|
442 | cancel: ".ui-dialog-content", |
---|
443 | containment: "document", |
---|
444 | alsoResize: this.element, |
---|
445 | maxWidth: options.maxWidth, |
---|
446 | maxHeight: options.maxHeight, |
---|
447 | minWidth: options.minWidth, |
---|
448 | minHeight: this._minHeight(), |
---|
449 | handles: resizeHandles, |
---|
450 | start: function( event, ui ) { |
---|
451 | $( this ).addClass( "ui-dialog-resizing" ); |
---|
452 | that._trigger( "resizeStart", event, filteredUi( ui ) ); |
---|
453 | }, |
---|
454 | resize: function( event, ui ) { |
---|
455 | that._trigger( "resize", event, filteredUi( ui ) ); |
---|
456 | }, |
---|
457 | stop: function( event, ui ) { |
---|
458 | $( this ).removeClass( "ui-dialog-resizing" ); |
---|
459 | options.height = $( this ).height(); |
---|
460 | options.width = $( this ).width(); |
---|
461 | that._trigger( "resizeStop", event, filteredUi( ui ) ); |
---|
462 | $.ui.dialog.overlay.resize(); |
---|
463 | } |
---|
464 | }) |
---|
465 | .css( "position", position ) |
---|
466 | .find( ".ui-resizable-se" ) |
---|
467 | .addClass( "ui-icon ui-icon-grip-diagonal-se" ); |
---|
468 | }, |
---|
469 | |
---|
470 | _minHeight: function() { |
---|
471 | var options = this.options; |
---|
472 | |
---|
473 | if ( options.height === "auto" ) { |
---|
474 | return options.minHeight; |
---|
475 | } else { |
---|
476 | return Math.min( options.minHeight, options.height ); |
---|
477 | } |
---|
478 | }, |
---|
479 | |
---|
480 | _position: function( position ) { |
---|
481 | var myAt = [], |
---|
482 | offset = [ 0, 0 ], |
---|
483 | isVisible; |
---|
484 | |
---|
485 | if ( position ) { |
---|
486 | // deep extending converts arrays to objects in jQuery <= 1.3.2 :-( |
---|
487 | // if (typeof position == 'string' || $.isArray(position)) { |
---|
488 | // myAt = $.isArray(position) ? position : position.split(' '); |
---|
489 | |
---|
490 | if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) { |
---|
491 | myAt = position.split ? position.split( " " ) : [ position[ 0 ], position[ 1 ] ]; |
---|
492 | if ( myAt.length === 1 ) { |
---|
493 | myAt[ 1 ] = myAt[ 0 ]; |
---|
494 | } |
---|
495 | |
---|
496 | $.each( [ "left", "top" ], function( i, offsetPosition ) { |
---|
497 | if ( +myAt[ i ] === myAt[ i ] ) { |
---|
498 | offset[ i ] = myAt[ i ]; |
---|
499 | myAt[ i ] = offsetPosition; |
---|
500 | } |
---|
501 | }); |
---|
502 | |
---|
503 | position = { |
---|
504 | my: myAt.join( " " ), |
---|
505 | at: myAt.join( " " ), |
---|
506 | offset: offset.join( " " ) |
---|
507 | }; |
---|
508 | } |
---|
509 | |
---|
510 | position = $.extend( {}, $.ui.dialog.prototype.options.position, position ); |
---|
511 | } else { |
---|
512 | position = $.ui.dialog.prototype.options.position; |
---|
513 | } |
---|
514 | |
---|
515 | // need to show the dialog to get the actual offset in the position plugin |
---|
516 | isVisible = this.uiDialog.is( ":visible" ); |
---|
517 | if ( !isVisible ) { |
---|
518 | this.uiDialog.show(); |
---|
519 | } |
---|
520 | this.uiDialog.position( position ); |
---|
521 | if ( !isVisible ) { |
---|
522 | this.uiDialog.hide(); |
---|
523 | } |
---|
524 | }, |
---|
525 | |
---|
526 | _setOptions: function( options ) { |
---|
527 | var that = this, |
---|
528 | resizableOptions = {}, |
---|
529 | resize = false; |
---|
530 | |
---|
531 | $.each( options, function( key, value ) { |
---|
532 | that._setOption( key, value ); |
---|
533 | |
---|
534 | if ( key in sizeRelatedOptions ) { |
---|
535 | resize = true; |
---|
536 | } |
---|
537 | if ( key in resizableRelatedOptions ) { |
---|
538 | resizableOptions[ key ] = value; |
---|
539 | } |
---|
540 | }); |
---|
541 | |
---|
542 | if ( resize ) { |
---|
543 | this._size(); |
---|
544 | } |
---|
545 | if ( this.uiDialog.is( ":data(resizable)" ) ) { |
---|
546 | this.uiDialog.resizable( "option", resizableOptions ); |
---|
547 | } |
---|
548 | }, |
---|
549 | |
---|
550 | _setOption: function( key, value ) { |
---|
551 | var isDraggable, isResizable, |
---|
552 | uiDialog = this.uiDialog; |
---|
553 | |
---|
554 | switch ( key ) { |
---|
555 | case "buttons": |
---|
556 | this._createButtons( value ); |
---|
557 | break; |
---|
558 | case "closeText": |
---|
559 | // ensure that we always pass a string |
---|
560 | this.uiDialogTitlebarCloseText.text( "" + value ); |
---|
561 | break; |
---|
562 | case "dialogClass": |
---|
563 | uiDialog |
---|
564 | .removeClass( this.options.dialogClass ) |
---|
565 | .addClass( uiDialogClasses + value ); |
---|
566 | break; |
---|
567 | case "disabled": |
---|
568 | if ( value ) { |
---|
569 | uiDialog.addClass( "ui-dialog-disabled" ); |
---|
570 | } else { |
---|
571 | uiDialog.removeClass( "ui-dialog-disabled" ); |
---|
572 | } |
---|
573 | break; |
---|
574 | case "draggable": |
---|
575 | isDraggable = uiDialog.is( ":data(draggable)" ); |
---|
576 | if ( isDraggable && !value ) { |
---|
577 | uiDialog.draggable( "destroy" ); |
---|
578 | } |
---|
579 | |
---|
580 | if ( !isDraggable && value ) { |
---|
581 | this._makeDraggable(); |
---|
582 | } |
---|
583 | break; |
---|
584 | case "position": |
---|
585 | this._position( value ); |
---|
586 | break; |
---|
587 | case "resizable": |
---|
588 | // currently resizable, becoming non-resizable |
---|
589 | isResizable = uiDialog.is( ":data(resizable)" ); |
---|
590 | if ( isResizable && !value ) { |
---|
591 | uiDialog.resizable( "destroy" ); |
---|
592 | } |
---|
593 | |
---|
594 | // currently resizable, changing handles |
---|
595 | if ( isResizable && typeof value === "string" ) { |
---|
596 | uiDialog.resizable( "option", "handles", value ); |
---|
597 | } |
---|
598 | |
---|
599 | // currently non-resizable, becoming resizable |
---|
600 | if ( !isResizable && value !== false ) { |
---|
601 | this._makeResizable( value ); |
---|
602 | } |
---|
603 | break; |
---|
604 | case "title": |
---|
605 | // convert whatever was passed in o a string, for html() to not throw up |
---|
606 | $( ".ui-dialog-title", this.uiDialogTitlebar ) |
---|
607 | .html( "" + ( value || " " ) ); |
---|
608 | break; |
---|
609 | } |
---|
610 | |
---|
611 | this._super( key, value ); |
---|
612 | }, |
---|
613 | |
---|
614 | _size: function() { |
---|
615 | /* If the user has resized the dialog, the .ui-dialog and .ui-dialog-content |
---|
616 | * divs will both have width and height set, so we need to reset them |
---|
617 | */ |
---|
618 | var nonContentHeight, minContentHeight, autoHeight, |
---|
619 | options = this.options, |
---|
620 | isVisible = this.uiDialog.is( ":visible" ); |
---|
621 | |
---|
622 | // reset content sizing |
---|
623 | this.element.show().css({ |
---|
624 | width: "auto", |
---|
625 | minHeight: 0, |
---|
626 | height: 0 |
---|
627 | }); |
---|
628 | |
---|
629 | if ( options.minWidth > options.width ) { |
---|
630 | options.width = options.minWidth; |
---|
631 | } |
---|
632 | |
---|
633 | // reset wrapper sizing |
---|
634 | // determine the height of all the non-content elements |
---|
635 | nonContentHeight = this.uiDialog.css({ |
---|
636 | height: "auto", |
---|
637 | width: options.width |
---|
638 | }) |
---|
639 | .outerHeight(); |
---|
640 | minContentHeight = Math.max( 0, options.minHeight - nonContentHeight ); |
---|
641 | |
---|
642 | if ( options.height === "auto" ) { |
---|
643 | // only needed for IE6 support |
---|
644 | if ( $.support.minHeight ) { |
---|
645 | this.element.css({ |
---|
646 | minHeight: minContentHeight, |
---|
647 | height: "auto" |
---|
648 | }); |
---|
649 | } else { |
---|
650 | this.uiDialog.show(); |
---|
651 | autoHeight = this.element.css( "height", "auto" ).height(); |
---|
652 | if ( !isVisible ) { |
---|
653 | this.uiDialog.hide(); |
---|
654 | } |
---|
655 | this.element.height( Math.max( autoHeight, minContentHeight ) ); |
---|
656 | } |
---|
657 | } else { |
---|
658 | this.element.height( Math.max( options.height - nonContentHeight, 0 ) ); |
---|
659 | } |
---|
660 | |
---|
661 | if (this.uiDialog.is( ":data(resizable)" ) ) { |
---|
662 | this.uiDialog.resizable( "option", "minHeight", this._minHeight() ); |
---|
663 | } |
---|
664 | } |
---|
665 | }); |
---|
666 | |
---|
667 | $.extend($.ui.dialog, { |
---|
668 | uuid: 0, |
---|
669 | maxZ: 0, |
---|
670 | |
---|
671 | getTitleId: function($el) { |
---|
672 | var id = $el.attr( "id" ); |
---|
673 | if ( !id ) { |
---|
674 | this.uuid += 1; |
---|
675 | id = this.uuid; |
---|
676 | } |
---|
677 | return "ui-dialog-title-" + id; |
---|
678 | }, |
---|
679 | |
---|
680 | overlay: function( dialog ) { |
---|
681 | this.$el = $.ui.dialog.overlay.create( dialog ); |
---|
682 | } |
---|
683 | }); |
---|
684 | |
---|
685 | $.extend( $.ui.dialog.overlay, { |
---|
686 | instances: [], |
---|
687 | // reuse old instances due to IE memory leak with alpha transparency (see #5185) |
---|
688 | oldInstances: [], |
---|
689 | maxZ: 0, |
---|
690 | events: $.map( |
---|
691 | "focus,mousedown,mouseup,keydown,keypress,click".split( "," ), |
---|
692 | function( event ) { |
---|
693 | return event + ".dialog-overlay"; |
---|
694 | } |
---|
695 | ).join( " " ), |
---|
696 | create: function( dialog ) { |
---|
697 | if ( this.instances.length === 0 ) { |
---|
698 | // prevent use of anchors and inputs |
---|
699 | // we use a setTimeout in case the overlay is created from an |
---|
700 | // event that we're going to be cancelling (see #2804) |
---|
701 | setTimeout(function() { |
---|
702 | // handle $(el).dialog().dialog('close') (see #4065) |
---|
703 | if ( $.ui.dialog.overlay.instances.length ) { |
---|
704 | $( document ).bind( $.ui.dialog.overlay.events, function( event ) { |
---|
705 | // stop events if the z-index of the target is < the z-index of the overlay |
---|
706 | // we cannot return true when we don't want to cancel the event (#3523) |
---|
707 | if ( $( event.target ).zIndex() < $.ui.dialog.overlay.maxZ ) { |
---|
708 | return false; |
---|
709 | } |
---|
710 | }); |
---|
711 | } |
---|
712 | }, 1 ); |
---|
713 | |
---|
714 | // handle window resize |
---|
715 | $( window ).bind( "resize.dialog-overlay", $.ui.dialog.overlay.resize ); |
---|
716 | } |
---|
717 | |
---|
718 | var $el = ( this.oldInstances.pop() || $( "<div>" ).addClass( "ui-widget-overlay" ) ); |
---|
719 | |
---|
720 | // allow closing by pressing the escape key |
---|
721 | $( document ).bind( "keydown.dialog-overlay", function( event ) { |
---|
722 | var instances = $.ui.dialog.overlay.instances; |
---|
723 | // only react to the event if we're the top overlay |
---|
724 | if ( instances.length !== 0 && instances[ instances.length - 1 ] === $el && |
---|
725 | dialog.options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode && |
---|
726 | event.keyCode === $.ui.keyCode.ESCAPE ) { |
---|
727 | |
---|
728 | dialog.close( event ); |
---|
729 | event.preventDefault(); |
---|
730 | } |
---|
731 | }); |
---|
732 | |
---|
733 | $el.appendTo( document.body ).css({ |
---|
734 | width: this.width(), |
---|
735 | height: this.height() |
---|
736 | }); |
---|
737 | |
---|
738 | if ( $.fn.bgiframe ) { |
---|
739 | $el.bgiframe(); |
---|
740 | } |
---|
741 | |
---|
742 | this.instances.push( $el ); |
---|
743 | return $el; |
---|
744 | }, |
---|
745 | |
---|
746 | destroy: function( $el ) { |
---|
747 | var indexOf = $.inArray( $el, this.instances ), |
---|
748 | maxZ = 0; |
---|
749 | |
---|
750 | if ( indexOf !== -1 ) { |
---|
751 | this.oldInstances.push( this.instances.splice( indexOf, 1 )[ 0 ] ); |
---|
752 | } |
---|
753 | |
---|
754 | if ( this.instances.length === 0 ) { |
---|
755 | $( [ document, window ] ).unbind( ".dialog-overlay" ); |
---|
756 | } |
---|
757 | |
---|
758 | $el.height( 0 ).width( 0 ).remove(); |
---|
759 | |
---|
760 | // adjust the maxZ to allow other modal dialogs to continue to work (see #4309) |
---|
761 | $.each( this.instances, function() { |
---|
762 | maxZ = Math.max( maxZ, this.css( "z-index" ) ); |
---|
763 | }); |
---|
764 | this.maxZ = maxZ; |
---|
765 | }, |
---|
766 | |
---|
767 | height: function() { |
---|
768 | var scrollHeight, |
---|
769 | offsetHeight; |
---|
770 | // handle IE |
---|
771 | if ( $.browser.msie ) { |
---|
772 | scrollHeight = Math.max( |
---|
773 | document.documentElement.scrollHeight, |
---|
774 | document.body.scrollHeight |
---|
775 | ); |
---|
776 | offsetHeight = Math.max( |
---|
777 | document.documentElement.offsetHeight, |
---|
778 | document.body.offsetHeight |
---|
779 | ); |
---|
780 | |
---|
781 | if ( scrollHeight < offsetHeight ) { |
---|
782 | return $( window ).height() + "px"; |
---|
783 | } else { |
---|
784 | return scrollHeight + "px"; |
---|
785 | } |
---|
786 | // handle "good" browsers |
---|
787 | } else { |
---|
788 | return $( document ).height() + "px"; |
---|
789 | } |
---|
790 | }, |
---|
791 | |
---|
792 | width: function() { |
---|
793 | var scrollWidth, |
---|
794 | offsetWidth; |
---|
795 | // handle IE |
---|
796 | if ( $.browser.msie ) { |
---|
797 | scrollWidth = Math.max( |
---|
798 | document.documentElement.scrollWidth, |
---|
799 | document.body.scrollWidth |
---|
800 | ); |
---|
801 | offsetWidth = Math.max( |
---|
802 | document.documentElement.offsetWidth, |
---|
803 | document.body.offsetWidth |
---|
804 | ); |
---|
805 | |
---|
806 | if ( scrollWidth < offsetWidth ) { |
---|
807 | return $( window ).width() + "px"; |
---|
808 | } else { |
---|
809 | return scrollWidth + "px"; |
---|
810 | } |
---|
811 | // handle "good" browsers |
---|
812 | } else { |
---|
813 | return $( document ).width() + "px"; |
---|
814 | } |
---|
815 | }, |
---|
816 | |
---|
817 | resize: function() { |
---|
818 | /* If the dialog is draggable and the user drags it past the |
---|
819 | * right edge of the window, the document becomes wider so we |
---|
820 | * need to stretch the overlay. If the user then drags the |
---|
821 | * dialog back to the left, the document will become narrower, |
---|
822 | * so we need to shrink the overlay to the appropriate size. |
---|
823 | * This is handled by shrinking the overlay before setting it |
---|
824 | * to the full document size. |
---|
825 | */ |
---|
826 | var $overlays = $( [] ); |
---|
827 | $.each( $.ui.dialog.overlay.instances, function() { |
---|
828 | $overlays = $overlays.add( this ); |
---|
829 | }); |
---|
830 | |
---|
831 | $overlays.css({ |
---|
832 | width: 0, |
---|
833 | height: 0 |
---|
834 | }).css({ |
---|
835 | width: $.ui.dialog.overlay.width(), |
---|
836 | height: $.ui.dialog.overlay.height() |
---|
837 | }); |
---|
838 | } |
---|
839 | }); |
---|
840 | |
---|
841 | $.extend( $.ui.dialog.overlay.prototype, { |
---|
842 | destroy: function() { |
---|
843 | $.ui.dialog.overlay.destroy( this.$el ); |
---|
844 | } |
---|
845 | }); |
---|
846 | |
---|
847 | }( jQuery ) ); |
---|