diff options
author | Scott González <scott.gonzalez@gmail.com> | 2008-06-26 00:55:24 +0000 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2008-06-26 00:55:24 +0000 |
commit | 93c2dfff7194fe7e45e6bd0bf4863d8604dab0bb (patch) | |
tree | e9ce9ae45068db8bf01105ab5b83791fdc93a45c /ui/ui.dialog.js | |
parent | 173eddaf46a90f4cca92d747d3a093aef5e0207c (diff) | |
download | jquery-ui-93c2dfff7194fe7e45e6bd0bf4863d8604dab0bb.tar.gz jquery-ui-93c2dfff7194fe7e45e6bd0bf4863d8604dab0bb.zip |
Dialog: Restructured button creation and fixed the problem with not being able to change the buttons after instantiation.
Diffstat (limited to 'ui/ui.dialog.js')
-rw-r--r-- | ui/ui.dialog.js | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/ui/ui.dialog.js b/ui/ui.dialog.js index d6a7fb220..120a855e3 100644 --- a/ui/ui.dialog.js +++ b/ui/ui.dialog.js @@ -77,7 +77,11 @@ $.widget("ui.dialog", { }) .mousedown(function() { self.moveToTop(); - }); + }), + + uiDialogButtonPane = (this.uiDialogButtonPane = $('<div/>')) + .addClass('ui-dialog-buttonpane') + .appendTo(uiDialog); this.uiDialogTitlebarClose = $('.ui-dialog-titlebar-close', uiDialogTitlebar) .hover( @@ -96,19 +100,6 @@ $.widget("ui.dialog", { return false; }); - var hasButtons = false; - $.each(options.buttons, function() { return !(hasButtons = true); }); - if (hasButtons) { - var uiDialogButtonPane = $('<div class="ui-dialog-buttonpane"/>') - .appendTo(uiDialog); - $.each(options.buttons, function(name, fn) { - $('<button/>') - .text(name) - .click(function() { fn.apply(self.element[0], arguments); }) - .appendTo(uiDialogButtonPane); - }); - } - if ($.fn.draggable) { uiDialog.draggable({ helper: options.dragHelper, @@ -152,6 +143,8 @@ $.widget("ui.dialog", { (options.resizable || uiDialog.resizable('disable')); } + this.createButtons(options.buttons); + (options.bgiframe && $.fn.bgiframe && uiDialog.bgiframe()); (options.autoOpen && this.open()); }, @@ -159,6 +152,9 @@ $.widget("ui.dialog", { setData: function(key, value){ (setDataSwitch[key] && this.uiDialog.data(setDataSwitch[key], value)); switch (key) { + case "buttons": + this.createButtons(value); + break; case "draggable": this.uiDialog.draggable(value ? 'enable' : 'disable'); break; @@ -296,6 +292,26 @@ $.widget("ui.dialog", { .removeClass('ui-dialog-content') .hide().appendTo('body'); this.uiDialog.remove(); + }, + + createButtons: function(buttons) { + var self = this, + hasButtons = false, + uiDialogButtonPane = this.uiDialogButtonPane; + + // remove any existing buttons + uiDialogButtonPane.empty().hide(); + + $.each(buttons, function() { return !(hasButtons = true); }); + if (hasButtons) { + uiDialogButtonPane.show(); + $.each(buttons, function(name, fn) { + $('<button/>') + .text(name) + .click(function() { fn.apply(self.element[0], arguments); }) + .appendTo(uiDialogButtonPane); + }); + } } }); |