source: extensions/stripped/js/scripts-tpp.js @ 11982

Last change on this file since 11982 was 11982, checked in by Zaphod, 13 years ago

version 1.4.4 : new option to select default tab to be displayed

File size: 16.0 KB
Line 
1var showtabs;
2var selectedTab;
3var interfaceTimerDelay;
4var isScrollable;
5var zoomMode;
6
7jQuery("document").ready(function(jQuery) {
8
9        zoomMode=options.defaultZoomSize;
10
11        // display alt from PWG stuffs actions
12
13        var stuffs_actions=jQuery(".categoryActions",".stuffs_block .stuffs");
14       
15        if (stuffs_actions.length != 0) {
16                stuffs_actions.each(function(index) {
17                        var images=jQuery(this).find("img");
18                        if (images.length !=0) {
19                                images.each(function(index) {
20                                        var alt_text = (jQuery(this).attr("alt"));
21                                        jQuery(this).before(alt_text);
22                                        jQuery(this).parents("li").css("width","auto");
23                                        jQuery(this).remove();
24                                });
25                        }
26                });
27        }
28       
29        // display alt from ALL actions.
30        if (options.replaceActionIcons) {
31                var actionBlock=jQuery(".randomButtons");
32               
33                if (actionBlock.length != 0) {
34                        var actionIcons=actionBlock.find("img.button");
35                        if (actionIcons.length !=0) {
36                                actionIcons.each(function(index) {
37                                        var alt_text = (jQuery(this).attr("alt"));
38                                        jQuery(this).before(alt_text);
39                                        jQuery(this).parents("li").css("width","auto");
40                                        jQuery(this).remove();
41                                });
42                        }
43                }
44        }
45
46        // gmaps icon
47       
48        var icon_gmaps=jQuery("#icon_gmaps");
49        var text_gmaps=jQuery("#text_gmaps");
50        if ((icon_gmaps.length == 1) && (text_gmaps.length ==1)) {
51                icon_gmaps.text(text_gmaps.text());
52                icon_gmaps.css("text-align","right");
53                icon_gmaps.wrapAll('<li>');
54        }
55               
56        // Tabs
57
58        var tab_loaded=0;
59        var delay=400;
60        var hfirst;
61        if (jQuery.browser.msie) {hfirst=false;} else {hfirst=true;}
62       
63        var tab_titles=jQuery(".tabTitle");
64        var tab_blocks=jQuery(".tabBlock");
65        var tab_name;
66        var tab_start = null;
67       
68        if (options.defaultTab) {
69                if (options.defaultTab != "none") tab_start = options.defaultTab;
70                if (options.defaultTab == "last") tab_start = jQuery.cookie("tabactive");
71        }
72
73        if ((tab_titles.length != 0) && (tab_titles.length == tab_blocks.length)) {
74
75                if (tab_start != null) {
76                        tab_blocks.each(function(index) {
77                                jQuery(this).css("display","none");
78                        });
79                        tab_loaded=1;
80                        jQuery("#tabs").css("height","auto");
81       
82                        tab_titles.each(function(index1) {
83                                tab_name = jQuery(this).attr("name");
84                                if (tab_name == tab_start) {
85                                        jQuery(this).addClass("tabSelected");
86                                        jQuery.cookie("tabactive",jQuery(this).attr("name"));
87                                        var old_selected_tab =-1;
88                                        tab_blocks.each(function(index2) {
89                                                if (index1 == index2) {
90                                                        jQuery(this).show();
91                                                }
92                                        });
93                                }
94                        });
95               
96                }
97
98                tab_titles.each(function(index1) {
99                        var tab_title = jQuery(this);
100                        tab_title.click(function () {
101                                if (tab_loaded==0) {
102                                        tab_blocks.each(function(index) {
103                                                jQuery(this).css("display","none");
104                                        });
105                                        tab_loaded=1;
106                                        jQuery("#tabs").css("height","auto");
107                                }
108                                if (jQuery(this).hasClass("tabSelected")) {
109                                        var tab_title = jQuery(this);
110                                        tab_blocks.each(function(index2) {
111                                                if ((index1 == index2) && (options.animatedTabs)) {
112                                                        jQuery(this).slideUp(delay, function() {tab_title.removeClass("tabSelected");});
113                                                } else {
114                                                        jQuery(this).hide();
115                                                }
116                                        });
117                                        jQuery.cookie("tabactive",null);
118                                } else {
119                                        jQuery(this).addClass("tabSelected");
120                                        jQuery.cookie("tabactive",jQuery(this).attr("name"));
121                                        var old_selected_tab =-1;
122                                        tab_titles.each(function(index2) {
123                                                if ((index1 != index2) && (jQuery(this).hasClass("tabSelected"))) {
124                                                old_selected_tab=index2;
125                                                jQuery(this).removeClass("tabSelected");
126                                                }
127                                        });
128                                        tab_blocks.each(function(index2) {
129                                                if (index1 == index2) {
130                                                        if ((old_selected_tab == -1) && (options.animatedTabs)) {
131                                                                jQuery(this).slideDown(delay);
132                                                        } else {
133                                                                jQuery(this).show();
134                                                        }
135                                                }
136                                        });
137                                        tab_blocks.each(function(index2) {
138                                                if (index2 != index1) {
139                                                        jQuery(this).hide();
140                                                }
141                                        });
142                                }
143                        });
144                }); 
145        }
146
147        Init_nav_thumbs();
148
149       
150        // Image autosize function inspired from Autosize Plugin (from cljosse)
151        var img_W0=0;
152        var img_H0=0;
153        var img_ratio=0;
154
155        if (options.imageAutosize) {
156                // Autosize image
157                jQuery(window).resize(function () {
158               
159                        var marge_inf_sup = options.imageAutosizeMargin;
160                        var Hmin = options.imageAutosizeMinHeight;
161                       
162                        var ImageContainer;
163                       
164                        if (options.imageAutosizeTitle) {
165                                ImageContainer = jQuery("#theImageAndTitle");
166                        } else {
167                                ImageContainer = jQuery("#theImage");
168                        }
169                        var Image = jQuery("img","#theImg");
170                        var TitleBox=jQuery("#imageTitleContainer");
171
172                        if (Image.length != 1) {
173                                if (TitleBox.length !=0) TitleBox.css("width","97%");
174                                return;
175                        }
176                       
177                        var marge_inf = ImageContainer.height()-Image.height()+marge_inf_sup;
178                        var pos0 = jQuery(Image).offset();
179                        if (!pos0) return;
180                        var img_top = Math.round(parseFloat(pos0.top));
181                        var win_height = jQuery(window).height();
182                        var img_H = win_height - img_top - marge_inf;
183                        var max_H = img_H;
184                       
185                        if (img_W0==0){
186                                img_W0=Image.width();
187                                img_H0=Image.height();
188                                img_ratio=img_W0/img_H0;
189                        }
190
191                        if (img_W0 == 0) return;
192
193                        if (img_H >= img_H0) img_H=img_H0;
194                        if (img_H <= Hmin) img_H=Hmin;
195
196                        var img_W = Math.round(parseFloat(img_H * img_ratio));
197                       
198                        var max_W = jQuery("#content").width() - Image.outerWidth() + Image.width();
199                        if (img_W > max_W) {
200                                var img_H = Math.round(parseFloat(max_W / img_ratio));
201                                if (img_H <= Hmin) {
202                                        img_H = Hmin;
203                                        img_W = Math.round(parseFloat(img_H * img_ratio));
204                                } else {
205                                        img_W = max_W;
206                                }
207                        }
208
209                        Image.css("width", img_W + "px");
210                        Image.css("height", img_H+ "px");
211                       
212                        jQuery.cookie("stripped_max_width",max_W);
213                        jQuery.cookie("stripped_max_height",max_H);
214
215                        // limit img title Container width
216
217                        if (TitleBox.length != 0) {
218                                TitleBox.css("min-width",jQuery("#theImg").outerWidth()+"px");
219                        }
220
221                        Calc_nav_thumbs_pos();
222                       
223                        return;
224
225                });
226               
227                jQuery(window).resize();
228       
229        }       else {
230
231                var TitleBox=jQuery("#imageTitleContainer");
232                if (TitleBox.length !=0) TitleBox.css("width","97%");
233               
234                jQuery(window).resize(function () {
235                        Calc_nav_thumbs_pos();
236                        return;
237                });
238               
239        }
240               
241        Calc_nav_thumbs_pos()
242
243});
244
245function Init_nav_thumbs() {
246        var tfade=options.navThumbsFade;
247
248        var PrevBoxOut = jQuery("#linkPrevOut");
249        if (PrevBoxOut.length !=0)
250        {
251                var PrevBoxIn=jQuery("#linkPrevIn");
252                var PrevImgBox=jQuery("#linkPrevIn > .navThumb");
253                var PrevImg=jQuery("#linkPrevIn > .navThumb > img");
254
255                if ((jQuery("#mapPicture").length==0) && (jQuery("#Panorama").length==0) && (jQuery("#pamoorama").length==0)){
256                        PrevBoxIn.mouseenter(function(){PrevImg.stop(true, false).animate({opacity:1},tfade);});
257                        PrevBoxOut.mouseleave(function(){PrevImg.stop(true, false).animate({opacity:0},tfade);});
258                } else {
259                        PrevBoxOut.css("display","none");
260                }
261        }
262
263        var NextBoxOut = jQuery("#linkNextOut");
264        if (NextBoxOut.length !=0)
265        {
266                var NextBoxIn=jQuery("#linkNextIn");
267                var NextImgBox=jQuery("#linkNextIn > .navThumb");
268                var NextImg=jQuery("#linkNextIn > .navThumb > img");
269
270                if ((jQuery("#mapPicture").length==0) && (jQuery("#Panorama").length==0) && (jQuery("#pamoorama").length==0)){
271                        NextBoxIn.mouseenter(function(){NextImg.stop(true, false).animate({opacity:1},tfade);});
272                        NextBoxOut.mouseleave(function(){NextImg.stop(true, false).animate({opacity:0},tfade);});
273                } else {
274                        NextBoxOut.css("display","none");
275                }
276        }
277}
278
279function Calc_nav_thumbs_pos() {
280
281        var Window = jQuery(window);
282        var Content = jQuery("#content");
283        var ImageBox = jQuery("#theImg");
284        var PrevImg=jQuery("#linkPrevIn > .navThumb > img");
285
286        var window_width = Window.width();
287        var content_width = Content.width();
288        var image_width = ImageBox.width();
289
290        var PrevBoxOut = jQuery("#linkPrevOut");
291        if (PrevBoxOut.length !=0)
292        {       
293                if (PrevBoxOut.css("display") != "none") {
294                        var PrevBoxIn=jQuery("#linkPrevIn");
295                        var PrevImgBox=jQuery("#linkPrevIn > .navThumb");
296                        var PrevImg=jQuery("#linkPrevIn > .navThumb > img");
297
298                        // height
299
300                        var imgHeight = ImageBox.height()||0;
301                        PrevBoxOut.css("height",imgHeight+"px");
302
303                        var prevImgTopMargin =  parseInt( (imgHeight - PrevImgBox.outerHeight()) / 2 );
304                        PrevImgBox.css("margin-top",prevImgTopMargin+"px");
305
306                        // position
307                       
308                        var prevbox_pos1= parseInt( ( content_width - image_width + PrevImg.outerWidth()) / 2 ) + 120;
309                        var prevbox_pos0= prevbox_pos1 - PrevBoxOut.width();
310                        var left_margin = parseInt( ( window_width - content_width ) / 2 );
311                       
312                        if (prevbox_pos0 + left_margin < 0 ) {
313                                prevbox_pos0 = - left_margin
314                                prevbox_pos1 = prevbox_pos0 + PrevBoxOut.width();
315                        }
316                        var prevbox_width = prevbox_pos1 - prevbox_pos0;
317                       
318                        PrevBoxOut.css("left",prevbox_pos0+"px");
319                        PrevBoxOut.css("width",prevbox_width+"px");
320                }
321        }
322
323        var NextBoxOut = jQuery("#linkNextOut");
324        if (NextBoxOut.length !=0)
325        {
326                if (NextBoxOut.css("display") != "none") {
327                        var NextBoxIn=jQuery("#linkNextIn");
328                        var NextImgBox=jQuery("#linkNextIn > .navThumb");
329                        var NextImg=jQuery("#linkNextIn > .navThumb > img");
330
331                        // height
332
333                        var imgHeight = ImageBox.height()||0;
334                        NextBoxOut.css("height",imgHeight+"px");
335
336                        var nextImgTopMargin =  parseInt( (imgHeight - NextImg.outerHeight()) / 2 );
337                        NextImgBox.css("margin-top",nextImgTopMargin+"px");
338
339                        // position
340
341                        var nextbox_pos1= parseInt( ( content_width - image_width + NextImg.outerWidth()) / 2 ) + 120;
342                        var nextbox_pos0= nextbox_pos1 - NextBoxOut.width();
343                        var right_margin = parseInt( ( window_width - content_width ) / 2 );
344                       
345                        if (nextbox_pos0 + right_margin < 0 ) {
346                                nextbox_pos0 = - right_margin
347                                nextbox_pos1 = nextbox_pos0 + NextBoxOut.width();
348                        }
349               
350                        var nextbox_width = nextbox_pos1 - nextbox_pos0;
351                       
352                        NextBoxOut.css("right",nextbox_pos0+"px");
353                        NextBoxOut.css("width",nextbox_width+"px");
354                }
355        }
356}
357
358
359// Scripts taken from Gally Theme
360
361function openDisplayHigh(url)
362{
363  jQuery('#theImageHigh').css(
364    {
365      width:jQuery("html").get(0).scrollWidth+"px",
366      height:jQuery("html").get(0).scrollHeight+"px",
367      display:"block"
368    }
369  );
370
371  if(jQuery("#theImgHigh").attr('src')=="")
372  {
373    p = new Object();
374    p.left = ((jQuery(window).width()-jQuery("#theImgHighContainer").attr("clientWidth")-options.paddingContainer*2)/2)+"px";
375    p.top = ((jQuery(window).height()-jQuery("#theImgHighContainer").attr("clientHeight")-options.paddingContainer*2)/2)+"px";
376
377
378    jQuery('#theImgHighContainer')
379      .css(
380        {
381          left:p.left,
382          top:p.top,
383          padding:options.paddingContainer+"px"
384        }
385      );
386
387
388    jQuery("#theImgHigh")
389      .load(
390        function ()
391        {
392          jQuery(document).data("highWidth", jQuery("#theImgHigh").width());
393          jQuery(document).data("highHeight", jQuery("#theImgHigh").height());
394
395          p=calcImgHighPositionAndSize(zoomMode);
396
397          jQuery('#theImgHighContainer').css("background-image", "none")
398          displayZoomHigh();
399          jQuery("#theImgHigh").css( {display:"block"} );
400        }
401      )
402      .attr('src', url);
403
404    if(options.highResClickMode=='close')
405    {
406      jQuery("#theImgHigh").bind('click', closeDisplayHigh);
407    }
408    else
409    {
410      // switch zoom
411      jQuery("#theImgHigh").bind('click', switchZoomHigh);
412    }
413  }
414  else
415  {
416    p=calcImgHighPositionAndSize(zoomMode);
417
418    jQuery('#theImgHighContainer')
419      .css(
420        {
421          left:p.left+"px",
422          top:p.top+"px",
423          width:p.width+"px",
424          height:p.height+"px"
425        }
426      );
427  }
428}
429
430function calcImgHighPositionAndSize(zoom)
431{
432  p = new Object();
433
434  if(zoom=='full')
435  {
436    p.width = (jQuery("html").get(0).clientWidth-(options.marginContainer+options.paddingContainer)*2);
437    p.height = (jQuery("html").get(0).clientHeight-(options.marginContainer+options.paddingContainer)*2);
438    p.left=options.marginContainer;
439    p.top=options.marginContainer;
440
441    if(p.width>jQuery(document).data("highWidth"))
442    {
443      p.width = jQuery(document).data("highWidth")-options.paddingContainer*2;
444      p.left = (jQuery("html").get(0).clientWidth-p.width)/2;
445    }
446
447    if(p.height>jQuery(document).data("highHeight"))
448    {
449      p.height = jQuery(document).data("highHeight")-options.paddingContainer*2;
450      p.top = (jQuery("html").get(0).clientHeight-p.height)/2;
451    }
452  }
453  else
454  {
455    //zoom = 'fit'
456    ratioImg = jQuery(document).data("highWidth") / jQuery(document).data("highHeight");
457    ratioPage = jQuery("html").get(0).clientWidth / jQuery("html").get(0).clientHeight;
458
459    if((ratioPage > 1 && (ratioPage > ratioImg)) ||
460       (ratioPage < 1 && (ratioPage < ratioImg)))
461    {
462      p.height = (jQuery("html").get(0).clientHeight-(options.marginContainer+options.paddingContainer)*2);
463      p.width = p.height*ratioImg;
464    }
465    else
466    {
467      p.width = (jQuery("html").get(0).clientWidth-(options.marginContainer+options.paddingContainer)*2);
468      p.height = p.width/ratioImg;
469    }
470    p.left = (jQuery("html").get(0).clientWidth-p.width)/2;
471    p.top = (jQuery("html").get(0).clientHeight-p.height)/2;
472  }
473
474  return(p);
475}
476
477function closeDisplayHigh()
478{
479  jQuery('#theImageHigh').css('display', 'none');
480}
481
482function switchZoomHigh()
483{
484  if(zoomMode=='full')
485  {
486    zoomMode="fit";
487  }
488  else
489  {
490    zoomMode="full";
491  }
492
493  jQuery("#theImgHighZoomButton").toggleClass('full').toggleClass('fit');
494
495  displayZoomHigh();
496}
497
498function displayZoomHigh()
499{
500  p=calcImgHighPositionAndSize(zoomMode);
501
502  jQuery('#theImgHighContainer').css(
503      {
504        left:p.left+"px",
505        top:p.top+"px",
506        width:p.width+"px",
507        height:p.height+"px"
508      }
509    );
510
511    if(zoomMode=="full")
512    {
513      jQuery("#theImgHigh")
514        .css(
515          {
516            width:jQuery(document).data("highWidth")+"px",
517            height:jQuery(document).data("highHeight")+"px"
518          }
519        );
520      jQuery('#theImgHighContainer').bind("mousemove",
521          function(event)
522          {
523            deadArea = options.marginContainer*2;
524            mouseX=Math.max(Math.min(event.clientX-this.offsetLeft, this.clientWidth - deadArea), deadArea);
525            mouseY=Math.max(Math.min(event.clientY-this.offsetTop, this.clientHeight - deadArea), deadArea);
526            jQuery("#theImgHigh")
527              .css("left",Math.round((jQuery("#theImgHigh").attr("scrollWidth")-this.clientWidth) * -(mouseX-deadArea)/(this.clientWidth-2*deadArea))+"px")
528              .css("top",Math.round((jQuery("#theImgHigh").attr("scrollHeight")-this.clientHeight) * -(mouseY-deadArea)/(this.clientHeight-2*deadArea))+"px");
529          }
530        );
531    }
532    else
533    {
534      jQuery("#theImgHigh")
535        .css(
536          {
537            width:p.width+"px",
538            height:p.height+"px",
539            left:"0px",
540            top:"0px"
541          }
542        );
543      jQuery('#theImgHighContainer').unbind("mousemove");
544    }
545}
546/**
547 * Cookie plugin
548 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
549 * Dual licensed under the MIT and GPL licenses:
550 */
551jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options=jQuery.extend({},options);options.expires=-1;}
552var 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;}
553expires='; expires='+date.toUTCString();}
554var 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;}}}
555return cookieValue;}};
556
557
558
559
Note: See TracBrowser for help on using the repository browser.