MDL-34209 JavaScript: Tidy up dragdrop code.
authorAndrew Nicols <andrew@nicols.co.uk>
Wed, 9 Oct 2013 11:15:00 +0000 (19:15 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Thu, 10 Oct 2013 06:42:06 +0000 (14:42 +0800)
course/yui/dragdrop/dragdrop.js
lib/yui/dragdrop/dragdrop.js

index a5085d2..fbf3728 100644 (file)
@@ -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();
index dddfee4..6f79c62 100644 (file)
@@ -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;