Nils Diewald | a944fab | 2015-04-08 21:02:04 +0000 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>Cookie demo</title> |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 5 | <link type="text/css" rel="stylesheet" href="../css/kalamar.css" /> |
| 6 | <script src="../js/src/session.js"></script> |
Nils Diewald | a944fab | 2015-04-08 21:02:04 +0000 | [diff] [blame] | 7 | <script> |
| 8 | |
| 9 | var cookey; |
| 10 | |
| 11 | function add (val) { |
| 12 | var list = document.getElementById('number'); |
| 13 | list.textContent += '-' + val; |
| 14 | cookey.set('n', list.textContent); |
| 15 | }; |
| 16 | |
| 17 | function removeCookie () { |
| 18 | cookey.clear(); |
| 19 | }; |
| 20 | |
| 21 | document.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> |