Skip to content

Instantly share code, notes, and snippets.

@Aldaviva
Forked from 140bytes/LICENSE.txt
Created November 9, 2012 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aldaviva/4043387 to your computer and use it in GitHub Desktop.
Save Aldaviva/4043387 to your computer and use it in GitHub Desktop.
ieDownloadBarWidth -- 140byt.es

ieDownloadBarWidth - 140byt.es

For a given window width, how wide would the IE 9 download bar be?

I usually call this method with window.innerWidth as the argument.

For more information

See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter.

To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to the wiki.

140byt.es is brought to you by Jed Schmidt, with help from Alex Kloss. It was inspired by work from Thomas Fuchs and Dustin Diaz.

function(a){ // a is the width of the window (e.g. window.innerWidth)
return
a > 1149 ? 960 // When the window is wider than 1160px, download bar is always centered and 960px wide
: a > 700 ? a - 200 // Between 700px and 1160px wide, take up all available width except 100px margins on left and right
: a > 599 ? 500 // Between 600px and 700px wide, download bar is always centered and 500px wide
: a > 460 ? a - 100 // Between 460px and 600px wide, take up all available width except 50px margins on left and right
: a > 359 ? 360 // Between 360px and 460px wide, download bar is always centered and 360px wide
: a > 240 ? a // Between 240px and 360px wide, take up 100% of the window
: 240 // IE window cannot resize to less than 240px wide.
}
function(a){return a>1149?960:a>700?a-200:a>599?500:a>460?a-100:a>359?360:a>240?a:240}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2012 Ben Hutchison <aldaviva.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "ieDownloadBarWidth",
"description": "For a given window width, how wide would the IE 9 download bar be?",
"keywords": [
"ie"
]
}
<!DOCTYPE html>
<title>ieDownloadBarWidth</title>
<div>1280px wide window expected value: <b>960</b>px</div>
<div>1280px wide window actual value: <b id="ret"></b>px</div>
<div>Your current window width: <b id="currWidth"></b>px</div>
<div>Your IE download bar width: <b id="retCurrWidth"></b>px</div>
<script>
// write a small example that shows off the API for your example
// and tests it in one fell swoop.
var myFunction = function(a){return a>1149?960:a>700?a-200:a>599?500:a>460?a-100:a>359?360:a>240?a:240};
document.getElementById( "ret" ).innerHTML = myFunction(1280);
document.getElementById( "currWidth" ).innerHTML = window.innerWidth;
document.getElementById( "retCurrWidth" ).innerHTML = myFunction(window.innerWidth);
</script>
@atk
Copy link

atk commented Nov 9, 2012

Only use the upper limits and the condition ? true : false shorthand to golf that down to 86 bytes:

function(a){return a>1149?960:a>700?a-200:a>599?500:a>460?a-100:a>359?360:a>240?a:240}

@Aldaviva
Copy link
Author

Thanks!. That's a good technique.

@atk
Copy link

atk commented Nov 12, 2012

You're welcome. Your previous attempt was still an interesting abuse of coercion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment