aboutsummaryrefslogtreecommitdiffstats
path: root/themes/elegant/scripts_pp.js
blob: be2bbfe26bd9931d357b734796c84c848bee1e06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
(function() {
  var session_storage = window.sessionStorage || {};

  var menubar=jQuery("#menubar"),
      menuswitcher,
      content=jQuery("#the_page > .content"),
      pcontent=jQuery("#content"),
      imageInfos=jQuery("#imageInfos"),
      infoswitcher,
      theImage=jQuery("#theImage"),
      comments=jQuery("#thePicturePage #comments"),
      comments_button,
      commentsswitcher,
      comments_add,
      comments_top_offset = 0;

  if (session_storage['picture-menu'] == 'visible') {
    jQuery("head").append('<style>#content.contentWithMenu, #the_page > .content {margin-left:240px;}</style>');
  }
  else {
    jQuery("head").append('<style>#the_page #menubar {display:none;} #content.contentWithMenu, #the_page > .content {margin-left:35px;}</style>');
  }

  function hideMenu(delay) {
    menubar.hide(delay);
    menuswitcher.addClass("menuhidden").removeClass("menushown");
    content.addClass("menuhidden").removeClass("menushown");
    pcontent.addClass("menuhidden").removeClass("menushown");
    session_storage['picture-menu'] = 'hidden';
  }

  function showMenu(delay) {
    menubar.show(delay);
    menuswitcher.addClass("menushown").removeClass("menuhidden");
    content.addClass("menushown").removeClass("menuhidden");
    pcontent.addClass("menushown").removeClass("menuhidden");
    session_storage['picture-menu'] = 'visible';
  }

  function hideInfo(delay) {
    imageInfos.hide(delay);
    infoswitcher.addClass("infohidden").removeClass("infoshown");
    theImage.addClass("infohidden").removeClass("infoshown");
    session_storage['side-info'] = 'hidden';
  }

  function showInfo(delay) {
    imageInfos.show(delay);
    infoswitcher.addClass("infoshown").removeClass("infohidden");
    theImage.addClass("infoshown").removeClass("infohidden");
    session_storage['side-info'] = 'visible';
  }

  function commentsToggle() {
    if (comments.hasClass("commentshidden")) {
      comments.removeClass("commentshidden").addClass("commentsshown");
      comments_button.addClass("comments_toggle_off").removeClass("comments_toggle_on");;
      session_storage['comments'] = 'visible';

      comments_top_offset = comments_add.offset().top - parseFloat(comments_add.css('marginTop').replace(/auto/, 0));
    }
    else {
      comments.addClass("commentshidden").removeClass("commentsshown");
      comments_button.addClass("comments_toggle_on").removeClass("comments_toggle_off");;
      session_storage['comments'] = 'hidden';
      comments_top_offset = 0;
    }
  }

  jQuery(function(){
    // side-menu show/hide
    if (menubar.length == 1 && p_main_menu!="disabled") {
      menuswitcher=jQuery("#menuSwitcher");

      menuswitcher.html('<div class="switchArrow">&nbsp;</div>');

      if (session_storage['picture-menu'] == 'hidden' || p_main_menu == 'off') {
        hideMenu(0);
      }
      else {
        showMenu(0);
      }

      menuswitcher.click(function(e){
        if (menubar.is(":hidden")) {
          showMenu(0);
        }
        else {
          hideMenu(0);
        }
        e.preventDefault();
      });
    }

    // info show/hide
    if (imageInfos.length == 1 && p_pict_descr!="disabled") {
      infoswitcher=jQuery("#infoSwitcher");

      infoswitcher.html('<div class="switchArrow">&nbsp;</div>');

      if (session_storage['side-info'] == 'hidden' || p_pict_descr == 'off') {
        hideInfo(0);
      }
      else {
        showInfo(0);
      }

      infoswitcher.click(function(e){
        if (imageInfos.is(":hidden")) {
          showInfo(0);
        }
        else {
          hideInfo(0);
        }
        e.preventDefault();
      });
    }

    // comments show/hide
    if (comments.length == 1 && p_pict_comment!="disabled") {
      commentsswitcher=jQuery("#commentsSwitcher");
      comments_button=jQuery("#comments h3");
      comments_add=jQuery('#commentAdd');

      commentsswitcher.html('<div class="switchArrow">&nbsp;</div>');

      if (comments_button.length == 0) {
        jQuery("#addComment").before("<h3>Comments</h3>");
        comments_button=jQuery("#comments h3");
      }

      if (session_storage['comments'] == 'hidden' || p_pict_comment == 'off') {
        comments.addClass("commentshidden");
        comments_button.addClass("comments_toggle comments_toggle_on");
      }
      else {
        comments.addClass("commentsshown");
        comments_button.addClass("comments_toggle comments_toggle_off");
      }

      comments_button.click(commentsToggle);
      commentsswitcher.click(commentsToggle);

      jQuery(window).scroll(function (event) {
        if (comments_top_offset==0) return;

        var y = jQuery(this).scrollTop();

        if (y >= comments_top_offset) {
          comments_add.css({
            'position': 'absolute',
            'top': y-comments.offset().top+10
          });
        }
        else {
          comments_add.css({
            'position': 'static',
            'top': 0
          });
        }
      });

      if (comments_add.is(":visible")) {
        comments_top_offset = comments_add.offset().top - parseFloat(comments_add.css('marginTop').replace(/auto/, 0));
      }
    }
  });
}());