Created
November 11, 2012 18:46
-
-
Save clooth/4055835 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//= require jquery_ujs | |
//= require jquery-fileupload/basic | |
//= require jquery-fileupload/vendor/tmpl | |
window.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); | |
// Flash messages display | |
App.Config.Flashes = { | |
selector: '.flash', | |
duration: 200 | |
} | |
App.Flashes = (function(container, config) { | |
// All flash messages | |
var messages = $('div', container); | |
// Remove them on click | |
messages.on('click', function(e) { | |
$(this).slideUp(200); | |
}); | |
})($(App.Config.Flashes.selector), App.Config.Flashes); | |
// Set up Tipped tooltips | |
App.Config.Tooltips = { | |
// Default options for each tooltip | |
skin: 'white', | |
delay: 200, | |
// Customized tooltips | |
elements: { | |
'.tooltip': null, // default options | |
'.tooltip-delayed': {delay: 800}, // override delay | |
'.tooltip-logo': {delay: 500} | |
} | |
}; | |
App.Tooltips = (function(config) { | |
// Bind tooltips to each of the given elements | |
$.each(config.elements, function(selector, options) { | |
// Figure out options to use | |
var opts = $.extend({ | |
skin: config.skin, | |
delay: config.delay, | |
}, options); | |
Tipped.create(selector, opts); | |
}); | |
})(App.Config.Tooltips); | |
// Files manager | |
App.Config.Files = { | |
}; | |
App.Files = (function(container, config) { | |
// Creating folders | |
var createFolderLink = $('a.create-folder'), | |
createFolderForm = $('.create-folder-form'), | |
createFolderInput = $('input[type=text]', createFolderForm); | |
createFolderLink.bind('click', function(e) { | |
e.preventDefault(); | |
if (createFolderForm.is(':hidden')) { | |
$(this).text('Cancel'); | |
createFolderForm.css('opacity', 0.0) | |
.slideDown(80) | |
.animate({opacity: 1.0}, {queue: false, duration: 350}); | |
createFolderInput.focus(); | |
} else { | |
$(this).text('Create Folder'); | |
createFolderForm.fadeOut(100); | |
} | |
}); | |
// Live filtering : plugin modified to support tables | |
var filterContainer = $('.filterbar .filter'), | |
listingSelector = '.listing'; | |
filterContainer.fastLiveFilter(listingSelector); | |
// Listing actions | |
var listingContainer = $('.listing'), | |
actionCell = $('.listing td:not(.name, .check)'), | |
nameCell = $('.listing td.name'); | |
// Showing and hiding action icons on hover | |
listingCells.hover( | |
function() { | |
$(this) | |
.parent() | |
.find('.actions .icon') | |
.css('display', 'inline-block'); | |
}, | |
function() { | |
$(this) | |
.parent() | |
.find('.actions .icon') | |
.css('display', 'none'); | |
} | |
); | |
// Rename functionality | |
nameCell.hover( | |
function() { | |
$(this) | |
.find('div.rename') | |
.css('display', 'inline-block'); | |
}, | |
function() { | |
$(this) | |
.find('div.rename') | |
.css('display', 'none'); | |
} | |
); | |
// Priority rows | |
var priorityRows = $('tr[data-priority="1"]', listingContainer); | |
priorityRows.addClass('priority'); | |
listingContainer.on('click', 'a.priority', function() { | |
var currentRow = $(this).parents('tr'), | |
newPriority = (currentRow.data('priority') == "1") ? "0" : "1", | |
priorityPath = encodeURIComponent(currentRow.data('path')), | |
priorityURL = "/assets/priority?priority=" + newPriority + "&path=" + priorityPath; | |
$.get(priorityURL, function(data) { | |
currentRow.toggleClass('priority'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment