$temp->add(new admin_setting_configcheckbox('enablesafebrowserintegration', new lang_string('enablesafebrowserintegration', 'admin'), new lang_string('configenablesafebrowserintegration', 'admin'), 0));
$temp->add(new admin_setting_configcheckbox('enablegroupmembersonly', new lang_string('enablegroupmembersonly', 'admin'), new lang_string('configenablegroupmembersonly', 'admin'), 0));
+ $temp->add(new admin_setting_configcheckbox('dndallowtextandlinks', new lang_string('dndallowtextandlinks', 'admin'), new lang_string('configdndallowtextandlinks', 'admin'), 0));
+
$ADMIN->add('experimental', $temp);
// "debugging" settingpage
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');
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'));
},
/**
*/
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;
* }
*/
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.
+ 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
+ // 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
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(' '));
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
* @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) {
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
'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'),
// Add some default types to handle.
// Note: 'Files' type is hard-coded into the Javascript as this needs to be ...
// ... treated a little differently.
- $this->add_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);
* @return object Data to pass on to Javascript code
*/
public function get_js_data() {
+ global $CFG;
+
$ret = new stdClass;
// Sort the types by priority.
uasort($this->types, array($this, 'type_compare'));
$ret->types = array();
- foreach ($this->types as $type) {
- if (empty($type->handlers)) {
- continue; // Skip any types without registered handlers.
+ if (!empty($CFG->dndallowtextandlinks)) {
+ foreach ($this->types as $type) {
+ if (empty($type->handlers)) {
+ continue; // Skip any types without registered handlers.
+ }
+ $ret->types[] = $type;
}
- $ret->types[] = $type;
}
$ret->filehandlers = $this->filehandlers;
if ($content != null) {
throw new moodle_exception('fileuploadwithcontent', 'moodle');
}
+ } else {
+ if (empty($content)) {
+ throw new moodle_exception('dnduploadwithoutcontent', 'moodle');
+ }
}
require_sesskey();
$string['configenabledevicedetection'] = 'Enables detection of mobiles, smartphones, tablets or default devices (desktop PCs, laptops, etc) for the application of themes and other features.';
$string['configdisableuserimages'] = 'Disable the ability for users to change user profile images.';
$string['configdisplayloginfailures'] = 'This will display information to selected users about previous failed logins.';
+$string['configdndallowtextandlinks'] = 'Enable or disable the dragging and dropping of text and links onto a course page, alongside the dragging and dropping of files. Note that the dragging of text into Firefox or between different browsers is unreliable and may result in no data being uploaded, or corrupted text being uploaded.';
$string['configdocroot'] = 'Defines the path to the Moodle Docs. You can change this if you wish to have your own custom online documentation. However, if you do that make sure that the paths in your documentation follow the same format as http://docs.moodle.org.';
$string['configdoctonewwindow'] = 'If you enable this, then links to Moodle Docs will be shown in a new window.';
$string['configeditordictionary'] = 'This value will be used if aspell doesn\'t have dictionary for users own language.';
$string['disableuserimages'] = 'Disable user profile images';
$string['displayerrorswarning'] = 'Enabling the PHP setting <em>display_errors</em> is not recommended on production sites because some error messages may reveal sensitive information about your server.';
$string['displayloginfailures'] = 'Display login failures to';
+$string['dndallowtextandlinks'] = 'Drag and drop upload of text/links';
$string['docroot'] = 'Moodle Docs document root';
$string['doctonewwindow'] = 'Open in new window';
$string['download'] = 'Download';
$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['dnduploadwithoutcontent'] = 'This upload does not have any content';
+$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';