You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
3.5 KiB
1 lines
3.5 KiB
define(["jquery","format_tiles/browser_storage_set_up"],function(a,b){"use strict";var c,d,e,f={prefix:"mdl-tiles-",course:"mdl-tiles-course-",lastSection:"-lastSecId",content:"-content",lastUpdated:"-lastUpdated",collapseSecZero:"-collapsesec0",user:"-user-",section:"-sec-",userChoicePrefix:"mdl-tiles-userPrefStorage-"},g=function(){return f.course+c+f.user+d+f.lastSection},h=function(a){return f.course+c+f.section+a.toString()+f.user+d+f.content},i=function(a){return f.course+c+f.section+a.toString()+f.user+d+f.lastUpdated},j=function(){return f.course+c+f.user+d+f.collapseSecZero},k=function(a){return 0===a.indexOf(f.prefix)&&a.substr(-f.lastUpdated.length)===f.lastUpdated},l=function(a,c,d){if(void 0===c||void 0===a)throw new Error("Missing section id");try{void 0!==d&&""!==d&&b.Enabled.session&&b.storageAllowed()===!0?(sessionStorage.setItem(h(c),d),sessionStorage.setItem(i(c),Math.round(Date.now()/1e3).toString())):(sessionStorage.removeItem(h(c)),sessionStorage.removeItem(i(c)))}catch(e){require(["core/log"],function(a){a.debug(e)})}},m=function(a){var b=a.split("-");if(k(a))return{courseId:parseInt(b[b.indexOf("course")+1]),sectionId:parseInt(b[b.indexOf("sec")+1]),userId:parseInt(b[b.indexOf("user")+1]),title:"lastUpdated"};throw new Error("Invalid lastUpdated key")},n=function(a,b,c){if(b)Object.keys(localStorage).filter(function(a){return 0===a.indexOf(f.prefix)&&0!==a.indexOf(f.userChoicePrefix)}).forEach(function(a){localStorage.removeItem(a)}),Object.keys(sessionStorage).filter(function(a){return 0===a.indexOf(f.prefix)}).forEach(function(a){if(k(a)){var b=m(a);l(b.courseId,b.sectionId,"")}});else{var d=Math.round(Date.now()/1e3)-60*a;Object.keys(sessionStorage).filter(function(a){return 0===a.indexOf(f.prefix)}).forEach(function(b){if(k(b)){var c=m(b);(sessionStorage.getItem(b)<d||0===a)&&l(c.courseId,c.sectionId,"")}});var e=Object.keys(sessionStorage).filter(function(a){return k(a)});if(e.length>c){var g=e.map(function(a){return parseInt(sessionStorage[a])}).sort(),h=g[g.length-c];0===c&&(h=Date.now());var i;e.filter(function(a){return sessionStorage[a]<h}).forEach(function(a){i=m(a),l(i.courseId,i.sectionId,"")})}}},o=function(){n(0,1,1)},p=function(a){a&&b.Enabled.local?localStorage.setItem(g(),a.toString()):localStorage.removeItem(g())},q={init:function(f,g,h,i,j,k,m){c=f.toString(),d=m.toString(),e=parseInt(g),b.init(d,k,o),a(document).ready(function(){if(b.storageAllowed()!==!0&&n(0,1,0),h)p(i),n(0,1,0),b.Enabled.session&&l(c,i,""),a('a.menu-action[data-title="switchroleto,moodle"]').click(function(){n(0,1,0)});else{var d=a("#page-content");0===d.length&&(d=a("#region-main")),d.on("click",".tile",function(){setTimeout(function(){n(parseInt(j),0,e)},2e3)})}})},storageEnabledSession:function(){return b.Enabled.session},storageEnabledLocal:function(){return b.Enabled.local},storagestorageSetUperence:function(){return b.storageAllowed()},getLastVisitedSection:function(){return b.Enabled.local&&localStorage.getItem(g())},getCourseContent:function(a,b){return sessionStorage.getItem(h(b))},getStoredContentAge:function(a,b){var c=parseInt(sessionStorage.getItem(i(b)));return!!c&&Math.round(Date.now()/1e3-c)},setSecZeroCollapseStatus:function(a){b.Enabled.local&&b.storageAllowed()&&("collapsed"===a?localStorage.removeItem(j()):localStorage.setItem(j(),"1"))},getSecZeroCollapseStatus:function(){return!!localStorage.getItem(j())},storeCourseContent:function(a,b,c){l(a,b,c)},cleanUpStorage:function(){o()},setLastVisitedSection:function(a){b.storageAllowed()&&p(a)}};return q});
|