Skip to content

Commit a09f5c0

Browse files
committed
Dialog: Follow-up to 9fe3a62 - also deprecate string notation for position option.
1 parent f3525af commit a09f5c0

File tree

3 files changed

+72
-93
lines changed

3 files changed

+72
-93
lines changed

tests/unit/dialog/dialog_deprecated.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module("dialog (deprecated): position opton with array");
1+
module("dialog (deprecated): position option with string and array");
22

33
if ( !$.ui.ie ) {
44
test("position, right bottom on window w/array", function() {
@@ -10,6 +10,16 @@ if ( !$.ui.ie ) {
1010
closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1);
1111
el.remove();
1212
});
13+
14+
test("position, right bottom on window", function() {
15+
expect( 2 );
16+
var el = $('<div></div>').dialog({ position: "right bottom" }),
17+
dialog = el.dialog('widget'),
18+
offset = dialog.offset();
19+
closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1);
20+
closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1);
21+
el.remove();
22+
});
1323
}
1424

1525
test("position, offset from top left w/array", function() {
@@ -21,3 +31,23 @@ test("position, offset from top left w/array", function() {
2131
closeEnough(offset.top, 10 + $(window).scrollTop(), 1);
2232
el.remove();
2333
});
34+
35+
test("position, top on window", function() {
36+
expect( 2 );
37+
var el = $('<div></div>').dialog({ position: "top" }),
38+
dialog = el.dialog('widget'),
39+
offset = dialog.offset();
40+
closeEnough(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft(), 1);
41+
closeEnough(offset.top, $(window).scrollTop(), 1);
42+
el.remove();
43+
});
44+
45+
test("position, left on window", function() {
46+
expect( 2 );
47+
var el = $('<div></div>').dialog({ position: "left" }),
48+
dialog = el.dialog('widget'),
49+
offset = dialog.offset();
50+
closeEnough(offset.left, 0, 1);
51+
closeEnough(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop(), 1);
52+
el.remove();
53+
});

tests/unit/dialog/dialog_options.js

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -298,39 +298,8 @@ test("position, default center on window", function() {
298298
el.remove();
299299
});
300300

301-
test("position, top on window", function() {
302-
expect( 2 );
303-
var el = $('<div></div>').dialog({ position: "top" }),
304-
dialog = el.dialog('widget'),
305-
offset = dialog.offset();
306-
closeEnough(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft(), 1);
307-
closeEnough(offset.top, $(window).scrollTop(), 1);
308-
el.remove();
309-
});
310-
311-
test("position, left on window", function() {
312-
expect( 2 );
313-
var el = $('<div></div>').dialog({ position: "left" }),
314-
dialog = el.dialog('widget'),
315-
offset = dialog.offset();
316-
closeEnough(offset.left, 0, 1);
317-
closeEnough(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop(), 1);
318-
el.remove();
319-
});
320-
321301
// todo: figure out these fails in IE7
322302
if ( !$.ui.ie ) {
323-
324-
test("position, right bottom on window", function() {
325-
expect( 2 );
326-
var el = $('<div></div>').dialog({ position: "right bottom" }),
327-
dialog = el.dialog('widget'),
328-
offset = dialog.offset();
329-
closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1);
330-
closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1);
331-
el.remove();
332-
});
333-
334303
test("position, right bottom at right bottom via ui.position args", function() {
335304
expect( 2 );
336305
var el = $('<div></div>').dialog({
@@ -346,7 +315,6 @@ if ( !$.ui.ie ) {
346315
closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1);
347316
el.remove();
348317
});
349-
350318
}
351319

352320
test("position, at another element", function() {

ui/jquery.ui.dialog.js

Lines changed: 41 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -495,33 +495,12 @@ $.widget("ui.dialog", {
495495
},
496496

497497
_position: function() {
498-
var position = this.options.position,
499-
myAt = [],
500-
isVisible;
501-
502-
if ( position ) {
503-
if ( typeof position === "string" ) {
504-
myAt = position.split( " " );
505-
if ( myAt.length === 1 ) {
506-
myAt[ 1 ] = myAt[ 0 ];
507-
}
508-
position = {
509-
my: myAt[0] + " " + myAt[1],
510-
at: myAt.join( " " )
511-
};
512-
position = $.extend( {}, $.ui.dialog.prototype.options.position, position );
513-
}
514-
515-
} else {
516-
position = $.ui.dialog.prototype.options.position;
517-
}
518-
519498
// need to show the dialog to get the actual offset in the position plugin
520-
isVisible = this.uiDialog.is( ":visible" );
499+
var isVisible = this.uiDialog.is( ":visible" );
521500
if ( !isVisible ) {
522501
this.uiDialog.show();
523502
}
524-
this.uiDialog.position( position );
503+
this.uiDialog.position( this.options.position );
525504
if ( !isVisible ) {
526505
this.uiDialog.hide();
527506
}
@@ -719,48 +698,50 @@ $.ui.dialog.overlay = {
719698
if ( $.uiBackCompat !== false ) {
720699
// position option with array notation
721700
// just override with old implementation
722-
$.ui.dialog.prototype._position = function() {
723-
var position = this.options.position,
724-
myAt = [],
725-
offset = [ 0, 0 ],
726-
isVisible;
727-
728-
if ( position ) {
729-
if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) {
730-
myAt = position.split ? position.split( " " ) : [ position[ 0 ], position[ 1 ] ];
731-
if ( myAt.length === 1 ) {
732-
myAt[ 1 ] = myAt[ 0 ];
733-
}
734-
735-
$.each( [ "left", "top" ], function( i, offsetPosition ) {
736-
if ( +myAt[ i ] === myAt[ i ] ) {
737-
offset[ i ] = myAt[ i ];
738-
myAt[ i ] = offsetPosition;
701+
$.widget( "ui.dialog", $.ui.dialog, {
702+
_position: function() {
703+
var position = this.options.position,
704+
myAt = [],
705+
offset = [ 0, 0 ],
706+
isVisible;
707+
708+
if ( position ) {
709+
if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) {
710+
myAt = position.split ? position.split( " " ) : [ position[ 0 ], position[ 1 ] ];
711+
if ( myAt.length === 1 ) {
712+
myAt[ 1 ] = myAt[ 0 ];
739713
}
740-
});
741714

742-
position = {
743-
my: myAt[0] + (offset[0] < 0 ? offset[0] : "+" + offset[0]) + " " +
744-
myAt[1] + (offset[1] < 0 ? offset[1] : "+" + offset[1]),
745-
at: myAt.join( " " )
746-
};
747-
}
715+
$.each( [ "left", "top" ], function( i, offsetPosition ) {
716+
if ( +myAt[ i ] === myAt[ i ] ) {
717+
offset[ i ] = myAt[ i ];
718+
myAt[ i ] = offsetPosition;
719+
}
720+
});
748721

749-
position = $.extend( {}, $.ui.dialog.prototype.options.position, position );
750-
} else {
751-
position = $.ui.dialog.prototype.options.position;
752-
}
722+
position = {
723+
my: myAt[0] + (offset[0] < 0 ? offset[0] : "+" + offset[0]) + " " +
724+
myAt[1] + (offset[1] < 0 ? offset[1] : "+" + offset[1]),
725+
at: myAt.join( " " )
726+
};
727+
}
753728

754-
// need to show the dialog to get the actual offset in the position plugin
755-
isVisible = this.uiDialog.is( ":visible" );
756-
if ( !isVisible ) {
757-
this.uiDialog.show();
758-
}
759-
this.uiDialog.position( position );
760-
if ( !isVisible ) {
761-
this.uiDialog.hide();
729+
position = $.extend( {}, $.ui.dialog.prototype.options.position, position );
730+
} else {
731+
position = $.ui.dialog.prototype.options.position;
732+
}
733+
734+
// need to show the dialog to get the actual offset in the position plugin
735+
isVisible = this.uiDialog.is( ":visible" );
736+
if ( !isVisible ) {
737+
this.uiDialog.show();
738+
}
739+
this.uiDialog.position( position );
740+
if ( !isVisible ) {
741+
this.uiDialog.hide();
742+
}
762743
}
763-
};
744+
});
764745
}
765746

766747
}( jQuery ) );

0 commit comments

Comments
 (0)