moodle/lib/amd/build/paged_content_paging_dropdown.min.js.map

1 line
9.8 KiB
Plaintext
Raw Normal View History

{"version":3,"file":"paged_content_paging_dropdown.min.js","sources":["../src/paged_content_paging_dropdown.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Javascript to manage the paging dropdown control.\n *\n * @module core/paged_content_paging_dropdown\n * @copyright 2018 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(\n [\n 'jquery',\n 'core/custom_interaction_events',\n 'core/paged_content_events',\n 'core/pubsub'\n ],\n function(\n $,\n CustomEvents,\n PagedContentEvents,\n PubSub\n ) {\n\n var SELECTORS = {\n ROOT: '[data-region=\"paging-dropdown-container\"]',\n DROPDOWN_ITEM: '[data-region=\"dropdown-item\"]',\n DROPDOWN_TOGGLE: '[data-region=\"dropdown-toggle\"]',\n ACTIVE_DROPDOWN_ITEM: '[data-region=\"dropdown-item\"].active',\n CARET: '[data-region=\"caret\"]'\n };\n\n /**\n * Get the page number.\n *\n * @param {jquery} item The dropdown item.\n * @returns {Number}\n */\n var getPageNumber = function(item) {\n return parseInt(item.attr('data-page-number'), 10);\n };\n\n /**\n * Get all paging dropdown items.\n *\n * @param {jquery} root The root element.\n * @returns {jquery} A jquery object with all items.\n */\n var getAllItems = function(root) {\n return root.find(SELECTORS.DROPDOWN_ITEM);\n };\n\n /**\n * Get all paging dropdown items with lower page numbers than the given\n * dropdown item.\n *\n * @param {jquery} root The root element.\n * @param {jquery} item The dropdown item.\n * @returns {jquery} A jquery object with all items.\n */\n var getPreviousItems = function(root, item) {\n var pageNumber = getPageNumber(item);\n return getAllItems(root).filter(function(index, element) {\n return getPageNumber($(element)) < pageNumber;\n });\n };\n\n /**\n * Get the number of items to be loaded for the dropdown item.\n *\n * @param {jquery} item The dropdown item.\n * @returns {Number}\n */\n var getLimit = function(item) {\n return parseInt(item.attr('data-item-count'), 10);\n };\n\n /**\n * Get the offset of items from the start of the itemset for the given\n * dropdown item.\n *\n * @param {jquery} root The root element.\n * @param {jquery} item The dropdown item.\n * @returns {Number}\n */\n var getOffset = function(root, item) {\n if (item.attr('data-offset') != undefined) {\n return parseInt(item.attr('data-offset'), 10);\n }\n\n var offset = 0;\n\n getPreviousItems(root, item).each(function(index, prevItem) {\n prevItem = $(prevItem);\n offset += getLimit(prevItem);\n });\n\n item.attr('data-offset', offset);\n return offset;\n };\n\n /**\n * Get the active dropdown item.\n *\n * @param {jquery} root The root element.\n * @returns {jquery} The active dropdown item.\n */\n var getActiveItem = function(root) {\n return root.find(SELECTORS.ACTIVE_DROPDOWN_ITEM);\n };\n\n /**\n * Create the event payload for the list of dropdown items. The event payload\n * is an array of objects with one object per dropdown item.\n