Current Path : C:/Users/Mahmood/Desktop/moodle/lib/amd/build/ |
Current File : C:/Users/Mahmood/Desktop/moodle/lib/amd/build/storagewrapper.min.js.map |
{"version":3,"sources":["../src/storagewrapper.js"],"names":["define","config","Wrapper","storage","supported","detectSupport","hashSource","wwwroot","jsrev","hash","hashString","prefix","jsrevPrefix","validateCache","prototype","setItem","removeItem","ex","prefixKey","key","cacheVersion","getItem","moodleVersion","clear","source","i","chr","len","length","charCodeAt","get","set","value","e"],"mappings":"AAwBAA,OAAM,uBAAC,CAAC,aAAD,CAAD,CAAkB,SAASC,CAAT,CAAiB,CAOrC,GAAIC,CAAAA,CAAO,CAAG,SAASC,CAAT,CAAkB,CAC5B,KAAKA,OAAL,CAAeA,CAAf,CACA,KAAKC,SAAL,CAAiB,KAAKC,aAAL,EAAjB,CACA,KAAKC,UAAL,CAAkBL,CAAM,CAACM,OAAP,CAAiB,GAAjB,CAAuBN,CAAM,CAACO,KAAhD,CACA,KAAKC,IAAL,CAAY,KAAKC,UAAL,CAAgB,KAAKJ,UAArB,CAAZ,CACA,KAAKK,MAAL,CAAc,KAAKF,IAAL,CAAY,GAA1B,CACA,KAAKG,WAAL,CAAmB,KAAKF,UAAL,CAAgBT,CAAM,CAACM,OAAvB,EAAkC,QAArD,CACA,KAAKM,aAAL,EACH,CARD,CAgBAX,CAAO,CAACY,SAAR,CAAkBT,aAAlB,CAAkC,UAAW,CACzC,GAAoB,CAAC,CAAjB,EAAAJ,CAAM,CAACO,KAAX,CAAwB,CAEpB,QACH,CACD,GAA8B,WAA1B,QAAQ,MAAKL,OAAjB,CAA2C,CACvC,QACH,CAED,GAAI,CACA,GAAqB,IAAjB,QAAKA,OAAT,CAA2B,CACvB,QACH,CAGD,KAAKA,OAAL,CAAaY,OAAb,QAA8B,GAA9B,EACA,KAAKZ,OAAL,CAAaa,UAAb,SACA,QACH,CAAC,MAAOC,CAAP,CAAW,CACT,QACH,CACJ,CArBD,CA8BAf,CAAO,CAACY,SAAR,CAAkBI,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AAqB,CACjB,QACH,CACDe,CAAG,CAAG,KAAKD,SAAL,CAAeC,CAAf,CAAN,CAEA,MAAO,MAAKhB,OAAL,CAAakB,OAAb,CAAqBF,CAArB,CACV,CAPD,CAiBAjB,CAAO,CAACY,SAAR,CAAkBiB,GAAlB,CAAwB,SAASZ,CAAT,CAAca,CAAd,CAAqB,CACzC,GAAI,CAAC,KAAK5B,SAAV,CAAqB,CACjB,QACH,CACDe,CAAG,CAAG,KAAKD,SAAL,CAAeC,CAAf,CAAN,CAEA,GAAI,CACA,KAAKhB,OAAL,CAAaY,OAAb,CAAqBI,CAArB,CAA0Ba,CAA1B,CACH,CAAC,MAAOC,CAAP,CAAU,CACR,QACH,CACD,QACH,CAZD,CAcA,MAAO/B,CAAAA,CACV,CA3IK,CAAN","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 * Wrap an instance of the browser's local or session storage to handle\n * cache expiry, key namespacing and other helpful things.\n *\n * @module core/storagewrapper\n * @package core\n * @copyright 2017 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['core/config'], function(config) {\n\n /**\n * Constructor.\n *\n * @param {object} storage window.localStorage or window.sessionStorage\n */\n var Wrapper = function(storage) {\n this.storage = storage;\n this.supported = this.detectSupport();\n this.hashSource = config.wwwroot + '/' + config.jsrev;\n this.hash = this.hashString(this.hashSource);\n this.prefix = this.hash + '/';\n this.jsrevPrefix = this.hashString(config.wwwroot) + '/jsrev';\n this.validateCache();\n };\n\n /**\n * Check if the browser supports the type of storage.\n *\n * @method detectSupport\n * @return {boolean} True if the browser supports storage.\n */\n Wrapper.prototype.detectSupport = function() {\n if (config.jsrev == -1) {\n // Disable cache if debugging.\n return false;\n }\n if (typeof (this.storage) === \"undefined\") {\n return false;\n }\n var testKey = 'test';\n try {\n if (this.storage === null) {\n return false;\n }\n // MDL-51461 - Some browsers misreport availability of the storage\n // so check it is actually usable.\n this.storage.setItem(testKey, '1');\n this.storage.removeItem(testKey);\n return true;\n } catch (ex) {\n return false;\n }\n };\n\n /**\n * Add a unique prefix to all keys so multiple moodle sites do not share caches.\n *\n * @method prefixKey\n * @param {string} key The cache key to prefix.\n * @return {string} The new key\n */\n Wrapper.prototype.prefixKey = function(key) {\n return this.prefix + key;\n };\n\n /**\n * Check the current jsrev version and clear the cache if it has been bumped.\n *\n * @method validateCache\n */\n Wrapper.prototype.validateCache = function() {\n var cacheVersion = this.storage.getItem(this.jsrevPrefix);\n if (cacheVersion === null) {\n this.storage.setItem(this.jsrevPrefix, config.jsrev);\n return;\n }\n\n var moodleVersion = config.jsrev;\n if (moodleVersion != cacheVersion) {\n this.storage.clear();\n this.storage.setItem(this.jsrevPrefix, config.jsrev);\n }\n };\n\n /**\n * Hash a string, used to make shorter key prefixes.\n *\n * @method hashString\n * @param {String} source The string to hash\n * @return {Number}\n */\n Wrapper.prototype.hashString = function(source) {\n // From http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery.\n /* jshint bitwise: false */\n /* eslint no-bitwise: \"off\" */\n var hash = 0;\n var i, chr, len;\n if (source.length === 0) {\n return hash;\n }\n for (i = 0, len = source.length; i < len; i++) {\n chr = source.charCodeAt(i);\n hash = ((hash << 5) - hash) + chr;\n hash |= 0; // Convert to 32bit integer\n }\n return hash;\n };\n\n /**\n * Get a value from local storage. Remember - all values must be strings.\n *\n * @method get\n * @param {string} key The cache key to check.\n * @return {boolean|string} False if the value is not in the cache, or some other error - a string otherwise.\n */\n Wrapper.prototype.get = function(key) {\n if (!this.supported) {\n return false;\n }\n key = this.prefixKey(key);\n\n return this.storage.getItem(key);\n };\n\n /**\n * Set a value to local storage. Remember - all values must be strings.\n *\n * @method set\n * @param {string} key The cache key to set.\n * @param {string} value The value to set.\n * @return {boolean} False if the value can't be saved in the cache, or some other error - true otherwise.\n */\n Wrapper.prototype.set = function(key, value) {\n if (!this.supported) {\n return false;\n }\n key = this.prefixKey(key);\n // This can throw exceptions when the storage limit is reached.\n try {\n this.storage.setItem(key, value);\n } catch (e) {\n return false;\n }\n return true;\n };\n\n return Wrapper;\n});\n"],"file":"storagewrapper.min.js"}