@@ -244,11 +244,110 @@ test("position, default center on window", function() {
244244 var el = $ ( '<div></div>' ) . dialog ( ) ;
245245 var offset = el . parent ( ) . offset ( ) ;
246246 // use .position() instead to avoid replicating center-logic?
247- same ( offset . left , Math . floor ( $ ( window ) . width ( ) / 2 - el . parent ( ) . width ( ) / 2 ) ) ;
248- same ( offset . top , Math . floor ( $ ( window ) . height ( ) / 2 - el . parent ( ) . height ( ) / 2 ) ) ;
247+ same ( offset . left , Math . floor ( $ ( window ) . width ( ) / 2 - dialog . outerWidth ( ) / 2 ) + $ ( window ) . scrollLeft ( ) ) ;
248+ same ( offset . top , Math . floor ( $ ( window ) . height ( ) / 2 - dialog . outerHeight ( ) / 2 ) + $ ( window ) . scrollTop ( ) ) ;
249249 el . remove ( ) ;
250250} ) ;
251251
252+ test ( "position, top on window" , function ( ) {
253+ var el = $ ( '<div></div>' ) . dialog ( { position : "top" } ) ;
254+ var dialog = el . closest ( '.ui-dialog' ) ;
255+ var offset = dialog . offset ( ) ;
256+ same ( offset . left , Math . floor ( $ ( window ) . width ( ) / 2 - dialog . outerWidth ( ) / 2 ) ) ;
257+ same ( offset . top , $ ( window ) . scrollTop ( ) ) ;
258+ el . remove ( ) ;
259+ } ) ;
260+
261+ test ( "position, left on window" , function ( ) {
262+ var el = $ ( '<div></div>' ) . dialog ( { position : "left" } ) ;
263+ var dialog = el . closest ( '.ui-dialog' ) ;
264+ var offset = dialog . offset ( ) ;
265+ same ( offset . left , 0 ) ;
266+ same ( offset . top , Math . floor ( $ ( window ) . height ( ) / 2 - dialog . outerHeight ( ) / 2 ) + $ ( window ) . scrollTop ( ) ) ;
267+ el . remove ( ) ;
268+ } ) ;
269+
270+ test ( "position, right bottom on window" , function ( ) {
271+ var el = $ ( '<div></div>' ) . dialog ( { position : "right bottom" } ) ;
272+ var dialog = el . closest ( '.ui-dialog' ) ;
273+ var offset = dialog . offset ( ) ;
274+ same ( offset . left , $ ( window ) . width ( ) - dialog . outerWidth ( ) ) ;
275+ same ( offset . top , $ ( window ) . height ( ) - dialog . outerHeight ( ) + $ ( window ) . scrollTop ( ) ) ;
276+ el . remove ( ) ;
277+ } ) ;
278+
279+ test ( "position, right bottom on window w/array" , function ( ) {
280+ var el = $ ( '<div></div>' ) . dialog ( { position : [ "right" , "bottom" ] } ) ;
281+ var dialog = el . closest ( '.ui-dialog' ) ;
282+ var offset = dialog . offset ( ) ;
283+ same ( offset . left , $ ( window ) . width ( ) - dialog . outerWidth ( ) ) ;
284+ same ( offset . top , $ ( window ) . height ( ) - dialog . outerHeight ( ) + $ ( window ) . scrollTop ( ) ) ;
285+ el . remove ( ) ;
286+ } ) ;
287+
288+ test ( "position, offset from top left w/array" , function ( ) {
289+ var el = $ ( '<div></div>' ) . dialog ( { position : [ 10 , 10 ] } ) ;
290+ var dialog = el . closest ( '.ui-dialog' ) ;
291+ var offset = dialog . offset ( ) ;
292+ same ( offset . left , 10 ) ;
293+ same ( offset . top , 10 + $ ( window ) . scrollTop ( ) ) ;
294+ el . remove ( ) ;
295+ } ) ;
296+
297+ test ( "position, right bottom at right bottom via ui.position args" , function ( ) {
298+ var el = $ ( '<div></div>' ) . dialog ( {
299+ position : {
300+ my : "right bottom" ,
301+ at : "right bottom"
302+ }
303+ } ) ;
304+
305+ var dialog = el . closest ( '.ui-dialog' ) ;
306+ var offset = dialog . offset ( ) ;
307+
308+ same ( offset . left , $ ( window ) . width ( ) - dialog . outerWidth ( ) ) ;
309+ same ( offset . top , $ ( window ) . height ( ) - dialog . outerHeight ( ) + $ ( window ) . scrollTop ( ) ) ;
310+ el . remove ( ) ;
311+ } ) ;
312+
313+ test ( "position, at another element" , function ( ) {
314+ var parent = $ ( '<div></div>' ) . css ( {
315+ position : 'absolute' ,
316+ top : 400 ,
317+ left : 600 ,
318+ height : 10 ,
319+ width : 10
320+ } ) ;
321+
322+ var el = $ ( '<div></div>' ) . dialog ( {
323+ position : {
324+ my : "left top" ,
325+ at : "top left" ,
326+ of : parent
327+ }
328+ } ) ;
329+
330+ var dialog = el . closest ( '.ui-dialog' ) ;
331+ var offset = dialog . offset ( ) ;
332+ var parentOffset = parent . offset ( ) ;
333+
334+ same ( offset . left , parentOffset . left ) ;
335+ same ( offset . top , parentOffset . top ) ;
336+
337+ el . dialog ( 'option' , 'position' , {
338+ my : "left top" ,
339+ at : "right bottom" ,
340+ of : parent
341+ } ) ;
342+
343+ same ( offset . left , parentOffset . left + parent . outerWidth ( ) ) ;
344+ same ( offset . top , parentOffset . top + parent . outerHeight ( ) ) ;
345+
346+ el . remove ( ) ;
347+ parent . remove ( ) ;
348+ } ) ;
349+
350+
252351test ( "position, others" , function ( ) {
253352 ok ( false , 'missing test - untested code is broken code' ) ;
254353} ) ;
0 commit comments