Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
{{!
2
    This file is part of Moodle - http://moodle.org/
3
 
4
    Moodle is free software: you can redistribute it and/or modify
5
    it under the terms of the GNU General Public License as published by
6
    the Free Software Foundation, either version 3 of the License, or
7
    (at your option) any later version.
8
 
9
    Moodle is distributed in the hope that it will be useful,
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
    GNU General Public License for more details.
13
 
14
    You should have received a copy of the GNU General Public License
15
    along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
}}
17
{{!
18
    @template core/select_menu
19
 
20
    Template for select_menu output component.
21
 
22
    Context variables required for this template:
23
    * name - name of the form element
24
    * value - value of the form element
25
    * baseid - id of the dropdown element and to be used to generate id for other elements used internally
26
    * label - Element label
27
    * labelattributes - Label attributes.
28
    * selectedoption - Text of the selected option
29
    * options - Array of options for the select with value, name, selected, isgroup and id properites.
30
 
31
    Example context (json):
32
    {
33
        "name": "menuname",
34
        "value": "opt2",
35
        "baseid": "select-menu56789",
36
        "label": "Select one option",
1441 ariadna 37
        "headinglevel": "2",
1 efrain 38
        "labelattributes": [
39
            {
40
                "name": "class",
1441 ariadna 41
                "value": "fw-bold"
1 efrain 42
            }
43
        ],
44
        "selectedoption": "Second option",
45
        "options": [
46
            {
47
                "name": "First option",
48
                "value": "opt1",
49
                "id": "select-menu-option1",
50
                "selected": false
51
            },
52
            {
53
                "name": "Second option",
54
                "value": "opt2",
55
                "id": "select-menu-option2",
56
                "selected": true
57
            },
58
            {
59
                "selected": false,
60
                "isgroup": {
61
                    "name": "First group",
62
                    "id": "select-menu-group1",
63
                    "options": [
64
                        {
65
                            "name": "Third option",
66
                            "value": "opt3",
67
                            "id": "select-menu-option3",
68
                            "selected": false
69
                        },
70
                        {
71
                            "name": "Fourth option",
72
                            "value": "opt4",
73
                            "id": "select-menu-option4",
74
                            "selected": false
75
                        }
76
                    ]
77
                }
78
            },
79
            {
80
                "name": "Fifth option",
81
                "value": "opt5",
82
                "id": "select-menu-option5",
83
                "selected": false
84
            }
85
        ]
86
    }
87
}}
88
<div class="dropdown select-menu" id="{{baseid}}">
1441 ariadna 89
    {{#label}}{{^inlinelabel}}
90
        <span id="{{baseid}}-label"{{#labelattributes}} {{name}}="{{value}}"{{/labelattributes}}>{{label}}</span>
91
    {{/inlinelabel}}{{/label}}
1 efrain 92
    <div
1441 ariadna 93
        class="btn dropdown-toggle{{#inlinelabel}} d-flex text-start align-items-center p-0{{/inlinelabel}}"
1 efrain 94
        role="combobox"
1441 ariadna 95
        data-bs-toggle="dropdown"
1 efrain 96
        {{#label}}aria-labelledby="{{baseid}}-label"{{/label}}
97
        aria-haspopup="listbox"
98
        aria-expanded="false"
99
        aria-controls="{{baseid}}-listbox"
100
        data-input-element="{{baseid}}-input"
101
        tabindex="0"
102
    >
1441 ariadna 103
        {{#inlinelabel}}
104
            <div
105
                class="pe-3 text-truncate"
106
                {{#headinglevel}}
107
                role="heading"
108
                aria-level="{{headinglevel}}"
109
                {{/headinglevel}}
110
            >
111
                {{#label}}
112
                    <span class="d-block m-0 small" id="{{baseid}}-label"{{#labelattributes}} {{name}}="{{value}}"{{/labelattributes}}>{{label}}</span>
113
                {{/label}}
114
                <span class="fw-bold" data-selected-option>
115
                    {{selectedoption}}
116
                </span>
117
            </div>
118
        {{/inlinelabel}}
119
        {{^inlinelabel}}
120
            {{#headinglevel}}
121
                <span
122
                    role="heading"
123
                    aria-level="{{headinglevel}}"
124
                >
125
                    {{selectedoption}}
126
                </span>
127
            {{/headinglevel}}
128
            {{^headinglevel}}
129
                {{selectedoption}}
130
            {{/headinglevel}}
131
        {{/inlinelabel}}
1 efrain 132
    </div>
133
    <ul class="dropdown-menu" role="listbox" id="{{baseid}}-listbox" {{#label}}aria-labelledby="{{baseid}}-label"{{/label}}>
134
        {{#options}}
135
            {{#isgroup}}
136
                <li role="none">
137
                    <ul role="group" aria-labelledby="{{id}}">
138
                        <li role="presentation" id="{{id}}">{{name}}</li>
139
                        {{#options}}
1441 ariadna 140
                            {{#isdivider}}
141
                                <li role="separator" class="dropdown-divider"></li>
142
                            {{/isdivider}}
143
                            {{^isdivider}}
144
                                <li class="dropdown-item" role="option" id="{{id}}" data-value="{{value}}" {{#selected}}aria-selected="true"{{/selected}}>
145
                                    {{name}}
146
                                </li>
147
                            {{/isdivider}}
1 efrain 148
                        {{/options}}
149
                    </ul>
150
                </li>
151
            {{/isgroup}}
152
            {{^isgroup}}
1441 ariadna 153
                {{#isdivider}}
154
                    <li role="separator" class="dropdown-divider"></li>
155
                {{/isdivider}}
156
                {{^isdivider}}
157
                    <li class="dropdown-item" role="option" id="{{id}}" data-value="{{value}}" {{#selected}}aria-selected="true"{{/selected}}>
158
                        {{name}}
159
                    </li>
160
                {{/isdivider}}
1 efrain 161
            {{/isgroup}}
162
        {{/options}}
163
    </ul>
164
    <input type="hidden" name="{{name}}" value="{{value}}" id="{{baseid}}-input">
165
</div>
166
{{#js}}
167
    var label = document.getElementById('{{baseid}}-label');
168
    if (label) {
169
        label.addEventListener('click', function() {
170
            this.parentElement.querySelector('.dropdown-toggle').focus();
171
        });
172
    }
173
{{/js}}