11 |
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 |
* format_buttons_renderer
|
|
|
18 |
*
|
|
|
19 |
* @package format_buttons
|
|
|
20 |
* @author Rodrigo Brandão <https://www.linkedin.com/in/brandaorodrigo>
|
|
|
21 |
* @copyright 2020 Rodrigo Brandão <rodrigo.brandao.contato@gmail.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
M.format_buttons = M.format_buttons || {
|
|
|
26 |
ourYUI: null,
|
|
|
27 |
numsections: 0
|
|
|
28 |
};
|
|
|
29 |
|
|
|
30 |
M.format_buttons.init = function(Y, numsections, currentsection, courseid) {
|
|
|
31 |
this.ourYUI = Y;
|
|
|
32 |
this.numsections = parseInt(numsections);
|
|
|
33 |
document.getElementById('buttonsectioncontainer').style.display = 'table';
|
|
|
34 |
|
|
|
35 |
var findHash = function (href) {
|
|
|
36 |
var id = null;
|
|
|
37 |
if (href.indexOf('#section-') !== 0) {
|
|
|
38 |
var split = href.split('#section-');
|
|
|
39 |
id = split[1];
|
|
|
40 |
}
|
|
|
41 |
return id;
|
|
|
42 |
};
|
|
|
43 |
|
|
|
44 |
var hash = findHash(window.location.href);
|
|
|
45 |
if (hash) {
|
|
|
46 |
currentsection = hash;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
if (currentsection) {
|
|
|
50 |
M.format_buttons.show(currentsection, courseid);
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
Y.delegate('click', function (e) {
|
|
|
54 |
var href = e.currentTarget.get('href');
|
|
|
55 |
currentsection = findHash(href);
|
|
|
56 |
M.format_buttons.show(currentsection, courseid)
|
|
|
57 |
}, '[data-region="drawer"]', '[data-type="30"]');
|
|
|
58 |
|
|
|
59 |
};
|
|
|
60 |
|
|
|
61 |
M.format_buttons.hide = function() {
|
|
|
62 |
for (var i = 1; i <= this.numsections; i++) {
|
|
|
63 |
if (document.getElementById('buttonsection-' + i) != undefined) {
|
|
|
64 |
var buttonsection = document.getElementById('buttonsection-' + i);
|
|
|
65 |
buttonsection.setAttribute('class', buttonsection.getAttribute('class').replace('sectionvisible', ''));
|
|
|
66 |
document.getElementById('section-' + i).style.display = 'none';
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
};
|
|
|
70 |
|
|
|
71 |
M.format_buttons.show = function(id, courseid) {
|
|
|
72 |
this.hide();
|
|
|
73 |
if (id > 0) {
|
|
|
74 |
var buttonsection = document.getElementById('buttonsection-' + id);
|
|
|
75 |
var currentsection = document.getElementById('section-' + id);
|
|
|
76 |
if (buttonsection && currentsection) {
|
|
|
77 |
buttonsection.setAttribute('class', buttonsection.getAttribute('class') + ' sectionvisible');
|
|
|
78 |
currentsection.style.display = 'block';
|
|
|
79 |
document.cookie = 'sectionvisible_' + courseid + '=' + id + '; path=/';
|
|
|
80 |
M.format_buttons.h5p();
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
};
|
|
|
84 |
|
|
|
85 |
M.format_buttons.h5p = function() {
|
|
|
86 |
window.h5pResizerInitialized = false;
|
|
|
87 |
var iframes = document.getElementsByTagName('iframe');
|
|
|
88 |
var ready = {
|
|
|
89 |
context: 'h5p',
|
|
|
90 |
action: 'ready'
|
|
|
91 |
};
|
|
|
92 |
for (var i = 0; i < iframes.length; i++) {
|
|
|
93 |
if (iframes[i].src.indexOf('h5p') !== -1) {
|
|
|
94 |
iframes[i].contentWindow.postMessage(ready, '*');
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
};
|