1 | (function(){ |
---|
2 | var session_storage = window.sessionStorage || {}; |
---|
3 | |
---|
4 | var comments=jQuery("#theCategoryPage #comments"), |
---|
5 | comments_button, |
---|
6 | commentsswitcher, |
---|
7 | comments_add, |
---|
8 | comments_top_offset = 0; |
---|
9 | |
---|
10 | function commentsToggle() { |
---|
11 | if (comments.hasClass("commentshidden")) { |
---|
12 | comments.removeClass("commentshidden").addClass("commentsshown"); |
---|
13 | comments_button.addClass("comments_toggle_off").removeClass("comments_toggle_on");; |
---|
14 | session_storage['comments'] = 'visible'; |
---|
15 | comments_top_offset = comments_add.offset().top - parseFloat(comments_add.css('marginTop').replace(/auto/, 0)); |
---|
16 | } |
---|
17 | else { |
---|
18 | comments.addClass("commentshidden").removeClass("commentsshown"); |
---|
19 | comments_button.addClass("comments_toggle_on").removeClass("comments_toggle_off");; |
---|
20 | session_storage['comments'] = 'hidden'; |
---|
21 | comments_top_offset = 0; |
---|
22 | } |
---|
23 | } |
---|
24 | |
---|
25 | jQuery(function(){ |
---|
26 | // comments show/hide |
---|
27 | if (comments.length == 1) { |
---|
28 | commentsswitcher=jQuery("#commentsSwitcher"); |
---|
29 | comments_button=jQuery("#comments h3"); |
---|
30 | comments_add=jQuery('#commentAdd'); |
---|
31 | |
---|
32 | commentsswitcher.html('<div class="switchArrow"> </div>'); |
---|
33 | |
---|
34 | if (comments_button.length == 0) { |
---|
35 | jQuery("#addComment").before("<h3>Comments</h3>"); |
---|
36 | comments_button=jQuery("#comments h3"); |
---|
37 | } |
---|
38 | |
---|
39 | if ((session_storage['comments'] == 'hidden' || coa_on_top) && !coa_force_open) { |
---|
40 | comments.addClass("commentshidden"); |
---|
41 | comments_button.addClass("comments_toggle comments_toggle_on"); |
---|
42 | } |
---|
43 | else { |
---|
44 | comments.addClass("commentsshown"); |
---|
45 | comments_button.addClass("comments_toggle comments_toggle_off"); |
---|
46 | } |
---|
47 | |
---|
48 | comments_button.click(commentsToggle); |
---|
49 | commentsswitcher.click(commentsToggle); |
---|
50 | |
---|
51 | jQuery(window).scroll(function (event) { |
---|
52 | if (comments_top_offset==0) return; |
---|
53 | |
---|
54 | var y = jQuery(this).scrollTop(); |
---|
55 | |
---|
56 | if (y >= comments_top_offset) { |
---|
57 | comments_add.css({ |
---|
58 | 'position': 'absolute', |
---|
59 | 'top': Math.min(y-comments.offset().top+10, comments.height()-comments_add.height()) |
---|
60 | }); |
---|
61 | } |
---|
62 | else { |
---|
63 | comments_add.css({ |
---|
64 | 'position': 'static', |
---|
65 | 'top': 0 |
---|
66 | }); |
---|
67 | } |
---|
68 | }); |
---|
69 | |
---|
70 | if (comments_add.is(":visible")) { |
---|
71 | comments_top_offset = comments_add.offset().top - parseFloat(comments_add.css('marginTop').replace(/auto/, 0)); |
---|
72 | } |
---|
73 | } |
---|
74 | }); |
---|
75 | }()); |
---|