Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@ var typeMap = {

/**
* Initialize a drop point
* on the given `el`.
* on the given `el`. Optionally use `selector`
* for delegated events.
*
* @param {Element} el
* @param {String} selector
* @api public
*/

function Dropload(el) {
function Dropload(el,selector) {
if (!(this instanceof Dropload)) return new Dropload(el);
Emitter.call(this);
this.el = el;
this.classes = classes(el);
this.selector = selector || '';
this.events = events(el, this);
this.events.bind('drop');
this.events.bind('dragenter');
this.events.bind('dragleave');
this.events.bind('dragover');
this.ignored = {};
}

Expand Down Expand Up @@ -74,6 +72,25 @@ Dropload.prototype.ignoring = function(name){
return !! this.ignored[name];
};

/**
* Bind event handlers. Optionally use `selector`
* to update the selector for delegated events.
*
* @param {String} selector
*
* @api public
*/

Dropload.prototype.bind = function(selector){
if( 'undefined' != typeof selector ){
this.selector = selector;
}
this.events.bind('drop '+this.selector);
this.events.bind('dragenter '+this.selector);
this.events.bind('dragleave '+this.selector);
this.events.bind('dragover '+this.selector);
}

/**
* Unbind event handlers.
*
Expand All @@ -89,7 +106,8 @@ Dropload.prototype.unbind = function(){
*/

Dropload.prototype.ondragenter = function(e){
this.classes.add('over');
console.log('drag enter',e);
classes(e.delegateTarget).add('over');
};

/**
Expand All @@ -105,7 +123,7 @@ Dropload.prototype.ondragover = function(e){
*/

Dropload.prototype.ondragleave = function(e){
this.classes.remove('over');
classes(e.delegateTarget).remove('over');
};

/**
Expand All @@ -115,7 +133,7 @@ Dropload.prototype.ondragleave = function(e){
Dropload.prototype.ondrop = function(e){
e.stopPropagation();
e.preventDefault();
this.classes.remove('over');
classes(e.delegateTarget).remove('over');
var items = e.dataTransfer.items;
var files = e.dataTransfer.files;
this.emit('drop', e);
Expand Down