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