{"version":3,"file":"tabbed.min.js","sources":["https:\/\/elearning.univ-guelma.dz\/theme\/adaptable\/amd\/src\/tabbed.js"],"sourcesContent":["\/\/\n\/\/ This file is part of Adaptable theme for moodle\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 .\n\n\/\/\n\/\/ Adaptable Tabbed JS file\n\/\/\n\/\/ @package theme_adaptable\n\/\/ @copyright 2015-2019 Jeremy Hopkins (Coventry University)\n\/\/ @copyright 2018-2019 Manoj Solanki (Coventry University)\n\/\/ @copyright 2019 G J Barnard\n\/\/ {@link https:\/\/moodle.org\/user\/profile.php?id=442195}\n\/\/ {@link https:\/\/gjbarnard.co.uk}\n\/\/ @license https:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later.\n\/\/\n\nimport $ from 'jquery';\nimport log from 'core\/log';\n\n\/**\n * Tabbed.\n *\n * @param {string} currentpage The current page.\n * @param {string} tabpersistencetime The persistance time of the current set tab.\n *\/\nconst tabbed = (currentpage, tabpersistencetime) => {\n if (currentpage == 'coursepage') {\n var hasStorage = (\"sessionStorage\" in window && window.sessionStorage);\n var now, expiration;\n var currentUrl = document.location.toString();\n\n if ((hasStorage) && (currentUrl.indexOf('course\/view.php?id=') != -1)) {\n\n var tabValues = JSON.parse(sessionStorage.getItem('tabValues')) || {};\n var tabTimestamp = JSON.parse(sessionStorage.getItem('tabTimestamp'));\n var $radiobuttons = $(\"#coursetabcontainer :radio\");\n var now = new Date();\n\n const setTimestamp = (timestamp) => {\n var timeStampJSON = JSON.stringify(timestamp);\n log.debug('Adaptable ES6 Tabbled: Setting timestamp to ' + timeStampJSON);\n sessionStorage.setItem(\"tabTimestamp\", timeStampJSON);\n };\n\n \/\/ Check timestamp for session.\n if (tabTimestamp) {\n \/\/ Calculate expiration time for content, to force periodic refresh after 'tabpersistencetime' minutes.\n expiration = new Date(tabTimestamp);\n expiration.setMinutes(expiration.getMinutes() + parseInt(tabpersistencetime));\n if (now.getTime() > expiration.getTime()) {\n log.debug('Adaptable ES6 Tabbled: Expired');\n sessionStorage.removeItem('tabValues');\n tabValues = {};\n }\n }\n setTimestamp(now);\n\n var params = (new URL(document.location)).searchParams;\n var courseid = params.get(\"id\");\n\n $radiobuttons.on(\"change\", function () {\n $radiobuttons.each(function () {\n if (this.checked) {\n tabValues[courseid] = this.id;\n }\n });\n sessionStorage.setItem(\"tabValues\", JSON.stringify(tabValues));\n });\n\n var tabhasbeenset = false;\n $.each(tabValues, function (key, value) {\n if (key == courseid) {\n $(\"#\" + value).prop('checked', true);\n tabhasbeenset = true;\n }\n });\n if (tabhasbeenset == false) {\n $(\"input:radio[name=tabs]:first\").attr('checked', true);\n }\n\n $('label.coursetab').show();\n }\n\n }\n};\n\n\/**\n * Init.\n *\n * @param {string} currentpage The current page.\n * @param {string} tabpersistencetime The persistance time of the current set tab.\n*\/\nexport const init = (currentpage, tabpersistencetime) => {\n log.debug('Adaptable ES6 Tabbled init');\n if (document.readyState !== 'loading') {\n log.debug(\"Adaptable ES6 Tabbled init DOM content already loaded\");\n tabbed(currentpage, tabpersistencetime);\n } else {\n log.debug(\"Adaptable ES6 Tabbled init JS DOM content not loaded\");\n document.addEventListener('DOMContentLoaded', function () {\n log.debug(\"Adaptable ES6 Tabbled init JS DOM content loaded\");\n tabbed(currentpage, tabpersistencetime);\n });\n }\n};\n"],"names":["tabbed","currentpage","tabpersistencetime","expiration","hasStorage","window","sessionStorage","currentUrl","document","location","toString","indexOf","tabValues","JSON","parse","getItem","tabTimestamp","$radiobuttons","now","Date","setTimestamp","timestamp","timeStampJSON","stringify","debug","setItem","setMinutes","getMinutes","parseInt","getTime","removeItem","courseid","URL","searchParams","get","on","each","this","checked","id","tabhasbeenset","key","value","prop","attr","show","readyState","addEventListener"],"mappings":";;6JAqCMA,OAAS,CAACC,YAAaC,yBACN,cAAfD,YAA6B,KAEpBE,WADLC,WAAc,mBAAoBC,QAAUA,OAAOC,eAEnDC,WAAaC,SAASC,SAASC,cAE9BN,aAA8D,GAA9CG,WAAWI,QAAQ,uBAA+B,KAE\/DC,UAAYC,KAAKC,MAAMR,eAAeS,QAAQ,eAAiB,GAC\/DC,aAAeH,KAAKC,MAAMR,eAAeS,QAAQ,iBACjDE,eAAgB,mBAAE,8BAClBC,IAAM,IAAIC,WAERC,aAAgBC,gBACdC,cAAgBT,KAAKU,UAAUF,wBAC\/BG,MAAM,+CAAiDF,eAC3DhB,eAAemB,QAAQ,eAAgBH,gBAIvCN,gBAEAb,WAAa,IAAIgB,KAAKH,eACXU,WAAWvB,WAAWwB,aAAeC,SAAS1B,qBACrDgB,IAAIW,UAAY1B,WAAW0B,yBACvBL,MAAM,kCACVlB,eAAewB,WAAW,aAC1BlB,UAAY,KAGpBQ,aAAaF,SAGTa,SADU,IAAIC,IAAIxB,SAASC,UAAWwB,aACpBC,IAAI,MAE1BjB,cAAckB,GAAG,UAAU,WACvBlB,cAAcmB,MAAK,WACXC,KAAKC,UACL1B,UAAUmB,UAAYM,KAAKE,OAGnCjC,eAAemB,QAAQ,YAAaZ,KAAKU,UAAUX,mBAGnD4B,eAAgB,kBAClBJ,KAAKxB,WAAW,SAAU6B,IAAKC,OACzBD,KAAOV,+BACL,IAAMW,OAAOC,KAAK,WAAW,GAC\/BH,eAAgB,MAGH,GAAjBA,mCACE,gCAAgCI,KAAK,WAAW,uBAGpD,mBAAmBC,wBAYb,CAAC5C,YAAaC,mCAC1BsB,MAAM,8BACkB,YAAxBhB,SAASsC,yBACLtB,MAAM,yDACVxB,OAAOC,YAAaC,mCAEhBsB,MAAM,wDACVhB,SAASuC,iBAAiB,oBAAoB,wBACtCvB,MAAM,oDACVxB,OAAOC,YAAaC"}