on-demand release 3.6dev+
[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.
47 */
48 var init = function(root, renderPagesContentCallback) {
49 root = $(root);
50 var pagesContainer = root.find(Pages.rootSelector);
51 var pagingBarContainer = root.find(PagingBar.rootSelector);
52 var dropdownContainer = root.find(Dropdown.rootSelector);
53 var pagingBarLimitSelectorContainer = root.find(PagingBarLimitSelector.rootSelector);
54 var id = root.attr('id');
55
56 Pages.init(pagesContainer, id, renderPagesContentCallback);
57
58 if (pagingBarContainer.length) {
59 PagingBar.init(pagingBarContainer, id);
60 }
61
62 if (pagingBarLimitSelectorContainer.length) {
63 PagingBarLimitSelector.init(pagingBarLimitSelectorContainer, id);
64 }
65
66 if (dropdownContainer.length) {
67 Dropdown.init(dropdownContainer, id);
68 }
69 };
70
71 return {
72 init: init,
73 rootSelector: '[data-region="paged-content-container"]'
74 };
75});