| Revision 3706:170617361020,
1.7 KB
checked in by franck <carnet.franck.paul@…>, 8 years ago
(diff) |
|
use strict and no more linter warnings/errors as far as possible
|
| Line | |
|---|
| 1 | /*global $, post_remember_str */ |
|---|
| 2 | 'use strict'; |
|---|
| 3 | |
|---|
| 4 | $(function() { |
|---|
| 5 | $('#comment-form p:has(input[type=submit][name=preview],button[type=submit][name=preview])'). |
|---|
| 6 | before( |
|---|
| 7 | '<p class="remember"><input type="checkbox" id="c_remember" name="c_remember" /> ' + |
|---|
| 8 | '<label for="c_remember">' + post_remember_str + '</label>' + |
|---|
| 9 | '</p>' |
|---|
| 10 | ); |
|---|
| 11 | |
|---|
| 12 | var cookie = readCookie($.cookie('comment_info')); |
|---|
| 13 | |
|---|
| 14 | if (cookie != false) { |
|---|
| 15 | $('#c_name').val(cookie[0]); |
|---|
| 16 | $('#c_mail').val(cookie[1]); |
|---|
| 17 | $('#c_site').val(cookie[2]); |
|---|
| 18 | $('#c_remember').attr('checked', 'checked'); |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | $('#c_remember').click(function() { |
|---|
| 22 | if (this.checked) { |
|---|
| 23 | setCookie(); |
|---|
| 24 | } else { |
|---|
| 25 | dropCookie(); |
|---|
| 26 | } |
|---|
| 27 | }); |
|---|
| 28 | |
|---|
| 29 | $('#c_name').change(function() { |
|---|
| 30 | if ($('#c_remember').get(0).checked) { |
|---|
| 31 | setCookie(); |
|---|
| 32 | } |
|---|
| 33 | }); |
|---|
| 34 | |
|---|
| 35 | $('#c_mail').change(function() { |
|---|
| 36 | if ($('#c_remember').get(0).checked) { |
|---|
| 37 | setCookie(); |
|---|
| 38 | } |
|---|
| 39 | }); |
|---|
| 40 | |
|---|
| 41 | $('#c_site').change(function() { |
|---|
| 42 | if ($('#c_remember').get(0).checked) { |
|---|
| 43 | setCookie(); |
|---|
| 44 | } |
|---|
| 45 | }); |
|---|
| 46 | |
|---|
| 47 | function setCookie() { |
|---|
| 48 | var name = $('#c_name').val(); |
|---|
| 49 | var mail = $('#c_mail').val(); |
|---|
| 50 | var site = $('#c_site').val(); |
|---|
| 51 | var cpath = $('link[rel=top]').attr('href'); |
|---|
| 52 | if (!cpath) { |
|---|
| 53 | cpath = '/'; |
|---|
| 54 | } else { |
|---|
| 55 | cpath = cpath.replace(/.*:\/\/[^\/]*([^?]*).*/g, '$1'); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | $.cookie('comment_info', name + '\n' + mail + '\n' + site, { |
|---|
| 59 | expires: 60, |
|---|
| 60 | path: cpath |
|---|
| 61 | }); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | function dropCookie() { |
|---|
| 65 | $.cookie('comment_info', '', { |
|---|
| 66 | expires: -30, |
|---|
| 67 | path: '/' |
|---|
| 68 | }); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | function readCookie(c) { |
|---|
| 72 | if (!c) { |
|---|
| 73 | return false; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | var s = c.split('\n'); |
|---|
| 77 | |
|---|
| 78 | if (s.length != 3) { |
|---|
| 79 | dropCookie(); |
|---|
| 80 | return false; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | return s; |
|---|
| 84 | } |
|---|
| 85 | }); |
|---|
Note: See
TracBrowser
for help on using the repository browser.