Skip to content

Instantly share code, notes, and snippets.

@jsvensson
Created April 14, 2011 19:22
Show Gist options
  • Save jsvensson/920259 to your computer and use it in GitHub Desktop.
Save jsvensson/920259 to your computer and use it in GitHub Desktop.
quickDrop = {
doBrowserWarning: function() {
var isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
// Show warning box if unsupported browser
// Only work for Chrome atm since that what I develop in
// Will test Firefox when the basic functionality is in.
if (!isChrome)
$("#browserwarning").fadeIn(500);
},
initHandlers: function() {
// The body listens for a dragged file entering
$("#body").bind("dragenter", this.onDragEnter);
// The overlay listens for the dragleave event
// The ondragover event needs to be canceled in Google Chrome
// and Safari to allow firing the ondrop event.
// ref: http://help.dottoro.com/ljrkqflw.php
$("#overlay").bind("dragleave", this.onDragLeave);
$("#overlay").bind("dragover", this.noopHandler);
// File gets dropped
$("#overlay").bind("drop", this.onDrop);
},
noopHandler: function(evt) {
evt.stopPropagation();
evt.preventDefault();
},
onDragEnter: function(evt) {
$("#overlay").fadeIn(150);
},
onDragLeave: function(evt) {
$("#overlay").fadeOut(150);
},
onDrop: function(evt) {
this.noopHandler(evt);
$("#overlay").fadeOut(150);
},
setStatus: function(msg) {
$("#status").html(msg);
}
};
$(document).ready(function() {
quickDrop.doBrowserWarning();
quickDrop.initHandlers();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment