MDL-63793 block_myoverview: Persist the user's paging limit preference
[moodle.git] / lib / amd / src / paged_content.js
CommitLineData
2c13ae01
RW
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 to load and render a paged content section.
18 *
19 * @module core/paged_content
20 * @copyright 2018 Ryan Wyllie <ryan@moodle.com>
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 */
23define(
24[
25 'jquery',
26 'core/paged_content_pages',
27 'core/paged_content_paging_bar',
28 'core/paged_content_paging_bar_limit_selector',
29 'core/paged_content_paging_dropdown'
30],
31function(
32 $,
33 Pages,
34 PagingBar,
35 PagingBarLimitSelector,
36 Dropdown
37) {
38
39 /**
40 * Initialise the paged content region by running the pages
41 * module and initialising any paging controls in the DOM.
42 *
43 * @param {object} root The paged content container element
44 * @param {function} renderPagesContentCallback (optional) A callback function to render a
45 * content page. See core/paged_content_pages for
46 * more defails.
11988d74
P
47 * @param {string} namespaceOverride (optional) Provide a unique namespace override. If none provided defaults
48 * to generate html's id
2c13ae01 49 */
11988d74 50 var init = function(root, renderPagesContentCallback, namespaceOverride) {
2c13ae01
RW
51 root = $(root);
52 var pagesContainer = root.find(Pages.rootSelector);
53 var pagingBarContainer = root.find(PagingBar.rootSelector);
54 var dropdownContainer = root.find(Dropdown.rootSelector);
55 var pagingBarLimitSelectorContainer = root.find(PagingBarLimitSelector.rootSelector);
56 var id = root.attr('id');
57
11988d74
P
58 // Set the id to the custom namespace provided
59 if (namespaceOverride) {
60 id = namespaceOverride;
61 }
62
2c13ae01
RW
63 Pages.init(pagesContainer, id, renderPagesContentCallback);
64
65 if (pagingBarContainer.length) {
66 PagingBar.init(pagingBarContainer, id);
67 }
68
69 if (pagingBarLimitSelectorContainer.length) {
70 PagingBarLimitSelector.init(pagingBarLimitSelectorContainer, id);
71 }
72
73 if (dropdownContainer.length) {
74 Dropdown.init(dropdownContainer, id);
75 }
76 };
77
78 return {
79 init: init,
80 rootSelector: '[data-region="paged-content-container"]'
81 };
82});