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

Last change on this file since 23233 was 23233, checked in by flop25, 11 years ago

bug:2923
adding js to fix the "Add acomment" div when scrolling

File size: 6.2 KB
Line 
1/**
2 * Cookie plugin
3 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
4 * Dual licensed under the MIT and GPL licenses:
5 */
6jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options=jQuery.extend({},options);options.expires=-1;}
7var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}
8expires='; expires='+date.toUTCString();}
9var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
10return cookieValue;}};
11
12if (jQuery.cookie('picture-menu') == 'visible') {
13        jQuery("head").append("<style type=\"text/css\">#content.contentWithMenu, #the_page > .content {margin-left:240px;}</style>");
14} else {
15        jQuery("head").append("<style type=\"text/css\">#the_page #menubar {display:none;} #content.contentWithMenu, #the_page > .content {margin-left:35px;}</style>");
16}
17
18function hideMenu(delay) {
19        var menubar=jQuery("#menubar");
20        var menuswitcher=jQuery("#menuSwitcher");
21        var content=jQuery("#the_page > .content");
22        var pcontent=jQuery("#content");
23       
24        menubar.hide(delay);
25        menuswitcher.addClass("menuhidden").removeClass("menushown");
26        content.addClass("menuhidden").removeClass("menushown");
27        pcontent.addClass("menuhidden").removeClass("menushown");
28        jQuery.cookie('picture-menu', 'hidden', {path: "/"});
29       
30}
31
32function showMenu(delay) {
33
34        var menubar=jQuery("#menubar");
35        var menuswitcher=jQuery("#menuSwitcher");
36        var content=jQuery("#the_page > .content");
37        var pcontent=jQuery("#content");
38
39        menubar.show(delay);
40        menuswitcher.addClass("menushown").removeClass("menuhidden");
41        content.addClass("menushown").removeClass("menuhidden");
42        pcontent.addClass("menushown").removeClass("menuhidden");
43        jQuery.cookie('picture-menu', 'visible', {path: "/"});
44       
45}
46
47function hideInfo(delay) {
48
49        var imageInfos=jQuery("#imageInfos");
50        var infoswitcher=jQuery("#infoSwitcher");
51        var theImage=jQuery("#theImage");
52       
53        imageInfos.hide(delay);
54        infoswitcher.addClass("infohidden").removeClass("infoshown");
55        theImage.addClass("infohidden").removeClass("infoshown");
56        jQuery.cookie('side-info', 'hidden', {path: "/"});
57
58}
59
60function showInfo(delay) {
61
62        var imageInfos=jQuery("#imageInfos");
63        var infoswitcher=jQuery("#infoSwitcher");
64        var theImage=jQuery("#theImage");
65       
66        imageInfos.show(delay);
67        infoswitcher.addClass("infoshown").removeClass("infohidden");
68        theImage.addClass("infoshown").removeClass("infohidden");
69        jQuery.cookie('side-info', 'visible', {path: "/"});
70
71}
72
73jQuery("document").ready(function(jQuery){
74       
75        // side-menu show/hide
76
77        var sidemenu = jQuery.cookie('picture-menu');
78        var menubar=jQuery("#menubar");
79
80        if (menubar.length == 1) {
81
82                jQuery("#menuSwitcher").html("<div class=\"switchArrow\">&nbsp;</div>");
83
84                // if cookie says the menu is hiding, keep it hidden!
85                if (sidemenu == 'visible') {
86                        showMenu(0);
87                } else {
88                        hideMenu(0);
89                }
90       
91                jQuery("#menuSwitcher").click(function(){
92                        if (jQuery("#menubar").is(":hidden")) {
93                                showMenu(0);
94                                return false;
95                        } else {
96                                hideMenu(0);
97                                return false;
98                        }
99                });
100       
101        }
102
103        // info show/hide
104       
105        var sideinfo = jQuery.cookie('side-info');
106        var imageInfos=jQuery("#imageInfos");
107
108        if (imageInfos.length == 1) {
109
110                jQuery("#infoSwitcher").html("<div class=\"switchArrow\">&nbsp;</div>");
111
112                // if cookie says the menu is hiding, keep it hidden!
113                if (sideinfo == 'hidden') {
114                        hideInfo(0);
115                } else {
116                        showInfo(0);
117                }
118       
119                jQuery("#infoSwitcher").click(function(){
120                        if (jQuery("#imageInfos").is(":hidden")) {
121                                showInfo(0);
122                                return false;
123                        } else {
124                                hideInfo(0);
125                                return false;
126                        }
127                });
128       
129        }
130
131        // comments show/hide
132
133        var commentsswicther=jQuery("#commentsSwitcher");
134        var comments=jQuery("#thePicturePage #comments");
135       
136        commentsswicther.html("<div class=\"switchArrow\">&nbsp;</div>");
137       
138        if (comments.length == 1) {
139                var comments_button=jQuery("#comments h3");
140
141                if (comments_button.length == 0) {
142                        jQuery("#addComment").before("<h3>Comments</h3>");
143                        comments_button=jQuery("#comments h3");
144                }
145       
146                if (jQuery.cookie('comments') == 'visible') {
147                        comments.addClass("commentsshown");
148                        comments_button.addClass("comments_toggle").addClass("comments_toggle_off");
149                } else {
150                        comments.addClass("commentshidden");
151                        comments_button.addClass("comments_toggle").addClass("comments_toggle_on");
152                }
153               
154                comments_button.click(function() { commentsToggle() });
155                commentsswicther.click(function() { commentsToggle() });
156       
157        }
158 
159  var top = jQuery('#commentAdd').offset().top - parseFloat(jQuery('#commentAdd').css('marginTop').replace(/auto/, 0));
160  jQuery(window).scroll(function (event) {
161    // what the y position of the scroll is
162    var y = jQuery(this).scrollTop();
163 
164    // whether that's below the form
165    if (y >= top) {
166      // if so, ad the fixed class
167      jQuery('#commentAdd').addClass('fixed');
168    } else {
169      // otherwise remove it
170      jQuery('#commentAdd').removeClass('fixed');
171    }
172  });
173
174       
175});
176
177function commentsToggle() {
178        var comments=jQuery("#thePicturePage #comments");
179        var comments_button=jQuery("#comments h3");
180
181        if (comments.hasClass("commentshidden")) {
182                        comments.removeClass("commentshidden").addClass("commentsshown");
183                        comments_button.addClass("comments_toggle_off").removeClass("comments_toggle_on");;
184                        jQuery.cookie('comments', 'visible', {path: "/"});
185                } else {
186                        comments.addClass("commentshidden").removeClass("commentsshown");
187                        comments_button.addClass("comments_toggle_on").removeClass("comments_toggle_off");;
188                        jQuery.cookie('comments', 'hidden', {path: "/"});
189                }
190
191}
Note: See TracBrowser for help on using the repository browser.