From 3a96a5a08a8c6a9a5aea30f01ab3e7e6603d3400 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 15 Jan 2014 22:50:56 +0400 Subject: [PATCH] added getDPI() function -- not yet sure if it should be as it is... Signed-off-by: Alex A. Naanou --- ui/lib/jli.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/ui/lib/jli.js b/ui/lib/jli.js index 6b3500f3..62301329 100755 --- a/ui/lib/jli.js +++ b/ui/lib/jli.js @@ -728,6 +728,39 @@ function makeDeferredsQ(first){ /**************************************************** JS utilities ***/ + +// Get screen dpi... +// +// This will calculate the value and save it to screen.dpi +// +// if force is true this will re-calculate the value. +// +// NOTE: this needs the body loaded to work... +// NOTE: this may depend on page zoom... +// NOTE: yes, this is a hack, but since we have no other reliable way to +// do this... +function getDPI(force){ + if(screen.dpi == null || force){ + var e = $('
') + .css({ + position: 'absolute', + width: '1in', + left: '-100%', + top: '-100%' + }) + .appendTo($('body')) + var res = e.width() + e.remove() + screen.dpi = res + return res + } else { + return screen.dpi + } +} +// XXX is this correct??? +$(getDPI) + + // return 1, -1, or 0 depending on sign of x function sign(x){ return (x > 0) - (x < 0)