Added orientation detection into the cookie generation JS #79

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@mpecan
mpecan commented Oct 7, 2012

Changed the javascript to add orientation detection.

@mpecan mpecan commented on the diff Oct 7, 2012
instructions.htm
@@ -21,12 +21,12 @@
<h1>Adaptive-Images Instructions</h1>
<h2>Basic instructions</h2>
<p>Copy <code>adaptive-images.php</code> and <code>.htaccess</code> into the root directory of your site. If you already have a htaccess file DO NOT OVERWRITE IT, skip down to the advanced instructions.</p>
- <p>Copy the following Javascript into the &lt;head&gt; of your site. It MUST go in the head as the first bit of JS, before any other JS. This is because it needs to work as soon as possible, any delay wil have adverse effects.</p>
-<pre><code>&lt;script&gt;document.cookie='resolution='+Math.max(screen.width,screen.height)+'; path=/';&lt;/script&gt;</code></pre>
+ <p>Copy the following Javascript into the &lt;head&gt; of your site. It MUST go in the head as the first bit of JS, before any other JS. This is because it needs to work as soon as possible, any delay wil have adverse effects. </p>
+<pre><code>&lt;script&gt;document.cookie='resolution='+((typeof window.orientation != 'undefined' && Math.abs(window.orientation)==90) ? screen.height:screen.width)+'; path=/';&lt;/script&gt;</code></pre>
@mpecan
mpecan Oct 7, 2012

If the orientation is 90 or -90 then the device is in landscape mode and as such it's height is gonna be the maximum width of an image we are displaying. If the information is not available or the device is in portrait default to width.

@MattWilcox

Sorry, but doing this would result in the same behaviour as if the JS was simply detecting device width. That's bad behaviour because it can cause images stored in cache to be too small for the device once the orientation is changed. Using the suggested code would result in broken pages for users changing from portrait to landscape within a session, for as long as the browser cache persists.

Owner

Thank you very much for the reply. Sorry for taking your time.

@MattWilcox MattWilcox closed this Oct 17, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment