mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Dialog: Added appendTo option. Fixes #7948 - Dialog: Allow dialog to be attached to a element other than body.
This commit is contained in:
parent
da17a232ca
commit
70b16ef445
@ -61,6 +61,8 @@
|
|||||||
<label for="favorite-food">Favorite food</label><input id="favorite-food">
|
<label for="favorite-food">Favorite food</label><input id="favorite-food">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="wrap" id="wrap1"></div>
|
||||||
|
<div class="wrap" id="wrap2"></div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
TestHelpers.commonWidgetTests( "dialog", {
|
TestHelpers.commonWidgetTests( "dialog", {
|
||||||
defaults: {
|
defaults: {
|
||||||
|
appendTo: "body",
|
||||||
autoOpen: true,
|
autoOpen: true,
|
||||||
buttons: {},
|
buttons: {},
|
||||||
closeOnEscape: true,
|
closeOnEscape: true,
|
||||||
|
@ -5,6 +5,47 @@
|
|||||||
|
|
||||||
module("dialog: options");
|
module("dialog: options");
|
||||||
|
|
||||||
|
test( "appendTo", function() {
|
||||||
|
expect( 8 );
|
||||||
|
var detached = $( "<div>" ),
|
||||||
|
element = $( "#dialog1" ).dialog();
|
||||||
|
equal( element.dialog( "widget" ).parent()[0], document.body, "defaults to body" );
|
||||||
|
element.dialog( "destroy" );
|
||||||
|
|
||||||
|
element.dialog({
|
||||||
|
appendTo: ".wrap"
|
||||||
|
});
|
||||||
|
equal( element.dialog( "widget" ).parent()[0], $( "#wrap1" )[0], "first found element" );
|
||||||
|
equal( $( "#wrap2 .ui-dialog" ).length, 0, "only appends to one element" );
|
||||||
|
element.dialog( "destroy" );
|
||||||
|
|
||||||
|
element.dialog({
|
||||||
|
appendTo: null
|
||||||
|
});
|
||||||
|
equal( element.dialog( "widget" ).parent()[0], document.body, "null" );
|
||||||
|
element.dialog( "destroy" );
|
||||||
|
|
||||||
|
element.dialog({ autoOpen: false }).dialog( "option", "appendTo", "#wrap1" ).dialog( "open" );
|
||||||
|
equal( element.dialog( "widget" ).parent()[0], $( "#wrap1" )[0], "modified after init" );
|
||||||
|
element.dialog( "destroy" );
|
||||||
|
|
||||||
|
element.dialog({
|
||||||
|
appendTo: detached
|
||||||
|
});
|
||||||
|
equal( element.dialog( "widget" ).parent()[0], detached[0], "detached jQuery object" );
|
||||||
|
element.dialog( "destroy" );
|
||||||
|
|
||||||
|
element.dialog({
|
||||||
|
appendTo: detached[0]
|
||||||
|
});
|
||||||
|
equal( element.dialog( "widget" ).parent()[0], detached[0], "detached DOM element" );
|
||||||
|
element.dialog( "destroy" );
|
||||||
|
|
||||||
|
element.dialog({ autoOpen: false }).dialog( "option", "appendTo", detached );
|
||||||
|
equal( element.dialog( "widget" ).parent()[0], detached[0], "detached DOM element via option()" );
|
||||||
|
element.dialog( "destroy" );
|
||||||
|
});
|
||||||
|
|
||||||
test("autoOpen", function() {
|
test("autoOpen", function() {
|
||||||
expect(2);
|
expect(2);
|
||||||
|
|
||||||
|
15
ui/jquery.ui.dialog.js
vendored
15
ui/jquery.ui.dialog.js
vendored
@ -39,6 +39,7 @@ var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ui-fr
|
|||||||
$.widget("ui.dialog", {
|
$.widget("ui.dialog", {
|
||||||
version: "@VERSION",
|
version: "@VERSION",
|
||||||
options: {
|
options: {
|
||||||
|
appendTo: "body",
|
||||||
autoOpen: true,
|
autoOpen: true,
|
||||||
buttons: {},
|
buttons: {},
|
||||||
closeOnEscape: true,
|
closeOnEscape: true,
|
||||||
@ -124,6 +125,14 @@ $.widget("ui.dialog", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_appendTo: function() {
|
||||||
|
var element = this.options.appendTo;
|
||||||
|
if ( element && (element.jquery || element.nodeType) ) {
|
||||||
|
return $( element );
|
||||||
|
}
|
||||||
|
return this.document.find( element || "body" ).eq( 0 );
|
||||||
|
},
|
||||||
|
|
||||||
_destroy: function() {
|
_destroy: function() {
|
||||||
var next,
|
var next,
|
||||||
oldPosition = this.oldPosition;
|
oldPosition = this.oldPosition;
|
||||||
@ -276,7 +285,7 @@ $.widget("ui.dialog", {
|
|||||||
tabIndex: -1,
|
tabIndex: -1,
|
||||||
role: "dialog"
|
role: "dialog"
|
||||||
})
|
})
|
||||||
.appendTo( this.document[ 0 ].body );
|
.appendTo( this._appendTo() );
|
||||||
|
|
||||||
this._on( this.uiDialog, {
|
this._on( this.uiDialog, {
|
||||||
keydown: function( event ) {
|
keydown: function( event ) {
|
||||||
@ -569,6 +578,10 @@ $.widget("ui.dialog", {
|
|||||||
|
|
||||||
this._super( key, value );
|
this._super( key, value );
|
||||||
|
|
||||||
|
if ( key === "appendTo" ) {
|
||||||
|
this.uiDialog.appendTo( this._appendTo() );
|
||||||
|
}
|
||||||
|
|
||||||
if ( key === "buttons" ) {
|
if ( key === "buttons" ) {
|
||||||
this._createButtons();
|
this._createButtons();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user