Bug Tracker

Changeset 5266

Show
Ignore:
Timestamp:
04/18/08 00:53:40 (8 months ago)
Author:
scott.gonzalez
Message:

UI Dialog: Fixed #2687: Removed "helpful element detection" and changed context of button clicks to the dialog element.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ui/ui.dialog.js

    r5185 r5266  
    1818     
    1919    $.fn.extend({ 
    20         dialog: function(options) { 
    21             var args = Array.prototype.slice.call(arguments, 1); 
    22  
     20        dialog: function(options, data) { 
    2321            return this.each(function() { 
    24                 if (typeof options == "string") { 
    25                     var elem = $(this).is('.ui-dialog') 
    26                         ? this 
    27                         : $(this).parents(".ui-dialog:first").find(".ui-dialog-content")[0]; 
    28                     var dialog = elem ? $.data(elem, "dialog") : {}; 
    29                     if (dialog[options]) 
    30                         dialog[options].apply(dialog, args); 
    31                 // INIT with optional options 
    32                 } else if (!$(this).is(".ui-dialog-content")) 
    33                     new $.ui.dialog(this, options); 
     22                var isMethodCall = (typeof options == "string"); 
     23                var instance = $.data(this, "dialog"); 
     24                 
     25                if (!instance && !isMethodCall) { 
     26                    $.data(this, "dialog", new $.ui.dialog(this, options)); 
     27                } else if (isMethodCall) { 
     28                    instance[options](data); 
     29                } 
    3430            }); 
    3531        } 
    3632    }); 
    37  
     33     
    3834    $.ui.dialog = function(el, options) { 
    3935         
     
    162158                ev.keyCode && ev.keyCode == ESC && self.close();  
    163159            }); 
    164  
    165         var l = 0; 
    166         $.each(options.buttons, function() { l = 1; return false; }); 
    167         if (l == 1) { 
    168             uiDialog.append('<div class="ui-dialog-buttonpane"></div>'); 
    169             var uiDialogButtonPane = $('.ui-dialog-buttonpane', uiDialog); 
    170             $.each(options.buttons, function(name, value) { 
    171                 var btn = $(document.createElement('button')).text(name).click(value); 
    172                 uiDialogButtonPane.append(btn); 
    173             }); 
    174         } 
    175  
     160         
     161        var hasButtons = false; 
     162        $.each(options.buttons, function() { return !(hasButtons = true); }); 
     163        if (hasButtons) { 
     164            var uiDialogButtonPane = $('<div class="ui-dialog-buttonpane"/>') 
     165                .appendTo(uiDialog); 
     166            $.each(options.buttons, function(name, fn) { 
     167                $(document.createElement('button')) 
     168                    .text(name) 
     169                    .click(function() { fn.apply(el, arguments) }) 
     170                    .appendTo(uiDialogButtonPane); 
     171            }); 
     172        } 
     173         
    176174        if ($.fn.draggable) { 
    177175            uiDialog.draggable({ 
     
    304302            autoOpen: true, 
    305303            bgiframe: false, 
    306             buttons: [], 
     304            buttons: {}, 
    307305            draggable: true, 
    308306            height: 200,