source: extensions/gally/piwigo-2.0/gallyjs-tpp.js @ 8528

Last change on this file since 8528 was 4517, checked in by grum, 14 years ago

[Template:Gally] Fixes some bugs

  • Property svn:executable set to *
File size: 10.4 KB
Line 
1/* -----------------------------------------------------------------------------
2  GALLY
3  Template for Piwigo
4  ------------------------------------------------------------------------------
5  file: gally/gallyjs-tpp.js
6  file release: 1.2.0
7  ------------------------------------------------------------------------------
8  author: grum at grum.dnsalias.com
9  << May the Little SpaceFrog be with you >>
10  ------------------------------------------------------------------------------
11  JS for the pictures pages
12
13  need jQuery 1.2.6
14
15  see the release_notes.txt file for more informations
16----------------------------------------------------------------------------- */
17
18
19var showtabs;
20var selectedTab;
21var interfaceTimerDelay;
22var isScrollable;
23
24$("document").ready(
25  function(){inittoolbar(); }
26);
27
28function inittoolbar()
29{
30  $(document).data("initialized", 0);
31  $(document).data("interface", false);
32
33  if(jQuery.browser.msie)
34  {
35    //this features don't work with the f*****g msie browser
36    options.interfaceAnimated="none";
37    options.imageAutoScroll=false;
38  }
39
40  if(options.imageAutoScroll)
41  {
42    $("html").css("overflow-x", "hidden");
43  }
44  else
45  {
46    $("html").css("overflow-x", "scroll");
47  }
48
49  if(options.imageCenterTopBorder == "imageHeaderBar")
50  {
51    options.imageCenterTopMin+=$("#imageHeaderBar").get(0).offsetTop+$("#imageHeaderBar").get(0).offsetHeight;
52  }
53
54  currentTab=-1;
55  selectedTab=-1;
56  interfaceTimerDelay = null;
57  switchInterface('0', true);
58  initializeImageMode("init");
59
60  if(options.interfaceOnImage=="always" || (options.interfaceOnImage=="noscroll" && !isScrollable))
61  {
62    $("#theImg").bind("mouseenter", function () { switchInterface('y', true); } )
63                .bind("mouseleave", function () { switchInterface('n', true); } )
64                .bind("mousemove", function () { switchInterface('y', true); } );
65  }
66
67  $("#imageHeaderBar").bind("mouseenter", function () { switchInterface('y', false); } )
68                      .bind("mousemove", function () { switchInterface('y', false); } );
69  $("#imageToolBar").bind("mouseenter", function () { switchInterface('y', true); } )
70                    .bind("mouseleave", function () { switchInterface('n', true); } )
71                    .bind("mousemove", function () { switchInterface('y', true); } );
72
73
74  $("#navThumbPrev").bind("mouseenter", function () { switchInterface('Y', true); } )
75                    .bind("mouseleave", function () { switchInterface('n', true); } )
76                    .bind("mousemove", function () { switchInterface('y', true); } )
77                    .css("top", $("#navThumbPrev").attr("offsetTop")+$("#theHeader").attr("offsetHeight")+"px");
78
79  $("#navThumbNext").bind("mouseenter", function () { switchInterface('Y', true); } )
80                    .bind("mouseleave", function () { switchInterface('n', true); } )
81                    .bind("mousemove", function () { switchInterface('y', true); } )
82                    .css("top", $("#navThumbNext").attr("offsetTop")+$("#theHeader").attr("offsetHeight")+"px");
83
84  $("#theImage").css("top", $("#theImage").attr("offsetTop")+$("#theHeader").attr("offsetHeight")+"px");
85
86  $("#contentid").attr("rows", options.commentRows);
87
88  /* fx duration option set to 0 doesn't work so... */
89  if(options.animateDelay>0)
90  {
91    $("#theTabs").tabs({ fx: { opacity: 'toggle', duration:options.animateDelay } } );
92  }
93  else
94  {
95    $("#theTabs").tabs();
96  }
97  switchTabs('n');
98
99  $('#theTabsContainer').bind("mouseenter", function () { switchInterface('Y', false); } )
100                        .bind("mouseleave", function () { switchInterface('n'); } )
101                        .bind("mousemove", function () { switchInterface('y', false); } );
102
103  $("#theTabs").bind('tabsselect', function(event, ui)
104    {
105      /* The "collapsible" option don't work with jQuery 1.2.6
106       * This function aims to reproduct this functionnality
107      */
108      selectedTab=ui.index;
109    }
110  );
111
112  $('.tab a').click(function()
113    {
114      /* The "collapsible" option don't work with jQuery 1.2.6
115       * This function aims to reproduct this functionnality
116      */
117      $(this).get(0).blur();
118      if(selectedTab == currentTab)
119      {
120        if (currentTab!=-1) switchTabs('n');
121        currentTab=-1;
122        selectedTab=-1;
123      }
124      else
125      {
126        if(currentTab==-1) switchTabs('y');
127        currentTab=selectedTab;
128      }
129    }
130  );
131
132  $(window).resize( function () { initializeImageMode("resize"); } );
133
134  $(document).data("initialized", 1);
135}
136
137function initializeImageMode(mode)
138{
139  if(mode=="init")
140  {
141    $("#imageToolBar").css("top", $("#imageToolBar").attr("offsetTop")+$("#theHeader").attr("offsetHeight")+$("#imageHeaderBar").attr("offsetHeight")+"px");
142
143    if(options.tabsPosition=="bottom")
144    {
145      copyrightArea = $("#copyright").attr("clientHeight")+1;
146      $("#theTabsContainer").css("bottom", copyrightArea+"px");
147    }
148    else if(options.tabsPosition=="top")
149    {
150      toolBarArea = $("#imageToolBar").attr("offsetTop")+$("#imageToolBar").attr("offsetHeight");
151      $("#theTabsContainer").css("top", toolBarArea+"px");
152    }
153
154    if($("#navThumbPrev").length>0)
155    {
156      $("#navThumbPrev").css("height", $("#copyright").attr("offsetTop")-$("#navThumbPrev").attr("offsetTop")-options.tabsHidden+"px");
157    }
158    if($("#navThumbNext").length>0)
159    {
160      $("#navThumbNext").css("height", $("#copyright").attr("offsetTop")-$("#navThumbNext").attr("offsetTop")-options.tabsHidden+"px");
161    }
162  }
163
164  cssValues = new Object;
165  cssValues.height = $("#theImg").attr("height")+"px";
166
167  // autoscroll
168  if(options.imageAutoScroll && ($("#theImg").attr("scrollWidth")>($("#theImage").attr("clientWidth")-2*options.margin_container)))
169  {
170    cssValues.width = ($("#theImage").attr("clientWidth")- 2*options.margin_container)+"px";
171
172    $("#theImage").bind("mousemove",
173      function(event){
174        deadArea = $("#navThumbPrev").attr("clientWidth")*1.2;
175        mouse=Math.max(Math.min(event.clientX-this.offsetLeft, this.clientWidth - deadArea), deadArea);
176        $("#theImg").css("left",Math.round(($("#theImg").attr("scrollWidth")-this.clientWidth) * -(mouse-deadArea)/(this.clientWidth-2*deadArea))+"px");
177      }
178    );
179    isScrollable=true;
180  }
181  else
182  {
183    $("#theImage").unbind("mousemove");
184    $("#theImg").css("left", "0px");
185    cssValues.width = $("#theImg").attr("scrollWidth")+"px";
186    isScrollable=false;
187  }
188  $("#theImgContainer").css(cssValues);
189
190  // imagecenter
191  if($("#copyright").css("position")=="fixed")
192  {
193    $("#theImage").css("padding-bottom", $("#copyright").attr("offsetHeight")+"px");
194  }
195  switch(options.imageCenterMode)
196  {
197    case "img":
198      imgTop = $("#theImgContainer").attr('offsetHeight');
199      break;
200    case "all":
201      imgTop = $("#theImage").attr('offsetHeight');
202      break;
203    default:
204      imgTop = -10000;
205      break;
206  }
207  imgTop = ($("#copyright").attr("offsetTop") - ($("#imageHeaderBar").attr("offsetTop") + $("#imageHeaderBar").attr("offsetHeight")) - imgTop)/2 + options.imageCenterOffset;
208
209  if(imgTop<options.imageCenterTopMin)
210  {
211    imgTop=options.imageCenterTopMin;
212  }
213  imgTop=imgTop+"px";
214
215  $("#theImage").css("top", imgTop);
216
217}
218
219function switchInterface(show, resetTimer)
220{
221  /*
222  uiImg class is affected on this elements :
223  $("#imageToolBarContainer").stop(true, false).fadeTo(animateDelay, 1);
224  $("#imageInfosContainer").stop(true, false).fadeTo(animateDelay, 1);
225  $("#navThumbPrevContainer").stop(true, false).fadeTo(animateDelay, 1);
226  $("#navThumbNextContainer").stop(true, false).fadeTo(animateDelay, 1);
227  */
228
229  if(($(document).data("initialized")==1)&&(options.interfaceHidden))
230  {
231    $(document).data("initialized", 2);
232    if(show=="Y") return('');
233  }
234
235  if(!options.interfaceHidden && show=="0")  { show="1"; }
236
237  // works with jQuery 1.2.6 (support function need jQuery 1.3)
238  if(options.interfaceAnimated=="fade")
239  {
240    switch(show)
241    {
242      case '0':
243        $(".uiImg").css({opacity: 0, visibility:"hidden"});
244        $(document).data("interface", false);
245        break;
246      case '1':
247        if(!$(document).data("interface")) $(".uiImg").css({opacity: 1, visibility:"visible"});
248        $(document).data("interface", true);
249        if(resetTimer) resetInterfaceTimer();
250        break;
251      case '2':
252        //if($(document).data("interface")) break;
253      case 'Y':
254      case 'y':
255        if(!$(document).data("interface")) $(".uiImg").css("visibility","visible").stop(true, false).fadeTo(options.animateDelay, 1);
256        $(document).data("interface", true);
257        if(resetTimer) resetInterfaceTimer();
258        break;
259      default:
260        $(".uiImg").stop(true, false).fadeTo(options.animateDelay, 0, function ()
261          {
262            this.style.visibility="hidden";
263            $(document).data("interface", false);
264          }
265        );
266        clearInterfaceTimer();
267        break;
268    }
269  }
270  else
271  {
272    //other value....
273    switch(show)
274    {
275      case 'y':
276      case 'Y':
277      case '1':
278      case '2':
279        if(!$(document).data("interface")) $(".uiImg").css("visibility", "visible");
280        $(document).data("interface", true);
281        if(resetTimer) resetInterfaceTimer();
282        break;
283      default:
284        $(".uiImg").css("visibility", "hidden");
285        $(document).data("interface", false);
286        clearInterfaceTimer();
287        break;
288    }
289  }
290}
291
292function switchTabs(show)
293{
294  if(show!='')
295  {
296    showtabs=show;
297  }
298  else
299  {
300    if(showtabs!='n')
301    {
302      showtabs='n';
303    }
304    else
305    {
306      showtabs='y';
307    }
308  }
309
310  if(options.tabsAnimated)
311  {
312    if(showtabs=='y')
313    {
314      $("#theTabsContainer").animate({height:options.tabsVisible+"px"}, options.animateDelay);
315    }
316    else
317    {
318      $('#theTabs div.tabPanel').addClass("ui-tabs-hide").css("display", "");
319      $('#theTabs li').removeClass("ui-tabs-selected");
320      $("#theTabsContainer").animate({height:options.tabsHidden+"px"}, options.animateDelay);
321    }
322  }
323  else
324  {
325    if(showtabs=='y')
326    {
327      $("#theTabsContainer").css({height:options.tabsVisible+"px"});
328    }
329    else
330    {
331      $('#theTabs div.tabPanel').addClass("ui-tabs-hide").css("display", "");
332      $('#theTabs li').removeClass("ui-tabs-selected");
333      $("#theTabsContainer").css({height:options.tabsHidden+"px"});
334    }
335  }
336}
337
338function clearInterfaceTimer()
339{
340  if(interfaceTimerDelay!=null)
341  {
342    window.clearInterval(interfaceTimerDelay);
343    interfaceTimerDelay=null;
344  }
345}
346
347function resetInterfaceTimer()
348{
349  clearInterfaceTimer();
350  if(options.interfaceTimerDelay>0) interfaceTimerDelay=window.setInterval(switchInterface, options.interfaceTimerDelay, "n", false);
351}
352
353
Note: See TracBrowser for help on using the repository browser.