// Nasty hack to distinguish between dragenter(first entry),
// dragenter+dragleave(moving between child elements) and dragleave (leaving element)
entercount: 0,
-
+ pageentercount: 0,
/**
* Initalise the drag and drop upload interface
}
this.init_events();
+ this.init_page_events();
this.Y.one('#dndenabled-'+this.clientid).setStyle('display', 'inline');
},
this.Y.on('drop', this.drop, this.container, this);
},
+ /**
+ * Initialise whole-page events (to show / hide the 'drop files here'
+ * message)
+ */
+ init_page_events: function() {
+ this.Y.on('dragenter', this.drag_enter_page, 'body', this);
+ this.Y.on('dragleave', this.drag_leave_page, 'body', this);
+ },
+
+ /**
+ * Show the 'drop files here' message when file(s) are dragged
+ * onto the page
+ */
+ drag_enter_page: function(e) {
+ if (!this.has_files(e) || this.reached_maxfiles()) {
+ return false;
+ }
+
+ this.pageentercount++;
+ if (this.pageentercount >= 2) {
+ this.pageentercount = 2;
+ return false;
+ }
+
+ this.show_drop_target();
+
+ return false;
+ },
+
+ /**
+ * Hide the 'drop files here' message when file(s) are dragged off
+ * the page again
+ */
+ drag_leave_page: function(e) {
+ this.pageentercount--;
+ if (this.pageentercount == 1) {
+ return false;
+ }
+ this.pageentercount = 0;
+
+ this.hide_drop_target();
+
+ return false;
+ },
+
/**
* Check if the drag contents are valid and then call
* preventdefault / stoppropagation to let the browser know
return false;
}
+ // These lines are needed if the user has dragged something directly
+ // from application onto the 'fileupload' box, without crossing another
+ // part of the page first
+ this.pageentercount = 2;
+ this.show_drop_target();
+
this.show_upload_ready();
return false;
},
}
this.entercount = 0;
+ this.pageentercount = 0;
this.hide_upload_ready();
+ this.hide_drop_target();
this.show_progress_spinner();
var files = e._event.dataTransfer.files;
},
/**
- * Highlight the destination node
+ * Highlight the area where files could be dropped
+ */
+ show_drop_target: function() {
+ this.Y.one('#filemanager-uploadmessage'+this.clientid).setStyle('display', 'block');
+ },
+
+ hide_drop_target: function() {
+ this.Y.one('#filemanager-uploadmessage'+this.clientid).setStyle('display', 'none');
+ },
+
+ /**
+ * Highlight the destination node (ready to drop)
*/
show_upload_ready: function() {
this.container.addClass('dndupload-over');
* Remove progress spinner in the destination node
*/
hide_progress_spinner: function() {
- this.Y.one('#dndprogresspinner-'+this.clientid).remove();
+ var spinner = this.Y.one('#dndprogresspinner-'+this.clientid);
+ if (spinner) {
+ spinner.remove();
+ }
},
/**
}, this);
},
empty_filelist: function(container) {
- container.set('innerHTML', '<div class="mdl-align">'+M.str.repository.nofilesattached+'</div>');
+ container.set('innerHTML', '<div class="mdl-align">'+M.str.repository.nofilesattached+'</div>'+this.upload_message());
+ },
+ upload_message: function() {
+ var div = '<div id="filemanager-uploadmessage'+this.client_id+'" style="display:none" class="dndupload-target">';
+ div += M.util.get_string('droptoupload', 'moodle');
+ div += '</div>';
+ return div;
},
render: function() {
var options = this.options;
var filelist = Y.Node.create('<ul id="draftfiles-'+this.client_id+'"></ul>');
container.appendChild(filelist);
}
+ listhtml += this.upload_message();
Y.one('#draftfiles-'+this.client_id).set('innerHTML', listhtml);
// click normal file menu
M.form_filepicker.callback = function(params) {
var html = '<a href="'+params['url']+'">'+params['file']+'</a>';
document.getElementById('file_info_'+params['client_id']).innerHTML = html;
+ M.form_filepicker.add_upload_message(params['client_id']);
//When file is added then set status of global variable to true
var elementname = M.core_filepicker.instances[params['client_id']].options.elementname;
M.form_filepicker.instances[elementname].fileadded = true;
M.form_filepicker.Y.one('#id_'+elementname).simulate('change');
};
+M.form_filepicker.add_upload_message = function(client_id) {
+ var div = '<div id="filemanager-uploadmessage'+client_id+'" style="display:none" class="dndupload-target">';
+ div += M.util.get_string('droptoupload', 'moodle');
+ div += '</div>';
+ var iteminfo = document.getElementById('file_info_'+client_id);
+ iteminfo.innerHTML += div;
+ iteminfo.style.position = 'relative';
+}
+
/**
* This fucntion is called for each file picker on page.
*/
item = document.getElementById('filepicker-wrapper-'+options.client_id);
if (item) {
item.style.display = '';
+ this.add_upload_message(options.client_id);
}
var dndoptions = {
.fm-file-entry{border: 1px solid red;}
.fm-operation {font-weight: bold;}
-.filemanager-container.dndupload-over,
-.filepicker-filelist.dndupload-over {background: #8EF947;}
+.filemanager-container,
+.filepicker-filelist {overflow:hidden;}
+.filemanager-container .dndupload-target,
+.filepicker-filelist .dndupload-target {background:#f7f998;position:absolute;height:100%;width:100%;top:0;left:0;text-align:center;padding:5px;z-index:1000}
+.filemanager-container.dndupload-over .dndupload-target,
+.filepicker-filelist.dndupload-over .dndupload-target {background:#8EF947;font-weight:bold}
/*
* Backup and Restore CSS