Commit 681113e9 authored by Tom Kunze's avatar Tom Kunze
Browse files

server/vendor: Update js-cookie to 3.0.1.

parent b85cbc46
'use strict';
Cookies.defaults.expires = 365;
const ck_api = Cookies.withAttributes({ expires: 365 });
var global_api = '/api';
var global_csrftoken = Cookies.get('csrftoken');
var global_csrftoken = ck_api.get('csrftoken');
var global_request_age = 0;
var global_timeout = 5000;
......@@ -34,7 +34,7 @@ function ajaxErrorHandler(jqXHR, textStatus, errorThrown) {
}
function setAllowStatistics(allowed) {
Cookies.set('allow_statistic', allowed);
ck_api.set('allow_statistic', allowed);
var requestBtn = $('#modal-statistics .modal-footer').data('request');
if (requestBtn !== undefined && requestBtn !== '') {
apiRequest($('#' + requestBtn + ' a'));
......@@ -75,7 +75,7 @@ function setCurrentRoom(room) {
}
function getHostname() {
return Cookies.get('hostname');
return ck_api.get('hostname');
}
function setHostnameCookie(hostname){
......@@ -89,19 +89,19 @@ function setHostnameCookie(hostname){
var date = new Date(); // now
date.setMinutes(date.getMinutes() + 10);
Cookies.set('hostname', hostname, {expires: date});
ck_api.set('hostname', hostname, {expires: date});
}
function getLecture() {
return Cookies.getJSON('lecture');
return JSON.parse(ck_api.get('lecture'));
}
function setLecture(id, name) {
var oldLecture = getLecture();
Cookies.set('lecture', {
ck_api.set('lecture', JSON.stringify({
id: id,
name: name
});
}));
$('#lecture span').text(name);
if (oldLecture === undefined || oldLecture.id != id) {
populateMap();
......@@ -121,7 +121,7 @@ function markCurrentRoom(roomname) {
}
function isBarCollapsed(name) {
var collapsed = Cookies.get(name + '-collapsed');
var collapsed = ck_api.get(name + '-collapsed');
if (collapsed === undefined) {
collapsed = $('#' + name).hasClass(name + '-collapsed');
} else {
......@@ -158,7 +158,7 @@ function showToast(message) {
*/
function apiRequest(e) {
var allowStatistic = Cookies.get('allow_statistic');
var allowStatistic = ck_api.get('allow_statistic');
if (allowStatistic === undefined) {
var requestBtn = $(e).parent().attr('id');
$('#modal-statistics .modal-footer').data('request', requestBtn);
......@@ -216,7 +216,7 @@ function apiRequest(e) {
*/
function toggleBar(name) {
var collapsed = Cookies.get(name + '-collapsed');
var collapsed = ck_api.get(name + '-collapsed');
if (collapsed === undefined) {
collapsed = $('#' + name).hasClass(name + '-collapsed');
} else {
......@@ -224,21 +224,21 @@ function toggleBar(name) {
}
if (collapsed) {
$('.' + name + '-float').removeClass(name + '-collapsed');
Cookies.set(name + '-collapsed', 'false');
ck_api.set(name + '-collapsed', 'false');
} else {
$('.' + name + '-float').addClass(name + '-collapsed');
Cookies.set(name + '-collapsed', 'true');
ck_api.set(name + '-collapsed', 'true');
}
}
function setColloquial(colloquial) {
Cookies.set('colloquial', colloquial);
ck_api.set('colloquial', colloquial);
$('#setting-colloquial').prop('checked', colloquial);
updateRoomNames();
}
function updateRoomNames() {
var colloquial = Cookies.get('colloquial');
var colloquial = ck_api.get('colloquial');
if (colloquial === undefined) {
colloquial = false;
} else {
......@@ -777,7 +777,7 @@ function initCookieBar() {
return;
}
if (Cookies.get('cookieconsent_status') === undefined){
if (ck_api.get('cookieconsent_status') === undefined){
cookieconsent.initialise({
"palette": {
"popup": {
......@@ -885,7 +885,7 @@ function compressSingleCoordinate(coord_list){
var transformed_coors = {}
var cur = mi;
if(Cookies.get('cipmap-beamer-user') == 'true'){
if(ck_api.get('cipmap-beamer-user') == 'true'){
for(var i = mi; i <= ma; i++){
transformed_coors[i] = cur;
if(used_coords.has(i)){
......@@ -1007,8 +1007,8 @@ function drawMap(cip) {
);
/*
$("#doorPreselect").children("option").prop("selected",false);
if(Cookies.get("rotate_"+cip) != undefined){
$($("#doorPreselect").children("option")[parseInt(Cookies.get("rotate_"+cip))]).prop("selected",true);
if(ck_api.get("rotate_"+cip) != undefined){
$($("#doorPreselect").children("option")[parseInt(ck_api.get("rotate_"+cip))]).prop("selected",true);
}else{
$($("#doorPreselect").children("option")[door.position]).prop("selected",true);
}
......@@ -1117,7 +1117,7 @@ function drawMap(cip) {
function getPreferedSideOrDoor(){
var cip = getCurrentRoom();
var preferedSideCookie = "rotate_" + cip;
var preferedSide = parseInt(Cookies.get(preferedSideCookie))
var preferedSide = parseInt(ck_api.get(preferedSideCookie))
if(isNaN(preferedSide)){
var door = global_map[cip]['door'];
if(door !== undefined){
......@@ -1132,7 +1132,7 @@ function getPreferedSideOrDoor(){
function setPreferedSide(side){
var cip = getCurrentRoom();
var preferedSideCookie = "rotate_" + cip;
Cookies.set(preferedSideCookie, side);
ck_api.set(preferedSideCookie, side);
}
//rotates the map so that the door is on the user's favorite position
......
/*! js-cookie v2.2.0 | MIT */
!function(e){var n=!1;if("function"==typeof define&&define.amd&&(define(e),n=!0),"object"==typeof exports&&(module.exports=e(),n=!0),!n){var o=window.Cookies,t=window.Cookies=e();t.noConflict=function(){return window.Cookies=o,t}}}(function(){function e(){for(var e=0,n={};e<arguments.length;e++){var o=arguments[e];for(var t in o)n[t]=o[t]}return n}function n(o){function t(n,r,i){var c;if("undefined"!=typeof document){if(arguments.length>1){if("number"==typeof(i=e({path:"/"},t.defaults,i)).expires){var a=new Date;a.setMilliseconds(a.getMilliseconds()+864e5*i.expires),i.expires=a}i.expires=i.expires?i.expires.toUTCString():"";try{c=JSON.stringify(r),/^[\{\[]/.test(c)&&(r=c)}catch(e){}r=o.write?o.write(r,n):encodeURIComponent(r+"").replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),n=(n=(n=encodeURIComponent(n+"")).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent)).replace(/[\(\)]/g,escape);var s="";for(var f in i)i[f]&&(s+="; "+f,!0!==i[f]&&(s+="="+i[f]));return document.cookie=n+"="+r+s}n||(c={});for(var p=document.cookie?document.cookie.split("; "):[],d=/(%[0-9A-Z]{2})+/g,u=0;u<p.length;u++){var l=p[u].split("="),C=l.slice(1).join("=");this.json||'"'!==C.charAt(0)||(C=C.slice(1,-1));try{var m=l[0].replace(d,decodeURIComponent);if(C=o.read?o.read(C,m):o(C,m)||C.replace(d,decodeURIComponent),this.json)try{C=JSON.parse(C)}catch(e){}if(n===m){c=C;break}n||(c[m]=C)}catch(e){}}return c}}return t.set=t,t.get=function(e){return t.call(t,e)},t.getJSON=function(){return t.apply({json:!0},[].slice.call(arguments))},t.defaults={},t.remove=function(n,o){t(n,"",e(o,{expires:-1}))},t.withConverter=n,t}return n(function(){})});
\ No newline at end of file
/*! js-cookie v3.0.1 | MIT */
;
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, (function () {
var current = global.Cookies;
var exports = global.Cookies = factory();
exports.noConflict = function () { global.Cookies = current; return exports; };
}()));
}(this, (function () { 'use strict';
/* eslint-disable no-var */
function assign (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
target[key] = source[key];
}
}
return target
}
/* eslint-enable no-var */
/* eslint-disable no-var */
var defaultConverter = {
read: function (value) {
if (value[0] === '"') {
value = value.slice(1, -1);
}
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
},
write: function (value) {
return encodeURIComponent(value).replace(
/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
decodeURIComponent
)
}
};
/* eslint-enable no-var */
/* eslint-disable no-var */
function init (converter, defaultAttributes) {
function set (key, value, attributes) {
if (typeof document === 'undefined') {
return
}
attributes = assign({}, defaultAttributes, attributes);
if (typeof attributes.expires === 'number') {
attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
}
if (attributes.expires) {
attributes.expires = attributes.expires.toUTCString();
}
key = encodeURIComponent(key)
.replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
.replace(/[()]/g, escape);
var stringifiedAttributes = '';
for (var attributeName in attributes) {
if (!attributes[attributeName]) {
continue
}
stringifiedAttributes += '; ' + attributeName;
if (attributes[attributeName] === true) {
continue
}
// Considers RFC 6265 section 5.2:
// ...
// 3. If the remaining unparsed-attributes contains a %x3B (";")
// character:
// Consume the characters of the unparsed-attributes up to,
// not including, the first %x3B (";") character.
// ...
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
}
return (document.cookie =
key + '=' + converter.write(value, key) + stringifiedAttributes)
}
function get (key) {
if (typeof document === 'undefined' || (arguments.length && !key)) {
return
}
// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all.
var cookies = document.cookie ? document.cookie.split('; ') : [];
var jar = {};
for (var i = 0; i < cookies.length; i++) {
var parts = cookies[i].split('=');
var value = parts.slice(1).join('=');
try {
var foundKey = decodeURIComponent(parts[0]);
jar[foundKey] = converter.read(value, foundKey);
if (key === foundKey) {
break
}
} catch (e) {}
}
return key ? jar[key] : jar
}
return Object.create(
{
set: set,
get: get,
remove: function (key, attributes) {
set(
key,
'',
assign({}, attributes, {
expires: -1
})
);
},
withAttributes: function (attributes) {
return init(this.converter, assign({}, this.attributes, attributes))
},
withConverter: function (converter) {
return init(assign({}, this.converter, converter), this.attributes)
}
},
{
attributes: { value: Object.freeze(defaultAttributes) },
converter: { value: Object.freeze(converter) }
}
)
}
var api = init(defaultConverter, { path: '/' });
/* eslint-enable no-var */
return api;
})));
/*! js-cookie v3.0.1 | MIT */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self,function(){var n=e.Cookies,o=e.Cookies=t();o.noConflict=function(){return e.Cookies=n,o}}())}(this,(function(){"use strict";function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}return function t(n,o){function r(t,r,i){if("undefined"!=typeof document){"number"==typeof(i=e({},o,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var c="";for(var u in i)i[u]&&(c+="; "+u,!0!==i[u]&&(c+="="+i[u].split(";")[0]));return document.cookie=t+"="+n.write(r,t)+c}}return Object.create({set:r,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],o={},r=0;r<t.length;r++){var i=t[r].split("="),c=i.slice(1).join("=");try{var u=decodeURIComponent(i[0]);if(o[u]=n.read(c,u),e===u)break}catch(e){}}return e?o[e]:o}},remove:function(t,n){r(t,"",e({},n,{expires:-1}))},withAttributes:function(n){return t(this.converter,e({},this.attributes,n))},withConverter:function(n){return t(e({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(o)},converter:{value:Object.freeze(n)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"})}));
......@@ -158,7 +158,7 @@
{# scripts #}
<script type="text/javascript" src="{% static 'server/vendor/jquery/jquery-3.3.1.min.js' %}"></script>
<script type="text/javascript" src="{% static 'server/vendor/js-cookie/js.cookie-2.2.0.min.js' %}"></script>
<script type="text/javascript" src="{% static 'server/vendor/js-cookie/js.cookie.min.js' %}"></script>
<script type="text/javascript" src="{% static 'server/vendor/materialize/js/bin/materialize.min.js' %}"></script>
<script type="text/javascript" src="{% static 'server/vendor/timetable.js/timetable.js' %}"></script>
......
......@@ -94,7 +94,7 @@
{% block scripts %}
<script type="text/javascript" src="{% static 'server/vendor/jquery/jquery-3.3.1.min.js' %}"></script>
<script type="text/javascript" src="{% static 'server/vendor/js-cookie/js.cookie-2.2.0.min.js' %}"></script>
<script type="text/javascript" src="{% static 'server/vendor/js-cookie/js.cookie.min.js' %}"></script>
<script type="text/javascript" src="{% static 'server/js/bootstrap.min.js' %}"></script>
<script type="text/javascript" src="{% static 'server/vendor/push/push.min.js' %}"></script>
{% endblock %}
......
{% load static %}
var global_csrftoken = Cookies.get('csrftoken');
const ck_api = Cookies.withAttributes({ expires: 365 });
var global_csrftoken = ck_api.get('csrftoken');
var hashcip = location.hash.substr(1);
var lastupdate = Date.now() / 1000; // Javascript uses milliseconds
......@@ -8,7 +10,6 @@ if (hashcip == '') {
hashcip = $('#nav-cips a:first').attr('data-cip');
}
Cookies.defaults.expires = 365;
init();
......@@ -19,7 +20,7 @@ function init() {
window.setInterval(populate, 1000 * 10);
if (Cookies.get('notifications') === 'true') {
if (ck_api.get('notifications') === 'true') {
$('#check-notify').attr('checked', 'checked');
}
......@@ -28,7 +29,7 @@ function init() {
checkNotifyPermissions();
}
Cookies.set('notifications', $(this).prop('checked'));
ck_api.set('notifications', $(this).prop('checked'));
});
}
......@@ -55,12 +56,12 @@ function checkNotifyPermissions() {
}
function enableNotifications() {
Cookies.set('notifications', 'true');
ck_api.set('notifications', 'true');
$('#check-notify').attr('checked', 'checked');
}
function disableNotifications() {
Cookies.set('notifications', 'false');
ck_api.set('notifications', 'false');
$('#check-notify').removeAttr('checked');
}
......@@ -120,7 +121,7 @@ function populate() {
}
function sendNotification(request) {
if (Cookies.get('notifications') === 'false' ||
if (ck_api.get('notifications') === 'false' ||
!Push.Permission.has()) {
return;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment