moodle/contentbank/amd/build/sort.min.js.map

1 line
11 KiB
Plaintext

{"version":3,"sources":["../src/sort.js"],"names":["init","contentBank","document","querySelector","selectors","regions","contentbank","Prefetch","prefetchStrings","registerListenerEvents","fileArea","filearea","shownItems","querySelectorAll","elements","listitem","viewGrid","actions","viewgrid","viewList","viewlist","addEventListener","classList","remove","add","sortByName","sortname","ascending","updateSortButtons","updateSortOrder","sortByDate","sortdate","sortBySize","sortsize","sortByType","sorttype","sortButton","sortButtons","sortbutton","forEach","button","updateButtonTitle","contains","sortString","dataset","string","then","columnName","sortByString","setAttribute","catch","itemList","attribute","sortList","slice","call","sort","a","b","aa","getAttribute","bb","isNaN","parseInt","listItem","appendChild"],"mappings":"kMAwBA,OAEA,O,mDAQO,GAAMA,CAAAA,CAAI,CAAG,UAAM,CACtB,GAAMC,CAAAA,CAAW,CAAGC,QAAQ,CAACC,aAAT,CAAuBC,UAAUC,OAAV,CAAkBC,WAAzC,CAApB,CACAC,UAASC,eAAT,CAAyB,aAAzB,CAAwC,CAAC,SAAD,CAAY,gBAAZ,CAA8B,aAA9B,CACpC,cADoC,CACpB,MADoB,CACZ,MADY,CAAxC,EAEAC,CAAsB,CAACR,CAAD,CACzB,CALM,C,YAcDQ,CAAAA,CAAsB,CAAG,SAACR,CAAD,CAAiB,IAGtCS,CAAAA,CAAQ,CAAGR,QAAQ,CAACC,aAAT,CAAuBC,UAAUC,OAAV,CAAkBM,QAAzC,CAH2B,CAItCC,CAAU,CAAGF,CAAQ,CAACG,gBAAT,CAA0BT,UAAUU,QAAV,CAAmBC,QAA7C,CAJyB,CAOtCC,CAAQ,CAAGf,CAAW,CAACE,aAAZ,CAA0BC,UAAUa,OAAV,CAAkBC,QAA5C,CAP2B,CAQtCC,CAAQ,CAAGlB,CAAW,CAACE,aAAZ,CAA0BC,UAAUa,OAAV,CAAkBG,QAA5C,CAR2B,CAU5CJ,CAAQ,CAACK,gBAAT,CAA0B,OAA1B,CAAmC,UAAM,CACrCpB,CAAW,C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,CAIzD,GAAI,CAACU,KAAK,CAACH,CAAD,CAAV,CAAgB,CACbA,CAAE,CAAGI,QAAQ,CAACJ,CAAD,CAAb,CACAE,CAAE,CAAGE,QAAQ,CAACF,CAAD,CACf,CAED,GAAIlC,CAAJ,CAAe,CACX,MAAOgC,CAAAA,CAAE,CAAGE,CAAL,CAAU,CAAV,CAAc,CAAC,CACzB,CAFD,IAEO,CACH,MAAOF,CAAAA,CAAE,CAAGE,CAAL,CAAU,CAAV,CAAc,CAAC,CACzB,CACJ,CAdgB,CAAjB,CAeAR,CAAQ,CAACd,OAAT,CAAiB,SAAUyB,CAAV,CAAoB,CACjCtD,CAAQ,CAACuD,WAAT,CAAqBD,CAArB,CACH,CAFD,CAGH,C","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 * Content bank UI actions.\n *\n * @module core_contentbank/sort\n * @package core_contentbank\n * @copyright 2020 Bas Brands <bas@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport selectors from 'core_contentbank/selectors';\nimport {get_string as getString} from 'core/str';\nimport Prefetch from 'core/prefetch';\n\n\n/**\n * Set up the contentbank views.\n *\n * @method init\n */\nexport const init = () => {\n const contentBank = document.querySelector(selectors.regions.contentbank);\n Prefetch.prefetchStrings('contentbank', ['sortbyx', 'sortbyxreverse', 'contentname',\n 'lastmodified', 'size', 'type']);\n registerListenerEvents(contentBank);\n};\n\n\n/**\n * Register contentbank related event listeners.\n *\n * @method registerListenerEvents\n * @param {HTMLElement} contentBank The DOM node of the content bank\n */\nconst registerListenerEvents = (contentBank) => {\n\n // The search.\n const fileArea = document.querySelector(selectors.regions.filearea);\n const shownItems = fileArea.querySelectorAll(selectors.elements.listitem);\n\n // The view buttons.\n const viewGrid = contentBank.querySelector(selectors.actions.viewgrid);\n const viewList = contentBank.querySelector(selectors.actions.viewlist);\n\n viewGrid.addEventListener('click', () => {\n contentBank.classList.remove('view-list');\n contentBank.classList.add('view-grid');\n viewGrid.classList.add('active');\n viewList.classList.remove('active');\n });\n\n viewList.addEventListener('click', () => {\n contentBank.classList.remove('view-grid');\n contentBank.classList.add('view-list');\n viewList.classList.add('active');\n viewGrid.classList.remove('active');\n });\n\n // Sort by file name alphabetical\n const sortByName = contentBank.querySelector(selectors.actions.sortname);\n sortByName.addEventListener('click', () => {\n const ascending = updateSortButtons(contentBank, sortByName);\n updateSortOrder(fileArea, shownItems, 'data-file', ascending);\n });\n\n // Sort by date.\n const sortByDate = contentBank.querySelector(selectors.actions.sortdate);\n sortByDate.addEventListener('click', () => {\n const ascending = updateSortButtons(contentBank, sortByDate);\n updateSortOrder(fileArea, shownItems, 'data-timemodified', ascending);\n });\n\n // Sort by size.\n const sortBySize = contentBank.querySelector(selectors.actions.sortsize);\n sortBySize.addEventListener('click', () => {\n const ascending = updateSortButtons(contentBank, sortBySize);\n updateSortOrder(fileArea, shownItems, 'data-bytes', ascending);\n });\n\n // Sort by type\n const sortByType = contentBank.querySelector(selectors.actions.sorttype);\n sortByType.addEventListener('click', () => {\n const ascending = updateSortButtons(contentBank, sortByType);\n updateSortOrder(fileArea, shownItems, 'data-type', ascending);\n });\n};\n\n/**\n * Update the sort button view.\n *\n * @method updateSortButtons\n * @param {HTMLElement} contentBank The DOM node of the contentbank button\n * @param {HTMLElement} sortButton The DOM node of the sort button\n * @return {Bool} sort ascending\n */\nconst updateSortButtons = (contentBank, sortButton) => {\n const sortButtons = contentBank.querySelectorAll(selectors.elements.sortbutton);\n\n sortButtons.forEach((button) => {\n if (button !== sortButton) {\n button.classList.remove('dir-asc');\n button.classList.remove('dir-desc');\n button.classList.add('dir-none');\n\n updateButtonTitle(button, false);\n }\n });\n\n let ascending = true;\n\n if (sortButton.classList.contains('dir-none')) {\n sortButton.classList.remove('dir-none');\n sortButton.classList.add('dir-asc');\n } else if (sortButton.classList.contains('dir-asc')) {\n sortButton.classList.remove('dir-asc');\n sortButton.classList.add('dir-desc');\n ascending = false;\n } else if (sortButton.classList.contains('dir-desc')) {\n sortButton.classList.remove('dir-desc');\n sortButton.classList.add('dir-asc');\n }\n\n updateButtonTitle(sortButton, ascending);\n\n return ascending;\n};\n\n/**\n * Update the button title.\n *\n * @method updateButtonTitle\n * @param {HTMLElement} button Button to update\n * @param {Bool} ascending Sort direction\n * @return {Promise} string promise\n */\nconst updateButtonTitle = (button, ascending) => {\n\n const sortString = (ascending ? 'sortbyxreverse' : 'sortbyx');\n\n return getString(button.dataset.string, 'contentbank')\n .then(columnName => {\n return getString(sortString, 'core', columnName);\n })\n .then(sortByString => {\n button.setAttribute('title', sortByString);\n return sortByString;\n })\n .catch();\n};\n\n/**\n * Update the sort order of the itemlist and update the DOM\n *\n * @method updateSortOrder\n * @param {HTMLElement} fileArea the Dom container for the itemlist\n * @param {Array} itemList Nodelist of Dom elements\n * @param {String} attribute, the attribut to sort on\n * @param {Bool} ascending, Sort Ascending\n */\nconst updateSortOrder = (fileArea, itemList, attribute, ascending) => {\n const sortList = [].slice.call(itemList).sort(function(a, b) {\n\n let aa = a.getAttribute(attribute);\n let bb = b.getAttribute(attribute);\n if (!isNaN(aa)) {\n aa = parseInt(aa);\n bb = parseInt(bb);\n }\n\n if (ascending) {\n return aa > bb ? 1 : -1;\n } else {\n return aa < bb ? 1 : -1;\n }\n });\n sortList.forEach(function (listItem) {\n fileArea.appendChild(listItem);\n });\n};"],"file":"sort.min.js"}