Bug Tracker

Changeset 4661

Show
Ignore:
Timestamp:
02/06/08 05:18:33 (10 months ago)
Author:
rdworth
Message:

Fixed #1669 - UI Dialog modal option - thanks Scott Gonzalez (ported Mike Alsup's blockUI)

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/themes/flora/flora.dialog.css

    r4588 r4661  
    2929    right: 7px; 
    3030    cursor: default; 
     31} 
     32 
     33.flora .ui-dialog .ui-dialog-titlebar-close span, 
     34.flora.ui-dialog .ui-dialog-titlebar-close span { 
     35    display: none; 
    3136} 
    3237 
  • trunk/ui/tests/uiTest.dialog.js

    r4590 r4661  
    4040                    "600" : "$('#foo').dialog({\n\t minWidth: 600 \n});" 
    4141                }, 
     42                "modal" : { 
     43                    "false" : "$('#foo').dialog({\n\t modal: false \n});", 
     44                    "true" : "$('#foo').dialog({\n\t modal: true \n});", 
     45                    "Css-BgWhiteOpacity0.5" : "$('#foo').dialog({\n\t modal: { backgroundColor: 'white', opacity: 0.5 } \n})" 
     46                }, 
    4247                "position" : { 
    4348                    "center" : "$('#foo').dialog({\n\t position: 'center' \n});", 
  • trunk/ui/ui.dialog.js

    r4612 r4661  
    11(function($) { 
    2  
     2     
    33    //If the UI scope is not available, add it 
    44    $.ui = $.ui || {}; 
     
    3232            buttons: [], 
    3333            draggable: true, 
    34             resizable: true 
    35         }; 
    36         options = $.extend({}, defaults, options); //Extend and copy options 
     34            resizable: true, 
     35            modal: false 
     36        }; 
     37        options = options || {}; 
     38        var defaultOverrides = options.modal ? {resizable: false} : {}; 
     39        options = $.extend({}, defaults, defaultOverrides, options); //Extend and copy options 
    3740        this.element = el; 
    3841        var self = this; //Do bindings 
     
    8487        var title = (options.title) ? options.title : (uiDialogContent.attr('title')) ? uiDialogContent.attr('title') : ''; 
    8588        uiDialogTitlebar.append('<span class="ui-dialog-title">' + title + '</span>'); 
    86         uiDialogTitlebar.append('<div class="ui-dialog-titlebar-close"></div>'); 
    87         $('.ui-dialog-titlebar-close', uiDialogTitlebar) 
     89        uiDialogTitlebar.append('<a href="#" class="ui-dialog-titlebar-close"><span>X</span></a>'); 
     90        this.uiDialogTitlebarClose = $('.ui-dialog-titlebar-close', uiDialogTitlebar) 
    8891            .hover(function() { $(this).addClass('ui-dialog-titlebar-close-hover'); },  
    8992                   function() { $(this).removeClass('ui-dialog-titlebar-close-hover'); }) 
     
    9396            .click(function() { 
    9497                self.close(); 
     98                return false; 
     99            }) 
     100            .keydown(function(ev) { 
     101                var ESC = 27; 
     102                ev.keyCode && ev.keyCode == ESC && self.close();  
    95103            }); 
    96104 
     
    122130     
    123131        this.open = function() { 
     132            options.modal && overlay.show(self, options.modal); 
    124133            uiDialog.appendTo('body'); 
    125134            var wnd = $(window), doc = $(document), top = doc.scrollTop(), left = doc.scrollLeft(); 
     
    166175                options: options 
    167176            }; 
     177            this.uiDialogTitlebarClose.focus(); 
    168178            $(this.element).triggerHandler("dialogopen", [openEV, openUI], options.open); 
    169179        }; 
    170180 
    171181        this.activate = function() { 
    172             var maxZ = curZ = 0; 
     182            var maxZ = 0; 
    173183            $('.ui-dialog:visible').each(function() { 
    174                 var z = parseInt($(this).css("z-index")); 
    175                 maxZ = z > maxZ ? z : maxZ; 
    176             }); 
    177             uiDialog.css("z-index", maxZ + 1); 
     184                maxZ = Math.max(maxZ, parseInt($(this).css("z-index"))); 
     185            }); 
     186            overlay.$el && overlay.$el.css('z-index', ++maxZ); 
     187            uiDialog.css("z-index", ++maxZ); 
    178188        }; 
    179189 
    180190        this.close = function() { 
     191            options.modal && overlay.hide(); 
    181192            uiDialog.hide(); 
    182193 
     
    194205    } 
    195206 
     207    // This is a port of relevant pieces of Mike Alsup's blockUI plugin (http://www.malsup.com/jquery/block/) 
     208    // duplicated here for minimal overlay functionality and no dependency on a non-UI plugin 
     209    var overlay = { 
     210        $el: null, 
     211        events: $.map('focus,mousedown,mouseup,keydown,keypress,click'.split(','), 
     212            function(e) { return e + '.ui-dialog-overlay'; }).join(' '), 
     213         
     214        show: function(dialog, css) { 
     215            if (this.$el) return; 
     216             
     217            this.selects = this.ie6 && $('select:visible').css('visibility', 'hidden'); 
     218            this.$el = $('<div"/>').appendTo(document.body) 
     219                .addClass('ui-dialog-overlay').css($.extend({ 
     220                    borderWidth: 0, margin: 0, padding: 0, 
     221                    position: 'absolute', top: 0, left: 0, 
     222                    width: $(document).width(), // TODO: fix 
     223                    height: $(document).height() // TODO: fix 
     224                }, css)); 
     225             
     226            $('a, :input').bind(this.events, function() { 
     227                if ($(this).parents('.ui-dialog').length == 0) { 
     228                    dialog.uiDialogTitlebarClose.focus(); 
     229                    return false; 
     230                } 
     231            }); 
     232            $(document).bind('keydown.ui-dialog-overlay', function(e) { 
     233                var ESC = 27; 
     234                e.keyCode && e.keyCode == ESC && dialog.close();  
     235            }); 
     236        }, 
     237         
     238        hide: function() { 
     239            $('a, :input').add(document).unbind('.ui-dialog-overlay'); 
     240            this.ie6 && this.selects.css('visibility', 'visible'); 
     241            this.$el = null; 
     242            $('.ui-dialog-overlay').remove(); 
     243        }, 
     244         
     245        // IE 6 compatibility 
     246        ie6: $.browser.msie && $.browser.version < 7, 
     247        selects: null 
     248    }; 
     249 
    196250})(jQuery);