{"version":3,"file":"apptimer.min.js","sources":["https:\/\/moodle.sonsbeekmedia.nl\/caie_39\/mod\/teachingtools\/amd\/src\/apptimer.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 .\n\n\/**\n * Global app timer.\n *\n * @module mod_teachingtools\/apptimer\n * @copyright 2023 Sonsbeek Media\n * @author Bas Brands \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\n import DurationPickerMaker from 'mod_teachingtools\/duration\/DurationPickerMaker';\n import FormattedDuration from 'mod_teachingtools\/duration\/FormattedDuration';\n import Stopwatch from 'mod_teachingtools\/duration\/Stopwatch';\n\n class TimerAnimation {\n constructor(rootElement) {\n this.rootElement = rootElement;\n this.animation = this.rootElement.querySelector(\".progress-bar\");\n this.running = 0;\n this.seconds = 0;\n this.totalseconds = 0;\n this.resetSeconds = 0;\n }\n\n setTotalSeconds(value) {\n this.resetSeconds = value;\n }\n\n setSecondsValue(value) {\n this.seconds = value;\n const percentage = (value \/ (this.resetSeconds) * 100);\n this.animation.style.width = percentage + \"%\";\n }\n}\n\nclass Timer {\n constructor(rootElement) {\n this.rootElement = rootElement;\n this.running = false;\n }\n\n start() {\n let pickerElement = this.rootElement.querySelector(\"[data-region='duration-picker-field']\");\n let timer = new TimerAnimation(this.rootElement);\n\n const config = {\n hoursUnitString: \"h \",\n minutesUnitString: \"m \",\n secondsUnitString: \"s \",\n };\n let formattedDuration = new FormattedDuration(config);\n let durationPickerMaker = new DurationPickerMaker(formattedDuration);\n\n durationPickerMaker.AddSecondChangeObserver(timer);\n durationPickerMaker.SetPickerElement(pickerElement, window, this.rootElement);\n\n let startButton = this.rootElement.querySelector(\"[data-action='start']\");\n let stopButton = this.rootElement.querySelector(\"[data-action='stop']\");\n let resetButton = this.rootElement.querySelector(\"[data-action='reset']\");\n\n const buttons = {\n startButton: startButton,\n stopButton: stopButton,\n resetButton: resetButton\n };\n\n const watch = new Stopwatch(\n durationPickerMaker,\n buttons,\n window\n );\n\n \/\/ Add time to the timer.\n const addTimeButtons = this.rootElement.querySelectorAll(\"[data-action='set-timer']\");\n addTimeButtons.forEach((button) => {\n button.addEventListener('click', () => {\n watch.Stop();\n const setTime = parseInt(button.dataset.time);\n durationPickerMaker.SetSeconds(setTime);\n timer.setTotalSeconds(setTime);\n\n watch.Start();\n });\n });\n }\n}\n\n const init = (cmid) => {\n if (!document.querySelector('[data-region=\"globaltimer\"]')) {\n return;\n }\n const rootElement = document.querySelector('#teachingtools-timer-' + cmid);\n new Timer(rootElement).start();\n\n const toolWrapper = document.querySelector('[data-region=\"toolwrapper\"]');\n if (!toolWrapper) {\n return;\n }\n if (toolWrapper.dataset.timerInitialised) {\n return;\n }\n document.addEventListener('click', (e) => {\n const timerVisibilityRegion = document.querySelector('[data-region=\"timer-visibility\"]');\n if (e.target.closest('[data-action=\"toggle-timer\"]')) {\n timerVisibilityRegion.classList.toggle('hidden');\n }\n });\n toolWrapper.dataset.timerInitialised = true;\n};\n\nexport default {\n init: init\n};"],"names":["TimerAnimation","constructor","rootElement","animation","this","querySelector","running","seconds","totalseconds","resetSeconds","setTotalSeconds","value","setSecondsValue","percentage","style","width","Timer","start","pickerElement","timer","formattedDuration","FormattedDuration","hoursUnitString","minutesUnitString","secondsUnitString","durationPickerMaker","DurationPickerMaker","AddSecondChangeObserver","SetPickerElement","window","buttons","startButton","stopButton","resetButton","watch","Stopwatch","querySelectorAll","forEach","button","addEventListener","Stop","setTime","parseInt","dataset","time","SetSeconds","Start","init","cmid","document","toolWrapper","timerInitialised","e","timerVisibilityRegion","target","closest","classList","toggle"],"mappings":";;;;;;;;yQA4BOA,eACHC,YAAYC,kBACHA,YAAcA,iBACdC,UAAYC,KAAKF,YAAYG,cAAc,sBAC3CC,QAAU,OACVC,QAAU,OACVC,aAAe,OACfC,aAAe,EAGxBC,gBAAgBC,YACPF,aAAeE,MAGxBC,gBAAgBD,YACPJ,QAAUI,YACTE,WAAcF,MAASP,KAAKK,aAAgB,SAC7CN,UAAUW,MAAMC,MAAQF,WAAa,WAI5CG,MACFf,YAAYC,kBACHA,YAAcA,iBACdI,SAAU,EAGnBW,YACQC,cAAgBd,KAAKF,YAAYG,cAAc,yCAC\/Cc,MAAQ,IAAInB,eAAeI,KAAKF,iBAOhCkB,kBAAoB,IAAIC,2BALb,CACXC,gBAAiB,KACjBC,kBAAmB,KACnBC,kBAAmB,OAGnBC,oBAAsB,IAAIC,6BAAoBN,mBAElDK,oBAAoBE,wBAAwBR,OAC5CM,oBAAoBG,iBAAiBV,cAAeW,OAAQzB,KAAKF,mBAM3D4B,QAAU,CACZC,YALc3B,KAAKF,YAAYG,cAAc,yBAM7C2B,WALa5B,KAAKF,YAAYG,cAAc,wBAM5C4B,YALc7B,KAAKF,YAAYG,cAAc,0BAQ3C6B,MAAQ,IAAIC,mBACdV,oBACAK,QACAD,QAImBzB,KAAKF,YAAYkC,iBAAiB,6BAC1CC,SAASC,SACpBA,OAAOC,iBAAiB,SAAS,KAC7BL,MAAMM,aACAC,QAAUC,SAASJ,OAAOK,QAAQC,MACxCnB,oBAAoBoB,WAAWJ,SAC\/BtB,MAAMT,gBAAgB+B,SAEtBP,MAAMY,4BA6BP,CACXC,KAxBWC,WACNC,SAAS5C,cAAc,4CAGtBH,YAAc+C,SAAS5C,cAAc,wBAA0B2C,UACjEhC,MAAMd,aAAae,cAEjBiC,YAAcD,SAAS5C,cAAc,+BACtC6C,cAGDA,YAAYP,QAAQQ,mBAGxBF,SAASV,iBAAiB,SAAUa,UAC1BC,sBAAwBJ,SAAS5C,cAAc,oCACjD+C,EAAEE,OAAOC,QAAQ,iCACjBF,sBAAsBG,UAAUC,OAAO,aAG\/CP,YAAYP,QAAQQ,kBAAmB"}