mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Dialog: Restructured button creation and fixed the problem with not being able to change the buttons after instantiation.
This commit is contained in:
parent
173eddaf46
commit
93c2dfff71
@ -77,7 +77,11 @@ $.widget("ui.dialog", {
|
|||||||
})
|
})
|
||||||
.mousedown(function() {
|
.mousedown(function() {
|
||||||
self.moveToTop();
|
self.moveToTop();
|
||||||
});
|
}),
|
||||||
|
|
||||||
|
uiDialogButtonPane = (this.uiDialogButtonPane = $('<div/>'))
|
||||||
|
.addClass('ui-dialog-buttonpane')
|
||||||
|
.appendTo(uiDialog);
|
||||||
|
|
||||||
this.uiDialogTitlebarClose = $('.ui-dialog-titlebar-close', uiDialogTitlebar)
|
this.uiDialogTitlebarClose = $('.ui-dialog-titlebar-close', uiDialogTitlebar)
|
||||||
.hover(
|
.hover(
|
||||||
@ -96,19 +100,6 @@ $.widget("ui.dialog", {
|
|||||||
return false;
|
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) {
|
if ($.fn.draggable) {
|
||||||
uiDialog.draggable({
|
uiDialog.draggable({
|
||||||
helper: options.dragHelper,
|
helper: options.dragHelper,
|
||||||
@ -152,6 +143,8 @@ $.widget("ui.dialog", {
|
|||||||
(options.resizable || uiDialog.resizable('disable'));
|
(options.resizable || uiDialog.resizable('disable'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.createButtons(options.buttons);
|
||||||
|
|
||||||
(options.bgiframe && $.fn.bgiframe && uiDialog.bgiframe());
|
(options.bgiframe && $.fn.bgiframe && uiDialog.bgiframe());
|
||||||
(options.autoOpen && this.open());
|
(options.autoOpen && this.open());
|
||||||
},
|
},
|
||||||
@ -159,6 +152,9 @@ $.widget("ui.dialog", {
|
|||||||
setData: function(key, value){
|
setData: function(key, value){
|
||||||
(setDataSwitch[key] && this.uiDialog.data(setDataSwitch[key], value));
|
(setDataSwitch[key] && this.uiDialog.data(setDataSwitch[key], value));
|
||||||
switch (key) {
|
switch (key) {
|
||||||
|
case "buttons":
|
||||||
|
this.createButtons(value);
|
||||||
|
break;
|
||||||
case "draggable":
|
case "draggable":
|
||||||
this.uiDialog.draggable(value ? 'enable' : 'disable');
|
this.uiDialog.draggable(value ? 'enable' : 'disable');
|
||||||
break;
|
break;
|
||||||
@ -296,6 +292,26 @@ $.widget("ui.dialog", {
|
|||||||
.removeClass('ui-dialog-content')
|
.removeClass('ui-dialog-content')
|
||||||
.hide().appendTo('body');
|
.hide().appendTo('body');
|
||||||
this.uiDialog.remove();
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user