blob: 034771cd749cf6b1d2178ac1992c8f7bf549356d [file] [log] [blame]
Nils Diewalda944fab2015-04-08 21:02:04 +00001 <!DOCTYPE html>
2<html>
3 <head>
4 <title>Cookie demo</title>
Nils Diewaldce328112015-04-08 22:48:18 +00005 <link type="text/css" rel="stylesheet" href="../css/kalamar.css" />
6 <script src="../js/src/session.js"></script>
Nils Diewalda944fab2015-04-08 21:02:04 +00007 <script>
8
9var cookey;
10
11function add (val) {
12 var list = document.getElementById('number');
13 list.textContent += '-' + val;
14 cookey.set('n', list.textContent);
15};
16
17function removeCookie () {
18 cookey.clear();
19};
20
21document.addEventListener('DOMContentLoaded', function () {
22 cookey = KorAP.Session.create('peter');
23 document.getElementById('number').textContent = cookey.get('n') || '';
24
25 var elements = document.getElementsByClassName('num');
26 for (var i = 0; i < elements.length; i++) {
27 elements[i].addEventListener(
28 'click',
29 function (e) {
30 add(this.textContent);
31 }
32 );
33 };
34});
35
36 </script>
37 </head>
38 <body>
39 <div id="number"></div>
40 <span class="num">1</span>
41 <span class="num">2</span>
42 <span class="num">3</span>
43 <div onclick="removeCookie()">remove</div>
44 </body>
45</html>