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

Last change on this file since 13245 was 12960, checked in by Zaphod, 12 years ago

version 2.1.0

File size: 13.8 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        // gmaps icon
30       
31        var icon_gmaps=jQuery("#icon_gmaps");
32        var text_gmaps=jQuery("#text_gmaps");
33        if ((icon_gmaps.length == 1) && (text_gmaps.length ==1)) {
34                icon_gmaps.text(text_gmaps.text());
35                icon_gmaps.css("text-align","right");
36                icon_gmaps.wrapAll('<li>');
37        }
38       
39        // Tabs
40
41        var tab_loaded=0;
42        var delay=400;
43        var hfirst;
44        if (jQuery.browser.msie) {hfirst=false;} else {hfirst=true;}
45       
46        var tab_titles=jQuery(".tabTitle");
47        var tab_blocks=jQuery(".tabBlock");
48        var tab_name;
49        var tab_start = null;
50       
51        if ( (options.defaultTab) && (options.themeStyle == "original") ) {
52                if (options.defaultTab != "none") tab_start = options.defaultTab;
53                if (options.defaultTab == "last") tab_start = jQuery.cookie("tabactive");
54        }
55
56        if ((tab_titles.length != 0) && (tab_titles.length == tab_blocks.length)) {
57
58                if (tab_start != null) {
59                        tab_blocks.each(function(index) {
60                                jQuery(this).css("display","none");
61                        });
62                        tab_loaded=1;
63                        jQuery("#tabs").css("height","auto");
64       
65                        tab_titles.each(function(index1) {
66                                tab_name = jQuery(this).attr("name");
67                                if (tab_name == tab_start) {
68                                        jQuery(this).addClass("tabSelected");
69                                        jQuery.cookie("tabactive",jQuery(this).attr("name"));
70                                        var old_selected_tab =-1;
71                                        tab_blocks.each(function(index2) {
72                                                if (index1 == index2) {
73                                                        jQuery(this).show();
74                                                }
75                                        });
76                                }
77                        });
78               
79                }
80
81                tab_titles.each(function(index1) {
82                        var tab_title = jQuery(this);
83                        tab_title.click(function () {
84                                if (tab_loaded==0) {
85                                        tab_blocks.each(function(index) {
86                                                jQuery(this).css("display","none");
87                                        });
88                                        tab_loaded=1;
89                                        jQuery("#tabs").css("height","auto");
90                                }
91                                if (jQuery(this).hasClass("tabSelected")) {
92                                        var tab_title = jQuery(this);
93                                        tab_blocks.each(function(index2) {
94                                                if (index1 == index2) {
95                                                        if (options.animatedTabs) {
96                                                                jQuery(this).slideUp(delay, function() {tab_title.removeClass("tabSelected");});
97                                                        } else {
98                                                                jQuery(this).hide();
99                                                                tab_title.removeClass("tabSelected");
100                                                        }
101                                                }
102                                        });
103                                        jQuery.cookie("tabactive",null);
104                                } else {
105                                        jQuery(this).addClass("tabSelected");
106                                        jQuery.cookie("tabactive",jQuery(this).attr("name"));
107                                        var old_selected_tab =-1;
108                                        tab_titles.each(function(index2) {
109                                                if ((index1 != index2) && (jQuery(this).hasClass("tabSelected"))) {
110                                                old_selected_tab=index2;
111                                                jQuery(this).removeClass("tabSelected");
112                                                }
113                                        });
114                                        tab_blocks.each(function(index2) {
115                                                if (index1 == index2) {
116                                                        if ((old_selected_tab == -1) && (options.animatedTabs)) {
117                                                                jQuery(this).slideDown(delay);
118                                                        } else {
119                                                                jQuery(this).show();
120                                                        }
121                                                }
122                                        });
123                                        tab_blocks.each(function(index2) {
124                                                if (index2 != index1) {
125                                                        jQuery(this).hide();
126                                                }
127                                        });
128                                }
129                        });
130                }); 
131               
132                if (options.themeStyle != "original") {
133                        jQuery(".hideTabs").click(function() {
134                               
135                                tab_titles.each(function(index1) {
136                                        if (jQuery(this).hasClass("tabSelected")) {
137                                                var tab_title = jQuery(this);
138                                                tab_blocks.each(function(index2) {
139                                                        if (index1 == index2) {
140                                                                if (options.animatedTabs) {
141                                                                        jQuery(this).slideUp(delay, function() {tab_title.removeClass("tabSelected");});
142                                                                } else {
143                                                                        jQuery(this).hide();
144                                                                        tab_title.removeClass("tabSelected");
145                                                                }
146                                                        }
147                                                });
148                                                jQuery.cookie("tabactive",null);
149                                        } 
150                                });
151                       
152                        });
153                }
154        }
155
156       
157        // Image autosize function inspired from Autosize Plugin (from cljosse)
158
159        var img_ratio=image_w / image_h;
160
161        if (options.imageAutosize) {
162       
163                // Autosize image
164                jQuery(window).resize(function () {
165                       
166                        var Fenetre = jQuery(window);
167                        var ImageContainer = jQuery("#theImageAndTitle");
168                        var ImageCadre = jQuery("#theImg");
169                        var Image = jQuery("img","#theImg");
170                        var TitleBox=jQuery("#imageTitleContainer");
171
172                        var marge_cote;
173
174                        if (ImageCadre.length == 0) {
175                                ImageContainer.css("opacity","1");
176                                jQuery("img","#theImageAndTitle").css("opacity","1");
177                                return;
178                        }
179                       
180                        if (options.navArrows) {marge_cote=30;} else {marge_cote=10;};
181
182                        var marge_sup = 30;
183                        var marge_inf;
184                        if (options.themeStyle == 'original') { marge_inf = options.imageAutosizeMargin+10;} else { marge_inf = 30;};
185                        var marge_spec = 0;
186                       
187                        var slideshow=jQuery("#light_slideshow");
188                        if (slideshow.length!=0) {
189                                marge_inf = 5;
190                                marge_spec = 25;
191                        }
192                       
193                        var Hmin = options.imageAutosizeMinHeight;
194                       
195                        if (Image.length != 1) {
196                                if (TitleBox.length !=0) TitleBox.css("width","97%");
197                                return;
198                        }
199
200                        marge_inf = ImageContainer.height()-Image.height()+marge_inf;
201                        var win_height = Fenetre.height();
202                        var img_H = win_height - marge_sup - marge_inf;
203                        var max_H = img_H;
204
205                       
206                        if (img_H >= image_h) img_H = image_h;
207                        if (img_H <= Hmin) img_H = Hmin;
208
209                        var img_W = Math.round(parseFloat(img_H * img_ratio));
210                       
211
212                        var marge_image = ImageCadre.outerWidth() - Image.width();
213/* à modifier */
214                        var ext_width;
215                       
216                        if (options.themeStyle == 'original') { ext_width = jQuery("#content").width();} else {ext_width = Fenetre.width();};
217                        var max_W = ext_width - marge_image - marge_cote * 2;
218                       
219                        if (img_W > max_W) {
220                                img_H = Math.round(parseFloat(max_W / img_ratio));
221                                img_W = max_W;
222                        }
223                       
224                        Image.css("width", img_W + "px");
225                        Image.css("height", img_H + "px");
226
227                        if (options.themeStyle != 'original') {
228                                var marge_tot = win_height - img_H - marge_inf - marge_sup - marge_spec;
229                                if (marge_tot < 0) marge_tot=0;
230                       
231                                var marge = marge_sup + Math.round(parseFloat(marge_tot / 2));
232
233                                ImageContainer.css("top",marge+"px");
234                        }
235
236                        // limit img title Container width
237
238                        if (TitleBox.length != 0) {
239                                TitleBox.css("min-width",jQuery("#theImg").outerWidth()+"px");
240                        }
241
242                        jQuery.cookie("stripped_max_width",max_W);
243                        jQuery.cookie("stripped_max_height",max_H);
244
245                        ImageContainer.css("opacity","1");
246                        ImageCadre.css("opacity","1");
247                        TitleBox.css("opacity","1");
248
249
250                        // limit img title Container width
251/*
252                        if (TitleBox.length != 0) {
253                                var TBminW = jQuery("#theImg").outerWidth();
254                                TitleBox.css("min-width",TBminW + "px");
255                                if (TitleBox.width() > TBminW) {
256                                        TitleBox.children().css("text-align","justify");
257                                } else {
258                                        TitleBox.children().css("text-align","center");
259                                }
260                        }
261*/
262                        // test
263                        if (options.themeStyle != 'original') {
264                                var max_footer_width = jQuery("#content").width() - jQuery("#tabTitles").width() - 5;
265                                jQuery("#copyright").css("max-width",max_footer_width);
266                        }
267                        return;
268
269                });
270               
271                jQuery(window).resize();
272                jQuery(window).resize();
273       
274        }       else {
275                jQuery("#theImageAndTitle").css("opacity","1");
276                jQuery("#theImg").css("opacity","1");
277                jQuery("#imageTitleContainer").css("opacity","1");
278                var TitleBox=jQuery("#imageTitleContainer");
279                if (TitleBox.length !=0) TitleBox.css("width","97%");
280               
281        }
282       
283               
284});
285
286
287
288// Scripts taken from Gally Theme
289
290function openDisplayHigh(url)
291{
292  jQuery('#theImageHigh').css(
293    {
294      width:jQuery("html").get(0).scrollWidth+"px",
295      height:jQuery("html").get(0).scrollHeight+"px",
296      display:"block"
297    }
298  );
299
300  if(jQuery("#theImgHigh").attr('src')=="")
301  {
302    p = new Object();
303    p.left = ((jQuery(window).width()-jQuery("#theImgHighContainer").prop("clientWidth")-options.paddingContainer*2)/2)+"px";
304    p.top = ((jQuery(window).height()-jQuery("#theImgHighContainer").prop("clientHeight")-options.paddingContainer*2)/2)+"px";
305
306
307    jQuery('#theImgHighContainer')
308      .css(
309        {
310          left:p.left,
311          top:p.top,
312          padding:options.paddingContainer+"px"
313        }
314      );
315
316
317    jQuery("#theImgHigh")
318      .load(
319        function ()
320        {
321          jQuery(document).data("highWidth", jQuery("#theImgHigh").width());
322          jQuery(document).data("highHeight", jQuery("#theImgHigh").height());
323
324          p=calcImgHighPositionAndSize(zoomMode);
325
326          jQuery('#theImgHighContainer').css("background-image", "none")
327          displayZoomHigh();
328          jQuery("#theImgHigh").css( {display:"block"} );
329        }
330      )
331      .attr('src', url);
332
333    if(options.highResClickMode=='close')
334    {
335      jQuery("#theImgHigh").bind('click', closeDisplayHigh);
336    }
337    else
338    {
339      // switch zoom
340      jQuery("#theImgHigh").bind('click', switchZoomHigh);
341    }
342  }
343  else
344  {
345    p=calcImgHighPositionAndSize(zoomMode);
346
347    jQuery('#theImgHighContainer')
348      .css(
349        {
350          left:p.left+"px",
351          top:p.top+"px",
352          width:p.width+"px",
353          height:p.height+"px"
354        }
355      );
356  }
357}
358
359function calcImgHighPositionAndSize(zoom)
360{
361  p = new Object();
362
363  if(zoom=='full')
364  {
365    p.width = (jQuery("html").get(0).clientWidth-(options.marginContainer+options.paddingContainer)*2);
366    p.height = (jQuery("html").get(0).clientHeight-(options.marginContainer+options.paddingContainer)*2);
367    p.left=options.marginContainer;
368    p.top=options.marginContainer;
369
370    if(p.width>jQuery(document).data("highWidth"))
371    {
372      p.width = jQuery(document).data("highWidth")-options.paddingContainer*2;
373      p.left = (jQuery("html").get(0).clientWidth-p.width)/2;
374    }
375
376    if(p.height>jQuery(document).data("highHeight"))
377    {
378      p.height = jQuery(document).data("highHeight")-options.paddingContainer*2;
379      p.top = (jQuery("html").get(0).clientHeight-p.height)/2;
380    }
381  }
382  else
383  {
384    //zoom = 'fit'
385    ratioImg = jQuery(document).data("highWidth") / jQuery(document).data("highHeight");
386    ratioPage = jQuery("html").get(0).clientWidth / jQuery("html").get(0).clientHeight;
387
388    if((ratioPage > 1 && (ratioPage > ratioImg)) ||
389       (ratioPage < 1 && (ratioPage < ratioImg)))
390    {
391      p.height = (jQuery("html").get(0).clientHeight-(options.marginContainer+options.paddingContainer)*2);
392      p.width = p.height*ratioImg;
393    }
394    else
395    {
396      p.width = (jQuery("html").get(0).clientWidth-(options.marginContainer+options.paddingContainer)*2);
397      p.height = p.width/ratioImg;
398    }
399    p.left = (jQuery("html").get(0).clientWidth-p.width)/2;
400    p.top = (jQuery("html").get(0).clientHeight-p.height)/2;
401  }
402
403  return(p);
404}
405
406function closeDisplayHigh()
407{
408  jQuery('#theImageHigh').css('display', 'none');
409}
410
411function switchZoomHigh()
412{
413  if(zoomMode=='full')
414  {
415    zoomMode="fit";
416  }
417  else
418  {
419    zoomMode="full";
420  }
421
422  jQuery("#theImgHighZoomButton").toggleClass('full').toggleClass('fit');
423
424  displayZoomHigh();
425}
426
427function displayZoomHigh()
428{
429  p=calcImgHighPositionAndSize(zoomMode);
430
431  jQuery('#theImgHighContainer').css(
432      {
433        left:p.left+"px",
434        top:p.top+"px",
435        width:p.width+"px",
436        height:p.height+"px"
437      }
438    );
439
440    if(zoomMode=="full")
441    {
442      jQuery("#theImgHigh")
443        .css(
444          {
445            width:jQuery(document).data("highWidth")+"px",
446            height:jQuery(document).data("highHeight")+"px"
447          }
448        );
449      jQuery('#theImgHighContainer').bind("mousemove",
450          function(event)
451          {
452            deadArea = options.marginContainer*2;
453            mouseX=Math.max(Math.min(event.clientX-this.offsetLeft, this.clientWidth - deadArea), deadArea);
454            mouseY=Math.max(Math.min(event.clientY-this.offsetTop, this.clientHeight - deadArea), deadArea);
455            jQuery("#theImgHigh")
456              .css("left",Math.round((jQuery("#theImgHigh").prop("scrollWidth")-this.clientWidth) * -(mouseX-deadArea)/(this.clientWidth-2*deadArea))+"px")
457              .css("top",Math.round((jQuery("#theImgHigh").prop("scrollHeight")-this.clientHeight) * -(mouseY-deadArea)/(this.clientHeight-2*deadArea))+"px");
458          }
459        );
460    }
461    else
462    {
463      jQuery("#theImgHigh")
464        .css(
465          {
466            width:p.width+"px",
467            height:p.height+"px",
468            left:"0px",
469            top:"0px"
470          }
471        );
472      jQuery('#theImgHighContainer').unbind("mousemove");
473    }
474}
475/**
476 * Cookie plugin
477 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
478 * Dual licensed under the MIT and GPL licenses:
479 */
480jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options=jQuery.extend({},options);options.expires=-1;}
481var 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;}
482expires='; expires='+date.toUTCString();}
483var 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;}}}
484return cookieValue;}};
485
486
487
488
Note: See TracBrowser for help on using the repository browser.