Skip to content

Instantly share code, notes, and snippets.

@drzax
Created July 31, 2012 23:34
Show Gist options
  • Save drzax/3221716 to your computer and use it in GitHub Desktop.
Save drzax/3221716 to your computer and use it in GitHub Desktop.
Common Code
with(document.documentElement){className=className.replace(/no-js/,'js')}
/*
A simple technique to centre absolute or fixed positioned elements within their container or the view port using only CSS.
The only requirement is that you know the width of the element. This also works for vertical centering assuming you know the height of the element.
*/
.dialog {
position: fixed;
left: 50%;
margin-left:-200px;
width: 400px;
}
formatFileSize: function(bytes) {
if (typeof bytes !== 'number') return '';
if (bytes >= 1073741824) return (bytes / 1073741824).toFixed(2) + ' GB';
if (bytes >= 1048576) return (bytes / 1048576).toFixed(2) + ' MB';
return (bytes / 1024).toFixed(2) + ' KB';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment