Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 * Potential user selector module.
18
 *
19
 * @module     tool_dataprivacy/expand_contract
20
 * @copyright  2018 Adrian Greeve
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
define(['jquery', 'core/url', 'core/str', 'core/notification'], function($, url, str, Notification) {
25
 
26
    var expandedImage = $('<img alt="" src="' + url.imageUrl('t/expanded') + '"/>');
27
    var collapsedImage = $('<img alt="" src="' + url.imageUrl('t/collapsed') + '"/>');
28
 
29
    /*
30
     * Class names to apply when expanding/collapsing nodes.
31
     */
32
    var CLASSES = {
33
        EXPAND: 'fa-caret-right',
34
        COLLAPSE: 'fa-caret-down'
35
    };
36
 
37
    return /** @alias module:tool_dataprivacy/expand-collapse */ {
38
        /**
39
         * Expand or collapse a selected node.
40
         *
41
         * @param  {object} targetnode The node that we want to expand / collapse
42
         * @param  {object} thisnode The node that was clicked.
43
         */
44
        expandCollapse: function(targetnode, thisnode) {
45
            if (targetnode.hasClass('hide')) {
46
                targetnode.removeClass('hide');
47
                targetnode.addClass('visible');
48
                targetnode.attr('aria-expanded', true);
49
                thisnode.find(':header i.fa').removeClass(CLASSES.EXPAND);
50
                thisnode.find(':header i.fa').addClass(CLASSES.COLLAPSE);
51
                thisnode.find(':header img.icon').attr('src', expandedImage.attr('src'));
52
            } else {
53
                targetnode.removeClass('visible');
54
                targetnode.addClass('hide');
55
                targetnode.attr('aria-expanded', false);
56
                thisnode.find(':header i.fa').removeClass(CLASSES.COLLAPSE);
57
                thisnode.find(':header i.fa').addClass(CLASSES.EXPAND);
58
                thisnode.find(':header img.icon').attr('src', collapsedImage.attr('src'));
59
            }
60
        },
61
 
62
        /**
63
         * Expand or collapse all nodes on this page.
64
         *
65
         * @param  {string} nextstate The next state to change to.
66
         */
67
        expandCollapseAll: function(nextstate) {
68
            var currentstate = (nextstate == 'visible') ? 'hide' : 'visible';
69
            var ariaexpandedstate = (nextstate == 'visible') ? true : false;
70
            var iconclassnow = (nextstate == 'visible') ? CLASSES.EXPAND : CLASSES.COLLAPSE;
71
            var iconclassnext = (nextstate == 'visible') ? CLASSES.COLLAPSE : CLASSES.EXPAND;
72
            var imagenow = (nextstate == 'visible') ? expandedImage.attr('src') : collapsedImage.attr('src');
73
            $('.' + currentstate).each(function() {
74
                $(this).removeClass(currentstate);
75
                $(this).addClass(nextstate);
76
                $(this).attr('aria-expanded', ariaexpandedstate);
77
            });
78
            $('.tool_dataprivacy-expand-all').data('visibilityState', currentstate);
79
 
80
            str.get_string(currentstate, 'tool_dataprivacy').then(function(langString) {
81
                $('.tool_dataprivacy-expand-all').html(langString);
82
                return;
83
            }).catch(Notification.exception);
84
 
85
            $(':header i.fa').each(function() {
86
                $(this).removeClass(iconclassnow);
87
                $(this).addClass(iconclassnext);
88
            });
89
            $(':header img.icon').each(function() {
90
                $(this).attr('src', imagenow);
91
            });
92
        }
93
    };
94
});