1 |
efrain |
1 |
// This file is part of Moodle - http://moodle.org/
|
|
|
2 |
//
|
|
|
3 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
4 |
// it under the terms of the GNU General Public License as published by
|
|
|
5 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
6 |
// (at your option) any later version.
|
|
|
7 |
//
|
|
|
8 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
9 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
10 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
11 |
// GNU General Public License for more details.
|
|
|
12 |
//
|
|
|
13 |
// You should have received a copy of the GNU General Public License
|
|
|
14 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* Drag and drop reorder via HTML5.
|
|
|
18 |
*
|
|
|
19 |
* @module tool_lp/dragdrop-reorder
|
|
|
20 |
* @copyright 2015 Damyon Wiese <damyon@moodle.com>
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
define(['core/str', 'core/yui'], function(str, Y) {
|
|
|
24 |
// Private variables and functions.
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Store the current instance of the core drag drop.
|
|
|
28 |
*
|
|
|
29 |
* @property {object} dragDropInstance M.tool_lp.dragdrop_reorder
|
|
|
30 |
*/
|
|
|
31 |
var dragDropInstance = null;
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Translate the drophit event from YUI
|
|
|
35 |
* into simple drag and drop nodes.
|
|
|
36 |
* @param {Y.Event} e The yui drop event.
|
|
|
37 |
*/
|
|
|
38 |
var proxyCallback = function(e) {
|
|
|
39 |
var dragNode = e.drag.get('node');
|
|
|
40 |
var dropNode = e.drop.get('node');
|
|
|
41 |
this.callback(dragNode.getDOMNode(), dropNode.getDOMNode());
|
|
|
42 |
};
|
|
|
43 |
|
|
|
44 |
return /** @alias module:tool_lp/dragdrop-reorder */ {
|
|
|
45 |
// Public variables and functions.
|
|
|
46 |
/**
|
|
|
47 |
* Create an instance of M.tool_lp.dragdrop
|
|
|
48 |
*
|
|
|
49 |
* @param {String} group Unique string to identify this interaction.
|
|
|
50 |
* @param {String} dragHandleText Alt text for the drag handle.
|
|
|
51 |
* @param {String} sameNodeText Used in keyboard drag drop for the list of items target.
|
|
|
52 |
* @param {String} parentNodeText Used in keyboard drag drop for the parent target.
|
|
|
53 |
* @param {String} sameNodeClass class used to find the each of the list of items.
|
|
|
54 |
* @param {String} parentNodeClass class used to find the container for the list of items.
|
|
|
55 |
* @param {String} dragHandleInsertClass class used to find the location to insert the drag handles.
|
|
|
56 |
* @param {function} callback Drop hit handler.
|
|
|
57 |
*/
|
|
|
58 |
dragdrop: function(group,
|
|
|
59 |
dragHandleText,
|
|
|
60 |
sameNodeText,
|
|
|
61 |
parentNodeText,
|
|
|
62 |
sameNodeClass,
|
|
|
63 |
parentNodeClass,
|
|
|
64 |
dragHandleInsertClass,
|
|
|
65 |
callback) {
|
|
|
66 |
// Here we are wrapping YUI. This allows us to start transitioning, but
|
|
|
67 |
// wait for a good alternative without having inconsistent UIs.
|
|
|
68 |
str.get_strings([
|
|
|
69 |
{key: 'emptydragdropregion', component: 'moodle'},
|
|
|
70 |
{key: 'movecontent', component: 'moodle'},
|
|
|
71 |
{key: 'tocontent', component: 'moodle'},
|
|
|
72 |
]).done(function() {
|
|
|
73 |
Y.use('moodle-tool_lp-dragdrop-reorder', function() {
|
|
|
74 |
|
|
|
75 |
var context = {
|
|
|
76 |
callback: callback
|
|
|
77 |
};
|
|
|
78 |
if (dragDropInstance) {
|
|
|
79 |
dragDropInstance.destroy();
|
|
|
80 |
}
|
|
|
81 |
dragDropInstance = M.tool_lp.dragdrop_reorder({
|
|
|
82 |
group: group,
|
|
|
83 |
dragHandleText: dragHandleText,
|
|
|
84 |
sameNodeText: sameNodeText,
|
|
|
85 |
parentNodeText: parentNodeText,
|
|
|
86 |
sameNodeClass: sameNodeClass,
|
|
|
87 |
parentNodeClass: parentNodeClass,
|
|
|
88 |
dragHandleInsertClass: dragHandleInsertClass,
|
|
|
89 |
callback: Y.bind(proxyCallback, context)
|
|
|
90 |
});
|
|
|
91 |
});
|
|
|
92 |
});
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
};
|
|
|
96 |
});
|