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

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

[Autosize]Improvement 'panoramas' compatibility


File size: 14.9 KB
Line 
1
2//==== remplace $(... avec jQuery( ====
3 var ov_map;
4 var d1 = 0;
5   var init_tb = 0;
6 function $(element) {
7  //========== test jQuery ===============
8     new_element = jQuery(element);
9     jq = new_element.selector;
10     if (jQuery("#Panorama").length) {
11
12         return new_element;
13     }
14     afq = jQuery(document).data("initialized") ; //2
15     if (element == window && afq != 1)
16         if (init_tb==1) {
17             init_tb = 2;
18             return new_element;
19         }
20
21         if (new_element.context && afq!=1 && afq != undefined ) {
22           if (init_tb != 2) init_tb = 1;
23            return new_element;
24        }
25        if (new_element.context)
26          if (new_element.context.loaded) {
27            return new_element;
28        }
29        init_tb = 0;
30        tp1 = typeof(MooTools);
31        if (tp1 != "undefined") {
32  //==== mootools prototype ====
33            if (MooTools.version == "1.2.4") {
34                return jQuery(element).get(0);
35
36            }else if( MooTools.version == "1.11") {
37            B = element;
38                if (!B) { 
39                        if (typeof (B) == "boolean") return null;
40                        return jQuery(); 
41                 }
42                if (B.htmlElement) {
43                    return Garbage.collect(B);
44
45                }
46                if ([window, document].contains(B)) { return B; }
47                var A = $type(B);
48                if (A == "string") { B = document.getElementById(B); A = (B) ? "element" : false; }
49                if (A != "element") {
50                    return null;
51                }
52                if (B.htmlElement) { return Garbage.collect(B); }
53                if (["object", "embed"].contains(B.tagName.toLowerCase())) { return B; }
54                $extend(B, Element.prototype);
55                B.htmlElement = function () { };
56                return Garbage.collect(B);
57            }
58           //
59        }
60        tp1 = typeof(Prototype);
61        if (tp1 == "undefined") { return jQuery(element); }
62        if (Prototype.Version != '1.6.0.2') {
63            return jQuery(element);
64        }
65
66     //======== prototype.js =====================
67     if (arguments.length > 1) {
68         for (var i = 0, elements = [], length = arguments.length; i < length; i++)
69             elements.push($(arguments[i]));
70         new_element= elements;
71     }
72     if (typeof(element)=="string")
73         element = jQuery("#" + element).get(0);
74     try {
75         new_element = Element.extend(element);
76     } catch (e) {
77         return new_element;
78     }
79     //==================================================
80     if (typeof (new_element) == "undefined") {
81         jQuery(document).data("initialized", 1);
82         return jQuery();
83     }
84      return new_element;
85   
86}
87
88jQuery(document).ready(
89function (jQuery) {
90
91    function Marge_haute(myObj, ajoute_h) {
92        Mon_obj = jQuery(myObj);
93        if (Mon_obj.length == 0) return 0;
94
95        if (ajoute_h) h_p = parseInt(jQuery(myObj).height());
96        else h_p = 0;
97
98        if (jQuery(myObj).css("marginTop"))
99            if (jQuery(myObj).css("marginTop") != "auto") h_p += parseInt(jQuery(myObj).css("marginTop"));
100        if (jQuery(myObj).css("marginBottom"))
101            if (jQuery(myObj).css("marginBottom") != "auto") h_p += parseInt(jQuery(myObj).css("marginBottom"));
102        if (jQuery(myObj).css("paddingTop"))
103            if (jQuery(myObj).css("paddingTop") != "auto") h_p += parseInt(jQuery(myObj).css("paddingTop"));
104        if (parseInt(jQuery(myObj).css("paddingBottom")))
105            if (jQuery(myObj).css("paddingBottom") != "auto") h_p += parseInt(jQuery(myObj).css("paddingBottom"));
106        return h_p;
107    }
108    //===================================================================       
109
110    jQuery(window).resize(function (event, ui) {
111        if (typeof (event) == 'undefined') return;
112        t = event.type;
113        var Type_Img = "";
114        //====== détection du type d'images ======
115        var Image = jQuery("#theImage").find("embed");
116        if (Image.length > 0) {
117            Type_Img = "embed";
118        } else if (jQuery("#map").length) {
119
120            Type_Img = "map";
121
122
123        } else if (jQuery("#pamoorama").length) {
124
125            Type_Img = "pamoorama";
126        } else if (jQuery("#Panorama").length) {
127
128            Type_Img = "panorama";
129            return;
130        } else if (jQuery("#theImage").find("img").length > 0) {
131            Type_Img = "img";
132        } else if (jQuery("img").length > 0) {
133            Type_Img = "img_autre";
134        } else {
135            return;
136        }
137        var winheight = jQuery(window).height();
138        var winwidth = jQuery(window).width();
139        //=================================================================
140        switch (Type_Img) {
141            case "map":
142
143
144                jQuery("#content").height(winheight);
145                var Image = jQuery("#map");
146                var TheImg = jQuery("#map").get(0);
147                position = jQuery("#map").position();
148                l2 = jQuery("#the_page").position();
149                img_height = winheight - position.top - l2.top;
150                img_width = winwidth - position.left - (l2.left * 2) - 5;
151
152
153                break
154            case "img":
155                var Image = jQuery("#theImage").find("img");
156                var TheImg = jQuery("#theImg").find("img").get(0);
157                if (!TheImg)
158                    TheImg = jQuery(Image).get(0);
159                break
160            case "img_autre":
161                var Image = jQuery("img");
162                var TheImg = jQuery(Image).get(0);
163                break
164            case "embed":
165                var Image = jQuery("#theImage").find("embed");
166                var TheImg = jQuery(Image).get(0);
167                img_height = TheImg.clientHeight;
168                img_width = TheImg.clientWidth;
169                break
170            case "pamoorama":
171                //=========================================================
172                var Images = jQuery("#pamoorama");
173                var Image = jQuery(Images).get(0);
174
175                var TheImg = jQuery("#pamoorama").get(0);
176                if (!TheImg) return;
177                TheImg = jQuery("#pamoorama_inner");
178                if (TheImg.length < 1) return;
179
180                break
181        }
182
183        //==================================================================================       
184
185        var sel0 = jQuery(TheImg).position();
186        jQuery("#theImage").css("top", sel0.top + "px")
187        jQuery().relativize("#theImage");
188        if (!sel0) return;
189        type_pos = jQuery(TheImg).css("position"); //static
190
191        sel0.top = 0;
192        sel0.top += Marge_haute("#theHeader", true);
193
194        sel0.top += Marge_haute("#imageHeaderBar", true);
195        if (!theme.match(RegExp("gally", "g"))) {
196            sel0.top += Marge_haute("#imageToolBar", true);
197        } else {
198            sel0.top += Marge_haute(TheImg, false);
199        }
200        if (jQuery("#theImage").css("marginTop"))
201            if (jQuery("#theImage").css("marginTop") != "auto")
202                sel0.top += parseInt(jQuery("#theImage").css("marginTop"));
203        if (jQuery("#theImage").css("paddingTop"))
204            if (jQuery("#theImage").css("paddingTop") != "auto")
205                sel0.top += parseInt(jQuery("#theImage").css("paddingTop"));
206
207        img_top = 0;
208
209        if (theme.match(RegExp("gally", "g"))) { img_top = sel0.top }
210        jQuery("#theImage").css("top", img_top + "px")
211
212
213        mini_width = parseInt(mini_width);
214        mini_height = parseInt(mini_height);
215
216        W0 = parseInt(img_width);
217        if (W0 < mini_width) return;
218
219        H0 = parseInt(img_height);
220        if (H0 < parseInt(mini_height)) return;
221        if (Type_Img != "map")
222            var rapport = (W0 / H0);
223        else
224            var rapport = -1;
225
226        //==========================================================================
227        var Licence = jQuery("#theImage").find(".licencetag");
228        if (Licence.length > 0) {
229            var lmt = jQuery(Licence.get(0)).height();
230            h_p = jQuery(Licence.get(0)).height();
231            jQuery(Licence.get(0)).css("position", "relative");
232
233            jQuery(Licence.get(0)).css("top", "0px");
234
235        } else {
236            var lmt = 0;
237
238        }
239        //==== paragraphe supplèmentaire ===
240        if (jQuery("#theImage").find("p")) {
241            h_p = 0;
242            Pars = jQuery("#theImage").find("p");
243
244            for (var i = 0; i < Pars.length; i++) {
245                P0 = Pars.get(i);
246                h_p += Marge_haute(P0, true);
247            }
248
249            //   n_t = (p_p.top - Image_height) + h_p;
250
251            lmt += h_p;
252            jQuery("#theImage").css("paddingBottom", 0 + "px");
253        }
254
255        //==========================================================================
256
257        var Image_height = (winheight - sel0.top) - parseInt(marge_basse) - lmt;
258        var height_user = eval(user_status + "_height");
259
260        //=============================================================
261        var reg1 = new RegExp("%", "g");
262        if (height_user.match(reg1))
263            Image_height = Image_height * parseInt(height_user) / 100;
264        else
265            Image_height = parseInt(height_user);
266
267        //============================================================
268        echelle_max = parseFloat(echelle_max, '3');
269        var echelle = parseFloat(Image_height / H0, 3);
270
271        if (echelle > echelle_max) {
272            echelle = echelle_max;
273            Image_height = parseInt(H0 * echelle);
274        }
275
276        if (rapport > 0)
277            var Image_Width = parseInt(Image_height * rapport);
278        else
279            var Image_Width = parseInt(W0);
280        //===============================================================
281        twidth = jQuery("#imageHeaderBar").width();
282        img_la = jQuery(TheImg).width(); //initiale
283        offset = jQuery(TheImg).position();
284
285        var width_user = eval(user_status + "_width");
286        align_auto = "center";
287        if (check_auto_w == 'checked="checked"') {
288            if (Type_Img != "pamoorama") {
289                widthmin = (winwidth - offset.left);
290
291                if (Image_Width > widthmin) {
292                    //=============================================================
293                    if (width_user.match(reg1))
294                        Image_Width = Image_Width * parseInt(width_user) / 100;
295                    else
296                        Image_Width = parseInt(width_user);
297
298                    var echelle_w = parseFloat(winwidth / W0, 3);
299                    if (echelle_w > echelle_max) {
300                        echelle_w = echelle_max;
301                        Image_Width = parseInt(W0 * echelle_w);
302                    }
303                    Image_Width = parseInt(W0 * echelle_w);
304
305                    align_auto = "left";
306                } else {
307
308                    align_auto = "center";
309                }
310                Image_height = parseInt(Image_Width / rapport);
311
312            }
313
314
315        }
316        //=============================================================
317
318        if (Type_Img == "pamoorama") {
319
320
321            jQuery("#pamoorama").css("height", Image_height + "px");
322            jQuery("#pamoorama").css("width", twidth + "px");
323
324            jQuery("#pamoorama").height(Image_height + "px");
325            jQuery("#pamoorama").width(twidth + "px");
326
327
328
329            jQuery("#pamoorama_outter").height(Image_height + "px");
330            jQuery("#pamoorama_outter").width(twidth + "px");
331
332            jQuery("#pamoorama_outter").css("height", Image_height + "px");
333            jQuery("#pamoorama_outter").css("width", twidth + "px");
334
335            zoom = Image_height / img_height;
336
337            h_frame = jQuery("#pamoorama_frame").height();
338            h_width = jQuery("#pamoorama_frame").width();
339            jQuery(TheImg).css("zoom", zoom);
340
341
342
343        } else {
344
345
346            if (jQuery("#theImg").css("textAlign"))
347                jQuery("#theImg").css("textAlign", align_auto);
348
349            jQuery(TheImg).height(Image_height + "px");
350            jQuery(TheImg).width(Image_Width + "px");
351            jQuery(TheImg).css("height", Image_height + "px");
352            jQuery(TheImg).css("width", Image_Width + "px");
353
354        }
355        try {
356            if (theme.match(RegExp("gally", "g"))) {
357
358                m = jQuery("#theImg");
359                if (m.length > 0) initializeImageMode('resize');
360
361
362            } else if (theme.match(RegExp("luciano", "g"))) {
363                jQuery("#theImage").height(Image_height);
364            }
365        } catch (e) {
366
367        }
368        // 
369
370        return;
371    });
372
373    //===================================================================         
374
375
376    jQuery(window).resize();
377    jQuery(window).resize();
378
379
380    /*  */
381
382
383});
384//=========================================================
385jQuery.fn.extend({
386//-----------------------------------------------------------------
387  absolutize: function(element) {
388    element = jQuery(element).get(0);
389    if (element.getStyle('position') == 'absolute') return;
390    // Position.prepare(); // To be done manually by Scripty when it needs it.
391
392    var offsets = element.positionedOffset();
393    var top     = offsets[1];
394    var left    = offsets[0];
395    var width   = element.clientWidth;
396    var height  = element.clientHeight;
397
398    element._originalLeft   = left - parseFloat(element.style.left  || 0);
399    element._originalTop    = top  - parseFloat(element.style.top || 0);
400    element._originalWidth  = element.style.width;
401    element._originalHeight = element.style.height;
402
403    element.style.position = 'absolute';
404    element.style.top    = top + 'px';
405    element.style.left   = left + 'px';
406    element.style.width  = width + 'px';
407    element.style.height = height + 'px';
408    return element;
409  },
410
411  relativize: function(element) {
412    element = jQuery(element).get(0);;
413    if (jQuery(element).css('position') == 'relative') return;
414    // Position.prepare(); // To be done manually by Scripty when it needs it.
415    element._originalLeft =  parseFloat(element.style.left || 0);
416    element._originalTop =  parseFloat(element.style.top || 0);
417    element._originalWidth = element.style.width;
418    element._originalHeight = element.style.height;
419
420    element.style.position = 'relative';
421    var top  = parseFloat(element.style.top  || 0) - (element._originalTop || 0);
422    var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0);
423
424    element.style.top    = top + 'px';
425    element.style.left   = left + 'px';
426  //  element.style.height = element._originalHeight;
427   // element.style.width  = element._originalWidth;
428    return element;
429  }
430//=========================================================
431 }); // fin extend
Note: See TracBrowser for help on using the repository browser.