Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 69... Línea 69...
69
    function isMultiSelect($el) {
69
    function isMultiSelect($el) {
70
        return ($el.is('select') && $el.prop('multiple'));
70
        return ($el.is('select') && $el.prop('multiple'));
71
    }
71
    }
Línea 72... Línea 72...
72
 
72
 
-
 
73
    /**
-
 
74
     * Are the selected values of a multi-select a subset of (i.e. 'in') the list of values provided?
-
 
75
     * @param {jQuery} $el
-
 
76
     * @param {array} values
-
 
77
     * @returns {boolean}
-
 
78
     */
-
 
79
    function multiSelectIn($el, values) {
-
 
80
        let selected = $el.val() || [];
-
 
81
        if (selected.length == 0) {
-
 
82
            selected.push('');
-
 
83
        }
-
 
84
 
-
 
85
        // Lock/hide if the selected values are a subset of the values.
-
 
86
        let isSubset = selected.every(element => values.includes(element));
-
 
87
        return isSubset;
-
 
88
    }
-
 
89
 
73
    /**
90
    /**
74
     * Does the multi-select exactly match the list of values provided?
91
     * Are the selected values of a multi-select an exact match (i.e. 'eq') to the list of values provided?
75
     * @param {jQuery} $el
92
     * @param {jQuery} $el
76
     * @param {array} values
93
     * @param {array} values
77
     * @returns {boolean}
94
     * @returns {boolean}
78
     */
95
     */
79
    function multiSelectMatches($el, values) {
96
    function multiSelectMatches($el, values) {
80
        var selected = $el.val() || [];
97
        var selected = $el.val() || [];
81
        if (!values.length) {
98
        if (values.length === 1 && values[0] === '') {
82
            // No values - nothing to match against.
99
            // Values array contains a single empty entry -> value was empty.
83
            return false;
100
            return selected.length === 0;
84
        }
101
        }
85
        if (selected.length !== values.length) {
102
        if (selected.length !== values.length) {
86
            // Different number of expected and actual values - cannot possibly be a match.
103
            // Different number of expected and actual values - cannot possibly be a match.
87
            return false;
104
            return false;
Línea 191... Línea 208...
191
                    // the associated hidden element, which we have already found, above.
208
                    // the associated hidden element, which we have already found, above.
192
                    hide = hide || hiddenVal;
209
                    hide = hide || hiddenVal;
193
                    return;
210
                    return;
194
                }
211
                }
195
                if (isMultiSelect($el)) {
212
                if (isMultiSelect($el)) {
196
                    // For multiselect, we check to see if the list of values provided matches the list selected.
213
                    // For multiselect, we check to see if the selected values are a subset of the list of values provided.
197
                    hide = multiSelectMatches($el, values);
214
                    hide = multiSelectIn($el, values);
198
                    return;
215
                    return;
199
                }
216
                }
200
                // All other element types - check to see if the value is in the list.
217
                // All other element types - check to see if the value is in the list.
201
                hide = hide || (values.indexOf($el.val()) > -1);
218
                hide = hide || (values.indexOf($el.val()) > -1);
202
            });
219
            });
Línea 326... Línea 343...
326
            dependencies = opts.dependencies;
343
            dependencies = opts.dependencies;
327
            initHandlers();
344
            initHandlers();
328
            hideDependencyInfo();
345
            hideDependencyInfo();
329
        }
346
        }
330
    };
347
    };
331
});
-
 
332
348
});
-
 
349