|
10 | 10 | * Depends: |
11 | 11 | * ui.core.js |
12 | 12 | * ui.draggable.js |
| 13 | + * ui.position.js |
13 | 14 | * ui.resizable.js |
14 | 15 | */ |
15 | 16 | (function($) { |
@@ -376,56 +377,50 @@ $.widget("ui.dialog", { |
376 | 377 | : Math.min(options.minHeight, options.height)); |
377 | 378 | }, |
378 | 379 |
|
379 | | - _position: function(pos) { |
380 | | - var wnd = $(window), doc = $(document), |
381 | | - pTop = doc.scrollTop(), pLeft = doc.scrollLeft(), |
382 | | - minTop = pTop, |
383 | | - uiDialog = this.uiDialog; |
384 | | - |
385 | | - if ($.inArray(pos, ['center','top','right','bottom','left']) >= 0) { |
386 | | - pos = [ |
387 | | - pos == 'right' || pos == 'left' ? pos : 'center', |
388 | | - pos == 'top' || pos == 'bottom' ? pos : 'middle' |
389 | | - ]; |
390 | | - } |
391 | | - if (pos.constructor != Array) { |
392 | | - pos = ['center', 'middle']; |
393 | | - } |
394 | | - if (pos[0].constructor == Number) { |
395 | | - pLeft += pos[0]; |
396 | | - } else { |
397 | | - switch (pos[0]) { |
398 | | - case 'left': |
399 | | - pLeft += 0; |
400 | | - break; |
401 | | - case 'right': |
402 | | - pLeft += wnd.width() - uiDialog.outerWidth(); |
403 | | - break; |
404 | | - default: |
405 | | - case 'center': |
406 | | - pLeft += (wnd.width() - uiDialog.outerWidth()) / 2; |
| 380 | + _position: function(position) { |
| 381 | + var myAt = [], |
| 382 | + offset = [0, 0]; |
| 383 | + |
| 384 | + // deep extending converts arrays to objects in jQuery <= 1.3.2 :-( |
| 385 | +// if (typeof position == 'string' || $.isArray(position)) { |
| 386 | +// myAt = $.isArray(position) ? position : position.split(' '); |
| 387 | + if (typeof position == 'string' || '0' in position) { |
| 388 | + myAt = position.split ? position.split(' ') : [position[0], position[1]]; |
| 389 | + if (myAt.length == 1) { |
| 390 | + myAt[1] = myAt[0]; |
407 | 391 | } |
408 | | - } |
409 | | - if (pos[1].constructor == Number) { |
410 | | - pTop += pos[1]; |
| 392 | + |
| 393 | + $.each(['left', 'top'], function(i, offsetPosition) { |
| 394 | + if (+myAt[i] == myAt[i]) { |
| 395 | + offset[i] = myAt[i]; |
| 396 | + myAt[i] = offsetPosition; |
| 397 | + } |
| 398 | + }); |
411 | 399 | } else { |
412 | | - switch (pos[1]) { |
413 | | - case 'top': |
414 | | - pTop += 0; |
415 | | - break; |
416 | | - case 'bottom': |
417 | | - pTop += wnd.height() - uiDialog.outerHeight(); |
418 | | - break; |
419 | | - default: |
420 | | - case 'middle': |
421 | | - pTop += (wnd.height() - uiDialog.outerHeight()) / 2; |
| 400 | + if ('left' in position) { |
| 401 | + myAt[0] = 'left'; |
| 402 | + offset[0] = position.left; |
| 403 | + } else if ('right' in position) { |
| 404 | + myAt[0] = 'right'; |
| 405 | + offset[0] = -position.right; |
| 406 | + } |
| 407 | + |
| 408 | + if ('top' in position) { |
| 409 | + myAt[1] = 'top'; |
| 410 | + offset[1] = position.top; |
| 411 | + } else if ('bottom' in position) { |
| 412 | + myAt[1] = 'bottom'; |
| 413 | + offset[1] = -position.bottom; |
422 | 414 | } |
423 | 415 | } |
424 | 416 |
|
425 | | - // prevent the dialog from being too high (make sure the titlebar |
426 | | - // is accessible) |
427 | | - pTop = Math.max(pTop, minTop); |
428 | | - uiDialog.css({top: pTop, left: pLeft}); |
| 417 | + this.uiDialog.position({ |
| 418 | + my: myAt.join(' '), |
| 419 | + at: myAt.join(' '), |
| 420 | + offset: offset.join(' '), |
| 421 | + of: window, |
| 422 | + collision: 'fit' |
| 423 | + }); |
429 | 424 | }, |
430 | 425 |
|
431 | 426 | _setData: function(key, value){ |
|
0 commit comments