source: extensions/gally/gally-cuise/js/crossbrowser.js @ 12655

Last change on this file since 12655 was 12655, checked in by cljosse, 12 years ago

[theme] set Gally-cuise to piwigo 2.3

File size: 37.5 KB
Line 
1; (function (jQuery) {
2                         
3 if (!document.namespaces.v) { document.namespaces.add("v", "urn:schemas-microsoft-com:vml"); }
4    var mode = document.documentMode || 0;
5    var noBottomFold = jQuery.browser.msie && ((jQuery.browser.version < 8 && !mode) || mode < 8);
6    var init = false;
7    var angle = 0;
8    var strokeWeight =0;
9
10//=======================================================================================
11//Filter: Alpha(Opacity=100, FinishOpacity=0, Style=2, StartX=20, StartY=40, FinishX=0, FinishY=0);
12//filter:progid:DXImageTransform.Microsoft.Alpha(opacity=20)"
13function opacity(obj) {
14        alpha_css=jQuery(obj).css("opacity");
15        fils=     $(obj).children() ;
16        if (fils.length>1) { 
17                jQuery( fils).css("opacity",alpha_css);
18            }
19}
20     //======================================================================================
21function transform(obj) {
22     if (!obj) return ;
23         if (typeof obj == "string") var s = document.getElementById(obj).style;
24         else var s = obj.style;
25       
26         if (typeof s.transform != "undefined") {
27             var angle1 = s.transform.split("rotate(");
28             angle1 = angle1[1].split("deg)");
29             angle = angle1[0];
30         }
31         //==================================================================================   
32         var deg2radians = Math.PI * 2 / 360;
33         var rad = angle * deg2radians;
34         var costheta = Math.cos(rad);
35         var sintheta = Math.sin(rad);
36
37         if (!obj.style.filter.match("progid:DXImageTransform.Microsoft.Matrix")) obj.style.filter += "  progid:DXImageTransform.Microsoft.Matrix() ";
38
39
40         centered = true;
41         try{
42         obj.filters.item("DXImageTransform.Microsoft.Matrix").M11 = costheta;
43         obj.filters.item("DXImageTransform.Microsoft.Matrix").M12 = -sintheta;
44         obj.filters.item("DXImageTransform.Microsoft.Matrix").M21 = sintheta;
45         obj.filters.item("DXImageTransform.Microsoft.Matrix").M22 = costheta;
46         obj.filters.item("DXImageTransform.Microsoft.Matrix").sizingMethod = 'auto expand'; //'clip to original' ; //
47         }  catch (_) { 
48         centered = true;
49         }
50
51  height = obj.clientHeight;
52  width = obj.clientWidth;
53  xleft= obj.offsetLeft;
54  ytop= obj.offsetTop;     
55  ntop = ((height - obj.offsetHeight) / 2);
56  nleft = ((width - obj.offsetWidth) / 2); 
57
58
59    if (obj.vml) {
60          if (!init) {
61            jQuery(obj).css("position", "absolute");
62          pos_img=jQuery(obj).findPos();
63           pos_vml=jQuery(obj.vml).findPos();
64                  nleft=-strokeWeight;
65                  ntop =-strokeWeight;
66
67                   var mode = document.documentMode || 0;
68                  if (getStyles(obj).position!="absolute"){
69
70                    init_x0=init_x - (0.5*strokeWeight) ;
71                   if (mode==8) init_y0=init_y + (0.5*strokeWeight) ;
72                   else init_y0=init_y + (1.5*strokeWeight) ;
73                    init_y=strokeWeight;
74                    init_x=strokeWeight;
75
76
77                  }else{
78                   init_y=parseInt(pos_img.x)+strokeWeight;
79                   init_x=parseInt(pos_img.y)+strokeWeight;
80                   init_x0=init_x+(0.5*strokeWeight);
81                    init_y0=init_y+(0.5*strokeWeight);
82
83                  }
84
85                   jQuery(obj).css("position", "absolute");
86                  init=true;
87                   
88                 }
89
90                        x = init_x+  nleft ;
91                        y = init_y+  ntop ;
92
93
94                 jQuery(obj).css("left",  x +  "px");
95                 jQuery(obj).css("top",  y +  "px");
96 
97                 jQuery(obj.vml).css("left",   init_x0 +  nleft+  "px");
98                 jQuery(obj.vml).css("top",  init_y0 +  ntop+  "px");
99       
100
101                 transform(obj.vml);
102                       
103                } 
104var name_id=obj.id ; 
105 jQuery(obj).css("opacity",alpha);
106 if (alpha!=1) {
107     opacity(obj);
108 
109 }
110 
111          return ;
112
113 
114   
115
116
117
118
119     
120
121     }
122//===========================================
123function onPropertyChange(e) {
124         var el = e.srcElement;
125
126         switch (e.propertyName) {
127            case "opacity":
128                 opacity(el);
129
130                 break;
131             case "style.transform":
132             // init=false;
133                 transform(el);
134
135                 break;
136             case "style.textShadow":
137
138                 var text_shadow = el.style.textShadow;
139                 var sizeShadow = text_shadow.split(" ");
140                 aff_filter(el, sizeShadow);
141                 break;
142             case "style.color":
143                 new_color = translateColor(el.style.color);
144                 el.style.color = new_color;
145                 break;
146             case 'width':
147
148                 el.style.width = el.attributes.width.nodeValue + 'px';
149                 // In IE8 this does not trigger onresize.
150                 el.firstChild.style.width = el.clientWidth + 'px';
151                 break;
152             case 'height':
153
154                 el.style.height = el.attributes.height.nodeValue + 'px';
155                 el.firstChild.style.height = el.clientHeight + 'px';
156                 break;
157         }
158     }
159//==================================================
160function findSize(obj) {
161         var cur_height = obj.offsetHeight;
162         var cur_width = obj.offsetWidth;
163
164     
165
166         return ({
167             'x': cur_width,
168             'y': cur_height
169         });
170     }
171//==================================================
172function roundWebkit(e, s) {
173    var radius = '' + s.sizex + 'px ' + s.sizey + 'px';
174    var $e = jQuery(e);
175    if (s.tl) $e.css('WebkitBorderTopLeftRadius', radius);
176    if (s.tr) $e.css('WebkitBorderTopRightRadius', radius);
177    if (s.bl) $e.css('WebkitBorderBottomLeftRadius', radius);
178    if (s.br) $e.css('WebkitBorderBottomRightRadius', radius);
179  }
180//================================================== 
181  function roundMozilla(e, s)
182  { 
183    var radius = '' + s.sizex + 'px';
184    var $e = jQuery(e);
185    if (s.tl) $e.css('-moz-border-radius-topleft', radius);
186    if (s.tr) $e.css('-moz-border-radius-topright', radius);
187    if (s.bl) $e.css('-moz-border-radius-bottomleft', radius);
188    if (s.br) $e.css('-moz-border-radius-bottomright', radius); 
189  }
190  //================================================== 
191  function roundOpera(e, s)
192  { 
193    var radius = '' + s.sizex + 'px';
194    var $e = jQuery(e);
195    if (s.tl) $e.css('-o-border-top-left-radius', radius);
196    if (s.tr) $e.css('-o-border-top-right-radius', radius);
197    if (s.bl) $e.css('-o-border-top-bottom-left-radius', radius);
198    if (s.br) $e.css('-o-border-top-bottom-right-radius', radius); 
199  }
200//=================================================================
201     var rect_init;
202     var css_init;
203     var fill_init;
204     //==============================================================
205
206     // precompute "00" to "FF"
207    var decToHex = [];
208    var alpha = 1;
209    var      init_x = 0;
210    var init_y = 0;
211    var  init_x0 =0;
212    var  init_y0 = 0;
213//==============================================================
214function oncontentready(Obj) {
215         //======== test si classe existe =============================
216         classID= Obj.uniqueID;
217         if (Obj.className.match(classID)) { return (false); }
218         if (!document.namespaces.v+classID) { document.namespaces.add("v"+classID, "urn:schemas-microsoft-com:vml"); }
219         Obj.className = Obj.className.concat(' ', classID);
220         // Find which element provides position:relative for the target element (default to BODY)
221 
222        pos=jQuery(Obj).findPos();
223        Left=pos.x;
224        Top=pos.y;
225        pos_src=jQuery(Obj.parentElement).findPos();
226
227    var limit = 100, i = 0;
228    var el = Obj; //(this) 
229           style= getStyles(el); 
230    strokeWeight = Get_stokeWeight( style.borderWidth);
231    strokeStyle  = Get_style( style.borderStyle);
232    strokeColor  = Get_Color( style.borderColor);
233
234         zindex = 3;
235         var El_src = el.element;
236
237         while ((typeof (El_src) != 'undefined') && ( getStyles(El_src).position != 'relative') && (El_src.tagName != 'BODY')) {
238             El_src = El_src.parentElement;
239             
240             if (El_src.style.zIndex> zindex) zindex++;
241             i++;
242             if (i >= limit) { return (false); }
243         }
244       
245
246         var el_zindex = parseInt(getStyles(el).zIndex);
247         if (isNaN(el_zindex)) { el_zindex = 3; }
248         var m = el.children;
249         for (i = 0; i < m.length; i++) {
250             echild = m.item(i);
251            echild.style.zIndex = el_zindex + 1  ;
252         }
253
254          Obj.style.zIndex = el_zindex+3 ;
255     
256
257         //=============================================================================       
258
259   
260         switch(getStyles(Obj).borderWidth)
261         {
262         case 'solid':
263            break;
264         default:
265         strokeWeight=parseInt(getStyles(Obj).borderWidth);
266             break;
267         }
268           
269         switch(getStyles(Obj).borderStyle)
270         {
271         case 'solid':
272         strokeStyle=getStyles(Obj).borderStyle;
273            break;
274        case 'double':
275        strokeStyle=getStyles(Obj).borderStyle;
276            break;
277
278         default:
279         strokeStyle=getStyles(Obj).borderStyle;
280
281             break;
282         }
283
284         if (isNaN(strokeWeight)) {
285             strokeWeight = 0;
286             
287         } 
288         stroked =( strokeWeight> 0);
289         
290
291         //================================================================================
292         for (var i = 0; i < 16; i++) {
293             for (var j = 0; j < 16; j++) {
294                 decToHex[i * 16 + j] = i.toString(16) + j.toString(16);
295             }
296         }
297         //==================================
298         var fillColor = translateColor(getStyles(Obj).backgroundColor);
299         var strokeColor =  translateColor(getStyles(Obj).borderColor);
300 
301
302         width=jQuery(Obj).width();
303         height=jQuery(Obj).height();
304              Width=(width+strokeWeight );
305     Height=(height+strokeWeight);
306
307         Left=parseInt(jQuery(Obj).css("left"));
308         if (isNaN(Left)) Left=0 ;
309         Top=parseInt(jQuery(Obj).css("top"));
310           if (isNaN(Top)) Top=0 ;
311   //=================================================================
312           s = getStyles(Obj);
313
314         if (typeof s.transform != "undefined") {
315             rotation = s['transform'];
316             var angle1 = s.transform.split("rotate(");
317             angle1 = angle1[1].split("deg)");
318             angle = angle1[0];
319         }
320         //=================================================================
321
322
323         var VgFillType = new Array("solid", "gradient", "gradientradial", "tile", "pattern", "frame");
324         var VgFillmethod = new Array("none", "linear", "sigma", "any");
325         var VgFillaspect = new Array("atless", "atmost")
326
327
328         alpha = getStyles(Obj)['opacity'] || 1;
329
330
331         var fillSrc = getStyles(Obj).backgroundImage.replace(/^url\("(.+)"\)$/, '$1');
332
333         if (fillSrc) var filltype = (getStyles(Obj)['type']) || "tile";
334         else var filltype = (getStyles(Obj)['type']) || "gradientRadial";
335  /*
336         var fillopacity = alpha;
337       
338         var fillmethod = "none";
339         var fillfocus = "100%";
340
341         var fillcolor2 = "#00FF00";
342         var fillcolors = "0,#ff0000, 0.5#00ff00, 0.6 #0000ff, 0.8 #ff0000, 0.9 #ff0000";
343
344         var fillopacity2 = "1.0";
345         var fillangle = "0";
346         var fillfocusposition = "0.5,0.5";
347         */
348       
349
350         //==================================================================================   
351         radius = s['-moz-border-radius'];
352
353
354         if (typeof radius == "undefined") { radius = "0" }
355         if (typeof radius == undefined) { radius = "" }
356                 
357         if (radius.match("\/")) {
358             //=============================================================
359
360             var tableau = radius.split("/");
361             var rect = document.createElement('v:oval');
362             var typeelement="oval";
363
364         } else {
365                   if (radius.match("\ ")) { 
366          var tableau = radius.split(" "); 
367
368          }
369
370  var tableau = radius.split(" "); 
371      tableau = radius + " " + radius + " " +tableau[0] +" " + tableau[0] + " " + tableau[0];   
372      tableau = tableau.split(" "); 
373      top_left = parseInt(s['-moz-border-top-left-radius']||tableau[0]) ;
374      top_right =  parseInt(s['-moz-border-top-right-radius']||tableau[1]);
375      bottom_right =  parseInt(s['-moz-border-radius-radius']||tableau[2]);
376      bottom_left =  parseInt(s['-moz-border-bottom-left-radius']||tableau[3]);       
377
378
379     radius=tableau[0];
380//=============================================================
381if (parseInt(radius) != "0") {
382    if (top_left!=top_right) {
383          var typeelement="shape";
384          var rect = document.createElement('v'+classID+':shape');     
385
386       with(rect){
387            fillColor = 'none'; 
388            fillStroked = 'true';
389             //   coordsize  = "100 , 100";
390             //    coordSize  = "100 , 100";
391               }
392     
393        rect.setAttribute("coordSize",Width + "," + Height); //mode7
394 TL =top_left ;
395 TR = top_right  ;
396 BR = bottom_right ;
397 BL =bottom_left ;
398
399
400
401 var Origine ={ x: Width - TR, y:0} ;
402 var TR_  ={ x: Width , y : 0 + TR} ;
403 var L1 ={ x: Width , y:Height-BR} ;
404 var BR_ ={ x: Width - BR, y:Height} ;
405 var L2 ={ x:BL, y:Height} ;
406 var BL_ ={ x:0 , y:Height-BL} ;
407 var L3 ={ x:0 , y:TL} ;
408 var TL_ ={ x:TL, y:0} ;
409 var L4 ={ x: Width - TR, y:0} ;
410
411 var path=" m "+ Origine.x +","+ Origine.y + 
412        " qx " + TR_.x + "," + TR_.y +
413        " l  " + L1.x + "," + L1.y +
414        " qy " + BR_.x + "," + BR_.y +
415        " l " + L2.x + "," + L2.y +
416        " qx "+ BL_.x + "," + BL_.y +
417        " l " + L3.x + "," + L3.y +
418        " qy "+ TL_.x + "," + TL_.y +
419        " l " + L4.x + "," + L4.y +
420        " x e";
421    rect.path=path ;
422
423 
424    }   else {       
425        var typeelement="roundrect";
426        var rect = document.createElement('v'+classID+':roundrect');
427        var arcSize = Math.min(parseInt(radius) / Math.min(Obj.offsetWidth, Obj.offsetHeight), 1);     
428        rect.arcsize = arcSize + 'px';
429        }
430  } else {
431                 var rect = document.createElement('v'+classID+':rect');
432                 var typeelement="rect";
433             }
434
435         }
436
437
438         /*===================================================================================*/
439         var text_shadow = getStyles(Obj)['text-shadow'];
440
441         var box_shadow = getStyles(Obj)['-moz-box-shadow'] ||
442                   getStyles(Obj)['box-shadow'] ||
443                   getStyles(Obj)['-webkit-box-shadow'] ||
444                   getStyles(Obj)['-khtml-box-shadow'];
445
446
447
448         if (text_shadow || box_shadow) {
449             if (text_shadow) {
450                 var sizeShadow = text_shadow.split(" ");
451                 aff_filter(Obj, sizeShadow);
452
453             }
454
455
456             if (box_shadow) {
457                 var sizeShadow = box_shadow.split(" ");
458                 aff_filter(rect, sizeShadow)
459             }
460
461         }
462         /*===================================================================================*/
463
464         var fill = document.createElement('v'+classID+':fill');
465
466         fill.src = fillSrc;
467         fill.color = fillColor;
468         fill.type = filltype;
469     
470
471/*
472         var fillopacity = alpha;
473if(fillopacity)      fill.opacity = fillopacity;
474
475         var fillmethod = "none";
476if (fillmethod) fill.method = fillmethod;
477
478         var fillfocus = "100%";
479         var fillcolor2 = "#00FF00";
480         var fillcolors = "0,#ff0000, 0.5#00ff00, 0.6 #0000ff, 0.8 #ff0000, 0.9 #ff0000";
481            if (fillfocus) fill.focus = fillfocus;
482            if (fillcolor2) fill.color2 = fillcolor2;
483            if (fillcolors) fill.colors = fillcolors;
484
485         var fillopacity2 = "1.0";
486         var fillangle = "0";
487         var fillfocusposition = "0.5,0.5";
488            if (fillopacity2) fill.opacity2 = fillopacity2;
489            if (fillangle) fill.angle = fillangle;
490            if (fillfocusposition) fill.focusposition = fillfocusposition;
491
492*/
493              jQuery(rect).width(Width  );
494              jQuery(rect).height(Height );
495               
496         rect.appendChild(fill);
497//================================================================
498         with(rect.style){
499                left=Left+(0.5*strokeWeight);
500                top=Top+(0.5*strokeWeight);
501                position="absolute"
502                display = 'block';
503                antialias = true;
504                zindex = el_zindex+3;
505
506             }
507//<v:stroke on="True" filltype="solid"
508 //   color="#9094C9" weight="8pt" />
509//   filltype="pattern" src="rond.gif" />
510
511if (stroked) {
512                    rect.strokecolor = strokeColor;
513                    rect.strokeWeight = strokeWeight + 'px';
514                    rect.stroked = stroked;
515   }
516        //================================================================
517document.body.appendChild(rect);
518  var css =  document.createStyleSheet(); 
519  var styleSheet = (document.styleSheets.length > 0) ? document.styleSheets[0] :  document.createStyleSheet();
520        //  css = styleSheet;
521//if (stroked)  css.addRule('v'+classID+"\\:stroke" , "behavior: url(#default#VML)");
522         css.addRule('v'+classID+"\\:"+typeelement, "behavior: url(#default#VML)");
523         css.addRule('v'+classID+"\\:fill", "behavior: url(#default#VML)");
524       //  css.addRule("v\\:*", "behavior: url(#default#VML)");
525         //=================================================================   
526   
527       
528
529          Obj.style.background =    'transparent';
530          Obj.style.borderColor = 'transparent';
531
532         isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
533         // IE6 doesn't support transparent borders, use padding to offset original element
534         if (isIE6 && (strokeWeight > 0)) {
535             Obj.style.borderStyle = 'none';
536             Obj.style.paddingTop = parseInt(getStyles(Obj).paddingTop || 0) + strokeWeight;
537             Obj.style.paddingBottom = parseInt(getStyles(Obj).paddingBottom || 0) + strokeWeight;
538         }
539
540
541   init_x = Left;
542   init_y = Top;
543   init_x0 = Left;
544   init_y0 = Top;
545
546        init_x  =parseInt(init_x)+strokeWeight;
547        init_y = parseInt(init_y)+strokeWeight;
548
549        init_x0  =parseInt(init_x);
550        init_y0 = parseInt(init_y);
551
552         Obj.vml = rect;
553
554//===============================================================================================
555         if (typeof (window.rounded_elements) == 'undefined') {
556             window.rounded_elements = new Array();
557
558             if (typeof (window.onresize) == 'function') { window.previous_onresize = window.onresize; }
559             window.onresize = window_resize;
560         }
561         window.rounded_elements[i]
562         window.rounded_elements.push(Obj);
563
564        // Resize(Obj.element);
565         obj = Obj;
566         init = false;
567    transform(obj)
568
569         Obj.attachEvent('onpropertychange', onPropertyChange);
570     }
571     //=====================================================================================
572     var Curwidth = 0;
573     var Curheight = 0;
574
575     function Resize(obj) {
576     return ;
577
578         var h0 = 0;
579         var strokeWeight = parseInt(getStyles(obj).borderWidth);
580         if (isNaN(strokeWeight)) { strokeWeight = 0; }
581
582
583         Size = findSize(obj);
584         //     obj.style.backgroundColor="green";
585
586         pos = findPos(obj);
587         var parent_pos = findPos(obj.vml.parentNode);
588         //var position = $(obj).position();
589         pos.y = pos.y + (0.5 * strokeWeight) - parent_pos.y;
590         pos.x = pos.x + (0.5 * strokeWeight) - parent_pos.x;
591         objvml = obj.vml;
592         objvml.style.top = pos.y + 'px';
593         objvml.style.left = pos.x + 'px';
594
595         //===================================================
596         if (Curwidth == 0) {
597             OldWidth =  objvml.offsetWidth;
598
599             OldHeight = objvml.offsetHeight;
600             Curwidth = obj.offsetWidth - strokeWeight;
601             Curheight =   obj.offsetHeight - strokeWeight;
602 
603         }
604
605         objvml.style.width= Curwidth ;
606         objvml.style.height=Curheight ;
607
608     }
609     //==================================================================================
610     function window_resize() {
611         if (typeof (window.rounded_elements) == 'undefined') { return (false); }
612         if (typeof (handle) == 'undefined') { return (false); }
613         old_handle = handle;
614         old_angle = nangle;
615         rotate(0, true)
616         Curwidth = 0;
617         for (var i in window.rounded_elements) {
618             Resize(window.rounded_elements[i]);
619         }
620
621         if (typeof (window.previous_onresize) == 'function') { window.previous_onresize(); }
622         nangle = old_angle
623         if (old_handle) toggleAnimation()
624
625     }
626     //=======================================================================================
627
628     function aff_filter(obj, sizeShadow) {
629     if (!obj) return ;
630
631         if (typeof obj == "string") var s = document.getElementById(obj).style;
632         else var s = obj.style;
633         Blur = 0;
634         ShadowColor = 0;
635         Horizontal = sizeShadow[0];
636         Vertical = sizeShadow[1];
637         if (sizeShadow.length > 2) Blur = sizeShadow[2]; //radius
638         if (sizeShadow.length > 3) ShadowColor = translateColor(sizeShadow[3]);
639
640
641         direction = 180 - Math.atan((parseInt(Horizontal)) / (parseInt(Vertical))) * 180 / Math.PI;
642         Strength = parseInt(Blur);
643         couleur = ShadowColor;
644
645         obj.style.filter = "progid:DXImageTransform.Microsoft.Shadow(color =" + couleur + ",Direction =" + direction + ",Strength = " + Strength + ") ";
646
647
648
649
650
651         return;
652
653     }
654
655     function hasSilverlight() {
656         try {
657             new ActiveXObject('AgControl.AgControl');
658             return true;
659         } catch (_) {
660             return false;
661         }
662     }
663
664     function getRgbHslContent(styleString) {
665         var start = styleString.indexOf('(', 3);
666         var end = styleString.indexOf(')', start + 1);
667         var parts = styleString.substring(start + 1, end).split(',');
668         // add alpha if needed
669         if (parts.length == 4 && styleString.substr(3, 1) == 'a') {
670             alpha = +parts[3];
671         } else {
672             parts[3] = 1;
673         }
674         return parts;
675     }
676
677     function percent(s) {
678         return parseFloat(s) / 100;
679     }
680
681     function clamp(v, min, max) {
682         return Math.min(max, Math.max(min, v));
683     }
684
685     function hslToRgb(parts) {
686         var r, g, b, h, s, l;
687         h = parseFloat(parts[0]) / 360 % 360;
688         if (h < 0)
689             h++;
690         s = clamp(percent(parts[1]), 0, 1);
691         l = clamp(percent(parts[2]), 0, 1);
692         if (s == 0) {
693             r = g = b = l; // achromatic
694         } else {
695             var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
696             var p = 2 * l - q;
697             r = hueToRgb(p, q, h + 1 / 3);
698             g = hueToRgb(p, q, h);
699             b = hueToRgb(p, q, h - 1 / 3);
700         }
701
702         return decToHex[Math.floor(r * 255)] +
703         decToHex[Math.floor(g * 255)] +
704         decToHex[Math.floor(b * 255)];
705     }
706
707     function hueToRgb(m1, m2, h) {
708         if (h < 0)
709             h++;
710         if (h > 1)
711             h--;
712
713         if (6 * h < 1)
714             return m1 + (m2 - m1) * 6 * h;
715         else if (2 * h < 1)
716             return m2;
717         else if (3 * h < 2)
718             return m1 + (m2 - m1) * (2 / 3 - h) * 6;
719         else
720             return m1;
721     }
722     function hexToDec(hex) {
723         return parseInt(hex, 16);
724     }
725
726
727     function translateColor(styleString) {
728         var str;
729         var n = 0;
730
731
732         styleString = String(styleString);
733         if (styleString.charAt(0) == '#') {
734             styleString = (styleString + "00000000").substring(0, 7);
735
736             return styleString;
737         } else if (/^rgb/.test(styleString)) {
738             var parts = getRgbHslContent(styleString);
739             var str = '', n;
740             for (var i = 0; i < 3; i++) {
741                 if (parts[i].indexOf('%') != -1) {
742                     n = Math.floor(percent(parts[i]) * 255);
743                 } else {
744                     n = +parts[i];
745                 }
746                 str += decToHex[clamp(n, 0, 255)];
747             }
748
749             alpha = parts[3];
750         } else if (/^hsl/.test(styleString)) {
751             var parts = getRgbHslContent(styleString);
752             str = hslToRgb(parts);
753             alpha = parts[3];
754         } else if (styleString in colorData) {
755             var exp = new RegExp(/^#/);
756
757             return colorData[styleString];
758
759
760
761         } else {
762
763
764             return styleString;
765
766
767         }
768         // decToHex[Math.floor(alpha * 255)] +
769         return '#' + str;
770     }         
771 
772      var colorData = {
773         aliceblue: '#F0F8FF',
774         antiquewhite: '#FAEBD7',
775         aquamarine: '#7FFFD4',
776         azure: '#F0FFFF',
777         beige: '#F5F5DC',
778         bisque: '#FFE4C4',
779         black: '#000000',
780         blanchedalmond: '#FFEBCD',
781         blueviolet: '#8A2BE2',
782         brown: '#A52A2A',
783         burlywood: '#DEB887',
784         cadetblue: '#5F9EA0',
785         chartreuse: '#7FFF00',
786         chocolate: '#D2691E',
787         coral: '#FF7F50',
788         cornflowerblue: '#6495ED',
789         cornsilk: '#FFF8DC',
790         crimson: '#DC143C',
791         cyan: '#00FFFF',
792         darkblue: '#00008B',
793         darkcyan: '#008B8B',
794         darkgoldenrod: '#B8860B',
795         darkgray: '#A9A9A9',
796         darkgreen: '#006400',
797         darkgrey: '#A9A9A9',
798         darkkhaki: '#BDB76B',
799         darkmagenta: '#8B008B',
800         darkolivegreen: '#556B2F',
801         darkorange: '#FF8C00',
802         darkorchid: '#9932CC',
803         darkred: '#8B0000',
804         darksalmon: '#E9967A',
805         darkseagreen: '#8FBC8F',
806         darkslateblue: '#483D8B',
807         darkslategray: '#2F4F4F',
808         darkslategrey: '#2F4F4F',
809         darkturquoise: '#00CED1',
810         darkviolet: '#9400D3',
811         deeppink: '#FF1493',
812         deepskyblue: '#00BFFF',
813         dimgray: '#696969',
814         dimgrey: '#696969',
815         dodgerblue: '#1E90FF',
816         firebrick: '#B22222',
817         floralwhite: '#FFFAF0',
818         forestgreen: '#228B22',
819         gainsboro: '#DCDCDC',
820         ghostwhite: '#F8F8FF',
821         gold: '#FFD700',
822         goldenrod: '#DAA520',
823         grey: '#808080',
824         greenyellow: '#ADFF2F',
825         honeydew: '#F0FFF0',
826         hotpink: '#FF69B4',
827         indianred: '#CD5C5C',
828         indigo: '#4B0082',
829         ivory: '#FFFFF0',
830         khaki: '#F0E68C',
831         lavender: '#E6E6FA',
832         lavenderblush: '#FFF0F5',
833         lawngreen: '#7CFC00',
834         lemonchiffon: '#FFFACD',
835         lightblue: '#ADD8E6',
836         lightcoral: '#F08080',
837         lightcyan: '#E0FFFF',
838         lightgoldenrodyellow: '#FAFAD2',
839         lightgreen: '#90EE90',
840         lightgrey: '#D3D3D3',
841         lightpink: '#FFB6C1',
842         lightsalmon: '#FFA07A',
843         lightseagreen: '#20B2AA',
844         lightskyblue: '#87CEFA',
845         lightslategray: '#778899',
846         lightslategrey: '#778899',
847         lightsteelblue: '#B0C4DE',
848         lightyellow: '#FFFFE0',
849         limegreen: '#32CD32',
850         linen: '#FAF0E6',
851         magenta: '#FF00FF',
852         mediumaquamarine: '#66CDAA',
853         mediumblue: '#0000CD',
854         mediumorchid: '#BA55D3',
855         mediumpurple: '#9370DB',
856         mediumseagreen: '#3CB371',
857         mediumslateblue: '#7B68EE',
858         mediumspringgreen: '#00FA9A',
859         mediumturquoise: '#48D1CC',
860         mediumvioletred: '#C71585',
861         midnightblue: '#191970',
862         mintcream: '#F5FFFA',
863         mistyrose: '#FFE4E1',
864         moccasin: '#FFE4B5',
865         navajowhite: '#FFDEAD',
866         oldlace: '#FDF5E6',
867         olivedrab: '#6B8E23',
868         orange: '#FFA500',
869         orangered: '#FF4500',
870         orchid: '#DA70D6',
871         palegoldenrod: '#EEE8AA',
872         palegreen: '#98FB98',
873         paleturquoise: '#AFEEEE',
874         palevioletred: '#DB7093',
875         papayawhip: '#FFEFD5',
876         peachpuff: '#FFDAB9',
877         peru: '#CD853F',
878         pink: '#FFC0CB',
879         plum: '#DDA0DD',
880         powderblue: '#B0E0E6',
881         rosybrown: '#BC8F8F',
882         royalblue: '#4169E1',
883         saddlebrown: '#8B4513',
884         salmon: '#FA8072',
885         sandybrown: '#F4A460',
886         seagreen: '#2E8B57',
887         seashell: '#FFF5EE',
888         sienna: '#A0522D',
889         skyblue: '#87CEEB',
890         slateblue: '#6A5ACD',
891         slategray: '#708090',
892         slategrey: '#708090',
893         snow: '#FFFAFA',
894         springgreen: '#00FF7F',
895         steelblue: '#4682B4',
896         tan: '#D2B48C',
897         thistle: '#D8BFD8',
898         tomato: '#FF6347',
899         turquoise: '#40E0D0',
900         violet: '#EE82EE',
901         wheat: '#F5DEB3',
902         whitesmoke: '#F5F5F5',
903         yellowgreen: '#9ACD32'
904     };
905//=====================================================================
906// Ajoute une fonctionnalité jQuery
907jQuery.extend(jQuery.expr[':'], {
908        // Nom du sélecteur personnalisé
909        Radius: function (a) {
910            if (!jQuery.browser.msie) return;
911             
912    s= getStyles(a);
913           var moz = s['-moz-border-radius'] !== undefined   ;
914            var webkit = s['-webkit-border-radius'] !== undefined;
915            var radius = s['border-radius'] !== undefined ||s['border-Radius'] !== undefined || s['Border-Radius'] !== undefined;
916
917            var mode = document.documentMode || 0;
918            var noBottomFold = jQuery.browser.msie && ((jQuery.browser.version < 8 && !mode) || mode < 8);
919
920            // Eléments correspondant
921       Attribut = s[radius ? 'border-radius' : moz ? '-moz-border-radius' : '-webkit-border-radius'];
922            if (Attribut != undefined) {
923                jQuery(a).crossbrowser(a);
924                 
925            }
926            return false;
927
928        }
929    });
930 //==============================================================================
931jQuery.fn.extend({
932   findPos : function() {
933 if(jQuery(this).length==0)  return {x:0,y:0};
934       obj = jQuery(this).get(0);
935       var curleft = obj.offsetLeft || 0;
936       var curtop = obj.offsetTop || 0;
937       while (obj = obj.offsetParent) {
938                curleft += obj.offsetLeft
939                curtop += obj.offsetTop
940       }
941       return {x:curleft,y:curtop};
942   }
943});
944 //==============================================================================       
945jQuery.fn.crossbrowser = function (options) {
946         oncontentready(options);
947 }
948 
949})(jQuery);
950//================================================================================
951 
952
953
954jQuery(document).ready(function () {
955
956 jQuery(':Radius');
957
958
959});
960
961
962//====================================================================
963function Get_Tableau(Val_src) {
964    Val_src = removeExtraSpace(Val_src)
965    var tableau = Val_src.split(" ");
966    tableau = Val_src + " " + Val_src + " " + tableau[0] + " " + tableau[0];
967    tableau = tableau.split(" ");
968    return { Top: tableau[0], Right: tableau[1], Bottom: tableau[2], Left: tableau[3] };
969}
970//============================================================
971function Get_radius(obj) {
972    /*
973    1 La valeur spécifiée est appliquée aux quatre coins.
974    2 La première valeur est appliquée aux coins supérieur gauche et inférieur droit, et la seconde, aux coins supérieur droit et inférieur gauche 
975    3 La première valeur est appliquée au coin supérieur gauche, la deuxième aux coins supérieur droit et inférieur gauche, et la troisième, au coin inférieur droit 
976    4 Les angles supérieur gauche, supérieur droit, inférieur droit et inférieur gauche sont respectivement définis 
977    */
978
979    var m1 = "border-radius,-o-border-radius,-moz-border-radius,-webkit-border-radius,star";
980    m1 += ",borderRadius,OBorderRadius,MozBorderRadius,WebkitBorderRadius,star";
981
982    $e = jQuery(obj);
983    m1 = m1.split(",");
984    s = obj.currentStyle;
985    // s = obj.style.cssText.split(";");
986
987    Attribut = false;
988    type = "";
989    for (i in m1)
990        if (s[m1[i]] != undefined) {
991            Attribut = true;
992            radius = s[m1[i]];
993            type = m1[i];
994            break;
995        }
996    if (typeof radius == "undefined") { radius = "0" }
997    var reg = new RegExp("\ \ ", "g");
998    nr = radius;
999    while (radius.match("\/")) {
1000        radius = radius.replace("\/", " ");
1001    }
1002
1003    while (radius.match("\ \ ")) {
1004        radius = radius.replace(reg, " ");
1005    }
1006
1007    if (type.match("star")) {
1008        var radius = (radius + " " + 1)
1009        var tableau = radius.split(" ");
1010        return { r: tableau[0],
1011            type: type
1012        }
1013    }
1014
1015
1016    v1 = Get_Tableau(radius);
1017
1018
1019
1020    top_left = parseInt(s['border-top-left-radius'] || v1.Top);
1021    top_right = parseInt(s['border-top-right-radius'] || v1.Right);
1022    bottom_right = parseInt(s['border-bottom-right-radius'] || v1.Bottom);
1023    bottom_left = parseInt(s['border-bottom-left-radius'] || v1.Left);
1024
1025
1026
1027    type = (nr.match("\/")) ? "oval" : (parseInt(v1.Left) == 0) ? "rect" : "shape";
1028
1029    return { r: v1.Left,
1030        top_left: top_left,
1031        top_right: top_right,
1032        bottom_right: bottom_right,
1033        bottom_left: bottom_left,
1034        type: type
1035    };
1036
1037}
1038//=======================================================================================
1039/*
1040Single (default)
1041ThinThin
1042ThinThick
1043ThickThin
1044ThickBetweenThin
1045*/
1046function Get_style(borderStyle_src) {
1047 strokeStyle=[];
1048    v1 = Get_Tableau(borderStyle_src);
1049
1050    for (i1 in v1) {
1051        borderStyle = v1[i1];
1052
1053
1054        switch (borderStyle) {
1055            case 'solid':
1056                strokeStyle[i1] = "Single";
1057                break;
1058            case 'double':
1059                strokeStyle[i1] = "thinThin";
1060                break;
1061            case 'none':
1062                strokeStyle[i1] = "Single";
1063                stroked = false
1064                break;
1065            default:
1066                strokeStyle[i1] = "Single";
1067
1068                break;
1069        }
1070
1071    }
1072    return strokeStyle;
1073}
1074
1075//=============================================================
1076function Get_Color(Color_src) {
1077strokeColor=[i1];
1078if(typeof translateColor=="undefined") return strokeColor;
1079    v1 = Get_Tableau(Color_src);
1080    for (i1 in v1) {
1081        strokeColor[i1] = (translateColor(v1[i1]) == "transparent") ? "none" : translateColor(v1[i1]);
1082
1083    }
1084
1085    return strokeColor;
1086}
1087
1088//=============================================================
1089function Get_stokeWeight(Weight_src) {
1090strokeWeight=[];
1091    v1 = Get_Tableau(Weight_src);
1092    stroked = false;
1093    for (i1 in v1) {
1094        Weight = v1[i1];
1095        p1 = Weight.match("%")
1096
1097        switch (Weight) {
1098            case p1:
1099                strokeWeight[i1] = 10;
1100                break;
1101            case 'thin':
1102                strokeWeight[i1] = 0.5;
1103                break;
1104            case 'medium':
1105                strokeWeight[i1] = 0.75;
1106                break;
1107            case 'thick':
1108                strokeWeight[i1] = 2;
1109                break;
1110            case 'inherit':
1111                if (Obj.parentElement)
1112                    strokeWeight[i1] = Get_stokeWeight(Obj.parentElement.currentStyle.borderWidth);
1113                else
1114                    strokeWeight[i1] = 0;
1115
1116                break;
1117
1118            default:
1119
1120           if( Weight!="")    strokeWeight[i1] = Weight;
1121                break;
1122        }
1123        strokeWeight[i1] = parseInt(strokeWeight[i1]);
1124        if (isNaN(strokeWeight[i1])) {
1125            strokeWeight[i1] = 0;
1126        }
1127
1128        stroked = (strokeWeight[i1] > 0) ? true : stroked;
1129    }
1130    return strokeWeight;
1131
1132}
1133
1134// Récupérer la valeur d'une propriété CSS d'un élément id
1135function getStyle(elt, pro) {
1136    var element = document.getElementById(elt);
1137    if (window.getComputedStyle) // Mozilla Firefox & cie
1138    {
1139        var propriete = window.getComputedStyle(element, null).getPropertyValue(pro);
1140    }
1141    else if (element.currentStyle) // Microsoft Internet Explorer
1142    {
1143        // Formatage (IE) de la propriété CSS
1144        while (pro.indexOf('-') != -1) {
1145            var lettresuivtiret = pro.charAt(pro.indexOf('-') + 1);
1146            pro = pro.replace(/-\S{1}/, lettresuivtiret.toUpperCase());
1147        }
1148        var propriete = eval('element.currentStyle.' + pro);
1149    }
1150    return propriete;
1151}
1152// Récupérer la valeur CSS
1153function getStyles(elt) {
1154    var element = elt;
1155    if (window.getComputedStyle) // Mozilla Firefox & cie
1156    {
1157        var propriete = window.getComputedStyle(element, null);
1158    }
1159    else if (element.currentStyle) // Microsoft Internet Explorer
1160    {
1161
1162        var propriete = element.currentStyle;
1163    }
1164    return propriete;
1165  }
1166  function removeExtraSpace(str) {
1167    str = str.replace(/[\s]{2,}/g, " "); // Enlève les espaces doubles, triples, etc.
1168    str = str.replace(/^[\s]/, ""); // Enlève les espaces au début
1169    str = str.replace(/[\s]$/, ""); // Enlève les espaces à la fin
1170    return str;
1171  }
Note: See TracBrowser for help on using the repository browser.