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
 * Javascript for dynamically changing the page limits.
18
 *
19
 * @module     core/paged_content_paging_bar_limit_selector
20
 * @copyright  2018 Ryan Wyllie <ryan@moodle.com>
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
define(
24
[
25
    'jquery',
26
    'core/custom_interaction_events',
27
    'core/paged_content_events',
28
    'core/pubsub'
29
],
30
function(
31
    $,
32
    CustomEvents,
33
    PagedContentEvents,
34
    PubSub
35
) {
36
 
37
    var SELECTORS = {
38
        ROOT: '[data-region="paging-control-limit-container"]',
39
        LIMIT_OPTION: '[data-limit]',
40
        LIMIT_TOGGLE: '[data-action="limit-toggle"]',
41
    };
42
 
43
    /**
44
     * Trigger the SET_ITEMS_PER_PAGE_LIMIT event when the page limit option
45
     * is modified.
46
     *
47
     * @param {object} root The root element.
48
     * @param {string} id A unique id for this instance.
49
     */
50
    var init = function(root, id) {
51
        root = $(root);
52
 
53
        CustomEvents.define(root, [
54
            CustomEvents.events.activate
55
        ]);
56
 
57
        root.on(CustomEvents.events.activate, SELECTORS.LIMIT_OPTION, function(e, data) {
58
            var optionElement = $(e.target).closest(SELECTORS.LIMIT_OPTION);
59
 
60
            if (optionElement.hasClass('active')) {
61
                // Don't do anything if it was the active option selected.
62
                return;
63
            }
64
 
65
            var limit = parseInt(optionElement.attr('data-limit'), 10);
66
            // Tell the rest of the pagination components that the limit has changed.
67
            PubSub.publish(id + PagedContentEvents.SET_ITEMS_PER_PAGE_LIMIT, limit);
68
 
69
            data.originalEvent.preventDefault();
70
        });
71
    };
72
 
73
    return {
74
        init: init,
75
        rootSelector: SELECTORS.ROOT
76
    };
77
});