A collection of common code snippets which shouldn't need to be re-invented every time they're required.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
A collection of common code snippets which shouldn't need to be re-invented every time they're required.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
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'; | |
} |