Skip to content

Commit

Permalink
MDL-36990 mod_feedback - moved css selectoren into constants
Browse files Browse the repository at this point in the history
  • Loading branch information
grabs committed Mar 9, 2013
1 parent bdd694f commit 3fa1aec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
5 changes: 5 additions & 0 deletions mod/feedback/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@

//Adding the javascript module for the items dragdrop.
if ($do_show == 'edit') {
$PAGE->requires->strings_for_js(array(
'pluginname',
'move_item',
'position',
), 'feedback');
$PAGE->requires->yui_module('moodle-mod_feedback-dragdrop', 'M.mod_feedback.init_dragdrop',
array(array('cmid' => $cm->id)));
}
Expand Down
26 changes: 18 additions & 8 deletions mod/feedback/yui/dragdrop/dragdrop.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
YUI.add('moodle-mod_feedback-dragdrop', function(Y) {
var DRAGDROPNAME = 'mod_feedback_dragdrop';
var CSS = {
OLDMOVESELECTOR : 'span.feedback_item_command_move',
OLDMOVEUPSELECTOR : 'span.feedback_item_command_moveup',
OLDMOVEDOWNSELECTOR : 'span.feedback_item_command_movedown',
DRAGAREASELECTOR : '#feedback_dragarea',
DRAGITEMSELECTOR : '#feedback_dragarea ul li.feedback_itemlist',
DRAGTARGETSELECTOR : '#feedback_dragarea ul#feedback_draglist',
POSITIONLABEL : '.feedback_item_commands.position',
ITEMBOXSELECTOR : '#feedback_item_box_'
};

var DRAGDROP = function() {
DRAGDROP.superclass.constructor.apply(this, arguments);
Expand Down Expand Up @@ -82,7 +92,7 @@ YUI.add('moodle-mod_feedback-dragdrop', function(Y) {
counter = 1;
drop.get('children').each(function(v) {
poslabeltext = '(' + M.util.get_string('position', 'feedback') + ':' + counter + ')';
poslabel = v.one('.feedback_item_commands.position');
poslabel = v.one(CSS.POSITIONLABEL);
poslabel.setHTML(poslabeltext);
myElements = myElements + ',' + this.get_node_id(v.get('id'));
counter++;
Expand All @@ -96,7 +106,7 @@ YUI.add('moodle-mod_feedback-dragdrop', function(Y) {
var goingUp = false, lastY = 0;

//Get the list of li's in the lists and make them draggable.
listitems = Y.Node.all('#feedback_dragarea ul li.feedback_itemlist');
listitems = Y.Node.all(CSS.DRAGITEMSELECTOR);

listitems.each(function(v) { //Make each item draggable.
var dd = new Y.DD.Drag({
Expand All @@ -107,30 +117,30 @@ YUI.add('moodle-mod_feedback-dragdrop', function(Y) {
}).plug(Y.Plugin.DDProxy, {
moveOnEnd: false
}).plug(Y.Plugin.DDConstrained, {
constrain2node: '#feedback_dragarea' //Prevent dragging outside the dragarea.
constrain2node: CSS.DRAGAREASELECTOR //Prevent dragging outside the dragarea.
});

item_id = this.get_node_id(v.get('id')); //Get the id of the feedback item.
item_box = Y.Node.one('#feedback_item_box_' + item_id); //Get the current item box so we can add the drag handle.
item_box = Y.Node.one(CSS.ITEMBOXSELECTOR + item_id); //Get the current item box so we can add the drag handle.
handletitle = M.util.get_string('move_item', 'feedback');
mydraghandle = this.get_drag_handle(handletitle, 'itemhandle');
v.insert(mydraghandle, item_box); //Insert the new handle into the item box.
dd.addHandle(mydraghandle); //Now we add the handle to the drag object, so the box only can be moved with this handle.
}, this);

// Remove all legacy move icons.
Y.Node.all('span.feedback_item_command_moveup').each(function(v, k) {
Y.Node.all(CSS.OLDMOVEUPSELECTOR).each(function(v, k) {
v.remove();
});;
Y.Node.all('span.feedback_item_command_movedown').each(function(v, k) {
Y.Node.all(CSS.OLDMOVEDOWNSELECTOR).each(function(v, k) {
v.remove();
});;
Y.Node.all('span.feedback_item_command_move').each(function(v, k) {
Y.Node.all(CSS.OLDMOVESELECTOR).each(function(v, k) {
v.remove();
});;

//Create targets for drop.
var droparea = Y.Node.one('#feedback_dragarea ul#feedback_draglist');
var droparea = Y.Node.one(CSS.DRAGTARGETSELECTOR);
var tar = new Y.DD.Drop({
node: droparea
});
Expand Down

0 comments on commit 3fa1aec

Please sign in to comment.