Skip to content

Instantly share code, notes, and snippets.

@clooth
Created November 11, 2012 17:46
Show Gist options
  • Save clooth/4055666 to your computer and use it in GitHub Desktop.
Save clooth/4055666 to your computer and use it in GitHub Desktop.
var App = {
// Configuration container
Config: {}
};
// Common utilities
App.Util = {
// Format bytes into human readable size notation
formatFileSize: function(bytes) {
if (typeof bytes !== 'number') { return ''; }
if (bytes >= 1000000000) {
return (bytes / 1000000000).toFixed(2) + ' GB';
}
if (bytes >= 1000000) {
return (bytes / 1000000).toFixed(2) + ' MB';
}
return (bytes / 1000).toFixed(2) + ' KB';
}
};
// Flyout menu
App.Config.Flyout = {
selector: '.flyout',
duration: 120
};
App.Flyout = (function(container, config) {
// Elements used with the flyout menu
var doc = $(document),
toggle = $('h3 a', container);
// Toggling of the flyout menu
toggle.bind('click', function(e) {
e.preventDefault();
container.fadeToggle(config.duration);
});
// Don't bubble up events inside the container
container.bind('click', function(e) {
e.stopPropagation();
});
// Close flyout menu when focus lost
doc.bind('click', function(e) {
if (container.is(':visible')) {
container.fadeOut(config.duration);
}
})
})($(App.Config.Flyout.selector), App.Config.Flyout);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment