Авторазмер диалогового окна jQuery UI в Internet Explorer - PullRequest
6 голосов
/ 24 ноября 2010

Как я могу автоматически изменить размер jQuery UI в Internet Explorer?

Этот код работает в Firefox, но не в Internet Explorer.

$('#dialog2').dialog({
    autoResize: true,
    show: "clip",
    hide: "clip",
    height: 'auto',
    width: 'auto',
    autoOpen: false,
    modal: true,
    position: 'center',
    draggable: true,

    open: function (type, data) {
        $(this).parent().appendTo("form");

    },
    buttons: { "close": function () { $(this).dialog("close"); document.getElementById("<%=btnnew.ClientID%>").click(); } }
});

Мой HTML-элемент - это DIV.

Ответы [ 2 ]

5 голосов
/ 14 декабря 2010

У меня есть успех с width: 'auto' определением размера диалогового окна jQuery UI с использованием следующего «патча» (для IE):

(function($) {
var fixDialogAutoWidth = $.noop;
if ( $.browser.msie ) {
    fixDialogAutoWidth = function(content) {
        var dialog = $(content).parent('.ui-dialog');
        var width = dialog.innerWidth();
        if ( width ) dialog.css('width', width);
    }
}

var _init = $.ui.dialog.prototype._init;
$.ui.dialog.prototype._init = function() {
    // IE magick: (width: 'auto' not working correctly) :
    // http://dev.jqueryui.com/ticket/4437
    if ( this.options.width == 'auto' ) {
        var open = this.options.open;
        this.options.open = function() {
            fixDialogAutoWidth(this);
            if ( open ) open.apply(this);
        }
    }
    // yet another bug options.hide: 'drop' does not work
    // in IE http://dev.jqueryui.com/ticket/5615
    if ( $.browser.msie && this.options.hide == 'drop' ) {
        this.options.hide = 'fold';
    }
    return _init.apply(this); // calls open() if autoOpen
};
})(jQuery);

Просто загрузите этот код после загрузки jquery-ui.js ...

Обратите внимание, что в соответствии с билетом http://dev.jqueryui.com/ticket/4437 мы не должны использовать width: 'auto', но я просто не могу без него ...:)

0 голосов
/ 24 ноября 2010

Пожалуйста, сначала добавьте , в конце следующей строки

buttons: { "close": function () { $(this).dialog("close"); document.getElementById("<%=btnnew.ClientID%>").click(); } }

IE ожидает, что все опции будут закрыты через ,

Посмотрим, сработает ли это (вероятно, стоит спросить, на какой версии IE это происходит?)

...