Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
YUI.add('moodle-block_course_overview_uwmoodle-showhide', function(Y) {
var ShowHide = function() {
ShowHide.superclass.constructor.apply(this, arguments);
};
ShowHide.prototype = {
id : null,
initializer : function(config) {
this.id = config.id;
var node = Y.one('#inst'+config.id);
// Can't find the block instance within the page
if (node === null) {
return;
}
var items = config.items.split(" ");
for(i=0; i<items.length; i++){
node.one('#uwm-'+this.id+'-'+items[i]).on('click', this.toggleExpansion, this, items[i]);
}
},
toggleExpansion : function(e, item) {
// First check if they managed to click on the li iteslf, then find the closest
// LI ancestor and use that
/*
if (e.target.test('a')) {
// A link has been clicked (or keypress is 'enter') don't fire any more events just do the default.
e.stopPropagation();
return;
}
*/
// Get the LI containing the branch.
var target = e.target;
if (!target.test('li')) {
target = target.ancestor('li')
}
if (!target) {
return;
}
// Get the A for the control (for aria)
var control = e.target;
if (!control.test('a')) {
control = control.ancestor('a')
}
if (!control) {
return;
}
e.preventDefault();
// Toggle expand/collapse
target.toggleClass('collapsed');
control.set('aria-expanded', !target.hasClass('collapsed'));
// update a show/hide text control, if any
var textcontrol = control.one('.showhidetext');
if (textcontrol) {
textcontrol.setHTML(target.hasClass('collapsed')? "Show" : "Hide");
}
M.util.set_user_preference('block_course_overview_uwmoodle-show-'+item, target.hasClass('collapsed')? 0 : 1);
}
};
Y.extend(ShowHide, Y.Base, ShowHide.prototype, {
NAME : 'Course Overview UWMoodle Tree Navigation'
});
M.block_course_overview_uwmoodle = M.block_course_overview_uwmoodle || {
initialize:function(properties) {
new ShowHide(properties);
}
};
}, '@VERSION@', {requires:['base','node']});