Merge "Fix regression in API log events (bug 35635)"
[lhc/web/wiklou.git] / resources / jquery.ui / jquery.ui.dialog.js
index 5f9b1f8..e7e05b1 100644 (file)
@@ -1,9 +1,9 @@
-/*
- * jQuery UI Dialog 1.8.2
+/*!
+ * jQuery UI Dialog 1.8.21
  *
- * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
- * Dual licensed under the MIT (MIT-LICENSE.txt)
- * and GPL (GPL-LICENSE.txt) licenses.
+ * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about)
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://jquery.org/license
  *
  * http://docs.jquery.com/UI/Dialog
  *
  *     jquery.ui.position.js
  *     jquery.ui.resizable.js
  */
-(function($) {
+(function( $, undefined ) {
 
 var uiDialogClasses =
-       'ui-dialog ' +
-       'ui-widget ' +
-       'ui-widget-content ' +
-       'ui-corner-all ';
+               'ui-dialog ' +
+               'ui-widget ' +
+               'ui-widget-content ' +
+               'ui-corner-all ',
+       sizeRelatedOptions = {
+               buttons: true,
+               height: true,
+               maxHeight: true,
+               maxWidth: true,
+               minHeight: true,
+               minWidth: true,
+               width: true
+       },
+       resizableRelatedOptions = {
+               maxHeight: true,
+               maxWidth: true,
+               minHeight: true,
+               minWidth: true
+       },
+       // support for jQuery 1.3.2 - handle common attrFn methods for dialog
+       attrFn = $.attrFn || {
+               val: true,
+               css: true,
+               html: true,
+               text: true,
+               data: true,
+               width: true,
+               height: true,
+               offset: true,
+               click: true
+       };
 
 $.widget("ui.dialog", {
        options: {
@@ -39,7 +66,18 @@ $.widget("ui.dialog", {
                minHeight: 150,
                minWidth: 150,
                modal: false,
-               position: 'center',
+               position: {
+                       my: 'center',
+                       at: 'center',
+                       collision: 'fit',
+                       // ensure that the titlebar is never outside the document
+                       using: function(pos) {
+                               var topOffset = $(this).css(pos).offset().top;
+                               if (topOffset < 0) {
+                                       $(this).css('top', pos.top - topOffset);
+                               }
+                       }
+               },
                resizable: true,
                show: null,
                stack: true,
@@ -47,13 +85,19 @@ $.widget("ui.dialog", {
                width: 300,
                zIndex: 1000
        },
+
        _create: function() {
                this.originalTitle = this.element.attr('title');
+               // #5742 - .attr() might return a DOMElement
+               if ( typeof this.originalTitle !== "string" ) {
+                       this.originalTitle = "";
+               }
 
+               this.options.title = this.options.title || this.originalTitle;
                var self = this,
                        options = self.options,
 
-                       title = options.title || self.originalTitle || '&#160;',
+                       title = options.title || '&#160;',
                        titleId = $.ui.dialog.getTitleId(self.element),
 
                        uiDialog = (self.uiDialog = $('<div></div>'))
@@ -66,7 +110,7 @@ $.widget("ui.dialog", {
                                // setting tabIndex makes the div focusable
                                // setting outline to 0 prevents a border on focus in Mozilla
                                .attr('tabIndex', -1).css('outline', 0).keydown(function(event) {
-                                       if (options.closeOnEscape && event.keyCode &&
+                                       if (options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
                                                event.keyCode === $.ui.keyCode.ESCAPE) {
                                                
                                                self.close(event);
@@ -161,6 +205,7 @@ $.widget("ui.dialog", {
                        uiDialog.bgiframe();
                }
        },
+
        _init: function() {
                if ( this.options.autoOpen ) {
                        this.open();
@@ -187,14 +232,14 @@ $.widget("ui.dialog", {
 
                return self;
        },
-       
+
        widget: function() {
                return this.uiDialog;
        },
 
        close: function(event) {
                var self = this,
-                       maxZ;
+                       maxZ, thisZ;
                
                if (false === self._trigger('beforeClose', event)) {
                        return;
@@ -223,7 +268,10 @@ $.widget("ui.dialog", {
                        maxZ = 0;
                        $('.ui-dialog').each(function() {
                                if (this !== self.uiDialog[0]) {
-                                       maxZ = Math.max(maxZ, $(this).css('z-index'));
+                                       thisZ = $(this).css('z-index');
+                                       if(!isNaN(thisZ)) {
+                                               maxZ = Math.max(maxZ, thisZ);
+                                       }
                                }
                        });
                        $.ui.dialog.maxZ = maxZ;
@@ -242,12 +290,12 @@ $.widget("ui.dialog", {
                var self = this,
                        options = self.options,
                        saveScroll;
-               
+
                if ((options.modal && !force) ||
                        (!options.stack && !options.modal)) {
                        return self._trigger('focus', event);
                }
-               
+
                if (options.zIndex > $.ui.dialog.maxZ) {
                        $.ui.dialog.maxZ = options.zIndex;
                }
@@ -258,7 +306,7 @@ $.widget("ui.dialog", {
 
                //Save and then restore scroll since Opera 9.5+ resets when parent z-Index is changed.
                //  http://ui.jquery.com/bugs/ticket/3193
-               saveScroll = { scrollTop: self.element.attr('scrollTop'), scrollLeft: self.element.attr('scrollLeft') };
+               saveScroll = { scrollTop: self.element.scrollTop(), scrollLeft: self.element.scrollLeft() };
                $.ui.dialog.maxZ += 1;
                self.uiDialog.css('z-index', $.ui.dialog.maxZ);
                self.element.attr(saveScroll);
@@ -275,25 +323,22 @@ $.widget("ui.dialog", {
                        uiDialog = self.uiDialog;
 
                self.overlay = options.modal ? new $.ui.dialog.overlay(self) : null;
-               if (uiDialog.next().length) {
-                       uiDialog.appendTo('body');
-               }
                self._size();
                self._position(options.position);
                uiDialog.show(options.show);
                self.moveToTop(true);
 
                // prevent tabbing out of modal dialogs
-               if (options.modal) {
-                       uiDialog.bind('keypress.ui-dialog', function(event) {
-                               if (event.keyCode !== $.ui.keyCode.TAB) {
+               if ( options.modal ) {
+                       uiDialog.bind( "keydown.ui-dialog", function( event ) {
+                               if ( event.keyCode !== $.ui.keyCode.TAB ) {
                                        return;
                                }
-       
+
                                var tabbables = $(':tabbable', this),
                                        first = tabbables.filter(':first'),
                                        last  = tabbables.filter(':last');
-       
+
                                if (event.target === last[0] && !event.shiftKey) {
                                        first.focus(1);
                                        return false;
@@ -306,15 +351,12 @@ $.widget("ui.dialog", {
 
                // set focus to the first tabbable element in the content area or the first button
                // if there are no tabbable elements, set focus on the dialog itself
-               $([])
-                       .add(uiDialog.find('.ui-dialog-content :tabbable:first'))
-                       .add(uiDialog.find('.ui-dialog-buttonpane :tabbable:first'))
-                       .add(uiDialog)
-                       .filter(':first')
-                       .focus();
+               $(self.element.find(':tabbable').get().concat(
+                       uiDialog.find('.ui-dialog-buttonpane :tabbable').get().concat(
+                               uiDialog.get()))).eq(0).focus();
 
-               self._trigger('open');
                self._isOpen = true;
+               self._trigger('open');
 
                return self;
        },
@@ -327,7 +369,10 @@ $.widget("ui.dialog", {
                                        'ui-dialog-buttonpane ' +
                                        'ui-widget-content ' +
                                        'ui-helper-clearfix'
-                               );
+                               ),
+                       uiButtonSet = $( "<div></div>" )
+                               .addClass( "ui-dialog-buttonset" )
+                               .appendTo( uiDialogButtonPane );
 
                // if we already have a button pane, remove it
                self.uiDialog.find('.ui-dialog-buttonpane').remove();
@@ -338,11 +383,26 @@ $.widget("ui.dialog", {
                        });
                }
                if (hasButtons) {
-                       $.each(buttons, function(name, fn) {
+                       $.each(buttons, function(name, props) {
+                               props = $.isFunction( props ) ?
+                                       { click: props, text: name } :
+                                       props;
                                var button = $('<button type="button"></button>')
-                                       .text(name)
-                                       .click(function() { fn.apply(self.element[0], arguments); })
-                                       .appendTo(uiDialogButtonPane);
+                                       .click(function() {
+                                               props.click.apply(self.element[0], arguments);
+                                       })
+                                       .appendTo(uiButtonSet);
+                               // can't use .attr( props, true ) with jQuery 1.3.2.
+                               $.each( props, function( key, value ) {
+                                       if ( key === "click" ) {
+                                               return;
+                                       }
+                                       if ( key in attrFn ) {
+                                               button[ key ]( value );
+                                       } else {
+                                               button.attr( key, value );
+                                       }
+                               });
                                if ($.fn.button) {
                                        button.button();
                                }
@@ -450,40 +510,34 @@ $.widget("ui.dialog", {
                        offset = [0, 0],
                        isVisible;
 
-               position = position || $.ui.dialog.prototype.options.position;
+               if (position) {
+                       // deep extending converts arrays to objects in jQuery <= 1.3.2 :-(
+       //              if (typeof position == 'string' || $.isArray(position)) {
+       //                      myAt = $.isArray(position) ? position : position.split(' ');
 
-               // deep extending converts arrays to objects in jQuery <= 1.3.2 :-(
-//             if (typeof position == 'string' || $.isArray(position)) {
-//                     myAt = $.isArray(position) ? position : position.split(' ');
+                       if (typeof position === 'string' || (typeof position === 'object' && '0' in position)) {
+                               myAt = position.split ? position.split(' ') : [position[0], position[1]];
+                               if (myAt.length === 1) {
+                                       myAt[1] = myAt[0];
+                               }
 
-               if (typeof position === 'string' || (typeof position === 'object' && '0' in position)) {
-                       myAt = position.split ? position.split(' ') : [position[0], position[1]];
-                       if (myAt.length === 1) {
-                               myAt[1] = myAt[0];
-                       }
+                               $.each(['left', 'top'], function(i, offsetPosition) {
+                                       if (+myAt[i] === myAt[i]) {
+                                               offset[i] = myAt[i];
+                                               myAt[i] = offsetPosition;
+                                       }
+                               });
 
-                       $.each(['left', 'top'], function(i, offsetPosition) {
-                               if (+myAt[i] === myAt[i]) {
-                                       offset[i] = myAt[i];
-                                       myAt[i] = offsetPosition;
-                               }
-                       });
-               } else if (typeof position === 'object') {
-                       if ('left' in position) {
-                               myAt[0] = 'left';
-                               offset[0] = position.left;
-                       } else if ('right' in position) {
-                               myAt[0] = 'right';
-                               offset[0] = -position.right;
-                       }
+                               position = {
+                                       my: myAt.join(" "),
+                                       at: myAt.join(" "),
+                                       offset: offset.join(" ")
+                               };
+                       } 
 
-                       if ('top' in position) {
-                               myAt[1] = 'top';
-                               offset[1] = position.top;
-                       } else if ('bottom' in position) {
-                               myAt[1] = 'bottom';
-                               offset[1] = -position.bottom;
-                       }
+                       position = $.extend({}, $.ui.dialog.prototype.options.position, position);
+               } else {
+                       position = $.ui.dialog.prototype.options.position;
                }
 
                // need to show the dialog to get the actual offset in the position plugin
@@ -494,31 +548,40 @@ $.widget("ui.dialog", {
                this.uiDialog
                        // workaround for jQuery bug #5781 http://dev.jquery.com/ticket/5781
                        .css({ top: 0, left: 0 })
-                       .position({
-                               my: myAt.join(' '),
-                               at: myAt.join(' '),
-                               offset: offset.join(' '),
-                               of: window,
-                               collision: 'fit',
-                               // ensure that the titlebar is never outside the document
-                               using: function(pos) {
-                                       var topOffset = $(this).css(pos).offset().top;
-                                       if (topOffset < 0) {
-                                               $(this).css('top', pos.top - topOffset);
-                                       }
-                               }
-                       });
+                       .position($.extend({ of: window }, position));
                if (!isVisible) {
                        this.uiDialog.hide();
                }
        },
 
-       _setOption: function(key, value){
+       _setOptions: function( options ) {
                var self = this,
-                       uiDialog = self.uiDialog,
-                       isResizable = uiDialog.is(':data(resizable)'),
+                       resizableOptions = {},
                        resize = false;
-               
+
+               $.each( options, function( key, value ) {
+                       self._setOption( key, value );
+                       
+                       if ( key in sizeRelatedOptions ) {
+                               resize = true;
+                       }
+                       if ( key in resizableRelatedOptions ) {
+                               resizableOptions[ key ] = value;
+                       }
+               });
+
+               if ( resize ) {
+                       this._size();
+               }
+               if ( this.uiDialog.is( ":data(resizable)" ) ) {
+                       this.uiDialog.resizable( "option", resizableOptions );
+               }
+       },
+
+       _setOption: function(key, value){
+               var self = this,
+                       uiDialog = self.uiDialog;
+
                switch (key) {
                        //handling of deprecated beforeclose (vs beforeClose) option
                        //Ticket #4669 http://dev.jqueryui.com/ticket/4669
@@ -530,7 +593,7 @@ $.widget("ui.dialog", {
                                self._createButtons(value);
                                break;
                        case "closeText":
-                               // convert whatever was passed in to a string, for text() to not throw up
+                               // ensure that we always pass a string
                                self.uiDialogTitlebarCloseText.text("" + value);
                                break;
                        case "dialogClass":
@@ -546,44 +609,21 @@ $.widget("ui.dialog", {
                                }
                                break;
                        case "draggable":
-                               if (value) {
-                                       self._makeDraggable();
-                               } else {
-                                       uiDialog.draggable('destroy');
-                               }
-                               break;
-                       case "height":
-                               resize = true;
-                               break;
-                       case "maxHeight":
-                               if (isResizable) {
-                                       uiDialog.resizable('option', 'maxHeight', value);
-                               }
-                               resize = true;
-                               break;
-                       case "maxWidth":
-                               if (isResizable) {
-                                       uiDialog.resizable('option', 'maxWidth', value);
-                               }
-                               resize = true;
-                               break;
-                       case "minHeight":
-                               if (isResizable) {
-                                       uiDialog.resizable('option', 'minHeight', value);
+                               var isDraggable = uiDialog.is( ":data(draggable)" );
+                               if ( isDraggable && !value ) {
+                                       uiDialog.draggable( "destroy" );
                                }
-                               resize = true;
-                               break;
-                       case "minWidth":
-                               if (isResizable) {
-                                       uiDialog.resizable('option', 'minWidth', value);
+                               
+                               if ( !isDraggable && value ) {
+                                       self._makeDraggable();
                                }
-                               resize = true;
                                break;
                        case "position":
                                self._position(value);
                                break;
                        case "resizable":
                                // currently resizable, becoming non-resizable
+                               var isResizable = uiDialog.is( ":data(resizable)" );
                                if (isResizable && !value) {
                                        uiDialog.resizable('destroy');
                                }
@@ -602,15 +642,9 @@ $.widget("ui.dialog", {
                                // convert whatever was passed in o a string, for html() to not throw up
                                $(".ui-dialog-title", self.uiDialogTitlebar).html("" + (value || '&#160;'));
                                break;
-                       case "width":
-                               resize = true;
-                               break;
                }
 
                $.Widget.prototype._setOption.apply(self, arguments);
-               if (resize) {
-                       self._size();
-               }
        },
 
        _size: function() {
@@ -618,16 +652,21 @@ $.widget("ui.dialog", {
                 * divs will both have width and height set, so we need to reset them
                 */
                var options = this.options,
-                       nonContentHeight;
+                       nonContentHeight,
+                       minContentHeight,
+                       isVisible = this.uiDialog.is( ":visible" );
 
                // reset content sizing
-               // hide for non content measurement because height: 0 doesn't work in IE quirks mode (see #4350)
-               this.element.css({
+               this.element.show().css({
                        width: 'auto',
                        minHeight: 0,
                        height: 0
                });
 
+               if (options.minWidth > options.width) {
+                       options.width = options.minWidth;
+               }
+
                // reset wrapper sizing
                // determine the height of all the non-content elements
                nonContentHeight = this.uiDialog.css({
@@ -635,16 +674,26 @@ $.widget("ui.dialog", {
                                width: options.width
                        })
                        .height();
-
-               this.element
-                       .css(options.height === 'auto' ? {
-                                       minHeight: Math.max(options.minHeight - nonContentHeight, 0),
-                                       height: 'auto'
-                               } : {
-                                       minHeight: 0,
-                                       height: Math.max(options.height - nonContentHeight, 0)                          
-                       })
-                       .show();
+               minContentHeight = Math.max( 0, options.minHeight - nonContentHeight );
+               
+               if ( options.height === "auto" ) {
+                       // only needed for IE6 support
+                       if ( $.support.minHeight ) {
+                               this.element.css({
+                                       minHeight: minContentHeight,
+                                       height: "auto"
+                               });
+                       } else {
+                               this.uiDialog.show();
+                               var autoHeight = this.element.css( "height", "auto" ).height();
+                               if ( !isVisible ) {
+                                       this.uiDialog.hide();
+                               }
+                               this.element.height( Math.max( autoHeight, minContentHeight ) );
+                       }
+               } else {
+                       this.element.height( Math.max( options.height - nonContentHeight, 0 ) );
+               }
 
                if (this.uiDialog.is(':data(resizable)')) {
                        this.uiDialog.resizable('option', 'minHeight', this._minHeight());
@@ -653,7 +702,7 @@ $.widget("ui.dialog", {
 });
 
 $.extend($.ui.dialog, {
-       version: "1.8.2",
+       version: "1.8.21",
 
        uuid: 0,
        maxZ: 0,
@@ -689,14 +738,17 @@ $.extend($.ui.dialog.overlay, {
                                if ($.ui.dialog.overlay.instances.length) {
                                        $(document).bind($.ui.dialog.overlay.events, function(event) {
                                                // stop events if the z-index of the target is < the z-index of the overlay
-                                               return ($(event.target).zIndex() >= $.ui.dialog.overlay.maxZ);
+                                               // we cannot return true when we don't want to cancel the event (#3523)
+                                               if ($(event.target).zIndex() < $.ui.dialog.overlay.maxZ) {
+                                                       return false;
+                                               }
                                        });
                                }
                        }, 1);
 
                        // allow closing by pressing the escape key
                        $(document).bind('keydown.dialog-overlay', function(event) {
-                               if (dialog.options.closeOnEscape && event.keyCode &&
+                               if (dialog.options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
                                        event.keyCode === $.ui.keyCode.ESCAPE) {
                                        
                                        dialog.close(event);
@@ -724,7 +776,10 @@ $.extend($.ui.dialog.overlay, {
        },
 
        destroy: function($el) {
-               this.oldInstances.push(this.instances.splice($.inArray($el, this.instances), 1)[0]);
+               var indexOf = $.inArray($el, this.instances);
+               if (indexOf != -1){
+                       this.oldInstances.push(this.instances.splice(indexOf, 1)[0]);
+               }
 
                if (this.instances.length === 0) {
                        $([document, window]).unbind('.dialog-overlay');
@@ -768,8 +823,8 @@ $.extend($.ui.dialog.overlay, {
        width: function() {
                var scrollWidth,
                        offsetWidth;
-               // handle IE 6
-               if ($.browser.msie && $.browser.version < 7) {
+               // handle IE
+               if ( $.browser.msie ) {
                        scrollWidth = Math.max(
                                document.documentElement.scrollWidth,
                                document.body.scrollWidth