Last active
August 29, 2015 14:04
-
-
Save restlessmedia/2317b8337aa20b7cec97 to your computer and use it in GitHub Desktop.
DropZone - jQuery drag and drop wrapper
This file contains 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
// var upload = function (url, files) { | |
// var data = new FormData(); | |
// app.utils.forEach(files, function () { | |
// data.append('file', this); | |
// }); | |
// return send({ type: 'POST', url: url, data: data, contentType: false, processData: false }); | |
// } | |
(function ($, app) { | |
var addHandler = function (element, type, handler) { | |
$(element).on(type, function (e) { | |
e.stopPropagation(); | |
e.preventDefault(); | |
handler.call(this, this, e); | |
}); | |
}; | |
var DropZone = function (element, dropped) { | |
if (typeof element === 'string') { | |
element = document.getElementById(element); | |
} | |
this.element = element; | |
if (dropped) { | |
this.drop(dropped); | |
} | |
}; | |
DropZone.prototype.enter = function (handler) { | |
addHandler(this.element, 'dragenter', handler); | |
}; | |
DropZone.prototype.over = function (handler) { | |
addHandler(this.element, 'dragover', handler); | |
}; | |
DropZone.prototype.drop = function (handler) { | |
addHandler(this.element, 'drop', handler); | |
}; | |
app.dropZone = { | |
attach: function (element, dropped) { | |
return new DropZone(element, dropped); | |
} | |
} | |
} ($, app)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment