From b19d6e6e4bd4575685b8c68ecbcaf98f833915fb Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 8 Nov 2010 14:24:34 +0300 Subject: [PATCH] js: move position stuff to separate file --- functions.js | 30 ------------------------------ lib/position.js | 31 +++++++++++++++++++++++++++++++ prefs.php | 1 + 3 files changed, 32 insertions(+), 30 deletions(-) create mode 100644 lib/position.js diff --git a/functions.js b/functions.js index f3756051..626a23a8 100644 --- a/functions.js +++ b/functions.js @@ -1633,36 +1633,6 @@ function openArticleInNewWindow(id) { } } -/* 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"; -} - - function isCdmMode() { return !$("headlinesList"); } diff --git a/lib/position.js b/lib/position.js new file mode 100644 index 00000000..29bb9a5c --- /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"; +} + + + diff --git a/prefs.php b/prefs.php index 365c75a6..c6d2605b 100644 --- a/prefs.php +++ b/prefs.php @@ -42,6 +42,7 @@ + -- 2.39.5