mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Dialog: Follow-up to 9fe3a62d8
- also deprecate string notation for position option.
This commit is contained in:
parent
f3525afe0e
commit
a09f5c07f5
@ -1,4 +1,4 @@
|
|||||||
module("dialog (deprecated): position opton with array");
|
module("dialog (deprecated): position option with string and array");
|
||||||
|
|
||||||
if ( !$.ui.ie ) {
|
if ( !$.ui.ie ) {
|
||||||
test("position, right bottom on window w/array", function() {
|
test("position, right bottom on window w/array", function() {
|
||||||
@ -10,6 +10,16 @@ if ( !$.ui.ie ) {
|
|||||||
closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1);
|
closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1);
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("position, right bottom on window", function() {
|
||||||
|
expect( 2 );
|
||||||
|
var el = $('<div></div>').dialog({ position: "right bottom" }),
|
||||||
|
dialog = el.dialog('widget'),
|
||||||
|
offset = dialog.offset();
|
||||||
|
closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1);
|
||||||
|
closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1);
|
||||||
|
el.remove();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
test("position, offset from top left w/array", function() {
|
test("position, offset from top left w/array", function() {
|
||||||
@ -21,3 +31,23 @@ test("position, offset from top left w/array", function() {
|
|||||||
closeEnough(offset.top, 10 + $(window).scrollTop(), 1);
|
closeEnough(offset.top, 10 + $(window).scrollTop(), 1);
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("position, top on window", function() {
|
||||||
|
expect( 2 );
|
||||||
|
var el = $('<div></div>').dialog({ position: "top" }),
|
||||||
|
dialog = el.dialog('widget'),
|
||||||
|
offset = dialog.offset();
|
||||||
|
closeEnough(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft(), 1);
|
||||||
|
closeEnough(offset.top, $(window).scrollTop(), 1);
|
||||||
|
el.remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("position, left on window", function() {
|
||||||
|
expect( 2 );
|
||||||
|
var el = $('<div></div>').dialog({ position: "left" }),
|
||||||
|
dialog = el.dialog('widget'),
|
||||||
|
offset = dialog.offset();
|
||||||
|
closeEnough(offset.left, 0, 1);
|
||||||
|
closeEnough(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop(), 1);
|
||||||
|
el.remove();
|
||||||
|
});
|
||||||
|
@ -298,39 +298,8 @@ test("position, default center on window", function() {
|
|||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("position, top on window", function() {
|
|
||||||
expect( 2 );
|
|
||||||
var el = $('<div></div>').dialog({ position: "top" }),
|
|
||||||
dialog = el.dialog('widget'),
|
|
||||||
offset = dialog.offset();
|
|
||||||
closeEnough(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft(), 1);
|
|
||||||
closeEnough(offset.top, $(window).scrollTop(), 1);
|
|
||||||
el.remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("position, left on window", function() {
|
|
||||||
expect( 2 );
|
|
||||||
var el = $('<div></div>').dialog({ position: "left" }),
|
|
||||||
dialog = el.dialog('widget'),
|
|
||||||
offset = dialog.offset();
|
|
||||||
closeEnough(offset.left, 0, 1);
|
|
||||||
closeEnough(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop(), 1);
|
|
||||||
el.remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
// todo: figure out these fails in IE7
|
// todo: figure out these fails in IE7
|
||||||
if ( !$.ui.ie ) {
|
if ( !$.ui.ie ) {
|
||||||
|
|
||||||
test("position, right bottom on window", function() {
|
|
||||||
expect( 2 );
|
|
||||||
var el = $('<div></div>').dialog({ position: "right bottom" }),
|
|
||||||
dialog = el.dialog('widget'),
|
|
||||||
offset = dialog.offset();
|
|
||||||
closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1);
|
|
||||||
closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1);
|
|
||||||
el.remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("position, right bottom at right bottom via ui.position args", function() {
|
test("position, right bottom at right bottom via ui.position args", function() {
|
||||||
expect( 2 );
|
expect( 2 );
|
||||||
var el = $('<div></div>').dialog({
|
var el = $('<div></div>').dialog({
|
||||||
@ -346,7 +315,6 @@ if ( !$.ui.ie ) {
|
|||||||
closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1);
|
closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1);
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test("position, at another element", function() {
|
test("position, at another element", function() {
|
||||||
|
99
ui/jquery.ui.dialog.js
vendored
99
ui/jquery.ui.dialog.js
vendored
@ -495,33 +495,12 @@ $.widget("ui.dialog", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_position: function() {
|
_position: function() {
|
||||||
var position = this.options.position,
|
|
||||||
myAt = [],
|
|
||||||
isVisible;
|
|
||||||
|
|
||||||
if ( position ) {
|
|
||||||
if ( typeof position === "string" ) {
|
|
||||||
myAt = position.split( " " );
|
|
||||||
if ( myAt.length === 1 ) {
|
|
||||||
myAt[ 1 ] = myAt[ 0 ];
|
|
||||||
}
|
|
||||||
position = {
|
|
||||||
my: myAt[0] + " " + myAt[1],
|
|
||||||
at: myAt.join( " " )
|
|
||||||
};
|
|
||||||
position = $.extend( {}, $.ui.dialog.prototype.options.position, position );
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
position = $.ui.dialog.prototype.options.position;
|
|
||||||
}
|
|
||||||
|
|
||||||
// need to show the dialog to get the actual offset in the position plugin
|
// need to show the dialog to get the actual offset in the position plugin
|
||||||
isVisible = this.uiDialog.is( ":visible" );
|
var isVisible = this.uiDialog.is( ":visible" );
|
||||||
if ( !isVisible ) {
|
if ( !isVisible ) {
|
||||||
this.uiDialog.show();
|
this.uiDialog.show();
|
||||||
}
|
}
|
||||||
this.uiDialog.position( position );
|
this.uiDialog.position( this.options.position );
|
||||||
if ( !isVisible ) {
|
if ( !isVisible ) {
|
||||||
this.uiDialog.hide();
|
this.uiDialog.hide();
|
||||||
}
|
}
|
||||||
@ -719,48 +698,50 @@ $.ui.dialog.overlay = {
|
|||||||
if ( $.uiBackCompat !== false ) {
|
if ( $.uiBackCompat !== false ) {
|
||||||
// position option with array notation
|
// position option with array notation
|
||||||
// just override with old implementation
|
// just override with old implementation
|
||||||
$.ui.dialog.prototype._position = function() {
|
$.widget( "ui.dialog", $.ui.dialog, {
|
||||||
var position = this.options.position,
|
_position: function() {
|
||||||
myAt = [],
|
var position = this.options.position,
|
||||||
offset = [ 0, 0 ],
|
myAt = [],
|
||||||
isVisible;
|
offset = [ 0, 0 ],
|
||||||
|
isVisible;
|
||||||
|
|
||||||
if ( position ) {
|
if ( position ) {
|
||||||
if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) {
|
if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) {
|
||||||
myAt = position.split ? position.split( " " ) : [ position[ 0 ], position[ 1 ] ];
|
myAt = position.split ? position.split( " " ) : [ position[ 0 ], position[ 1 ] ];
|
||||||
if ( myAt.length === 1 ) {
|
if ( myAt.length === 1 ) {
|
||||||
myAt[ 1 ] = myAt[ 0 ];
|
myAt[ 1 ] = myAt[ 0 ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$.each( [ "left", "top" ], function( i, offsetPosition ) {
|
||||||
|
if ( +myAt[ i ] === myAt[ i ] ) {
|
||||||
|
offset[ i ] = myAt[ i ];
|
||||||
|
myAt[ i ] = offsetPosition;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
position = {
|
||||||
|
my: myAt[0] + (offset[0] < 0 ? offset[0] : "+" + offset[0]) + " " +
|
||||||
|
myAt[1] + (offset[1] < 0 ? offset[1] : "+" + offset[1]),
|
||||||
|
at: myAt.join( " " )
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
$.each( [ "left", "top" ], function( i, offsetPosition ) {
|
position = $.extend( {}, $.ui.dialog.prototype.options.position, position );
|
||||||
if ( +myAt[ i ] === myAt[ i ] ) {
|
} else {
|
||||||
offset[ i ] = myAt[ i ];
|
position = $.ui.dialog.prototype.options.position;
|
||||||
myAt[ i ] = offsetPosition;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
position = {
|
|
||||||
my: myAt[0] + (offset[0] < 0 ? offset[0] : "+" + offset[0]) + " " +
|
|
||||||
myAt[1] + (offset[1] < 0 ? offset[1] : "+" + offset[1]),
|
|
||||||
at: myAt.join( " " )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
position = $.extend( {}, $.ui.dialog.prototype.options.position, position );
|
// need to show the dialog to get the actual offset in the position plugin
|
||||||
} else {
|
isVisible = this.uiDialog.is( ":visible" );
|
||||||
position = $.ui.dialog.prototype.options.position;
|
if ( !isVisible ) {
|
||||||
|
this.uiDialog.show();
|
||||||
|
}
|
||||||
|
this.uiDialog.position( position );
|
||||||
|
if ( !isVisible ) {
|
||||||
|
this.uiDialog.hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
// need to show the dialog to get the actual offset in the position plugin
|
|
||||||
isVisible = this.uiDialog.is( ":visible" );
|
|
||||||
if ( !isVisible ) {
|
|
||||||
this.uiDialog.show();
|
|
||||||
}
|
|
||||||
this.uiDialog.position( position );
|
|
||||||
if ( !isVisible ) {
|
|
||||||
this.uiDialog.hide();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}( jQuery ) );
|
}( jQuery ) );
|
||||||
|
Loading…
Reference in New Issue
Block a user