mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 07:56:06 +02:00
MDL-42117 JavaScript: Don't rely on node data for course toolboxes
The YUI versions of getData and setData do not store the data in the DOM, but in an instance of YUI. If you make modifications in one instance, but apply them in another, then the data values are not accessible between these two instances. Additionally, there's no benefit to storing the instances on initialisation - if anything, it increases the load overhead. This change moves toolboxes to calculating their ancestors on click in the same way it was done in the initialiser.
This commit is contained in:
parent
4e47920f08
commit
b676db838b
13
course/yui/toolboxes/toolboxes.js
vendored
13
course/yui/toolboxes/toolboxes.js
vendored
@ -204,12 +204,6 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
*/
|
||||
initializer : function(config) {
|
||||
M.course.coursebase.register_module(this);
|
||||
Y.all(SELECTOR.ACTIVITYLI).each(function(activity){
|
||||
activity.setData('toolbox', this);
|
||||
activity.all(SELECTOR.COMMANDSPAN+ ' ' + SELECTOR.ACTIVITYACTION).each(function(){
|
||||
this.setData('activity', activity);
|
||||
});
|
||||
}, this);
|
||||
Y.delegate('click', this.handle_data_action, BODY, SELECTOR.ACTIVITYACTION, this);
|
||||
},
|
||||
|
||||
@ -233,7 +227,8 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
// From the anchor we can get both the activity (added during initialisation) and the action being
|
||||
// performed (added by the UI as a data attribute).
|
||||
var action = node.getData('action'),
|
||||
activity = node.getData('activity');
|
||||
activity = node.ancestor(SELECTOR.ACTIVITYLI);
|
||||
|
||||
if (!node.test('a') || !action || !activity) {
|
||||
// It wasn't a valid action node.
|
||||
return;
|
||||
@ -689,7 +684,7 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
action = 'hide';
|
||||
}
|
||||
if (visible != shouldbevisible) {
|
||||
this.handle_resource_dim(buttonnode, buttonnode.getData('activity'), action);
|
||||
this.handle_resource_dim(buttonnode, element, action);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -800,7 +795,7 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
// NOTE: resourcestotoggle is returned as a string instead
|
||||
// of a Number so we must cast our activityid to a String.
|
||||
if (Y.Array.indexOf(response.resourcestotoggle, "" + activityid) != -1) {
|
||||
node.getData('toolbox').handle_resource_dim(button, node, action);
|
||||
M.course.resource_toolbox.handle_resource_dim(button, node, action);
|
||||
}
|
||||
}, this);
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user