From 9f3f4a3c3f7d87fe4db9b66c255f71af39d9e67e Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 9 Oct 2013 19:15:00 +0800 Subject: [PATCH] MDL-34209 JavaScript: Tidy up dragdrop code. --- course/yui/dragdrop/dragdrop.js | 22 +++++++++++++--------- lib/yui/dragdrop/dragdrop.js | 15 +++++++++------ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/course/yui/dragdrop/dragdrop.js b/course/yui/dragdrop/dragdrop.js index a5085d276d7..fbf37284aad 100644 --- a/course/yui/dragdrop/dragdrop.js +++ b/course/yui/dragdrop/dragdrop.js @@ -27,7 +27,7 @@ YUI.add('moodle-course-dragdrop', function(Y) { Y.extend(DRAGSECTION, M.core.dragdrop, { sectionlistselector : null, - initializer : function(params) { + initializer : function() { // Set group for parent class this.groups = [ CSS.SECTIONDRAGGABLE ]; this.samenodeclass = M.course.format.get_sectionwrapperclass(); @@ -163,18 +163,22 @@ YUI.add('moodle-course-dragdrop', function(Y) { loopend = dragnodeid; } - // Get the list of nodes + // Get the list of nodes. drag.get('dragNode').removeClass(CSS.COURSECONTENT); var sectionlist = Y.Node.all(this.sectionlistselector); - // Add lightbox if it not there + // Add a lightbox if it's not there. var lightbox = M.util.add_lightbox(Y, dragnode); - var params = {}; + // Handle any variables which we must pass via AJAX. + var params = {}, + pageparams = this.get('config').pageparams, + varname; - // Handle any variables which we must pass back through to - var pageparams = this.get('config').pageparams; for (varname in pageparams) { + if (!pageparams.hasOwnProperty(varname)) { + continue; + } params[varname] = pageparams[varname]; } @@ -186,14 +190,13 @@ YUI.add('moodle-course-dragdrop', function(Y) { params.id = dragnodeid; params.value = dropnodeindex; - // Do AJAX request + // Perform the AJAX request. var uri = M.cfg.wwwroot + this.get('ajaxurl'); - Y.io(uri, { method: 'POST', data: params, on: { - start : function(tid) { + start : function() { lightbox.show(); }, success: function(tid, response) { @@ -240,6 +243,7 @@ YUI.add('moodle-course-dragdrop', function(Y) { lightbox.hide(); }, 250); }, + failure: function(tid, response) { this.ajax_failure(response); lightbox.hide(); diff --git a/lib/yui/dragdrop/dragdrop.js b/lib/yui/dragdrop/dragdrop.js index dddfee47e26..6f79c6234f2 100644 --- a/lib/yui/dragdrop/dragdrop.js +++ b/lib/yui/dragdrop/dragdrop.js @@ -161,16 +161,19 @@ YUI.add('moodle-core-dragdrop', function(Y) { }, global_drop_over : function(e) { - // Check that drop object belong to correct group + // Check that drop object belong to correct group. if (!e.drop || !e.drop.inGroup(this.groups)) { return; } - //Get a reference to our drag and drop nodes - var drag = e.drag.get('node'); - var drop = e.drop.get('node'); - // Save last drop target for the case of missed target processing + + // Get a reference to our drag and drop nodes. + var drag = e.drag.get('node'), + drop = e.drop.get('node'); + + // Save last drop target for the case of missed target processing. this.lastdroptarget = e.drop; - //Are we dropping on the same node? + + // Are we dropping within the same parent node? if (drop.hasClass(this.samenodeclass)) { var where; -- 2.43.0