mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 09:56:38 +02:00
MDL-34328: course section "toolboxes" - performance rewrite
Use YUI event delegation to handle events in course section "toolboxes" (visibility and highlight toggles) rather than attaching event handlers to each individual button we care about. Also remove the (now unused) replace_button() function.
This commit is contained in:
parent
de21fb1def
commit
a000ff6833
1 changed files with 11 additions and 32 deletions
43
course/yui/toolboxes/toolboxes.js
vendored
43
course/yui/toolboxes/toolboxes.js
vendored
|
@ -49,32 +49,9 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||||
|
|
||||||
Y.extend(TOOLBOX, Y.Base, {
|
Y.extend(TOOLBOX, Y.Base, {
|
||||||
/**
|
/**
|
||||||
* Replace the button click at the selector with the specified
|
* Toggle the visibility and availability for the specified
|
||||||
* callback
|
* resource show/hide button
|
||||||
*
|
|
||||||
* @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
|
|
||||||
*/
|
*/
|
||||||
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) {
|
toggle_hide_resource_ui : function(button) {
|
||||||
var element = button.ancestor(CSS.ACTIVITYLI);
|
var element = button.ancestor(CSS.ACTIVITYLI);
|
||||||
var hideicon = button.one('img');
|
var hideicon = button.one('img');
|
||||||
|
@ -634,6 +611,11 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||||
initializer : function(config) {
|
initializer : function(config) {
|
||||||
this.setup_for_section();
|
this.setup_for_section();
|
||||||
M.course.coursebase.register_module(this);
|
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
|
* Update any section areas within the scope of the specified
|
||||||
|
@ -643,18 +625,15 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
setup_for_section : function(baseselector) {
|
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;
|
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) {
|
_setup_for_section : function(toolboxtarget) {
|
||||||
// Section Highlighting
|
// Left here for potential future use - not currently needed due to YUI delegation in initializer()
|
||||||
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);
|
|
||||||
},
|
},
|
||||||
toggle_hide_section : function(e) {
|
toggle_hide_section : function(e) {
|
||||||
// Prevent the default button action
|
// Prevent the default button action
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue