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