Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#136 changes commited #137

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
48 changes: 31 additions & 17 deletions jquery.filedrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,33 @@
speedUpdated: empty
},
errors = ["BrowserNotSupported", "TooManyFiles", "FileTooLarge", "FileTypeNotAllowed", "NotFound", "NotReadable", "AbortError", "ReadError"],
doc_leave_timer, stop_loop = false,
doc_leave_timer = {},
stop_loop = false,
files_count = 0,
files;

$.fn.filedrop = function(options) {
var opts = $.extend({}, default_opts, options),
global_progress = [];
global_progress = [],
namespace = ".filedrop_" + opts.fallback_id;

this.on('drop', drop).on('dragstart', opts.dragStart).on('dragenter', dragEnter).on('dragover', dragOver).on('dragleave', dragLeave);
$(document).on('drop', docDrop).on('dragenter', docEnter).on('dragover', docOver).on('dragleave', docLeave);

$('#' + opts.fallback_id).change(function(e) {
opts.drop(e);
files = e.target.files;
files_count = files.length;
upload();
});
this
.off('drop' + namespace).off('dragstart' + namespace).off('dragenter' + namespace).off('dragover' + namespace).off('dragleave' + namespace)
.on('drop' + namespace, drop).on('dragstart' + namespace, opts.dragStart).on('dragenter' + namespace, dragEnter).on('dragover' + namespace, dragOver).on('dragleave' + namespace, dragLeave);

$(document)
.off('drop' + namespace).off('dragenter' + namespace).off('dragover' + namespace).off('dragleave' + namespace)
.on('drop' + namespace, docDrop).on('dragenter' + namespace, docEnter).on('dragover' + namespace, docOver).on('dragleave' + namespace, docLeave);

$('#' + opts.fallback_id)
.off("change" + namespace)
.on("change" + namespace, function(e) {
opts.drop(e);
files = e.target.files;
files_count = files.length;
upload();
});

function drop(e) {
if( opts.drop.call(this, e) === false ) return false;
Expand Down Expand Up @@ -439,20 +449,20 @@
}

function dragEnter(e) {
clearTimeout(doc_leave_timer);
clearTimeout(docLeaveTimer());
e.preventDefault();
opts.dragEnter.call(this, e);
}

function dragOver(e) {
clearTimeout(doc_leave_timer);
clearTimeout(docLeaveTimer());
e.preventDefault();
opts.docOver.call(this, e);
opts.dragOver.call(this, e);
}

function dragLeave(e) {
clearTimeout(doc_leave_timer);
clearTimeout(docLeaveTimer());
opts.dragLeave.call(this, e);
e.stopPropagation();
}
Expand All @@ -464,27 +474,31 @@
}

function docEnter(e) {
clearTimeout(doc_leave_timer);
clearTimeout(docLeaveTimer());
e.preventDefault();
opts.docEnter.call(this, e);
return false;
}

function docOver(e) {
clearTimeout(doc_leave_timer);
clearTimeout(docLeaveTimer());
e.preventDefault();
opts.docOver.call(this, e);
return false;
}

function docLeave(e) {
doc_leave_timer = setTimeout((function(_this) {
doc_leave_timer[namespace] = setTimeout((function(_this) {
return function() {
opts.docLeave.call(_this, e);
};
})(this), 200);
}

function docLeaveTimer() {
return doc_leave_timer[namespace];
}

return this;
};

Expand All @@ -504,4 +518,4 @@
};
} catch (e) {}

})(jQuery);
})(jQuery);