source: trunk/themes/elegant/scripts_pp.js @ 26086

Last change on this file since 26086 was 26086, checked in by mistic100, 10 years ago

[elegant] fix comment form width change when scrolling caused by menubar size

File size: 5.1 KB
Line 
1(function() {
2  var session_storage = window.sessionStorage || {};
3
4  var menubar=jQuery("#menubar"),
5      menuswitcher,
6      content=jQuery("#the_page > .content"),
7      pcontent=jQuery("#content"),
8      imageInfos=jQuery("#imageInfos"),
9      infoswitcher,
10      theImage=jQuery("#theImage"),
11      comments=jQuery("#thePicturePage #comments"),
12      comments_button,
13      commentsswitcher,
14      comments_add,
15      comments_top_offset = 0;
16
17  if (session_storage['picture-menu'] == 'visible') {
18    jQuery("head").append('<style>#content.contentWithMenu, #the_page > .content {margin-left:240px;}</style>');
19  }
20  else {
21    jQuery("head").append('<style>#the_page #menubar {display:none;} #content.contentWithMenu, #the_page > .content {margin-left:35px;}</style>');
22  }
23
24  function hideMenu(delay) {
25    menubar.hide(delay);
26    menuswitcher.addClass("menuhidden").removeClass("menushown");
27    content.addClass("menuhidden").removeClass("menushown");
28    pcontent.addClass("menuhidden").removeClass("menushown");
29    session_storage['picture-menu'] = 'hidden';
30  }
31
32  function showMenu(delay) {
33    menubar.show(delay);
34    menuswitcher.addClass("menushown").removeClass("menuhidden");
35    content.addClass("menushown").removeClass("menuhidden");
36    pcontent.addClass("menushown").removeClass("menuhidden");
37    session_storage['picture-menu'] = 'visible';
38  }
39
40  function hideInfo(delay) {
41    imageInfos.hide(delay);
42    infoswitcher.addClass("infohidden").removeClass("infoshown");
43    theImage.addClass("infohidden").removeClass("infoshown");
44    session_storage['side-info'] = 'hidden';
45  }
46
47  function showInfo(delay) {
48    imageInfos.show(delay);
49    infoswitcher.addClass("infoshown").removeClass("infohidden");
50    theImage.addClass("infoshown").removeClass("infohidden");
51    session_storage['side-info'] = 'visible';
52  }
53
54  function commentsToggle() {
55    if (comments.hasClass("commentshidden")) {
56      comments.removeClass("commentshidden").addClass("commentsshown");
57      comments_button.addClass("comments_toggle_off").removeClass("comments_toggle_on");;
58      session_storage['comments'] = 'visible';
59
60      comments_top_offset = comments_add.offset().top - parseFloat(comments_add.css('marginTop').replace(/auto/, 0));
61    }
62    else {
63      comments.addClass("commentshidden").removeClass("commentsshown");
64      comments_button.addClass("comments_toggle_on").removeClass("comments_toggle_off");;
65      session_storage['comments'] = 'hidden';
66      comments_top_offset = 0;
67    }
68  }
69
70  jQuery(function(){
71    // side-menu show/hide
72    if (menubar.length == 1 && p_main_menu!="disabled") {
73      menuswitcher=jQuery("#menuSwitcher");
74
75      menuswitcher.html('<div class="switchArrow">&nbsp;</div>');
76
77      if (session_storage['picture-menu'] == 'hidden' || p_main_menu == 'off') {
78        hideMenu(0);
79      }
80      else {
81        showMenu(0);
82      }
83
84      menuswitcher.click(function(e){
85        if (menubar.is(":hidden")) {
86          showMenu(0);
87        }
88        else {
89          hideMenu(0);
90        }
91        e.preventDefault();
92      });
93    }
94
95    // info show/hide
96    if (imageInfos.length == 1 && p_pict_descr!="disabled") {
97      infoswitcher=jQuery("#infoSwitcher");
98
99      infoswitcher.html('<div class="switchArrow">&nbsp;</div>');
100
101      if (session_storage['side-info'] == 'hidden' || p_pict_descr == 'off') {
102        hideInfo(0);
103      }
104      else {
105        showInfo(0);
106      }
107
108      infoswitcher.click(function(e){
109        if (imageInfos.is(":hidden")) {
110          showInfo(0);
111        }
112        else {
113          hideInfo(0);
114        }
115        e.preventDefault();
116      });
117    }
118
119    // comments show/hide
120    if (comments.length == 1 && p_pict_comment!="disabled") {
121      commentsswitcher=jQuery("#commentsSwitcher");
122      comments_button=jQuery("#comments h3");
123      comments_add=jQuery('#commentAdd');
124
125      commentsswitcher.html('<div class="switchArrow">&nbsp;</div>');
126
127      if (comments_button.length == 0) {
128        jQuery("#addComment").before("<h3>Comments</h3>");
129        comments_button=jQuery("#comments h3");
130      }
131
132      if (session_storage['comments'] == 'hidden' || p_pict_comment == 'off') {
133        comments.addClass("commentshidden");
134        comments_button.addClass("comments_toggle comments_toggle_on");
135      }
136      else {
137        comments.addClass("commentsshown");
138        comments_button.addClass("comments_toggle comments_toggle_off");
139      }
140
141      comments_button.click(commentsToggle);
142      commentsswitcher.click(commentsToggle);
143
144      jQuery(window).scroll(function (event) {
145        if (comments_top_offset==0) return;
146
147        var y = jQuery(this).scrollTop();
148
149        if (y >= comments_top_offset) {
150          comments_add.css({
151            'position': 'absolute',
152            'top': y-comments.offset().top+10
153          });
154        }
155        else {
156          comments_add.css({
157            'position': 'static',
158            'top': 0
159          });
160        }
161      });
162
163      if (comments_add.is(":visible")) {
164        comments_top_offset = comments_add.offset().top - parseFloat(comments_add.css('marginTop').replace(/auto/, 0));
165      }
166    }
167  });
168}());
Note: See TracBrowser for help on using the repository browser.