From 5a4decbc2d271d4459dd8a9e6eb131df956570e9 Mon Sep 17 00:00:00 2001 From: Davo Smith Date: Thu, 17 May 2012 21:19:52 +0100 Subject: [PATCH] MDL-22504 Course drag and drop upload - (mostly) fixed the dragging of text between Firefox <==> Chrome --- course/dndupload.js | 73 ++++++++++++++++++++++++++++++++--------- course/dnduploadlib.php | 2 +- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/course/dndupload.js b/course/dndupload.js index 3dbe326eddb..bdfe18a99d9 100644 --- a/course/dndupload.js +++ b/course/dndupload.js @@ -235,15 +235,17 @@ M.course_dndupload = { // 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. + if (e.type != 'drop' || e._event.dataTransfer.files.length != 0) { + if (this.handlers.filehandlers.length == 0) { + return false; // No available file handlers - ignore this drag. + } + return { + realtype: 'Files', + addmessage: M.util.get_string('addfilehere', 'moodle'), + namemessage: null, // Should not be asked for anyway + type: 'Files' + }; } - return { - realtype: 'Files', - addmessage: M.util.get_string('addfilehere', 'moodle'), - namemessage: null, // Should not be asked for anyway - type: 'Files' - }; } // Check each of the registered types. @@ -703,6 +705,11 @@ M.course_dndupload = { if (result.onclick) { resel.a.onclick = result.onclick; } + if (self.Y.UA.gecko > 0) { + // Fix a Firefox bug which makes sites with a '~' in their wwwroot + // log the user out when clicking on the link (before refreshing the page). + resel.div.innerHTML = unescape(resel.div.innerHTML); + } self.add_editing(result.elementid); } else { // Error - remove the dummy element @@ -844,6 +851,7 @@ M.course_dndupload = { * @param contents the actual data that was dropped * @param section the DOM element representing the selected course section * @param sectionnumber the number of the selected course section + * @param module the module chosen to handle this upload */ upload_item: function(name, type, contents, section, sectionnumber, module) { @@ -877,6 +885,11 @@ M.course_dndupload = { if (result.onclick) { resel.a.onclick = result.onclick; } + if (self.Y.UA.gecko > 0) { + // Fix a Firefox bug which makes sites with a '~' in their wwwroot + // log the user out when clicking on the link (before refreshing the page). + resel.div.innerHTML = unescape(resel.div.innerHTML); + } self.add_editing(result.elementid, sectionnumber); } else { // Error - remove the dummy element @@ -890,6 +903,34 @@ M.course_dndupload = { } }; + if (type == 'text/html') { + // If this was html content dragged from Chrome => Firefox, we will + // need to fix the byte order of the content. + if (this.Y.UA.gecko > 0) { + if (contents.indexOf('<') == -1) { + // There are no html tags in this content => it probably needs fixing. + var codes = new Array(); + for (i=0; i it is probably correct. + contents = fixedcontents; + } + } + } + } + // Prepare the data to send var formData = new FormData(); formData.append('contents', contents); @@ -900,15 +941,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 0 && this.Y.UA.os == 'linux') { + var fixedcontents = ''; + for (i=0; iadd_type('url', array('url', 'text/uri-list'), get_string('addlinkhere', 'moodle'), + $this->add_type('url', array('url', 'text/uri-list', 'text/x-moz-url'), get_string('addlinkhere', 'moodle'), get_string('nameforlink', 'moodle'), 10); $this->add_type('text/html', array('text/html'), get_string('addpagehere', 'moodle'), get_string('nameforpage', 'moodle'), 20);