{"version":3,"file":"browser_storage_set_up.min.js","sources":["https:\/\/kundenportal.comm-unity.at\/course\/format\/tiles\/amd\/src\/browser_storage_set_up.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 * Javascript Module to help set up user needs browser storage.\n *\n * @module format_tiles\/browser_storage_set_up\n * @copyright 2019 David Watson {@link http:\/\/evolutioncode.uk}\n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n * @since Moodle 3.3\n *\/\n\n\/* eslint space-before-function-paren: 0 *\/\n\ndefine([\"jquery\"], function ($) {\n \"use strict\";\n\n var storageUserConsent = {\n GIVEN: \"yes\", \/\/ What to store in local storage to indicate consent granted.\n DENIED: \"no\" \/\/ Or to indicate consent denied.\n };\n\n var localStorageKeyElements = {\n userPrefStorage: \"mdl-tiles-userPrefStorage\",\n user: \"-user-\"\n };\n\n var storageType = {\n local: \"local\",\n session: \"session\"\n };\n\n var Enabled = {\n local: false,\n session: false\n };\n var userId;\n\n var userChoice = null; \/\/ The user's current choice - initially null as we have not yet checked local storage or asked user.\n\n var encodeStorageKey = function() {\n return localStorageKeyElements.userPrefStorage + localStorageKeyElements.user + userId;\n };\n\n var storageAllowed = function() {\n if (userChoice !== null) {\n return userChoice;\n } else {\n var browserChoice = localStorage.getItem(encodeStorageKey());\n if (browserChoice) {\n userChoice = browserChoice === storageUserConsent.GIVEN;\n return userChoice;\n } else {\n \/\/ This shouldn't happen much as user asked for pref if not present.\n return null;\n }\n }\n };\n\n var setAllowed = function(allowedOrNot) {\n if (allowedOrNot) {\n userChoice = true;\n localStorage.setItem(encodeStorageKey(), storageUserConsent.GIVEN);\n } else {\n userChoice = false;\n localStorage.setItem(encodeStorageKey(), storageUserConsent.DENIED);\n }\n };\n\n \/**\n * Launch the window enabling the user to select whether we want to store data locally or not\n *\/\n var obtainUserPreference = function () {\n require([\"core\/str\", \"core\/notification\"], function(str, Notification) {\n str.get_strings([\n {key: \"datapref\", component: \"format_tiles\"},\n {key: \"dataprefquestion\", component: \"format_tiles\"},\n {key: \"yes\"},\n {key: \"cancel\", component: \"moodle\"}\n ]).done(function (s) {\n Notification.confirm(\n s[0],\n s[1],\n s[2],\n s[3],\n function() {\n setAllowed(true);\n },\n function() {\n setAllowed(false);\n }\n );\n });\n });\n };\n\n \/**\n * Check if the user's browser supports localstorage or session storage\n * @param {String} localOrSession the type of storage we wish to check\n * @returns {boolean} whether or not storage is supported\n *\/\n var storageInitialCheck = function (localOrSession) {\n var storage;\n try {\n if (localOrSession === storageType.local) {\n storage = localStorage;\n } else if (localOrSession === storageType.session) {\n storage = sessionStorage;\n }\n if (typeof storage === \"undefined\") {\n return false;\n }\n storage.setItem(\"testItem\", \"testValue\");\n if (storage.getItem(\"testItem\") === \"testValue\") {\n storage.removeItem(\"testItem\");\n return true;\n }\n return false;\n } catch (err) {\n require([\"core\/log\"], function(log) {\n log.debug(err);\n });\n return false;\n }\n };\n\n return {\n\n setAllowed: function(allowedOrNot) {\n setAllowed(allowedOrNot);\n },\n storageAllowed: function() {\n return storageAllowed();\n },\n getStorageKey: function() {\n return encodeStorageKey();\n },\n Enabled: Enabled,\n\n init: function(userIdInit, assumeConsent) {\n userId = userIdInit;\n $(document).ready(function () {\n Enabled.local = storageInitialCheck(storageType.local);\n Enabled.session = storageInitialCheck(storageType.session);\n\n if (assumeConsent) {\n userChoice = true;\n } else if (storageAllowed() === null && Enabled.local) {\n \/\/ We wait 3 seconds before launching the dialog to ensure content finished loading.\n setTimeout(function() {\n obtainUserPreference();\n }, 3000);\n }\n\n \/\/ If the user clicks the \"Data preference\" item in the navigation menu,\n \/\/ show them the dialogue box to re-enter their local storage choice.\n $('a[href*=\"datapref\"]').click(function (e) {\n e.preventDefault();\n obtainUserPreference();\n });\n });\n }\n };\n\n});"],"names":["define","$","userId","storageUserConsent","localStorageKeyElements","storageType","Enabled","local","session","userChoice","encodeStorageKey","storageAllowed","browserChoice","localStorage","getItem","setAllowed","allowedOrNot","setItem","obtainUserPreference","require","str","Notification","get_strings","key","component","done","s","confirm","storageInitialCheck","localOrSession","storage","sessionStorage","removeItem","err","log","debug","getStorageKey","init","userIdInit","assumeConsent","document","ready","setTimeout","click","e","preventDefault"],"mappings":";;;;;;;;AA0BAA,6CAAO,CAAC,WAAW,SAAUC,OAsBrBC,OAnBAC,yBACO,MADPA,0BAEQ,KAGRC,wCACiB,4BADjBA,6BAEM,SAGNC,kBACO,QADPA,oBAES,UAGTC,QAAU,CACVC,OAAO,EACPC,SAAS,GAITC,WAAa,KAEbC,iBAAmB,kBACZN,wCAA0CA,6BAA+BF,QAGhFS,eAAiB,cACE,OAAfF,kBACOA,eAEHG,cAAgBC,aAAaC,QAAQJ,2BACrCE,cACAH,WAAaG,gBAAkBT,yBAIxB,MAKfY,WAAa,SAASC,cAClBA,cACAP,YAAa,EACbI,aAAaI,QAAQP,mBAAoBP,4BAEzCM,YAAa,EACbI,aAAaI,QAAQP,mBAAoBP,6BAO7Ce,qBAAuB,WACvBC,QAAQ,CAAC,WAAY,sBAAsB,SAASC,IAAKC,cACrDD,IAAIE,YAAY,CACZ,CAACC,IAAK,WAAYC,UAAW,gBAC7B,CAACD,IAAK,mBAAoBC,UAAW,gBACrC,CAACD,IAAK,OACN,CAACA,IAAK,SAAUC,UAAW,YAC5BC,MAAK,SAAUC,GACdL,aAAaM,QACTD,EAAE,GACFA,EAAE,GACFA,EAAE,GACFA,EAAE,IACF,WACIX,YAAW,MAEf,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