summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2010-11-08 14:24:34 +0300
committerAndrew Dolgov <[email protected]>2010-11-08 14:24:34 +0300
commitb19d6e6e4bd4575685b8c68ecbcaf98f833915fb (patch)
tree8e0e799923ad79000a0c6cc005b8c63c6221f0f1 /lib
parent019dd98d05160190d6dcf8c6031f881d280d7a92 (diff)
js: move position stuff to separate file
Diffstat (limited to 'lib')
-rw-r--r--lib/position.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/position.js b/lib/position.js
new file mode 100644
index 000000000..29bb9a5ca
--- /dev/null
+++ b/lib/position.js
@@ -0,0 +1,31 @@
+/* http://textsnippets.com/posts/show/835 */
+
+Position.GetWindowSize = function(w) {
+ w = w ? w : window;
+ var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
+ var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
+ return [width, height]
+}
+
+/* http://textsnippets.com/posts/show/836 */
+
+Position.Center = function(element, parent) {
+ var w, h, pw, ph;
+ var d = Element.getDimensions(element);
+ w = d.width;
+ h = d.height;
+ Position.prepare();
+ if (!parent) {
+ var ws = Position.GetWindowSize();
+ pw = ws[0];
+ ph = ws[1];
+ } else {
+ pw = parent.offsetWidth;
+ ph = parent.offsetHeight;
+ }
+ element.style.top = (ph/2) - (h/2) - Position.deltaY + "px";
+ element.style.left = (pw/2) - (w/2) - Position.deltaX + "px";
+}
+
+
+