Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'MDL-34328-MOODLE_23_STABLE-2' of git://git.luns.net.uk/…

…moodle into MOODLE_23_STABLE
  • Loading branch information...
commit 2d39f72b593f70a0aaf4b17fed478dfcc0dd20b5 2 parents 790ad23 + cffbc80
@danpoltawski danpoltawski authored
View
87 course/yui/dragdrop/dragdrop.js
@@ -41,6 +41,26 @@ YUI.add('moodle-course-dragdrop', function(Y) {
if (this.sectionlistselector) {
this.sectionlistselector = '.'+CSS.COURSECONTENT+' '+this.sectionlistselector;
this.setup_for_section(this.sectionlistselector);
+
+ // Make each li element in the lists of sections draggable
+ var nodeselector = this.sectionlistselector.slice(CSS.COURSECONTENT.length+2);
+ var del = new Y.DD.Delegate({
+ container: '.'+CSS.COURSECONTENT,
+ nodes: nodeselector,
+ target: true,
+ handles: ['.'+CSS.LEFT],
+ dragConfig: {groups: this.groups}
+ });
+ del.dd.plug(Y.Plugin.DDProxy, {
+ // Don't move the node at the end of the drag
+ moveOnEnd: false
+ });
+ del.dd.plug(Y.Plugin.DDConstrained, {
+ // Keep it inside the .course-content
+ constrain: '#'+CSS.PAGECONTENT,
+ stickY: true
+ });
+ del.dd.plug(Y.Plugin.DDWinScroll);
}
},
@@ -76,22 +96,6 @@ YUI.add('moodle-course-dragdrop', function(Y) {
if (movedown) {
movedown.remove();
}
-
- // Make each li element in the lists of sections draggable
- var dd = new Y.DD.Drag({
- node: sectionnode,
- // Make each li a Drop target too
- groups: this.groups,
- target: true,
- handles: ['.'+CSS.LEFT]
- }).plug(Y.Plugin.DDProxy, {
- // Don't move the node at the end of the drag
- moveOnEnd: false
- }).plug(Y.Plugin.DDConstrained, {
- // Keep it inside the .course-content
- constrain: '#'+CSS.PAGECONTENT,
- stickY: true
- }).plug(Y.Plugin.DDWinScroll);
}
}
}, this);
@@ -244,12 +248,33 @@ YUI.add('moodle-course-dragdrop', function(Y) {
this.groups = ['resource'];
this.samenodeclass = CSS.ACTIVITY;
this.parentnodeclass = CSS.SECTION;
+ this.resourcedraghandle = this.get_drag_handle(M.str.moodle.move, CSS.EDITINGMOVE, CSS.ICONCLASS);
// Go through all sections
var sectionlistselector = M.course.format.get_section_selector(Y);
if (sectionlistselector) {
sectionlistselector = '.'+CSS.COURSECONTENT+' '+sectionlistselector;
this.setup_for_section(sectionlistselector);
+
+ // Initialise drag & drop for all resources/activities
+ var nodeselector = sectionlistselector.slice(CSS.COURSECONTENT.length+2)+' li.'+CSS.ACTIVITY;
+ var del = new Y.DD.Delegate({
+ container: '.'+CSS.COURSECONTENT,
+ nodes: nodeselector,
+ target: true,
+ handles: ['.' + CSS.EDITINGMOVE],
+ dragConfig: {groups: this.groups}
+ });
+ del.dd.plug(Y.Plugin.DDProxy, {
+ // Don't move the node at the end of the drag
+ moveOnEnd: false
+ });
+ del.dd.plug(Y.Plugin.DDConstrained, {
+ // Keep it inside the .course-content
+ constrain: '#'+CSS.PAGECONTENT
+ });
+ del.dd.plug(Y.Plugin.DDWinScroll);
+
M.course.coursebase.register_module(this);
M.course.dragres = this;
}
@@ -269,15 +294,15 @@ YUI.add('moodle-course-dragdrop', function(Y) {
var resources = Y.Node.create('<ul></ul>');
resources.addClass(CSS.SECTION);
sectionnode.one('.'+CSS.CONTENT+' div.'+CSS.SUMMARY).insert(resources, 'after');
+ // Define empty ul as droptarget, so that item could be moved to empty list
+ var tar = new Y.DD.Drop({
+ node: resources,
+ groups: this.groups,
+ padding: '20 0 20 0'
+ });
}
- // Define each ul as droptarget, so that item could be moved to empty list
- var tar = new Y.DD.Drop({
- node: resources,
- groups: this.groups,
- padding: '20 0 20 0'
- });
- // Go through each li element and make them draggable
+ // Initialise each resource/activity in this section
this.setup_for_resource('#'+sectionnode.get('id')+' li.'+CSS.ACTIVITY);
}, this);
},
@@ -292,21 +317,7 @@ YUI.add('moodle-course-dragdrop', function(Y) {
// Replace move icons
var move = resourcesnode.one('a.'+CSS.EDITINGMOVE);
if (move) {
- move.replace(this.get_drag_handle(M.str.moodle.move, CSS.EDITINGMOVE, CSS.ICONCLASS));
- // Make each li element in the lists of sections draggable
- var dd = new Y.DD.Drag({
- node: resourcesnode,
- groups: this.groups,
- // Make each li a Drop target too
- target: true,
- handles: ['.' + CSS.EDITINGMOVE]
- }).plug(Y.Plugin.DDProxy, {
- // Don't move the node at the end of the drag
- moveOnEnd: false
- }).plug(Y.Plugin.DDConstrained, {
- // Keep it inside the .course-content
- constrain: '#'+CSS.PAGECONTENT
- }).plug(Y.Plugin.DDWinScroll);
+ move.replace(this.resourcedraghandle.cloneNode(true));
}
}, this);
},
View
85 course/yui/toolboxes/toolboxes.js
@@ -49,32 +49,9 @@ YUI.add('moodle-course-toolboxes', function(Y) {
Y.extend(TOOLBOX, Y.Base, {
/**
- * Replace the button click at the selector with the specified
- * callback
- *
- * @param toolboxtarget The selector of the working area
- * @param selector The 'button' to replace
- * @param callback The callback to apply
- * @param cursor An optional cursor style to apply
+ * Toggle the visibility and availability for the specified
+ * resource show/hide button
*/
- replace_button : function(toolboxtarget, selector, callback, cursor) {
- if (!cursor) {
- // Set the default cursor type to pointer to match the
- // anchor
- cursor = 'pointer';
- }
- var button = Y.one(toolboxtarget).all(selector)
- .setStyle('cursor', cursor);
-
- // on isn't chainable and will return an event
- button.on('click', callback, this);
-
- return button;
- },
- /**
- * Toggle the visibility and availability for the specified
- * resource show/hide button
- */
toggle_hide_resource_ui : function(button) {
var element = button.ancestor(CSS.ACTIVITYLI);
var hideicon = button.one('img');
@@ -241,6 +218,17 @@ YUI.add('moodle-course-toolboxes', function(Y) {
initializer : function(config) {
this.setup_for_resource();
M.course.coursebase.register_module(this);
+
+ var prefix = CSS.ACTIVITYLI + ' ' + CSS.COMMANDSPAN + ' ';
+ Y.delegate('click', this.edit_resource_title, CSS.PAGECONTENT, prefix + CSS.EDITTITLE, this);
+ Y.delegate('click', this.move_left, CSS.PAGECONTENT, prefix + CSS.MOVELEFT, this);
+ Y.delegate('click', this.move_right, CSS.PAGECONTENT, prefix + CSS.MOVERIGHT, this);
+ Y.delegate('click', this.delete_resource, CSS.PAGECONTENT, prefix + CSS.DELETE, this);
+ Y.delegate('click', this.toggle_hide_resource, CSS.PAGECONTENT, prefix + CSS.HIDE, this);
+ Y.delegate('click', this.toggle_hide_resource, CSS.PAGECONTENT, prefix + CSS.SHOW, this);
+ Y.delegate('click', this.toggle_groupmode, CSS.PAGECONTENT, prefix + CSS.GROUPSNONE, this);
+ Y.delegate('click', this.toggle_groupmode, CSS.PAGECONTENT, prefix + CSS.GROUPSSEPARATE, this);
+ Y.delegate('click', this.toggle_groupmode, CSS.PAGECONTENT, prefix + CSS.GROUPSVISIBLE, this);
},
/**
@@ -252,27 +240,16 @@ YUI.add('moodle-course-toolboxes', function(Y) {
*/
setup_for_resource : function(baseselector) {
if (!baseselector) {
- var baseselector = CSS.PAGECONTENT + ' ' + CSS.ACTIVITYLI;;
+ var baseselector = CSS.PAGECONTENT + ' ' + CSS.ACTIVITYLI;
}
Y.all(baseselector).each(this._setup_for_resource, this);
},
_setup_for_resource : function(toolboxtarget) {
- // Edit Title
- this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.EDITTITLE, this.edit_resource_title);
-
- // Move left and right
- this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.MOVELEFT, this.move_left);
- this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.MOVERIGHT, this.move_right);
-
- // Delete
- this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.DELETE, this.delete_resource);
-
- // Show/Hide
- var showhide = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.HIDE, this.toggle_hide_resource);
- var shown = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.SHOW, this.toggle_hide_resource);
-
- showhide = showhide.concat(shown);
+ toolboxtarget = Y.one(toolboxtarget);
+ // "Disable" show/hide icons (change cursor to not look clickable) if section is hidden
+ var showhide = toolboxtarget.all(CSS.COMMANDSPAN + ' ' + CSS.HIDE);
+ showhide.concat(toolboxtarget.all(CSS.COMMANDSPAN + ' ' + CSS.SHOW));
showhide.each(function(node) {
var section = node.ancestor(CSS.SECTIONLI);
if (section && section.hasClass(CSS.SECTIONHIDDENCLASS)) {
@@ -280,15 +257,15 @@ YUI.add('moodle-course-toolboxes', function(Y) {
}
});
- // Change Group Mode
+ // Set groupmode attribute for use by this.toggle_groupmode()
var groups;
- groups = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.GROUPSNONE, this.toggle_groupmode);
+ groups = toolboxtarget.all(CSS.COMMANDSPAN + ' ' + CSS.GROUPSNONE);
groups.setAttribute('groupmode', this.GROUPS_NONE);
- groups = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.GROUPSSEPARATE, this.toggle_groupmode);
+ groups = toolboxtarget.all(CSS.COMMANDSPAN + ' ' + CSS.GROUPSSEPARATE);
groups.setAttribute('groupmode', this.GROUPS_SEPARATE);
- groups = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.GROUPSVISIBLE, this.toggle_groupmode);
+ groups = toolboxtarget.all(CSS.COMMANDSPAN + ' ' + CSS.GROUPSVISIBLE);
groups.setAttribute('groupmode', this.GROUPS_VISIBLE);
},
move_left : function(e) {
@@ -405,6 +382,7 @@ YUI.add('moodle-course-toolboxes', function(Y) {
};
var spinner = M.util.add_spinner(Y, element.one(CSS.SPINNERCOMMANDSPAN));
this.send_request(data, spinner);
+ return false; // Need to return false to stop the delegate for the new state firing
},
toggle_groupmode : function(e) {
// Prevent the default button action
@@ -460,6 +438,7 @@ YUI.add('moodle-course-toolboxes', function(Y) {
};
var spinner = M.util.add_spinner(Y, element.one(CSS.SPINNERCOMMANDSPAN));
this.send_request(data, spinner);
+ return false; // Need to return false to stop the delegate for the new state firing
},
/**
* Add the moveleft button
@@ -632,6 +611,11 @@ YUI.add('moodle-course-toolboxes', function(Y) {
initializer : function(config) {
this.setup_for_section();
M.course.coursebase.register_module(this);
+
+ // Section Highlighting
+ Y.delegate('click', this.toggle_highlight, CSS.PAGECONTENT, CSS.SECTIONLI + ' ' + CSS.HIGHLIGHT, this);
+ // Section Visibility
+ Y.delegate('click', this.toggle_hide_section, CSS.PAGECONTENT, CSS.SECTIONLI + ' ' + CSS.SHOWHIDE, this);
},
/**
* Update any section areas within the scope of the specified
@@ -641,18 +625,15 @@ YUI.add('moodle-course-toolboxes', function(Y) {
* @return void
*/
setup_for_section : function(baseselector) {
- if (!baseselector) {
+ // Left here for potential future use - not currently needed due to YUI delegation in initializer()
+ /*if (!baseselector) {
var baseselector = CSS.PAGECONTENT;
}
- Y.all(baseselector).each(this._setup_for_section, this);
+ Y.all(baseselector).each(this._setup_for_section, this);*/
},
_setup_for_section : function(toolboxtarget) {
- // Section Highlighting
- this.replace_button(toolboxtarget, CSS.RIGHTSIDE + ' ' + CSS.HIGHLIGHT, this.toggle_highlight);
-
- // Section Visibility
- this.replace_button(toolboxtarget, CSS.RIGHTSIDE + ' ' + CSS.SHOWHIDE, this.toggle_hide_section);
+ // Left here for potential future use - not currently needed due to YUI delegation in initializer()
},
toggle_hide_section : function(e) {
// Prevent the default button action
View
26 lib/yui/blocks/blocks.js
@@ -68,23 +68,27 @@ YUI.add('moodle-core-blocks', function(Y) {
padding: '40 240 40 240'
});
+ // Make each div element in the list of blocks draggable
+ var del = new Y.DD.Delegate({
+ container: blockregionnode,
+ nodes: '.'+CSS.BLOCK,
+ target: true,
+ handles: ['.'+CSS.HEADER],
+ invalid: '.block-hider-hide, .block-hider-show, .moveto',
+ dragConfig: {groups: this.groups}
+ });
+ del.dd.plug(Y.Plugin.DDProxy, {
+ // Don't move the node at the end of the drag
+ moveOnEnd: false
+ });
+ del.dd.plug(Y.Plugin.DDWinScroll);
+
var blocklist = blockregionnode.all('.'+CSS.BLOCK);
blocklist.each(function(blocknode) {
var move = blocknode.one('a.'+CSS.EDITINGMOVE);
if (move) {
move.remove();
blocknode.one('.'+CSS.HEADER).setStyle('cursor', 'move');
- // Make each div element in the list of blocks draggable
- var dd = new Y.DD.Drag({
- node: blocknode,
- groups: this.groups,
- // Make each div a Drop target too
- target: true,
- handles: ['.'+CSS.HEADER]
- }).plug(Y.Plugin.DDProxy, {
- // Don't move the node at the end of the drag
- moveOnEnd: false
- }).plug(Y.Plugin.DDWinScroll);
}
}, this);
}, this);
View
2  lib/yui/dragdrop/dragdrop.js
@@ -167,11 +167,11 @@ YUI.add('moodle-core-dragdrop', function(Y) {
// we substitute them for the ease of use. For e.drop we use,
// this.lastdroptarget (ghost node we use for indicating where to drop)
e.drag = e.target;
+ e.drop = this.lastdroptarget;
// Check that drop object belong to correct group
if (!e.drop || !e.drop.inGroup(this.groups)) {
return;
}
- e.drop = this.lastdroptarget;
this.drag_dropmiss(e);
},
Please sign in to comment.
Something went wrong with that request. Please try again.