source: extensions/Autosize/js/Affiche_script.js @ 7124

Last change on this file since 7124 was 7124, checked in by cljosse, 14 years ago

[Autosize][beta]Improvement theme compatibility.


File size: 24.1 KB
Line 
1/*
2var thumbnail= '{$thumbnail}';
3var theme = '{$theme}';
4var version = '{$version}';
5var scaled_width = '{$SCALED_WIDTH}'; // valeur par defaut
6var scaled_height = '{$SCALED_HEIGHT}'; // valeur par defaut
7var img_width = '{$IMG_WIDTH }';
8var img_height = '{ $IMG_HEIGHT }';$picture['current']['height']
9
10var marge_basse = '{ $MARGE_BASSE }';
11var echelle_max = '{ $ECHELLE_MAX }';
12var mini_width = '{ $MINI_WIDTH   }';
13var mini_height = '{ $MINI_HEIGHT   }';
14
15var webmaster_width = '{$webmaster_width   }';
16var webmaster_height = '{ $webmaster_height   }';
17var admin_width = '{ $admin_width   }';
18var admin_height = '{ $admin_height   }';
19var generic_width = '{ $generic_width   }';
20var generic_height = '{ $generic_height   }';
21var guest_width = '{ $guest_width   }';
22var guest_height = '{$guest_height}';
23var normal_width = '{$normal_width}';
24var normal_height = '{$normal_height}';
25var user_status = '{$user_status}';
26var user_status = '{$user_status}';
27var check_auto_w = '{$check_auto_w}';
28*/
29
30 var d1 = 0;
31 var init_tb = 0;
32
33 function set_autosize() {
34     visible = !visible;
35
36 }
37
38/* ready
39*
40*
41*/
42 jQuery(document).ready(
43
44    function (jQuery) {
45        /* jQuery */
46        var img_init = { height: img_height, width: img_width };  // taille initiale
47        var img_defaut = { height: scaled_height, width: scaled_width };
48        var img_reelle = { height: img_height, width: img_width };
49        var img_finale = { height: 0, width: 0 };
50        var zone_affichage = { height: 0, width: 0 };
51        /*
52        * recherche la plus grande image (hauteur ou largeur)
53        */
54        function Get_Img_Maxi(myobj) {
55            var w00 = 0;
56            var TheImg = null;
57            jQuery(myobj).each(function (i) {
58                w0 = this.width;
59                h0 = this.height;
60                if (h0 > w0) w0 = h0;
61                if (w0 > w00) {
62                    if (!this.nameProp.match(RegExp(thumbnail, "g"))) {
63                        TheImg = this;
64                        w00 = w0;
65                    }
66
67                }
68            });
69            return TheImg;
70        }
71        /*
72        * Get_val_int
73        * params: element,valeur maxi
74        * return: valeur entiere
75        */
76        function Get_Val_int(myObj, Maxi_val) {
77            var val = 0;
78            var reg1 = new RegExp("%", "g")
79            Maxi_val = parseInt(Maxi_val || 400);
80
81            if (!myObj) return Maxi_val;
82            if (myObj == "none") return Maxi_val;
83            if (myObj == "auto") return Maxi_val;
84            if (myObj.match(reg1))
85                val = myObj * Maxi_val / 100;
86            else
87                val = parseInt(myObj);
88            if (typeof (val) == "NaN") return Maxi_val;
89            return val;
90        }
91
92        /*
93        * Marge_haute
94        * params: element,boolean ajoute_h(ajoute la hauteur de l'element)
95        * return: valeur margin+padding+[hauteur]
96        */
97        function Marge_haute(myObj, ajoute_h) {
98            Mon_obj = jQuery(myObj);
99            if (Mon_obj.length == 0) return 0;
100
101            if (ajoute_h) h_p = parseInt(jQuery(myObj).height());
102            else h_p = 0;
103
104            if (jQuery(myObj).css("marginTop"))
105                if (jQuery(myObj).css("marginTop") != "auto") h_p += parseInt(jQuery(myObj).css("marginTop"));
106            if (jQuery(myObj).css("marginBottom"))
107                if (jQuery(myObj).css("marginBottom") != "auto") h_p += parseInt(jQuery(myObj).css("marginBottom"));
108            if (jQuery(myObj).css("paddingTop"))
109                if (jQuery(myObj).css("paddingTop") != "auto") h_p += parseInt(jQuery(myObj).css("paddingTop"));
110            if (parseInt(jQuery(myObj).css("paddingBottom")))
111                if (jQuery(myObj).css("paddingBottom") != "auto") h_p += parseInt(jQuery(myObj).css("paddingBottom"));
112            return h_p;
113        }
114        //===================================================================   
115        var old_w = 0;
116        var old_h = 0;
117        var rapport = -1;
118        var init_taille_thumblink = { height: 0, width: 0 };
119        /*
120        * window .resize
121        */
122        jQuery(window).resize(function (event, ui) {
123            if (typeof (event) == 'undefined') return;
124
125            w1 = jQuery(window).width();
126            h1 = jQuery(window).height();
127
128
129            if (!visible) return;
130            if (old_w == w1 && old_h == h1) return;
131
132            if (old_w != w1) {
133                old_w = w1;
134            } else {
135                if (old_h != h1) old_h = h1;
136            }
137            var Type_Img = "";
138            //====== détection du type d'images ======
139            if (jQuery("#charlie").length > 0) {
140                Type_Img = "charlie";
141            } else if (jQuery("#pamoorama").length) {
142                Type_Img = "pamoorama";
143            } else if (jQuery("#theImage embed").length > 0) {
144                Type_Img = "embed";
145            } else if (jQuery("#map").length) {
146                Type_Img = "map";
147            } else if (jQuery("#Panorama").length) {
148                Type_Img = "panorama";
149            } else if (jQuery("#theImage").find("img").length > 0) {
150                Type_Img = "img";
151            } else if (jQuery("img").length > 0) {
152                Type_Img = "img_autre";
153                return;
154            } else {
155                return;
156            }
157
158            var winwidth = old_w;
159            var twidth = jQuery("#imageHeaderBar").width();
160            var twidth1 = jQuery("#imageToolBar").width();
161
162            var winheight = old_h;
163            //==== récupère Img la plus grande  =====
164            if (jQuery("#theImg")) IMG = "#theImg";
165            else IMG = "#theImage";
166
167            TheImg2 = Get_Img_Maxi(IMG + " img");
168            //=================================================================
169            if (TheImg2 == null) {
170                if (jQuery("#theImage").find("img").length > 0) {
171                    IMG = "#theImage";
172                    TheImg = Get_Img_Maxi("#theImage img");
173                }
174            } else {
175                TheImg = TheImg2
176
177            }
178
179            //=================================================================
180            switch (Type_Img) {
181                case "map":
182
183                    jQuery("#content").height(winheight);
184
185                    var TheImg = jQuery("#map").get(0);
186                    pos_image = jQuery("#map").position();
187                    pos_page = jQuery("#the_page").position();
188
189
190                    break
191
192
193                case "panorama":
194
195                    var w00 = 0;
196                    jQuery("#Panorama img").each(function (i) {
197                        w0 = this.width;
198                        if (w0 > w00) {
199                            TheImg = this;
200                            n = TheImg.nameProp;
201                            w00 = w0;
202                        }
203                    });
204
205                    pos_image = jQuery(TheImg).position();
206                    pos_page = jQuery("#the_page").position();
207
208                    break
209                case "img":
210
211                    if (!TheImg) return;
212                    pos_image = jQuery(TheImg).position();
213                    pos_page = jQuery("#the_page").position();
214
215
216                    break
217                case "img_autre":
218                    if (!TheImg) return;
219                    pos_image = jQuery(TheImg).position();
220                    pos_page = jQuery("#the_page").position();
221
222
223                    break
224                case "embed":
225                    //
226
227                    var TheImg = jQuery("#theImage").find("embed");
228
229                    pos_image = jQuery("#theImage").position();
230                    pos_page = jQuery("#the_page").position();
231                    if (rapport < 0) {
232                        img_height = parseInt(TheImg.height);
233                        img_width = parseInt(TheImg.width);
234
235                        img_reelle.height = parseInt(TheImg.height);
236                        img_reelle.width = parseInt(TheImg.width);
237                    }
238
239                    break
240                case "charlie":
241
242                    var TheImg = jQuery('#charlie object').get(0);
243                    pos_image = jQuery("#theImage").position();
244                    pos_page = jQuery("#the_page").position();
245                    if (rapport < 0) {
246                        img_height = parseInt(TheImg.height);
247                        img_width = parseInt(TheImg.width);
248
249                        img_reelle.height = parseInt(TheImg.height);
250                        img_reelle.width = parseInt(TheImg.width);
251                    }
252
253                    break
254                case "pamoorama":
255                    //=========================================================
256                    var Images = jQuery("#pamoorama img");
257                    var Image = jQuery("#pamoorama").find("img");
258
259                    pos_image = jQuery("#pamoorama").position();
260                    pos_page = jQuery("#the_page").position();
261                    break
262                    return;
263
264            }
265            //=============== Vérification taille minimale  autorizée ======================
266            miniWidth = Get_Val_int(jQuery(TheImg).css("min-width"), mini_width);
267            miniHeight = Get_Val_int(jQuery(TheImg).css("min-height"), mini_height);
268            maxWidth = Get_Val_int(jQuery(TheImg).css("max-width"), winwidth);
269            maxHeight = Get_Val_int(jQuery(TheImg).css("max-height"), winheight);
270
271            mini_width = parseInt(miniWidth);
272            mini_height = parseInt(miniHeight);
273
274            img_reelle.width = parseInt(img_reelle.width);
275            if (img_reelle.width < mini_width) return;
276
277            img_reelle.height = parseInt(img_reelle.height);
278            if (img_reelle.height < parseInt(mini_height)) return;
279            //==================================================================================   
280            if (rapport < 0) {
281                img_init.height = parseInt(img_height || TheImg.height);
282                img_init.width = parseInt(img_width || TheImg.width);
283                rapport = img_width / img_height;
284                if (Type_Img != "map")
285                    rapport = (img_init.width / img_init.height);
286                else
287                    rapport = -1;
288
289            }
290
291
292            //=============== Zone d'affichage ============================
293            zone_affichage.width = winwidth - 0 - (pos_page.left * 2) - 5;
294            zone_affichage.height = winheight - 0 - pos_page.top;
295
296
297            //=========================================================================== 
298            var sel0 = { top: 0 };
299            sel0.top += Marge_haute("#theHeader", true);
300
301            sel0.top += Marge_haute("#imageHeaderBar", true);
302            if (!theme.match(RegExp("gally", "g"))) {
303                sel0.top += Marge_haute("#imageToolBar", true);
304            } else {
305                sel0.top += Marge_haute(TheImg, false);
306            }
307            if (jQuery("#theImage").css("marginTop"))
308                if (jQuery("#theImage").css("marginTop") != "auto")
309                    sel0.top += parseInt(jQuery("#theImage").css("marginTop"));
310            if (jQuery("#theImage").css("paddingTop"))
311                if (jQuery("#theImage").css("paddingTop") != "auto")
312                    sel0.top += parseInt(jQuery("#theImage").css("paddingTop"));
313
314            img_top = 0;
315            if (jQuery("#theImage").css("position") != "absolute")
316                zone_affichage.height -= sel0.top;
317
318            if (theme.match(RegExp("gally", "g"))) { img_top = sel0.top }
319            jQuery("#theImage").css("top", img_top + "px")
320
321            jQuery("#theImage #theImg IMG").css("marginTop", "0px")
322
323
324
325            var lmt = 0;
326            h = 0;
327            //================ Licence  ========================
328            var Licence = jQuery("#theImage span");
329            if (Licence.length > 0) {
330                jQuery("#theImage span").css("background", "blue");
331                t1 = jQuery("#theImage span").position();
332                h = jQuery("#theImage span").height();
333            }
334            //==== paragraphe supplèmentaire ===
335            if (jQuery("#theImage table")) {
336                jQuery("#theImage table").css("background", "yellow");
337                t1 = jQuery("#theImage table").position();
338            }
339
340            if (jQuery("#theImage p")) {
341                jQuery("#theImage p").css("background", "red");
342                t1 = jQuery("#theImage p").position();
343                h += jQuery("#theImage p").height();
344            }
345            if (jQuery("#theImage br")) {
346
347
348            }
349
350
351
352            lmt = jQuery("#theImage span").height() - jQuery("#theImage p").height();
353
354            //==========================================================================
355            Marge_Basse = parseInt(marge_basse || 0);
356            zone_affichage.height = zone_affichage.height - Marge_Basse;
357
358            var Image_height = zone_affichage.height - h;
359
360            var height_user = eval(user_status + "_height");
361
362            //=============================================================
363            var reg1 = new RegExp("%", "g");
364            if (height_user.match(reg1))
365                Image_height = Image_height * parseInt(height_user) / 100;
366            else
367                Image_height = parseInt(height_user);
368
369            //============================================================
370            echelle_max = parseFloat(echelle_max, '3');
371            var echelle = parseFloat(Image_height / img_reelle.height, 3);
372
373            if (echelle > echelle_max) { echelle = echelle_max; }
374
375            Image_height = parseInt(img_reelle.height * echelle);
376
377            if (rapport > 0) var Image_Width = parseInt(Image_height * rapport);
378            else var Image_Width = parseInt(img_reelle.width * echelle);
379            //===============================================================
380
381            align_auto = "center";
382            if (jQuery("#theImg").css("textAlign"))
383                align_auto = jQuery("#theImg").css("textAlign");
384
385            if (check_auto_w == 'checked="checked"') {
386                // if (Type_Img != "pamoorama" && Type_Img != "panorama" ) {
387                //==== largeur à atteindre ===
388                var width_user = eval(user_status + "_width");
389                // Largeur maximale en fonction du statut
390                if (width_user.match(reg1))
391                // pourcentage
392                    widthmin = twidth * parseInt(width_user) / 100;
393                else
394                    widthmin = parseInt(width_user);
395
396                if (Image_Width > widthmin) {
397                    //   Image_Width largeur à atteindre
398                    //  Calcul du rapport d'agrandissement
399                    var echelle_w = parseFloat(widthmin / img_reelle.width, 3);
400                    if (echelle_w > echelle_max) { echelle_w = echelle_max; }
401                    Image_Width = parseInt(img_reelle.width * echelle_w);
402                }
403
404                if (rapport > 0) Image_height = parseInt(Image_Width / rapport);
405
406            }
407
408
409            // }
410
411            zoom = echelle;
412
413            if (TheImg.src) {
414                w_init = TheImg.width;
415                h_init = TheImg.height;
416            }
417            //  zone_affichage.height *= zoom;
418            //  zone_affichage.width *= zoom;
419            //=============LLGBO2 ===========================
420            marges = 0;
421
422            if (jQuery("#gbo") && jQuery("#gbo div:first").length > 0) {
423                llgboframe = jQuery("#gbo div:first");
424                marges = jQuery(llgboframe).width() - jQuery("#gbo div:last").width();
425                cadre = {};
426                m1 = jQuery(llgboframe).height();
427                t1 = jQuery(llgboframe).position();
428
429
430                if (TheImg.src) {
431                    Image_height = Image_height - marges;
432                    Image_Width = Image_Width - marges;
433
434                    jQuery("#gbo").width(Image_Width + marges);
435                    jQuery("#gbo").height(Image_height + marges);
436                    jQuery("#gbo").css("width", Image_Width + marges + "px");
437                    jQuery("#gbo").css("height", Image_height + marges + "px");
438                } else {
439
440                    jQuery("#gbo").width(zone_affichage.width - marges);
441                    jQuery("#gbo").height(Image_height + marges)
442                    jQuery("#gbo").css("width", zone_affichage.width - marges + "px");
443                    jQuery("#gbo").css("height", Image_height - marges + "px")
444
445                }
446
447
448
449                if (jQuery("#prevnext")) {
450                    areas = jQuery("area");
451
452                }
453
454
455            }
456
457            //=========================================================
458            zone_affichage.height = (Image_height + marges)
459            jQuery("#linkNext").height(Image_height);
460            jQuery("#linkPrev").height(Image_height);
461            //================ Zone affichage =========================
462            //  Image_height, Image_Width = valeur a atteindre.
463            jQuery("#theImage").css("backgroundColor", "green");
464            jQuery("#theImage").height(zone_affichage.height);
465            jQuery("#theImage").width(zone_affichage.width);
466            //==============================================================
467            img_finale.height = Image_height;
468            img_finale.width = Image_Width;
469            //==============================================================
470
471            if (Type_Img == "charlie") {
472                t1 = jQuery("#charlie").position();
473                /**/
474                pdf = 2 * parseInt(jQuery(".none_2").css("paddingRight"));
475                jQuery("#charlie").css("width", Image_Width + pdf);
476                jQuery("#charlie").css("height", Image_height);
477                jQuery("#charlie").css("margin", "auto");
478
479
480                jQuery("#player").css("width", Image_Width + 100 + "px");
481                jQuery("#player").css("height", Image_height);
482
483                jQuery("#embedplayer").css("width", Image_Width);
484                jQuery("#embedplayer").css("height", Image_height);
485
486
487                jQuery("object").width(Image_Width);
488                jQuery("object").height(Image_height);
489            } else if (Type_Img == "panorama") {
490                jQuery(TheImg).height(img_finale.height);
491                jQuery(TheImg).width(img_finale.width);
492                jQuery("#Panorama div").height(Image_height);
493                //  class=simple_panorama
494                jQuery(TheImg).attr("id", "Img1");
495                var settings = {
496                    viewport_width: 600,
497                    speed: 20000,
498                    direction: 'left',
499                    control_display: 'auto',
500                    start_position: 0,
501                    auto_start: true,
502                    mode_360: true,
503                    loop_180: true
504                };
505                element = TheImg; //panorama_animate(element, elemWidth, settings);
506                n = $.fn;
507                pc = jQuery(TheImg)
508                options = pc.extend();
509
510                if (options) jQuery.extend(settings, options);
511
512
513                n = 1;
514                ;
515
516
517                /*
518                jQuery("DIV .panoramaContainer").css("background", "red");
519                jQuery("DIV .panoramaContainer").css("background", "red");
520                jQuery("DIV .panoramaViewport").css("background", "red");
521                jQuery("DIV .panoramaControl").css("background", "red");
522                */
523
524            } else if (Type_Img == "pamoorama") {
525
526
527                jQuery("#pamoorama").css("height", Image_height + "px");
528                jQuery("#pamoorama").css("width", twidth + "px");
529
530                jQuery("#pamoorama").height(Image_height);
531                jQuery("#pamoorama").width(twidth);
532
533
534
535                jQuery("#pamoorama_outter").height(Image_height);
536                jQuery("#pamoorama_outter").width(twidth);
537
538                jQuery("#pamoorama_outter").css("height", Image_height + "px");
539                jQuery("#pamoorama_outter").css("width", twidth + "px");
540                jQuery("#pamoorama_footer").width(twidth);
541                jQuery("#pamoorama_footer").css('width', twidth + "px");
542                zoom = Image_height / img_height;
543
544                h_frame = jQuery("#pamoorama_frame").height();
545                h_width = jQuery("#pamoorama_frame").width();
546                jQuery(TheImg).css("zoom", zoom);
547
548
549
550            } else if (TheImg.src) {
551                //--- background ?? ---
552                jQuery(TheImg).height(img_finale.height);
553                jQuery(TheImg).width(img_finale.width);
554                jQuery(TheImg).css("height", img_finale.height + "px");
555                jQuery(TheImg).css("width", img_finale.width + "px");
556
557            } else {
558
559                jQuery(TheImg).height(img_finale.height);
560                jQuery(TheImg).width(img_finale.width);
561            }
562
563
564            try {
565                if (theme.match(RegExp("gally", "g"))) {
566                    if (init_taille_thumblink.height == 0)
567                        init_taille_thumblink = { height: jQuery(".thumbLink").height(), width: jQuery(".thumbLink").height() };
568
569                    jQuery(".thumbLink").css("height", init_taille_thumblink.height + "px");
570                    jQuery(".thumbLink").css("width", init_taille_thumblink.width + "px");
571                }
572            } catch (e) {
573
574            }
575            // 
576            jQuery(window).resize();
577            return;
578        });
579
580        //===================================================================     
581
582
583        jQuery(window).resize();
584        jQuery(window).resize();
585
586    } // function
587);                   // ready
588
589/* Extension
590 * absolutize:
591 * relativize:
592 */
593//=========================================================
594jQuery.fn.extend({
595    //-------------------------------------------------------
596    absolutize: function (element) {
597        element = jQuery(element).get(0);
598        if (element.getStyle('position') == 'absolute') return;
599        // Position.prepare(); // To be done manually by Scripty when it needs it.
600
601        var offsets = element.positionedOffset();
602        var top = offsets[1];
603        var left = offsets[0];
604        var width = element.clientWidth;
605        var height = element.clientHeight;
606
607        element._originalLeft = left - parseFloat(element.style.left || 0);
608        element._originalTop = top - parseFloat(element.style.top || 0);
609        element._originalWidth = element.style.width;
610        element._originalHeight = element.style.height;
611
612        element.style.position = 'absolute';
613        element.style.top = top + 'px';
614        element.style.left = left + 'px';
615        element.style.width = width + 'px';
616        element.style.height = height + 'px';
617        return element;
618    },
619
620    relativize: function (element) {
621        element = jQuery(element).get(0); ;
622        if (jQuery(element).css('position') == 'relative') return;
623        // Position.prepare(); // To be done manually by Scripty when it needs it.
624        element._originalLeft = parseFloat(element.style.left || 0);
625        element._originalTop = parseFloat(element.style.top || 0);
626        element._originalWidth = element.style.width;
627        element._originalHeight = element.style.height;
628
629        element.style.position = 'relative';
630        var top = parseFloat(element.style.top || 0) - (element._originalTop || 0);
631        var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0);
632
633        element.style.top = top + 'px';
634        element.style.left = left + 'px';
635        //  element.style.height = element._originalHeight;
636        // element.style.width  = element._originalWidth;
637        return element;
638    }
639    //=========================================================
640});   // fin extend
Note: See TracBrowser for help on using the repository browser.