mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-22504 Improved drag and drop status message, fixed text dragged from firefox, fix icon
This commit is contained in:
parent
ffa7d1cda0
commit
b64300fc42
@ -92,14 +92,12 @@ M.course_dndupload = {
|
||||
this.init_events(el);
|
||||
}, this);
|
||||
|
||||
var div = this.add_status_div();
|
||||
div.setContent(M.util.get_string('dndworking', 'moodle'));
|
||||
this.add_status_div();
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a div element to tell the user that drag and drop upload
|
||||
* is available (or to explain why it is not available)
|
||||
* @return the DOM element to add messages to
|
||||
*/
|
||||
add_status_div: function() {
|
||||
var div = document.createElement('div');
|
||||
@ -108,7 +106,34 @@ M.course_dndupload = {
|
||||
if (coursecontents) {
|
||||
coursecontents.insertBefore(div, coursecontents.firstChild);
|
||||
}
|
||||
return this.Y.one(div);
|
||||
div = this.Y.one(div);
|
||||
|
||||
var handlefile = (this.handlers.filehandlers.length > 0);
|
||||
var handletext = false;
|
||||
var handlelink = false;
|
||||
var i;
|
||||
for (i=0; i<this.handlers.types.length; i++) {
|
||||
switch (this.handlers.types[i].identifier) {
|
||||
case 'text':
|
||||
case 'text/html':
|
||||
handletext = true;
|
||||
break;
|
||||
case 'url':
|
||||
handlelink = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$msgident = 'dndworking';
|
||||
if (handlefile) {
|
||||
$msgident += 'file';
|
||||
}
|
||||
if (handletext) {
|
||||
$msgident += 'text';
|
||||
}
|
||||
if (handlelink) {
|
||||
$msgident += 'link';
|
||||
}
|
||||
div.setContent(M.util.get_string($msgident, 'moodle'));
|
||||
},
|
||||
|
||||
/**
|
||||
@ -176,14 +201,7 @@ M.course_dndupload = {
|
||||
*/
|
||||
types_includes: function(e, type) {
|
||||
var i;
|
||||
if (e._event.dataTransfer === null) {
|
||||
// TODO MDL-33054: If we get here then something has gone wrong.
|
||||
return false;
|
||||
}
|
||||
var types = e._event.dataTransfer.types;
|
||||
if (types == null) {
|
||||
return false;
|
||||
}
|
||||
for (i=0; i<types.length; i++) {
|
||||
if (types[i] == type) {
|
||||
return true;
|
||||
@ -204,6 +222,18 @@ M.course_dndupload = {
|
||||
* }
|
||||
*/
|
||||
drag_type: function(e) {
|
||||
// Check there is some data attached.
|
||||
if (e._event.dataTransfer === null) {
|
||||
return false;
|
||||
}
|
||||
if (e._event.dataTransfer.types === null) {
|
||||
return false;
|
||||
}
|
||||
if (e._event.dataTransfer.types.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for files first.
|
||||
if (this.types_includes(e, 'Files')) {
|
||||
if (this.handlers.filehandlers.length == 0) {
|
||||
return false; // No available file handlers - ignore this drag.
|
||||
@ -216,7 +246,7 @@ M.course_dndupload = {
|
||||
};
|
||||
}
|
||||
|
||||
// Check each of the registered types
|
||||
// Check each of the registered types.
|
||||
var types = this.handlers.types;
|
||||
for (var i=0; i<types.length; i++) {
|
||||
// Check each of the different identifiers for this type
|
||||
@ -401,6 +431,7 @@ M.course_dndupload = {
|
||||
resel.div.appendChild(resel.a);
|
||||
|
||||
resel.icon.src = M.util.image_url('i/ajaxloader');
|
||||
resel.icon.className = 'activityicon';
|
||||
resel.a.appendChild(resel.icon);
|
||||
|
||||
resel.a.appendChild(document.createTextNode(' '));
|
||||
@ -869,6 +900,17 @@ M.course_dndupload = {
|
||||
formData.append('type', type);
|
||||
formData.append('module', module);
|
||||
|
||||
// Contents from Firefox have their unicode byte-order reversed, swap back and
|
||||
// provide as an alternative.
|
||||
if (type == 'text/html') {
|
||||
var fixedcontents = '';
|
||||
for (i=0; i<contents.length; i+=2) {
|
||||
var val = contents.charCodeAt(i+1) * 256 + contents.charCodeAt(i);
|
||||
fixedcontents += String.fromCharCode(val);
|
||||
}
|
||||
formData.append('fixedcontents', fixedcontents);
|
||||
}
|
||||
|
||||
// Send the data
|
||||
xhr.open("POST", this.url, true);
|
||||
xhr.send(formData);
|
||||
|
@ -34,6 +34,10 @@ $type = required_param('type', PARAM_TEXT);
|
||||
$modulename = required_param('module', PARAM_PLUGIN);
|
||||
$displayname = optional_param('displayname', null, PARAM_TEXT);
|
||||
$contents = optional_param('contents', null, PARAM_RAW); // It will be up to each plugin to clean this data, before saving it.
|
||||
if (!$contents) {
|
||||
// Check if there was a fixed version of contents provided (to cope with dragging from Firefox).
|
||||
$contents = optional_param('fixedcontents', null, PARAM_RAW);
|
||||
}
|
||||
|
||||
$dndproc = new dndupload_ajax_processor($courseid, $section, $type, $modulename);
|
||||
$dndproc->process($displayname, $contents);
|
||||
|
@ -52,7 +52,13 @@ function dndupload_add_to_course($course, $modnames) {
|
||||
'fullpath' => new moodle_url('/course/dndupload.js'),
|
||||
'strings' => array(
|
||||
array('addfilehere', 'moodle'),
|
||||
array('dndworking', 'moodle'),
|
||||
array('dndworkingfiletextlink', 'moodle'),
|
||||
array('dndworkingfilelink', 'moodle'),
|
||||
array('dndworkingfiletext', 'moodle'),
|
||||
array('dndworkingfile', 'moodle'),
|
||||
array('dndworkingtextlink', 'moodle'),
|
||||
array('dndworkingtext', 'moodle'),
|
||||
array('dndworkinglink', 'moodle'),
|
||||
array('filetoolarge', 'moodle'),
|
||||
array('actionchoice', 'moodle'),
|
||||
array('servererror', 'moodle'),
|
||||
|
@ -466,7 +466,13 @@ $string['dndenabled'] = 'Drag and drop available';
|
||||
$string['dndenabled_help'] = 'You can drag one or more files from your desktop and drop them onto the box below to upload them.<br />Note: this may not work with other web browsers';
|
||||
$string['dndenabled_insentence'] = 'drag and drop available';
|
||||
$string['dndenabled_inbox'] = 'drag and drop files here to upload them';
|
||||
$string['dndworking'] = 'Drag and drop files, text or links onto course sections to upload them';
|
||||
$string['dndworkingfiletextlink'] = 'Drag and drop files, text or links onto course sections to upload them';
|
||||
$string['dndworkingfilelink'] = 'Drag and drop files or links onto course sections to upload them';
|
||||
$string['dndworkingfiletext'] = 'Drag and drop files or text onto course sections to upload them';
|
||||
$string['dndworkingfile'] = 'Drag and drop files onto course sections to upload them';
|
||||
$string['dndworkingtextlink'] = 'Drag and drop text or links onto course sections to upload them';
|
||||
$string['dndworkingtext'] = 'Drag and drop text onto course sections to upload it';
|
||||
$string['dndworkinglink'] = 'Drag and drop links onto course sections to upload them';
|
||||
$string['documentation'] = 'Moodle documentation';
|
||||
$string['down'] = 'Down';
|
||||
$string['download'] = 'Download';
|
||||
|
Loading…
x
Reference in New Issue
Block a user