Permalink
Browse files

Window moving routines including window centering.

  • Loading branch information...
1 parent c1d7de1 commit e05641982b3a6f14a45ff4309bb9993d86a51baf @rafalwrzeszcz rafalwrzeszcz committed Apr 13, 2011
Showing with 27 additions and 2 deletions.
  1. +27 −2 src/ui/controls/dialog.js
View
29 src/ui/controls/dialog.js
@@ -427,9 +427,34 @@
*
* Checks if window has alwaysOnTop flag set.
**/
- isAlwaysOnTop: function()
- {
+ isAlwaysOnTop: function() {
return this.element.hasClassName('alwaysOnTop');
+ },
+
+ /**
+ * S2.UI.Dialog#moveTo(left, top) -> this
+ *
+ * Moves window to given position.
+ **/
+ moveTo: function(left, top) {
+ this.element.morph('left:' + left + 'px;top:' + top + 'px', { duration: .7 } );
+ },
+
+ /**
+ * S2,UI.Dialog#center() -> this
+ *
+ * Moves window to the center of viewport.
+ **/
+ center: function() {
+ var layout = this.element.getLayout();
+ var viewport = document.viewport.getDimensions();
+
+ // calculates coordinates
+ var left = viewport.width / 2 - layout.get('width') / 2;
+ var top = viewport.height / 2 - layout.get('height') / 2;
+
+ // moves window
+ this.moveTo(left, top);
}
});

0 comments on commit e056419

Please sign in to comment.