1 |
efrain |
1 |
{"version":3,"file":"stickycolspan.min.js","sources":["../src/stickycolspan.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 module for fixing the position of sticky headers with multiple colspans\n *\n * @module gradereport_grader/stickycolspan\n * @copyright 2022 Bas Brands <bas@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\nimport {SELECTORS as stickyFooterSelectors, eventTypes as stickyFooterEvents} from 'core/sticky-footer';\n\nconst SELECTORS = {\n GRADEPARENT: '.gradeparent',\n STUDENTHEADER: '#studentheader',\n TABLEHEADER: 'th.header',\n BEHAT: 'body.behat-site',\n USERDROPDOWN: '.userrow th .dropdown',\n LASTROW: '.lastrow',\n};\n\n/**\n * Initialize module\n */\nexport const init = () => {\n // The sticky positioning attributed to the user column cells affects the stacking context and makes the dropdowns\n // within these cells to be cut off. To solve this problem, whenever one of these action menus (dropdowns) is opened\n // we need to manually bump up the z-index value of the parent container element and revert once closed.\n $(SELECTORS.USERDROPDOWN).on('show.bs.dropdown hide.bs.dropdown', (e) => {\n // The closest heading element has sticky positioning which affects the stacking context in this case.\n e.target.closest(SELECTORS.TABLEHEADER).classList.toggle('actions-menu-active');\n });\n\n defineLastRowIntersectionObserver(true);\n // Add an event listener to the sticky footer toggled event to re-define the average row intersection observer\n // accordingly. This is needed as on narrow screens when scrolling vertically the sticky footer is enabled and\n // disabled dynamically.\n document.addEventListener(stickyFooterEvents.stickyFooterStateChanged, (e) => {\n defineLastRowIntersectionObserver(e.detail.enabled);\n });\n\n if (!document.querySelector(SELECTORS.BEHAT)) {\n const grader = document.querySelector(SELECTORS.GRADEPARENT);\n const tableHeaders = grader.querySelectorAll(SELECTORS.TABLEHEADER);\n const studentHeader = grader.querySelector(SELECTORS.STUDENTHEADER);\n const leftOffset = getComputedStyle(studentHeader).getPropertyValue('left');\n const rightOffset = getComputedStyle(studentHeader).getPropertyValue('right');\n\n tableHeaders.forEach((tableHeader) => {\n if (tableHeader.colSpan > 1) {\n const addOffset = (tableHeader.offsetWidth - studentHeader.offsetWidth);\n if (window.right_to_left()) {\n tableHeader.style.right = 'calc(' + rightOffset + ' - ' + addOffset + 'px )';\n } else {\n tableHeader.style.left = 'calc(' + leftOffset + ' - ' + addOffset + 'px )';\n }\n }\n });\n }\n};\n\n/**\n * Define the intersection observer that will make sure that the last row is properly pinned.\n *\n * In certain scenarios, such as when both 'Overall average' and 'Range' are set not to be shown in the Grader report,\n * a user row will end up being the last row in the Grader report table. In this particular case, we want to avoid\n * pinning the last row.\n *\n * @param {boolean} stickyFooterEnabled Whether the page shows a sticky footer or not.\n */\nconst defineLastRowIntersectionObserver = (stickyFooterEnabled) => {\n const lastRow = document.querySelector(SELECTORS.LASTROW);\n // Ensure that the last row is not a user row before defining the intersection observer.\n if (!lastRow.classList.contains('userrow')) {\n const stickyFooterHeight = stickyFooterEnabled ?\n document.querySelector(stickyFooterSelectors.STICKYFOOTER).offsetHeight : null;\n // Register an observer that will bump up the z-index value of the last row when it's pinned to prevent the row\n // being cut-off by the user column cells or other components within the report table that have higher z-index\n // values. If the page has a sticky footer, we need to make sure that the bottom root margin of the observer\n // subtracts the height of the sticky footer to prevent the row being cut-off by the footer.\n const intersectionObserver = new IntersectionObserver(\n ([e]) => lastRow.classList.toggle('pinned', e.intersectionRatio < 1),\n {\n rootMargin: stickyFooterHeight ? `0px 0px -${stickyFooterHeight}px 0px` : \"0px\",\n threshold: [1]\n }\n );\n intersectionObserver.observe(lastRow.querySelector('th'));\n }\n};\n"],"names":["SELECTORS","on","e","target","closest","classList","toggle","defineLastRowIntersectionObserver","document","addEventListener","stickyFooterEvents","stickyFooterStateChanged","detail","enabled","querySelector","grader","tableHeaders","querySelectorAll","studentHeader","leftOffset","getComputedStyle","getPropertyValue","rightOffset","forEach","tableHeader","colSpan","addOffset","offsetWidth","window","right_to_left","style","right","left","stickyFooterEnabled","lastRow","contains","stickyFooterHeight","stickyFooterSelectors","STICKYFOOTER","offsetHeight","IntersectionObserver","_ref","intersectionRatio","rootMargin","threshold","observe"],"mappings":";;;;;;;gJA0BMA,sBACW,eADXA,wBAEa,iBAFbA,sBAGW,YAHXA,gBAIK,kBAJLA,uBAKY,wBALZA,kBAMO,yBAMO,4BAIdA,wBAAwBC,GAAG,qCAAsCC,IAE/DA,EAAEC,OAAOC,QAAQJ,uBAAuBK,UAAUC,OAAO,0BAG7DC,mCAAkC,GAIlCC,SAASC,iBAAiBC,yBAAmBC,0BAA2BT,IACpEK,kCAAkCL,EAAEU,OAAOC,aAG1CL,SAASM,cAAcd,iBAAkB,OACpCe,OAASP,SAASM,cAAcd,uBAChCgB,aAAeD,OAAOE,iBAAiBjB,uBACvCkB,cAAgBH,OAAOD,cAAcd,yBACrCmB,WAAaC,iBAAiBF,eAAeG,iBAAiB,QAC9DC,YAAcF,iBAAiBF,eAAeG,iBAAiB,SAErEL,aAAaO,SAASC,iBACdA,YAAYC,QAAU,EAAG,OACnBC,UAAaF,YAAYG,YAAcT,cAAcS,YACvDC,OAAOC,gBACPL,YAAYM,MAAMC,MAAQ,QAAUT,YAAc,MAAQI,UAAY,OAEtEF,YAAYM,MAAME,KAAO,QAAUb,WAAa,MAAQO,UAAY,mBAgBlFnB,kCAAqC0B,4BACjCC,QAAU1B,SAASM,cAAcd,uBAElCkC,QAAQ7B,UAAU8B,SAAS,WAAY,OAClCC,mBAAqBH,oBACvBzB,SAASM,cAAcuB,wBAAsBC,cAAcC,aAAe,KAKjD,IAAIC,sBAC7BC,WAAEvC,eAAOgC,QAAQ7B,UAAUC,OAAO,SAAUJ,EAAEwC,kBAAoB,KAClE,CACIC,WAAYP,sCAAiCA,6BAA6B,MAC1EQ,UAAW,CAAC,KAGCC,QAAQX,QAAQpB,cAAc"}
|