Dotclear

Changeset 15


Ignore:
Timestamp:
03/03/08 10:24:05 (16 years ago)
Author:
olivier
Message:

JS update on Upian-Krome themes.

Location:
themes
Files:
8 added
11 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • themes/friendly/behavior.js

    r9 r15  
    1 // JavaScript Document 
    2 window.onload=function(){ 
    3  
    4      init(); 
    5  
    6      if(!NiftyCheck()) 
    7     return; 
    8       
    9      Rounded("p.post-info-co","all","#fff","transparent"); 
    10      Rounded("div#calendar","all","#F5F6FA","#fff"); 
    11      Rounded("div#tb","all","#fff","transparent"); 
    12      Rounded("div#co","all","#fff","transparent"); 
    13       
    14 } 
    15  
    16  
    17 function NiftyCheck(){ 
    18 if(!document.getElementById || !document.createElement) 
    19     return(false); 
    20 isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName); 
    21 if(Array.prototype.push==null){Array.prototype.push=function(){ 
    22       this[this.length]=arguments[0]; return(this.length);}} 
    23 return(true); 
    24 } 
    25  
    26 function Rounded(selector,wich,bk,color,opt){ 
    27 var i,prefixt,prefixb,cn="r",ecolor="",edges=false,eclass="",b=false,t=false; 
    28  
    29 if(color=="transparent"){ 
    30     cn=cn+"x"; 
    31     ecolor=bk; 
    32     bk="transparent"; 
    33     } 
    34 else if(opt && opt.indexOf("border")>=0){ 
    35     var optar=opt.split(" "); 
    36     for(i=0;i<optar.length;i++) 
    37         if(optar[i].indexOf("#")>=0) ecolor=optar[i]; 
    38     if(ecolor=="") ecolor="#666"; 
    39     cn+="e"; 
    40     edges=true; 
    41     } 
    42 else if(opt && opt.indexOf("smooth")>=0){ 
    43     cn+="a"; 
    44     ecolor=Mix(bk,color); 
    45     } 
    46 if(opt && opt.indexOf("small")>=0) cn+="s"; 
    47 prefixt=cn; 
    48 prefixb=cn; 
    49 if(wich.indexOf("all")>=0){t=true;b=true} 
    50 else if(wich.indexOf("top")>=0) t="true"; 
    51 else if(wich.indexOf("tl")>=0){ 
    52     t="true"; 
    53     if(wich.indexOf("tr")<0) prefixt+="l"; 
    54     } 
    55 else if(wich.indexOf("tr")>=0){ 
    56     t="true"; 
    57     prefixt+="r"; 
    58     } 
    59 if(wich.indexOf("bottom")>=0) b=true; 
    60 else if(wich.indexOf("bl")>=0){ 
    61     b="true"; 
    62     if(wich.indexOf("br")<0) prefixb+="l"; 
    63     } 
    64 else if(wich.indexOf("br")>=0){ 
    65     b="true"; 
    66     prefixb+="r"; 
    67     } 
    68 var v=getElementsBySelector(selector); 
    69 var l=v.length; 
    70 for(i=0;i<l;i++){ 
    71     if(edges) AddBorder(v[i],ecolor); 
    72     if(t) AddTop(v[i],bk,color,ecolor,prefixt); 
    73     if(b) AddBottom(v[i],bk,color,ecolor,prefixb); 
    74     } 
    75 } 
    76  
    77 function AddBorder(el,bc){ 
    78 var i; 
    79 if(!el.passed){ 
    80     if(el.childNodes.length==1 && el.childNodes[0].nodeType==3){ 
    81         var t=el.firstChild.nodeValue; 
    82         el.removeChild(el.lastChild); 
    83         var d=CreateEl("span"); 
    84         d.style.display="block"; 
    85         d.appendChild(document.createTextNode(t)); 
    86         el.appendChild(d); 
     1$(function() { 
     2     if ($('#content').height() < 925) { 
     3          $('#content').css('height','925px'); 
     4     } 
     5      
     6     $('.post-info-co').corner('#fff 6px'); 
     7     $('#comments dd').corner('#fff 10px'); 
     8     $('#pings dd').corner('#fff 10px'); 
     9}); 
     10 
     11// jquery-roundcorners-canvas 
     12// www.meerbox.nl 
     13 
     14(function($){ 
     15      
     16     var _corner = function(options) { 
     17      
     18          // nothing to do, so return 
     19          if (this.length==0) return this; 
     20           
     21          // excanvas.js not loaded 
     22          if ($.browser.msie && typeof G_vmlCanvasManager == 'undefined') return this; 
     23           
     24          // get lowest number from array 
     25          var asNum = function(a, b) { return a-b; }; 
     26          var getMin = function(a) { 
     27               var b = a.concat(); 
     28               return b.sort(asNum)[0]; 
     29          }; 
     30           
     31          // get CSS value as integer 
     32          var getCSSint = function(el, prop) { 
     33               return parseInt($.css(el.jquery?el[0]:el,prop))||0; 
     34          }; 
     35                
     36          // draw the round corner in Canvas object 
     37          var drawRoundCornerCanvasShape = function(canvas,radius,r_type,bg_color,border_width,border_color) { 
     38                
     39               // change rgba(1,2,3,0.9) to rgb(1,2,3) 
     40               var reg = /^rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/;    
     41               var bits = reg.exec(bg_color); 
     42               if (bits) { 
     43                    channels = new Array(parseInt(bits[1]),parseInt(bits[2]),parseInt(bits[3])); 
     44                    bg_color = 'rgb('+channels[0]+', '+channels[1]+', '+channels[2]+')'; 
     45               }  
     46           
     47               var border_width = parseInt(border_width); 
     48                
     49               var ctx = canvas.getContext('2d'); 
     50                
     51               if (radius == 1) { 
     52                    ctx.fillStyle = bg_color; 
     53                    ctx.fillRect(0,0,1,1); 
     54                    return; 
     55               } 
     56      
     57               if (r_type == 'tl') { 
     58                    var steps = new Array(0,0,radius,0,radius,0,0,radius,0,0); 
     59               } else if (r_type == 'tr') { 
     60                    var steps = new Array(radius,0,radius,radius,radius,0,0,0,0,0); 
     61               } else if (r_type == 'bl') { 
     62                    var steps = new Array(0,radius,radius,radius,0,radius,0,0,0,radius); 
     63               } else if (r_type == 'br') { 
     64                    var steps = new Array(radius,radius,radius,0,radius,0,0,radius,radius,radius); 
     65               } 
     66                
     67               ctx.fillStyle = bg_color; 
     68          ctx.beginPath(); 
     69               ctx.moveTo(steps[0],steps[1]);  
     70               ctx.lineTo(steps[2], steps[3]);  
     71          if(r_type == 'br') ctx.bezierCurveTo(steps[4], steps[5], radius, radius, steps[6], steps[7]);  
     72          else ctx.bezierCurveTo(steps[4], steps[5], 0, 0, steps[6], steps[7]); 
     73               ctx.lineTo(steps[8], steps[9]);  
     74             ctx.fill();  
     75              
     76             // draw border 
     77             if (border_width > 0 && border_width < radius) { 
     78                   
     79                  // offset caused by border 
     80                  var offset = border_width/2;  
     81                   
     82                  if (r_type == 'tl') { 
     83                         var steps = new Array(radius-offset,offset,radius-offset,offset,offset,radius-offset); 
     84                         var curve_to = new Array(0,0); 
     85                    } else if (r_type == 'tr') { 
     86                         var steps = new Array(radius-offset,radius-offset,radius-offset,offset,offset,offset); 
     87                         var curve_to = new Array(0,0); 
     88                    } else if (r_type == 'bl') { 
     89                         var steps = new Array(radius-offset,radius-offset,offset,radius-offset,offset,offset,offset,radius-offset); 
     90                         var curve_to = new Array(0,0); 
     91                    } else if (r_type == 'br') { 
     92                         var steps = new Array(radius-offset,offset,radius-offset,offset,offset,radius-offset,radius-offset,radius-offset); 
     93                         var curve_to = new Array(radius, radius); 
     94                    } 
     95                   
     96                  ctx.strokeStyle = border_color; 
     97                  ctx.lineWidth = border_width; 
     98               ctx.beginPath(); 
     99               // go to corner to begin curve 
     100                    ctx.moveTo(steps[0], steps[1]);  
     101                    // curve from righttop to leftbottom (for the tl canvas) 
     102               ctx.bezierCurveTo(steps[2], steps[3], curve_to[0], curve_to[1], steps[4], steps[5]);  
     103                    ctx.stroke(); 
     104                   
     105              } 
     106          }; 
     107           
     108          var creatCanvas = function(p,radius) { 
     109               var elm = document.createElement('canvas'); 
     110               elm.setAttribute("height", radius); 
     111          elm.setAttribute("width", radius);  
     112               elm.style.display = "block"; 
     113               elm.style.position = "absolute"; 
     114               elm.className = "cornercanvas"; 
     115               elm = p.appendChild(elm);  
     116               if (!elm.getContext && typeof G_vmlCanvasManager != 'undefined') { 
     117                    elm = G_vmlCanvasManager.initElement(elm); 
     118               } 
     119               return elm; 
     120          }; 
     121           
     122          // interpret the (string) argument 
     123          var o = (options || "").toLowerCase(); 
     124          var radius = parseInt((o.match(/(\d+)px/)||[])[1]) || null; // corner width 
     125          var bg_color = ((o.match(/(#[0-9a-f]+)/)||[])[1]);  // strip color 
     126          if (radius == null) { radius = "auto"; } 
     127           
     128          var edges = { T:0, B:1 }; 
     129     var opts = { 
     130          tl:  /top|tl/.test(o),        
     131          tr:  /top|tr/.test(o), 
     132          bl:  /bottom|bl/.test(o),     
     133          br:  /bottom|br/.test(o) 
     134     }; 
     135     if ( !opts.tl && !opts.tr && !opts.bl && !opts.br) { 
     136          opts = { tl:1, tr:1, bl:1, br:1 }; 
    87137        } 
    88     for(i=0;i<el.childNodes.length;i++){ 
    89         if(el.childNodes[i].nodeType==1){ 
    90             el.childNodes[i].style.borderLeft="1px solid "+bc; 
    91             el.childNodes[i].style.borderRight="1px solid "+bc; 
    92             } 
    93         } 
    94     } 
    95 el.passed=true; 
    96 } 
    97      
    98 function AddTop(el,bk,color,bc,cn){ 
    99 var i,lim=4,d=CreateEl("b"); 
    100  
    101 if(cn.indexOf("s")>=0) lim=2; 
    102 if(bc) d.className="artop"; 
    103 else d.className="rtop"; 
    104 d.style.backgroundColor=bk; 
    105 for(i=1;i<=lim;i++){ 
    106     var x=CreateEl("b"); 
    107     x.className=cn + i; 
    108     x.style.backgroundColor=color; 
    109     if(bc) x.style.borderColor=bc; 
    110     d.appendChild(x); 
    111     } 
    112 el.style.paddingTop=0; 
    113 el.insertBefore(d,el.firstChild); 
    114 } 
    115  
    116 function AddBottom(el,bk,color,bc,cn){ 
    117 var i,lim=4,d=CreateEl("b"); 
    118  
    119 if(cn.indexOf("s")>=0) lim=2; 
    120 if(bc) d.className="artop"; 
    121 else d.className="rtop"; 
    122 d.style.backgroundColor=bk; 
    123 for(i=lim;i>0;i--){ 
    124     var x=CreateEl("b"); 
    125     x.className=cn + i; 
    126     x.style.backgroundColor=color; 
    127     if(bc) x.style.borderColor=bc; 
    128     d.appendChild(x); 
    129     } 
    130 el.style.paddingBottom=0; 
    131 el.appendChild(d); 
    132 } 
    133  
    134 function CreateEl(x){ 
    135 if(isXHTML) return(document.createElementNS('http://www.w3.org/1999/xhtml',x)); 
    136 else return(document.createElement(x)); 
    137 } 
    138  
    139 function getElementsBySelector(selector){ 
    140 var i,selid="",selclass="",tag=selector,f,s=[],objlist=[]; 
    141  
    142 if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag" 
    143     s=selector.split(" "); 
    144     var fs=s[0].split("#"); 
    145     if(fs.length==1) return(objlist); 
    146     f=document.getElementById(fs[1]); 
    147     if(f) return(f.getElementsByTagName(s[1])); 
    148     return(objlist); 
    149     } 
    150 if(selector.indexOf("#")>0){ //id selector like "tag#id" 
    151     s=selector.split("#"); 
    152     tag=s[0]; 
    153     selid=s[1]; 
    154     } 
    155 if(selid!=""){ 
    156     f=document.getElementById(selid); 
    157     if(f) objlist.push(f); 
    158     return(objlist); 
    159     } 
    160 if(selector.indexOf(".")>0){  //class selector like "tag.class" 
    161     s=selector.split("."); 
    162     tag=s[0]; 
    163     selclass=s[1]; 
    164     } 
    165 var v=document.getElementsByTagName(tag);  // tag selector like "tag" 
    166 if(selclass=="") 
    167     return(v); 
    168 for(i=0;i<v.length;i++){ 
    169     if(v[i].className.indexOf(selclass)>=0){ 
    170         objlist.push(v[i]); 
    171         } 
    172     } 
    173 return(objlist); 
    174 } 
    175  
    176 function Mix(c1,c2){ 
    177 var i,step1,step2,x,y,r=new Array(3); 
    178 if(c1.length==4)step1=1; 
    179 else step1=2; 
    180 if(c2.length==4) step2=1; 
    181 else step2=2; 
    182 for(i=0;i<3;i++){ 
    183     x=parseInt(c1.substr(1+step1*i,step1),16); 
    184     if(step1==1) x=16*x+x; 
    185     y=parseInt(c2.substr(1+step2*i,step2),16); 
    186     if(step2==1) y=16*y+y; 
    187     r[i]=Math.floor((x*50+y*50)/100); 
    188     } 
    189 return("#"+r[0].toString(16)+r[1].toString(16)+r[2].toString(16)); 
    190 } 
    191  
    192 /***********************************************************************************************************************/ 
    193 function $() 
    194 { 
    195   var elements = new Array(); 
    196  
    197   for (var i = 0; i < arguments.length; i++) { 
    198     var element = arguments[i]; 
    199     if (typeof element == 'string') 
    200       element = document.getElementById(element); 
    201  
    202     if (arguments.length == 1) 
    203       return element; 
    204  
    205     elements.push(element); 
    206   } 
    207  
    208   return elements; 
    209 } 
    210  
    211 Object.extend = function(destination, source) { 
    212   for (property in source) { 
    213     destination[property] = source[property]; 
    214   } 
    215   return destination; 
    216 } 
    217  
    218 if (!window.Element) { 
    219   var Element = new Object(); 
    220 } 
    221  
    222 Object.extend(Element, { 
    223    
    224   getHeight: function(element) { 
    225     element = $(element); 
    226     return element.offsetHeight; 
    227   } 
    228  
    229 }); 
    230  
    231 function getTotalHeight() 
    232 { 
    233      if (self.innerHeight) { 
    234           return parseInt(self.innerHeight); 
    235      } else if (document.documentElement && document.documentElement.clientHeight) { 
    236           return document.documentElement.clientHeight; 
    237      } else if (document.body) { 
    238           return document.body.clientHeight; 
    239      } 
    240 } 
    241  
    242 function init() 
    243 { 
    244    
    245   if( Element.getHeight('content') < 925 ) { 
    246     $('content').style.height = '925px'; 
    247   } 
    248    
    249   var divs = $('blognav').getElementsByTagName('div'); 
    250   j=0; 
    251   for(i=0;i<divs.length;i++) { 
    252        j++; 
    253     /*if(i == 0) { 
    254       if(i%2 != 1) 
    255         divs[i].className = 'first-odd'; 
    256       else 
    257         divs[i].className = 'first'; 
    258     } else if(i == divs.length - 1) { 
    259       if(i%2 != 1) 
    260         divs[i].className = 'last-odd'; 
    261       else 
    262         divs[i].className = 'last'; 
    263     } else { 
    264       if(i%2 != 1) 
    265         divs[i].className = 'odd'; 
    266     }*/ 
    267      if(j==2){ 
    268           divs[i].className = 'odd'; 
    269           j=0; 
    270      } 
    271   } 
    272  
    273   var divs = $('blogextra').getElementsByTagName('div'); 
    274   p=0; 
    275   for(i=0;i<divs.length;i++) { 
    276        p++; 
    277     /*if(i == 0) { 
    278       if(i%2 != 0) 
    279         divs[i].className = 'first-odd'; 
    280       else 
    281         divs[i].className = 'first'; 
    282     } else if(i == divs.length - 1) { 
    283       if(i%2 != 0) 
    284         divs[i].className = 'last-odd'; 
    285       else 
    286         divs[i].className = 'last'; 
    287     } else { 
    288       if(i%2 != 0) 
    289         divs[i].className = 'odd'; 
    290     }*/ 
    291      if(p==2){ 
    292           divs[i].className = 'odd'; 
    293           p=0; 
    294      } 
    295   } 
    296  
    297 } 
    298  
    299 //window.onload = init 
    300 //window.onresize = init 
     138       
     139          return this.each(function() { 
     140 
     141               var elm = $(this); 
     142               var hover = /hover/.test(o); 
     143                
     144               if (hover) { 
     145                     
     146                    options = options.replace(/hover/i, ""); 
     147                     
     148                    elm.hover(function(){ 
     149                         $(this).addClass('jrcHover'); 
     150                         $(this).corner(options); 
     151                    },function(){ 
     152                         $(this).removeClass('jrcHover');    
     153                         $(this).corner(options); 
     154                    }); 
     155                     
     156               } 
     157                
     158               if ($.browser.msie) {  
     159 
     160                    // give element 'haslayout' 
     161                    elm.css('zoom','1'); 
     162                    // give the child elements 'haslayout' 
     163                    elm.children().css('zoom','1'); 
     164                     
     165                    if (elm.css('height') == 'auto') elm.height(elm.height()); 
     166                     
     167                    // msie6 rendering bugs :( 
     168                    if ($.browser.msie && typeof document.body.style.maxHeight == "undefined") { 
     169                         if (elm.width()%2 != 0) { elm.width(elm.width()+1); } 
     170                         if (elm.height()%2 != 0) { elm.height(elm.height()+1); } 
     171                         if (elm.css('lineHeight') != 'normal' && elm.height() < elm.css('lineHeight')) { 
     172                              elm.css('lineHeight', elm.height()); 
     173                         } 
     174                         if (elm.css('lineHeight') == 'normal') elm.css('lineHeight','1'); // dont ask 
     175                    } 
     176               } 
     177                
     178               var arr = new Array(elm.get(0).offsetHeight,elm.get(0).offsetWidth); 
     179               if (elm.height() != 0) arr[arr.length] = elm.height(); 
     180               if (elm.width() != 0) arr[arr.length] = elm.width(); 
     181               var widthheight_smallest = getMin(arr); 
     182                
     183               // the size of the corner is not defined... 
     184               if (radius == "auto") { 
     185                    radius = widthheight_smallest/2; 
     186                    if (radius > 10) { radius = 10; } 
     187               } 
     188 
     189               // the size of the corner can't be to high 
     190               if (radius > widthheight_smallest/2) {  
     191                    radius = (widthheight_smallest/2);  
     192               } 
     193                
     194               radius = Math.floor(radius); 
     195                
     196               // some css thats required in order to position the canvas elements 
     197               if (elm.css('position') == 'static') {  
     198                    elm.css('position','relative');  
     199               // only needed for ie6 and (ie7 in Quirks mode) , CSS1Compat == Strict mode 
     200               } else if (elm.css('position') == 'fixed' && $.browser.msie && !(document.compatMode == 'CSS1Compat' && typeof document.body.style.maxHeight != "undefined")) {  
     201                    elm.css('position','absolute'); 
     202               } 
     203               elm.css('overflow','visible');  
     204                
     205               // get border width 
     206               var border_t = getCSSint(this, 'borderTopWidth'); 
     207               var border_r = getCSSint(this, 'borderRightWidth'); 
     208               var border_b = getCSSint(this, 'borderBottomWidth'); 
     209               var border_l = getCSSint(this, 'borderLeftWidth'); 
     210                
     211               // get the lowest borderwidth of the corners in use 
     212               var bordersWidth = new Array(); 
     213               if (opts.tl || opts.tr) { bordersWidth.push(border_t); } 
     214               if (opts.br || opts.tr) { bordersWidth.push(border_r); } 
     215               if (opts.br || opts.bl) { bordersWidth.push(border_b); } 
     216               if (opts.bl || opts.tl) { bordersWidth.push(border_l); } 
     217                
     218               var borderswidth_smallest = getMin(bordersWidth); 
     219                
     220               // creat the canvas elements and position them 
     221               var p_top = 0-border_t; 
     222               var p_right = 0-border_r; 
     223               var p_bottom = 0-border_b; 
     224               var p_left = 0-border_l;  
     225                
     226               // remove old stuff 
     227               elm.children("canvas.cornercanvas").remove(); 
     228 
     229               if (opts.tl) { var tl = $(creatCanvas(this,radius)).css({left:p_left,top:p_top}).get(0); } 
     230               if (opts.tr) { var tr = $(creatCanvas(this,radius)).css({right:p_right,top:p_top}).get(0); } 
     231               if (opts.bl) { var bl = $(creatCanvas(this,radius)).css({left:p_left,bottom:p_bottom}).get(0); } 
     232               if (opts.br) { var br = $(creatCanvas(this,radius)).css({right:p_right,bottom:p_bottom}).get(0); } 
     233                
     234               // get the background color of parent element 
     235               if (bg_color == undefined) { 
     236                    var current_p = elm.parent(); 
     237                    var bg = current_p.css('background-color'); 
     238                    while((bg == "transparent" || bg == "rgba(0, 0, 0, 0)") && (typeof current_p == 'object') && !current_p.is("html")) { 
     239                         bg = current_p.css('background-color'); 
     240                         current_p = current_p.parent(); 
     241                    } 
     242                     
     243               } else { 
     244                    bg = bg_color; 
     245               } 
     246 
     247               if (bg == "transparent" || bg == "rgba(0, 0, 0, 0)") { bg = "#ffffff"; } 
     248                
     249               if (opts.tl) { drawRoundCornerCanvasShape(tl,radius,'tl',bg,borderswidth_smallest,elm.css('borderTopColor')); } 
     250               if (opts.tr) { drawRoundCornerCanvasShape(tr,radius,'tr',bg,borderswidth_smallest,elm.css('borderTopColor')); } 
     251               if (opts.bl) { drawRoundCornerCanvasShape(bl,radius,'bl',bg,borderswidth_smallest,elm.css('borderBottomColor')); } 
     252               if (opts.br) { drawRoundCornerCanvasShape(br,radius,'br',bg,borderswidth_smallest,elm.css('borderBottomColor')); } 
     253                
     254               elm.addClass('roundCornersParent'); 
     255                     
     256          });   
     257     }; 
     258      
     259     $.fn.corner = _corner; 
     260      
     261})(jQuery); 
  • themes/ktouch/behavior.js

    r11 r15  
    1 // JavaScript Document 
    2 window.onload=function(){ 
    3  
    4      if(!NiftyCheck()) 
    5     return; 
    6       
    7      Rounded("div#search","all","#c00000","transparent"); 
    8      Rounded("div#topnav","all","#c00000","transparent"); 
    9      Rounded("div.tags","all","#c00000","transparent"); 
    10      Rounded("div.syndicate","all","#c00000","transparent"); 
    11      Rounded("div.selected","all","#c00000","transparent"); 
    12      Rounded("div.categories","all","#c00000","transparent"); 
    13      Rounded("div.links","all","#c00000","transparent"); 
    14      Rounded("div.feed","all","#c00000","transparent"); 
    15       
    16      //Rounded("div.post","tltr","#c00000","transparent"); 
    17      /*Rounded("div.post-content","all","transparent","transparent"); 
    18      Rounded("div.post-info","all","transparent","transparent"); 
    19      Rounded("div.post-tags","all","transparent","transparent"); 
    20      Rounded("div.post-title","all","transparent","transparent"); 
    21      Rounded("div.post-info-co","all","transparent","transparent");*/ 
    22      /*Rounded("div.post-content","tltr","white","white"); 
    23       
    24       
    25      Rounded("div#comments dd","all","white","transparent"); 
    26      Rounded("div#pings dd","all","white","transparent"); 
    27      /*Rounded("div#comment-form","all","#c00000","transparent"); 
    28      Rounded("div.comment-content","all","white","transparent");*/ 
    29       
    30 } 
    31  
    32  
    33 function NiftyCheck(){ 
    34 if(!document.getElementById || !document.createElement) 
    35     return(false); 
    36 isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName); 
    37 if(Array.prototype.push==null){Array.prototype.push=function(){ 
    38       this[this.length]=arguments[0]; return(this.length);}} 
    39 return(true); 
    40 } 
    41  
    42 function Rounded(selector,wich,bk,color,opt){ 
    43 var i,prefixt,prefixb,cn="r",ecolor="",edges=false,eclass="",b=false,t=false; 
    44  
    45 if(color=="transparent"){ 
    46     cn=cn+"x"; 
    47     ecolor=bk; 
    48     bk="transparent"; 
    49     } 
    50 else if(opt && opt.indexOf("border")>=0){ 
    51     var optar=opt.split(" "); 
    52     for(i=0;i<optar.length;i++) 
    53         if(optar[i].indexOf("#")>=0) ecolor=optar[i]; 
    54     if(ecolor=="") ecolor="#666"; 
    55     cn+="e"; 
    56     edges=true; 
    57     } 
    58 else if(opt && opt.indexOf("smooth")>=0){ 
    59     cn+="a"; 
    60     ecolor=Mix(bk,color); 
    61     } 
    62 if(opt && opt.indexOf("small")>=0) cn+="s"; 
    63 prefixt=cn; 
    64 prefixb=cn; 
    65 if(wich.indexOf("all")>=0){t=true;b=true} 
    66 else if(wich.indexOf("top")>=0) t="true"; 
    67 else if(wich.indexOf("tl")>=0){ 
    68     t="true"; 
    69     if(wich.indexOf("tr")<0) prefixt+="l"; 
    70     } 
    71 else if(wich.indexOf("tr")>=0){ 
    72     t="true"; 
    73     prefixt+="r"; 
    74     } 
    75 if(wich.indexOf("bottom")>=0) b=true; 
    76 else if(wich.indexOf("bl")>=0){ 
    77     b="true"; 
    78     if(wich.indexOf("br")<0) prefixb+="l"; 
    79     } 
    80 else if(wich.indexOf("br")>=0){ 
    81     b="true"; 
    82     prefixb+="r"; 
    83     } 
    84 var v=getElementsBySelector(selector); 
    85 var l=v.length; 
    86 for(i=0;i<l;i++){ 
    87     if(edges) AddBorder(v[i],ecolor); 
    88     if(t) AddTop(v[i],bk,color,ecolor,prefixt); 
    89     if(b) AddBottom(v[i],bk,color,ecolor,prefixb); 
    90     } 
    91 } 
    92  
    93 function AddBorder(el,bc){ 
    94 var i; 
    95 if(!el.passed){ 
    96     if(el.childNodes.length==1 && el.childNodes[0].nodeType==3){ 
    97         var t=el.firstChild.nodeValue; 
    98         el.removeChild(el.lastChild); 
    99         var d=CreateEl("span"); 
    100         d.style.display="block"; 
    101         d.appendChild(document.createTextNode(t)); 
    102         el.appendChild(d); 
     1$(function() { 
     2     $('#sidebar>div>div').corner('10px'); 
     3      
     4     $('#comments dd').corner('10px'); 
     5     $('#pings dd').corner('10px'); 
     6}); 
     7 
     8// jquery-roundcorners-canvas 
     9// www.meerbox.nl 
     10 
     11(function($){ 
     12      
     13     var _corner = function(options) { 
     14      
     15          // nothing to do, so return 
     16          if (this.length==0) return this; 
     17           
     18          // excanvas.js not loaded 
     19          if ($.browser.msie && typeof G_vmlCanvasManager == 'undefined') return this; 
     20           
     21          // get lowest number from array 
     22          var asNum = function(a, b) { return a-b; }; 
     23          var getMin = function(a) { 
     24               var b = a.concat(); 
     25               return b.sort(asNum)[0]; 
     26          }; 
     27           
     28          // get CSS value as integer 
     29          var getCSSint = function(el, prop) { 
     30               return parseInt($.css(el.jquery?el[0]:el,prop))||0; 
     31          }; 
     32                
     33          // draw the round corner in Canvas object 
     34          var drawRoundCornerCanvasShape = function(canvas,radius,r_type,bg_color,border_width,border_color) { 
     35                
     36               // change rgba(1,2,3,0.9) to rgb(1,2,3) 
     37               var reg = /^rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/;    
     38               var bits = reg.exec(bg_color); 
     39               if (bits) { 
     40                    channels = new Array(parseInt(bits[1]),parseInt(bits[2]),parseInt(bits[3])); 
     41                    bg_color = 'rgb('+channels[0]+', '+channels[1]+', '+channels[2]+')'; 
     42               }  
     43           
     44               var border_width = parseInt(border_width); 
     45                
     46               var ctx = canvas.getContext('2d'); 
     47                
     48               if (radius == 1) { 
     49                    ctx.fillStyle = bg_color; 
     50                    ctx.fillRect(0,0,1,1); 
     51                    return; 
     52               } 
     53      
     54               if (r_type == 'tl') { 
     55                    var steps = new Array(0,0,radius,0,radius,0,0,radius,0,0); 
     56               } else if (r_type == 'tr') { 
     57                    var steps = new Array(radius,0,radius,radius,radius,0,0,0,0,0); 
     58               } else if (r_type == 'bl') { 
     59                    var steps = new Array(0,radius,radius,radius,0,radius,0,0,0,radius); 
     60               } else if (r_type == 'br') { 
     61                    var steps = new Array(radius,radius,radius,0,radius,0,0,radius,radius,radius); 
     62               } 
     63                
     64               ctx.fillStyle = bg_color; 
     65          ctx.beginPath(); 
     66               ctx.moveTo(steps[0],steps[1]);  
     67               ctx.lineTo(steps[2], steps[3]);  
     68          if(r_type == 'br') ctx.bezierCurveTo(steps[4], steps[5], radius, radius, steps[6], steps[7]);  
     69          else ctx.bezierCurveTo(steps[4], steps[5], 0, 0, steps[6], steps[7]); 
     70               ctx.lineTo(steps[8], steps[9]);  
     71             ctx.fill();  
     72              
     73             // draw border 
     74             if (border_width > 0 && border_width < radius) { 
     75                   
     76                  // offset caused by border 
     77                  var offset = border_width/2;  
     78                   
     79                  if (r_type == 'tl') { 
     80                         var steps = new Array(radius-offset,offset,radius-offset,offset,offset,radius-offset); 
     81                         var curve_to = new Array(0,0); 
     82                    } else if (r_type == 'tr') { 
     83                         var steps = new Array(radius-offset,radius-offset,radius-offset,offset,offset,offset); 
     84                         var curve_to = new Array(0,0); 
     85                    } else if (r_type == 'bl') { 
     86                         var steps = new Array(radius-offset,radius-offset,offset,radius-offset,offset,offset,offset,radius-offset); 
     87                         var curve_to = new Array(0,0); 
     88                    } else if (r_type == 'br') { 
     89                         var steps = new Array(radius-offset,offset,radius-offset,offset,offset,radius-offset,radius-offset,radius-offset); 
     90                         var curve_to = new Array(radius, radius); 
     91                    } 
     92                   
     93                  ctx.strokeStyle = border_color; 
     94                  ctx.lineWidth = border_width; 
     95               ctx.beginPath(); 
     96               // go to corner to begin curve 
     97                    ctx.moveTo(steps[0], steps[1]);  
     98                    // curve from righttop to leftbottom (for the tl canvas) 
     99               ctx.bezierCurveTo(steps[2], steps[3], curve_to[0], curve_to[1], steps[4], steps[5]);  
     100                    ctx.stroke(); 
     101                   
     102              } 
     103          }; 
     104           
     105          var creatCanvas = function(p,radius) { 
     106               var elm = document.createElement('canvas'); 
     107               elm.setAttribute("height", radius); 
     108          elm.setAttribute("width", radius);  
     109               elm.style.display = "block"; 
     110               elm.style.position = "absolute"; 
     111               elm.className = "cornercanvas"; 
     112               elm = p.appendChild(elm);  
     113               if (!elm.getContext && typeof G_vmlCanvasManager != 'undefined') { 
     114                    elm = G_vmlCanvasManager.initElement(elm); 
     115               } 
     116               return elm; 
     117          }; 
     118           
     119          // interpret the (string) argument 
     120          var o = (options || "").toLowerCase(); 
     121          var radius = parseInt((o.match(/(\d+)px/)||[])[1]) || null; // corner width 
     122          var bg_color = ((o.match(/(#[0-9a-f]+)/)||[])[1]);  // strip color 
     123          if (radius == null) { radius = "auto"; } 
     124           
     125          var edges = { T:0, B:1 }; 
     126     var opts = { 
     127          tl:  /top|tl/.test(o),        
     128          tr:  /top|tr/.test(o), 
     129          bl:  /bottom|bl/.test(o),     
     130          br:  /bottom|br/.test(o) 
     131     }; 
     132     if ( !opts.tl && !opts.tr && !opts.bl && !opts.br) { 
     133          opts = { tl:1, tr:1, bl:1, br:1 }; 
    103134        } 
    104     for(i=0;i<el.childNodes.length;i++){ 
    105         if(el.childNodes[i].nodeType==1){ 
    106             el.childNodes[i].style.borderLeft="1px solid "+bc; 
    107             el.childNodes[i].style.borderRight="1px solid "+bc; 
    108             } 
    109         } 
    110     } 
    111 el.passed=true; 
    112 } 
    113      
    114 function AddTop(el,bk,color,bc,cn){ 
    115 var i,lim=4,d=CreateEl("b"); 
    116  
    117 if(cn.indexOf("s")>=0) lim=2; 
    118 if(bc) d.className="artop"; 
    119 else d.className="rtop"; 
    120 d.style.backgroundColor=bk; 
    121 for(i=1;i<=lim;i++){ 
    122     var x=CreateEl("b"); 
    123     x.className=cn + i; 
    124     x.style.backgroundColor=color; 
    125     if(bc) x.style.borderColor=bc; 
    126     d.appendChild(x); 
    127     } 
    128 el.style.paddingTop=0; 
    129 el.insertBefore(d,el.firstChild); 
    130 } 
    131  
    132 function AddBottom(el,bk,color,bc,cn){ 
    133 var i,lim=4,d=CreateEl("b"); 
    134  
    135 if(cn.indexOf("s")>=0) lim=2; 
    136 if(bc) d.className="artop"; 
    137 else d.className="rtop"; 
    138 d.style.backgroundColor=bk; 
    139 for(i=lim;i>0;i--){ 
    140     var x=CreateEl("b"); 
    141     x.className=cn + i; 
    142     x.style.backgroundColor=color; 
    143     if(bc) x.style.borderColor=bc; 
    144     d.appendChild(x); 
    145     } 
    146 el.style.paddingBottom=0; 
    147 el.appendChild(d); 
    148 } 
    149  
    150 function CreateEl(x){ 
    151 if(isXHTML) return(document.createElementNS('http://www.w3.org/1999/xhtml',x)); 
    152 else return(document.createElement(x)); 
    153 } 
    154  
    155 function getElementsBySelector(selector){ 
    156 var i,selid="",selclass="",tag=selector,f,s=[],objlist=[]; 
    157  
    158 if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag" 
    159     s=selector.split(" "); 
    160     var fs=s[0].split("#"); 
    161     if(fs.length==1) return(objlist); 
    162     f=document.getElementById(fs[1]); 
    163     if(f) return(f.getElementsByTagName(s[1])); 
    164     return(objlist); 
    165     } 
    166 if(selector.indexOf("#")>0){ //id selector like "tag#id" 
    167     s=selector.split("#"); 
    168     tag=s[0]; 
    169     selid=s[1]; 
    170     } 
    171 if(selid!=""){ 
    172     f=document.getElementById(selid); 
    173     if(f) objlist.push(f); 
    174     return(objlist); 
    175     } 
    176 if(selector.indexOf(".")>0){  //class selector like "tag.class" 
    177     s=selector.split("."); 
    178     tag=s[0]; 
    179     selclass=s[1]; 
    180     } 
    181 var v=document.getElementsByTagName(tag);  // tag selector like "tag" 
    182 if(selclass=="") 
    183     return(v); 
    184 for(i=0;i<v.length;i++){ 
    185     if(v[i].className.indexOf(selclass)>=0){ 
    186         objlist.push(v[i]); 
    187         } 
    188     } 
    189 return(objlist); 
    190 } 
    191  
    192 function Mix(c1,c2){ 
    193 var i,step1,step2,x,y,r=new Array(3); 
    194 if(c1.length==4)step1=1; 
    195 else step1=2; 
    196 if(c2.length==4) step2=1; 
    197 else step2=2; 
    198 for(i=0;i<3;i++){ 
    199     x=parseInt(c1.substr(1+step1*i,step1),16); 
    200     if(step1==1) x=16*x+x; 
    201     y=parseInt(c2.substr(1+step2*i,step2),16); 
    202     if(step2==1) y=16*y+y; 
    203     r[i]=Math.floor((x*50+y*50)/100); 
    204     } 
    205 return("#"+r[0].toString(16)+r[1].toString(16)+r[2].toString(16)); 
    206 } 
     135       
     136          return this.each(function() { 
     137 
     138               var elm = $(this); 
     139               var hover = /hover/.test(o); 
     140                
     141               if (hover) { 
     142                     
     143                    options = options.replace(/hover/i, ""); 
     144                     
     145                    elm.hover(function(){ 
     146                         $(this).addClass('jrcHover'); 
     147                         $(this).corner(options); 
     148                    },function(){ 
     149                         $(this).removeClass('jrcHover');    
     150                         $(this).corner(options); 
     151                    }); 
     152                     
     153               } 
     154                
     155               if ($.browser.msie) {  
     156 
     157                    // give element 'haslayout' 
     158                    elm.css('zoom','1'); 
     159                    // give the child elements 'haslayout' 
     160                    elm.children().css('zoom','1'); 
     161                     
     162                    if (elm.css('height') == 'auto') elm.height(elm.height()); 
     163                     
     164                    // msie6 rendering bugs :( 
     165                    if ($.browser.msie && typeof document.body.style.maxHeight == "undefined") { 
     166                         if (elm.width()%2 != 0) { elm.width(elm.width()+1); } 
     167                         if (elm.height()%2 != 0) { elm.height(elm.height()+1); } 
     168                         if (elm.css('lineHeight') != 'normal' && elm.height() < elm.css('lineHeight')) { 
     169                              elm.css('lineHeight', elm.height()); 
     170                         } 
     171                         if (elm.css('lineHeight') == 'normal') elm.css('lineHeight','1'); // dont ask 
     172                    } 
     173               } 
     174                
     175               var arr = new Array(elm.get(0).offsetHeight,elm.get(0).offsetWidth); 
     176               if (elm.height() != 0) arr[arr.length] = elm.height(); 
     177               if (elm.width() != 0) arr[arr.length] = elm.width(); 
     178               var widthheight_smallest = getMin(arr); 
     179                
     180               // the size of the corner is not defined... 
     181               if (radius == "auto") { 
     182                    radius = widthheight_smallest/2; 
     183                    if (radius > 10) { radius = 10; } 
     184               } 
     185 
     186               // the size of the corner can't be to high 
     187               if (radius > widthheight_smallest/2) {  
     188                    radius = (widthheight_smallest/2);  
     189               } 
     190                
     191               radius = Math.floor(radius); 
     192                
     193               // some css thats required in order to position the canvas elements 
     194               if (elm.css('position') == 'static') {  
     195                    elm.css('position','relative');  
     196               // only needed for ie6 and (ie7 in Quirks mode) , CSS1Compat == Strict mode 
     197               } else if (elm.css('position') == 'fixed' && $.browser.msie && !(document.compatMode == 'CSS1Compat' && typeof document.body.style.maxHeight != "undefined")) {  
     198                    elm.css('position','absolute'); 
     199               } 
     200               elm.css('overflow','visible');  
     201                
     202               // get border width 
     203               var border_t = getCSSint(this, 'borderTopWidth'); 
     204               var border_r = getCSSint(this, 'borderRightWidth'); 
     205               var border_b = getCSSint(this, 'borderBottomWidth'); 
     206               var border_l = getCSSint(this, 'borderLeftWidth'); 
     207                
     208               // get the lowest borderwidth of the corners in use 
     209               var bordersWidth = new Array(); 
     210               if (opts.tl || opts.tr) { bordersWidth.push(border_t); } 
     211               if (opts.br || opts.tr) { bordersWidth.push(border_r); } 
     212               if (opts.br || opts.bl) { bordersWidth.push(border_b); } 
     213               if (opts.bl || opts.tl) { bordersWidth.push(border_l); } 
     214                
     215               var borderswidth_smallest = getMin(bordersWidth); 
     216                
     217               // creat the canvas elements and position them 
     218               var p_top = 0-border_t; 
     219               var p_right = 0-border_r; 
     220               var p_bottom = 0-border_b; 
     221               var p_left = 0-border_l;  
     222                
     223               // remove old stuff 
     224               elm.children("canvas.cornercanvas").remove(); 
     225 
     226               if (opts.tl) { var tl = $(creatCanvas(this,radius)).css({left:p_left,top:p_top}).get(0); } 
     227               if (opts.tr) { var tr = $(creatCanvas(this,radius)).css({right:p_right,top:p_top}).get(0); } 
     228               if (opts.bl) { var bl = $(creatCanvas(this,radius)).css({left:p_left,bottom:p_bottom}).get(0); } 
     229               if (opts.br) { var br = $(creatCanvas(this,radius)).css({right:p_right,bottom:p_bottom}).get(0); } 
     230                
     231               // get the background color of parent element 
     232               if (bg_color == undefined) { 
     233                    var current_p = elm.parent(); 
     234                    var bg = current_p.css('background-color'); 
     235                    while((bg == "transparent" || bg == "rgba(0, 0, 0, 0)") && (typeof current_p == 'object') && !current_p.is("html")) { 
     236                         bg = current_p.css('background-color'); 
     237                         current_p = current_p.parent(); 
     238                    } 
     239                     
     240               } else { 
     241                    bg = bg_color; 
     242               } 
     243 
     244               if (bg == "transparent" || bg == "rgba(0, 0, 0, 0)") { bg = "#ffffff"; } 
     245                
     246               if (opts.tl) { drawRoundCornerCanvasShape(tl,radius,'tl',bg,borderswidth_smallest,elm.css('borderTopColor')); } 
     247               if (opts.tr) { drawRoundCornerCanvasShape(tr,radius,'tr',bg,borderswidth_smallest,elm.css('borderTopColor')); } 
     248               if (opts.bl) { drawRoundCornerCanvasShape(bl,radius,'bl',bg,borderswidth_smallest,elm.css('borderBottomColor')); } 
     249               if (opts.br) { drawRoundCornerCanvasShape(br,radius,'br',bg,borderswidth_smallest,elm.css('borderBottomColor')); } 
     250                
     251               elm.addClass('roundCornersParent'); 
     252                     
     253          });   
     254     }; 
     255      
     256     $.fn.corner = _corner; 
     257      
     258})(jQuery); 
  • themes/odahlia/behavior.js

    r11 r15  
    1 // JavaScript Document 
    2 window.onload=function(){ 
    3  
    4      if(!NiftyCheck()) 
    5     return; 
    6       
    7      Rounded("div.categories","all","#000","transparent"); 
    8      Rounded("div#search","all","#000","transparent"); 
    9      Rounded("div.calendar","all","#000","transparent"); 
    10      Rounded("div.lastcomments","all","#000","transparent"); 
    11      Rounded("div.links","all","#000","transparent"); 
    12      Rounded("div.archives","all","#000","transparent"); 
    13      Rounded("div.topnav","all","#000","transparent"); 
    14      Rounded("div.tags","all","#000","transparent"); 
    15      Rounded("div.syndicate","all","#000","transparent"); 
    16      Rounded("div.selected","all","#000","transparent"); 
    17      Rounded("div.feed","all","#000","transparent"); 
    18       
    19 } 
    20  
    21  
    22 function NiftyCheck(){ 
    23 if(!document.getElementById || !document.createElement) 
    24     return(false); 
    25 isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName); 
    26 if(Array.prototype.push==null){Array.prototype.push=function(){ 
    27       this[this.length]=arguments[0]; return(this.length);}} 
    28 return(true); 
    29 } 
    30  
    31 function Rounded(selector,wich,bk,color,opt){ 
    32 var i,prefixt,prefixb,cn="r",ecolor="",edges=false,eclass="",b=false,t=false; 
    33  
    34 if(color=="transparent"){ 
    35     cn=cn+"x"; 
    36     ecolor=bk; 
    37     bk="transparent"; 
    38     } 
    39 else if(opt && opt.indexOf("border")>=0){ 
    40     var optar=opt.split(" "); 
    41     for(i=0;i<optar.length;i++) 
    42         if(optar[i].indexOf("#")>=0) ecolor=optar[i]; 
    43     if(ecolor=="") ecolor="#666"; 
    44     cn+="e"; 
    45     edges=true; 
    46     } 
    47 else if(opt && opt.indexOf("smooth")>=0){ 
    48     cn+="a"; 
    49     ecolor=Mix(bk,color); 
    50     } 
    51 if(opt && opt.indexOf("small")>=0) cn+="s"; 
    52 prefixt=cn; 
    53 prefixb=cn; 
    54 if(wich.indexOf("all")>=0){t=true;b=true} 
    55 else if(wich.indexOf("top")>=0) t="true"; 
    56 else if(wich.indexOf("tl")>=0){ 
    57     t="true"; 
    58     if(wich.indexOf("tr")<0) prefixt+="l"; 
    59     } 
    60 else if(wich.indexOf("tr")>=0){ 
    61     t="true"; 
    62     prefixt+="r"; 
    63     } 
    64 if(wich.indexOf("bottom")>=0) b=true; 
    65 else if(wich.indexOf("bl")>=0){ 
    66     b="true"; 
    67     if(wich.indexOf("br")<0) prefixb+="l"; 
    68     } 
    69 else if(wich.indexOf("br")>=0){ 
    70     b="true"; 
    71     prefixb+="r"; 
    72     } 
    73 var v=getElementsBySelector(selector); 
    74 var l=v.length; 
    75 for(i=0;i<l;i++){ 
    76     if(edges) AddBorder(v[i],ecolor); 
    77     if(t) AddTop(v[i],bk,color,ecolor,prefixt); 
    78     if(b) AddBottom(v[i],bk,color,ecolor,prefixb); 
    79     } 
    80 } 
    81  
    82 function AddBorder(el,bc){ 
    83 var i; 
    84 if(!el.passed){ 
    85     if(el.childNodes.length==1 && el.childNodes[0].nodeType==3){ 
    86         var t=el.firstChild.nodeValue; 
    87         el.removeChild(el.lastChild); 
    88         var d=CreateEl("span"); 
    89         d.style.display="block"; 
    90         d.appendChild(document.createTextNode(t)); 
    91         el.appendChild(d); 
     1$(function() { 
     2     $('#sidebar>div>div').corner('10px'); 
     3}); 
     4 
     5// jquery-roundcorners-canvas 
     6// www.meerbox.nl 
     7 
     8(function($){ 
     9      
     10     var _corner = function(options) { 
     11      
     12          // nothing to do, so return 
     13          if (this.length==0) return this; 
     14           
     15          // excanvas.js not loaded 
     16          if ($.browser.msie && typeof G_vmlCanvasManager == 'undefined') return this; 
     17           
     18          // get lowest number from array 
     19          var asNum = function(a, b) { return a-b; }; 
     20          var getMin = function(a) { 
     21               var b = a.concat(); 
     22               return b.sort(asNum)[0]; 
     23          }; 
     24           
     25          // get CSS value as integer 
     26          var getCSSint = function(el, prop) { 
     27               return parseInt($.css(el.jquery?el[0]:el,prop))||0; 
     28          }; 
     29                
     30          // draw the round corner in Canvas object 
     31          var drawRoundCornerCanvasShape = function(canvas,radius,r_type,bg_color,border_width,border_color) { 
     32                
     33               // change rgba(1,2,3,0.9) to rgb(1,2,3) 
     34               var reg = /^rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/;    
     35               var bits = reg.exec(bg_color); 
     36               if (bits) { 
     37                    channels = new Array(parseInt(bits[1]),parseInt(bits[2]),parseInt(bits[3])); 
     38                    bg_color = 'rgb('+channels[0]+', '+channels[1]+', '+channels[2]+')'; 
     39               }  
     40           
     41               var border_width = parseInt(border_width); 
     42                
     43               var ctx = canvas.getContext('2d'); 
     44                
     45               if (radius == 1) { 
     46                    ctx.fillStyle = bg_color; 
     47                    ctx.fillRect(0,0,1,1); 
     48                    return; 
     49               } 
     50      
     51               if (r_type == 'tl') { 
     52                    var steps = new Array(0,0,radius,0,radius,0,0,radius,0,0); 
     53               } else if (r_type == 'tr') { 
     54                    var steps = new Array(radius,0,radius,radius,radius,0,0,0,0,0); 
     55               } else if (r_type == 'bl') { 
     56                    var steps = new Array(0,radius,radius,radius,0,radius,0,0,0,radius); 
     57               } else if (r_type == 'br') { 
     58                    var steps = new Array(radius,radius,radius,0,radius,0,0,radius,radius,radius); 
     59               } 
     60                
     61               ctx.fillStyle = bg_color; 
     62          ctx.beginPath(); 
     63               ctx.moveTo(steps[0],steps[1]);  
     64               ctx.lineTo(steps[2], steps[3]);  
     65          if(r_type == 'br') ctx.bezierCurveTo(steps[4], steps[5], radius, radius, steps[6], steps[7]);  
     66          else ctx.bezierCurveTo(steps[4], steps[5], 0, 0, steps[6], steps[7]); 
     67               ctx.lineTo(steps[8], steps[9]);  
     68             ctx.fill();  
     69              
     70             // draw border 
     71             if (border_width > 0 && border_width < radius) { 
     72                   
     73                  // offset caused by border 
     74                  var offset = border_width/2;  
     75                   
     76                  if (r_type == 'tl') { 
     77                         var steps = new Array(radius-offset,offset,radius-offset,offset,offset,radius-offset); 
     78                         var curve_to = new Array(0,0); 
     79                    } else if (r_type == 'tr') { 
     80                         var steps = new Array(radius-offset,radius-offset,radius-offset,offset,offset,offset); 
     81                         var curve_to = new Array(0,0); 
     82                    } else if (r_type == 'bl') { 
     83                         var steps = new Array(radius-offset,radius-offset,offset,radius-offset,offset,offset,offset,radius-offset); 
     84                         var curve_to = new Array(0,0); 
     85                    } else if (r_type == 'br') { 
     86                         var steps = new Array(radius-offset,offset,radius-offset,offset,offset,radius-offset,radius-offset,radius-offset); 
     87                         var curve_to = new Array(radius, radius); 
     88                    } 
     89                   
     90                  ctx.strokeStyle = border_color; 
     91                  ctx.lineWidth = border_width; 
     92               ctx.beginPath(); 
     93               // go to corner to begin curve 
     94                    ctx.moveTo(steps[0], steps[1]);  
     95                    // curve from righttop to leftbottom (for the tl canvas) 
     96               ctx.bezierCurveTo(steps[2], steps[3], curve_to[0], curve_to[1], steps[4], steps[5]);  
     97                    ctx.stroke(); 
     98                   
     99              } 
     100          }; 
     101           
     102          var creatCanvas = function(p,radius) { 
     103               var elm = document.createElement('canvas'); 
     104               elm.setAttribute("height", radius); 
     105          elm.setAttribute("width", radius);  
     106               elm.style.display = "block"; 
     107               elm.style.position = "absolute"; 
     108               elm.className = "cornercanvas"; 
     109               elm = p.appendChild(elm);  
     110               if (!elm.getContext && typeof G_vmlCanvasManager != 'undefined') { 
     111                    elm = G_vmlCanvasManager.initElement(elm); 
     112               } 
     113               return elm; 
     114          }; 
     115           
     116          // interpret the (string) argument 
     117          var o = (options || "").toLowerCase(); 
     118          var radius = parseInt((o.match(/(\d+)px/)||[])[1]) || null; // corner width 
     119          var bg_color = ((o.match(/(#[0-9a-f]+)/)||[])[1]);  // strip color 
     120          if (radius == null) { radius = "auto"; } 
     121           
     122          var edges = { T:0, B:1 }; 
     123     var opts = { 
     124          tl:  /top|tl/.test(o),        
     125          tr:  /top|tr/.test(o), 
     126          bl:  /bottom|bl/.test(o),     
     127          br:  /bottom|br/.test(o) 
     128     }; 
     129     if ( !opts.tl && !opts.tr && !opts.bl && !opts.br) { 
     130          opts = { tl:1, tr:1, bl:1, br:1 }; 
    92131        } 
    93     for(i=0;i<el.childNodes.length;i++){ 
    94         if(el.childNodes[i].nodeType==1){ 
    95             el.childNodes[i].style.borderLeft="1px solid "+bc; 
    96             el.childNodes[i].style.borderRight="1px solid "+bc; 
    97             } 
    98         } 
    99     } 
    100 el.passed=true; 
    101 } 
    102      
    103 function AddTop(el,bk,color,bc,cn){ 
    104 var i,lim=4,d=CreateEl("b"); 
    105  
    106 if(cn.indexOf("s")>=0) lim=2; 
    107 if(bc) d.className="artop"; 
    108 else d.className="rtop"; 
    109 d.style.backgroundColor=bk; 
    110 for(i=1;i<=lim;i++){ 
    111     var x=CreateEl("b"); 
    112     x.className=cn + i; 
    113     x.style.backgroundColor=color; 
    114     if(bc) x.style.borderColor=bc; 
    115     d.appendChild(x); 
    116     } 
    117 el.style.paddingTop=0; 
    118 el.insertBefore(d,el.firstChild); 
    119 } 
    120  
    121 function AddBottom(el,bk,color,bc,cn){ 
    122 var i,lim=4,d=CreateEl("b"); 
    123  
    124 if(cn.indexOf("s")>=0) lim=2; 
    125 if(bc) d.className="artop"; 
    126 else d.className="rtop"; 
    127 d.style.backgroundColor=bk; 
    128 for(i=lim;i>0;i--){ 
    129     var x=CreateEl("b"); 
    130     x.className=cn + i; 
    131     x.style.backgroundColor=color; 
    132     if(bc) x.style.borderColor=bc; 
    133     d.appendChild(x); 
    134     } 
    135 el.style.paddingBottom=0; 
    136 el.appendChild(d); 
    137 } 
    138  
    139 function CreateEl(x){ 
    140 if(isXHTML) return(document.createElementNS('http://www.w3.org/1999/xhtml',x)); 
    141 else return(document.createElement(x)); 
    142 } 
    143  
    144 function getElementsBySelector(selector){ 
    145 var i,selid="",selclass="",tag=selector,f,s=[],objlist=[]; 
    146  
    147 if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag" 
    148     s=selector.split(" "); 
    149     var fs=s[0].split("#"); 
    150     if(fs.length==1) return(objlist); 
    151     f=document.getElementById(fs[1]); 
    152     if(f) return(f.getElementsByTagName(s[1])); 
    153     return(objlist); 
    154     } 
    155 if(selector.indexOf("#")>0){ //id selector like "tag#id" 
    156     s=selector.split("#"); 
    157     tag=s[0]; 
    158     selid=s[1]; 
    159     } 
    160 if(selid!=""){ 
    161     f=document.getElementById(selid); 
    162     if(f) objlist.push(f); 
    163     return(objlist); 
    164     } 
    165 if(selector.indexOf(".")>0){  //class selector like "tag.class" 
    166     s=selector.split("."); 
    167     tag=s[0]; 
    168     selclass=s[1]; 
    169     } 
    170 var v=document.getElementsByTagName(tag);  // tag selector like "tag" 
    171 if(selclass=="") 
    172     return(v); 
    173 for(i=0;i<v.length;i++){ 
    174     if(v[i].className.indexOf(selclass)>=0){ 
    175         objlist.push(v[i]); 
    176         } 
    177     } 
    178 return(objlist); 
    179 } 
    180  
    181 function Mix(c1,c2){ 
    182 var i,step1,step2,x,y,r=new Array(3); 
    183 if(c1.length==4)step1=1; 
    184 else step1=2; 
    185 if(c2.length==4) step2=1; 
    186 else step2=2; 
    187 for(i=0;i<3;i++){ 
    188     x=parseInt(c1.substr(1+step1*i,step1),16); 
    189     if(step1==1) x=16*x+x; 
    190     y=parseInt(c2.substr(1+step2*i,step2),16); 
    191     if(step2==1) y=16*y+y; 
    192     r[i]=Math.floor((x*50+y*50)/100); 
    193     } 
    194 return("#"+r[0].toString(16)+r[1].toString(16)+r[2].toString(16)); 
    195 } 
     132       
     133          return this.each(function() { 
     134 
     135               var elm = $(this); 
     136               var hover = /hover/.test(o); 
     137                
     138               if (hover) { 
     139                     
     140                    options = options.replace(/hover/i, ""); 
     141                     
     142                    elm.hover(function(){ 
     143                         $(this).addClass('jrcHover'); 
     144                         $(this).corner(options); 
     145                    },function(){ 
     146                         $(this).removeClass('jrcHover');    
     147                         $(this).corner(options); 
     148                    }); 
     149                     
     150               } 
     151                
     152               if ($.browser.msie) {  
     153 
     154                    // give element 'haslayout' 
     155                    elm.css('zoom','1'); 
     156                    // give the child elements 'haslayout' 
     157                    elm.children().css('zoom','1'); 
     158                     
     159                    if (elm.css('height') == 'auto') elm.height(elm.height()); 
     160                     
     161                    // msie6 rendering bugs :( 
     162                    if ($.browser.msie && typeof document.body.style.maxHeight == "undefined") { 
     163                         if (elm.width()%2 != 0) { elm.width(elm.width()+1); } 
     164                         if (elm.height()%2 != 0) { elm.height(elm.height()+1); } 
     165                         if (elm.css('lineHeight') != 'normal' && elm.height() < elm.css('lineHeight')) { 
     166                              elm.css('lineHeight', elm.height()); 
     167                         } 
     168                         if (elm.css('lineHeight') == 'normal') elm.css('lineHeight','1'); // dont ask 
     169                    } 
     170               } 
     171                
     172               var arr = new Array(elm.get(0).offsetHeight,elm.get(0).offsetWidth); 
     173               if (elm.height() != 0) arr[arr.length] = elm.height(); 
     174               if (elm.width() != 0) arr[arr.length] = elm.width(); 
     175               var widthheight_smallest = getMin(arr); 
     176                
     177               // the size of the corner is not defined... 
     178               if (radius == "auto") { 
     179                    radius = widthheight_smallest/2; 
     180                    if (radius > 10) { radius = 10; } 
     181               } 
     182 
     183               // the size of the corner can't be to high 
     184               if (radius > widthheight_smallest/2) {  
     185                    radius = (widthheight_smallest/2);  
     186               } 
     187                
     188               radius = Math.floor(radius); 
     189                
     190               // some css thats required in order to position the canvas elements 
     191               if (elm.css('position') == 'static') {  
     192                    elm.css('position','relative');  
     193               // only needed for ie6 and (ie7 in Quirks mode) , CSS1Compat == Strict mode 
     194               } else if (elm.css('position') == 'fixed' && $.browser.msie && !(document.compatMode == 'CSS1Compat' && typeof document.body.style.maxHeight != "undefined")) {  
     195                    elm.css('position','absolute'); 
     196               } 
     197               elm.css('overflow','visible');  
     198                
     199               // get border width 
     200               var border_t = getCSSint(this, 'borderTopWidth'); 
     201               var border_r = getCSSint(this, 'borderRightWidth'); 
     202               var border_b = getCSSint(this, 'borderBottomWidth'); 
     203               var border_l = getCSSint(this, 'borderLeftWidth'); 
     204                
     205               // get the lowest borderwidth of the corners in use 
     206               var bordersWidth = new Array(); 
     207               if (opts.tl || opts.tr) { bordersWidth.push(border_t); } 
     208               if (opts.br || opts.tr) { bordersWidth.push(border_r); } 
     209               if (opts.br || opts.bl) { bordersWidth.push(border_b); } 
     210               if (opts.bl || opts.tl) { bordersWidth.push(border_l); } 
     211                
     212               var borderswidth_smallest = getMin(bordersWidth); 
     213                
     214               // creat the canvas elements and position them 
     215               var p_top = 0-border_t; 
     216               var p_right = 0-border_r; 
     217               var p_bottom = 0-border_b; 
     218               var p_left = 0-border_l;  
     219                
     220               // remove old stuff 
     221               elm.children("canvas.cornercanvas").remove(); 
     222 
     223               if (opts.tl) { var tl = $(creatCanvas(this,radius)).css({left:p_left,top:p_top}).get(0); } 
     224               if (opts.tr) { var tr = $(creatCanvas(this,radius)).css({right:p_right,top:p_top}).get(0); } 
     225               if (opts.bl) { var bl = $(creatCanvas(this,radius)).css({left:p_left,bottom:p_bottom}).get(0); } 
     226               if (opts.br) { var br = $(creatCanvas(this,radius)).css({right:p_right,bottom:p_bottom}).get(0); } 
     227                
     228               // get the background color of parent element 
     229               if (bg_color == undefined) { 
     230                    var current_p = elm.parent(); 
     231                    var bg = current_p.css('background-color'); 
     232                    while((bg == "transparent" || bg == "rgba(0, 0, 0, 0)") && (typeof current_p == 'object') && !current_p.is("html")) { 
     233                         bg = current_p.css('background-color'); 
     234                         current_p = current_p.parent(); 
     235                    } 
     236                     
     237               } else { 
     238                    bg = bg_color; 
     239               } 
     240 
     241               if (bg == "transparent" || bg == "rgba(0, 0, 0, 0)") { bg = "#ffffff"; } 
     242                
     243               if (opts.tl) { drawRoundCornerCanvasShape(tl,radius,'tl',bg,borderswidth_smallest,elm.css('borderTopColor')); } 
     244               if (opts.tr) { drawRoundCornerCanvasShape(tr,radius,'tr',bg,borderswidth_smallest,elm.css('borderTopColor')); } 
     245               if (opts.bl) { drawRoundCornerCanvasShape(bl,radius,'bl',bg,borderswidth_smallest,elm.css('borderBottomColor')); } 
     246               if (opts.br) { drawRoundCornerCanvasShape(br,radius,'br',bg,borderswidth_smallest,elm.css('borderBottomColor')); } 
     247                
     248               elm.addClass('roundCornersParent'); 
     249                     
     250          });   
     251     }; 
     252      
     253     $.fn.corner = _corner; 
     254      
     255})(jQuery); 
  • themes/shikros-city/behavior.js

    r11 r15  
    1 // JavaScript Document 
    2 window.onload=function(){ 
    3  
    4      if(!NiftyCheck()) 
    5     return; 
    6       
    7      //Rounded("div#top","tlbr","#000","#595041"); 
    8      //Rounded("div#footer","tltr","#000","#595041"); 
    9       
    10      Rounded("div#search","tlbr","#000","#383229"); 
    11      Rounded("div.categories","tlbr","#000","#383229"); 
    12      Rounded("div#archives","tlbr","#000","#383229"); 
    13      Rounded("div#lastcomments","tlbr","#000","#383229"); 
    14      Rounded("div#calendar","tlbr","#000","#383229"); 
    15      Rounded("div.links","tlbr","#000","#383229"); 
    16      Rounded("div.syndicate","tlbr","#000","#383229"); 
    17      Rounded("div.tags","tlbr","#000","#383229"); 
    18      Rounded("div.langs","tlbr","#000","#383229"); 
    19      Rounded("div#topnav","tlbr","#000","#383229"); 
    20      Rounded("div.selected","tlbr","#000","#383229"); 
    21      Rounded("div.feed","tlbr","#000","#383229"); 
    22       
    23       
    24      /*Rounded("div.post","tl","#000","#383229"); 
    25      Rounded("div.post-content","tl","#383229","#383229"); 
    26      Rounded("div.post-content","none","red","blue");*/ 
    27       
    28      /*Rounded("div#trackbacks","tl","#000","#595041"); 
    29      Rounded("div#comments","tl","#000","#383229"); 
    30      Rounded("div#comment-form","tl","#000","#595041");*/ 
    31       
    32       
    33 } 
    34  
    35  
    36 function NiftyCheck(){ 
    37 if(!document.getElementById || !document.createElement) 
    38     return(false); 
    39 isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName); 
    40 if(Array.prototype.push==null){Array.prototype.push=function(){ 
    41       this[this.length]=arguments[0]; return(this.length);}} 
    42 return(true); 
    43 } 
    44  
    45 function Rounded(selector,wich,bk,color,opt){ 
    46 var i,prefixt,prefixb,cn="r",ecolor="",edges=false,eclass="",b=false,t=false; 
    47  
    48 if(color=="transparent"){ 
    49     cn=cn+"x"; 
    50     ecolor=bk; 
    51     bk="transparent"; 
    52     } 
    53 else if(opt && opt.indexOf("border")>=0){ 
    54     var optar=opt.split(" "); 
    55     for(i=0;i<optar.length;i++) 
    56         if(optar[i].indexOf("#")>=0) ecolor=optar[i]; 
    57     if(ecolor=="") ecolor="#666"; 
    58     cn+="e"; 
    59     edges=true; 
    60     } 
    61 else if(opt && opt.indexOf("smooth")>=0){ 
    62     cn+="a"; 
    63     ecolor=Mix(bk,color); 
    64     } 
    65 if(opt && opt.indexOf("small")>=0) cn+="s"; 
    66 prefixt=cn; 
    67 prefixb=cn; 
    68 if(wich.indexOf("all")>=0){t=true;b=true} 
    69 else if(wich.indexOf("top")>=0) t="true"; 
    70 else if(wich.indexOf("tl")>=0){ 
    71     t="true"; 
    72     if(wich.indexOf("tr")<0) prefixt+="l"; 
    73     } 
    74 else if(wich.indexOf("tr")>=0){ 
    75     t="true"; 
    76     prefixt+="r"; 
    77     } 
    78 if(wich.indexOf("bottom")>=0) b=true; 
    79 else if(wich.indexOf("bl")>=0){ 
    80     b="true"; 
    81     if(wich.indexOf("br")<0) prefixb+="l"; 
    82     } 
    83 else if(wich.indexOf("br")>=0){ 
    84     b="true"; 
    85     prefixb+="r"; 
    86     } 
    87 var v=getElementsBySelector(selector); 
    88 var l=v.length; 
    89 for(i=0;i<l;i++){ 
    90     if(edges) AddBorder(v[i],ecolor); 
    91     if(t) AddTop(v[i],bk,color,ecolor,prefixt); 
    92     if(b) AddBottom(v[i],bk,color,ecolor,prefixb); 
    93     } 
    94 } 
    95  
    96 function AddBorder(el,bc){ 
    97 var i; 
    98 if(!el.passed){ 
    99     if(el.childNodes.length==1 && el.childNodes[0].nodeType==3){ 
    100         var t=el.firstChild.nodeValue; 
    101         el.removeChild(el.lastChild); 
    102         var d=CreateEl("span"); 
    103         d.style.display="block"; 
    104         d.appendChild(document.createTextNode(t)); 
    105         el.appendChild(d); 
     1$(function() { 
     2     $('#sidebar>div>div').corner('tl br 10px'); 
     3}); 
     4 
     5// jquery-roundcorners-canvas 
     6// www.meerbox.nl 
     7 
     8(function($){ 
     9      
     10     var _corner = function(options) { 
     11      
     12          // nothing to do, so return 
     13          if (this.length==0) return this; 
     14           
     15          // excanvas.js not loaded 
     16          if ($.browser.msie && typeof G_vmlCanvasManager == 'undefined') return this; 
     17           
     18          // get lowest number from array 
     19          var asNum = function(a, b) { return a-b; }; 
     20          var getMin = function(a) { 
     21               var b = a.concat(); 
     22               return b.sort(asNum)[0]; 
     23          }; 
     24           
     25          // get CSS value as integer 
     26          var getCSSint = function(el, prop) { 
     27               return parseInt($.css(el.jquery?el[0]:el,prop))||0; 
     28          }; 
     29                
     30          // draw the round corner in Canvas object 
     31          var drawRoundCornerCanvasShape = function(canvas,radius,r_type,bg_color,border_width,border_color) { 
     32                
     33               // change rgba(1,2,3,0.9) to rgb(1,2,3) 
     34               var reg = /^rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/;    
     35               var bits = reg.exec(bg_color); 
     36               if (bits) { 
     37                    channels = new Array(parseInt(bits[1]),parseInt(bits[2]),parseInt(bits[3])); 
     38                    bg_color = 'rgb('+channels[0]+', '+channels[1]+', '+channels[2]+')'; 
     39               }  
     40           
     41               var border_width = parseInt(border_width); 
     42                
     43               var ctx = canvas.getContext('2d'); 
     44                
     45               if (radius == 1) { 
     46                    ctx.fillStyle = bg_color; 
     47                    ctx.fillRect(0,0,1,1); 
     48                    return; 
     49               } 
     50      
     51               if (r_type == 'tl') { 
     52                    var steps = new Array(0,0,radius,0,radius,0,0,radius,0,0); 
     53               } else if (r_type == 'tr') { 
     54                    var steps = new Array(radius,0,radius,radius,radius,0,0,0,0,0); 
     55               } else if (r_type == 'bl') { 
     56                    var steps = new Array(0,radius,radius,radius,0,radius,0,0,0,radius); 
     57               } else if (r_type == 'br') { 
     58                    var steps = new Array(radius,radius,radius,0,radius,0,0,radius,radius,radius); 
     59               } 
     60                
     61               ctx.fillStyle = bg_color; 
     62          ctx.beginPath(); 
     63               ctx.moveTo(steps[0],steps[1]);  
     64               ctx.lineTo(steps[2], steps[3]);  
     65          if(r_type == 'br') ctx.bezierCurveTo(steps[4], steps[5], radius, radius, steps[6], steps[7]);  
     66          else ctx.bezierCurveTo(steps[4], steps[5], 0, 0, steps[6], steps[7]); 
     67               ctx.lineTo(steps[8], steps[9]);  
     68             ctx.fill();  
     69              
     70             // draw border 
     71             if (border_width > 0 && border_width < radius) { 
     72                   
     73                  // offset caused by border 
     74                  var offset = border_width/2;  
     75                   
     76                  if (r_type == 'tl') { 
     77                         var steps = new Array(radius-offset,offset,radius-offset,offset,offset,radius-offset); 
     78                         var curve_to = new Array(0,0); 
     79                    } else if (r_type == 'tr') { 
     80                         var steps = new Array(radius-offset,radius-offset,radius-offset,offset,offset,offset); 
     81                         var curve_to = new Array(0,0); 
     82                    } else if (r_type == 'bl') { 
     83                         var steps = new Array(radius-offset,radius-offset,offset,radius-offset,offset,offset,offset,radius-offset); 
     84                         var curve_to = new Array(0,0); 
     85                    } else if (r_type == 'br') { 
     86                         var steps = new Array(radius-offset,offset,radius-offset,offset,offset,radius-offset,radius-offset,radius-offset); 
     87                         var curve_to = new Array(radius, radius); 
     88                    } 
     89                   
     90                  ctx.strokeStyle = border_color; 
     91                  ctx.lineWidth = border_width; 
     92               ctx.beginPath(); 
     93               // go to corner to begin curve 
     94                    ctx.moveTo(steps[0], steps[1]);  
     95                    // curve from righttop to leftbottom (for the tl canvas) 
     96               ctx.bezierCurveTo(steps[2], steps[3], curve_to[0], curve_to[1], steps[4], steps[5]);  
     97                    ctx.stroke(); 
     98                   
     99              } 
     100          }; 
     101           
     102          var creatCanvas = function(p,radius) { 
     103               var elm = document.createElement('canvas'); 
     104               elm.setAttribute("height", radius); 
     105          elm.setAttribute("width", radius);  
     106               elm.style.display = "block"; 
     107               elm.style.position = "absolute"; 
     108               elm.className = "cornercanvas"; 
     109               elm = p.appendChild(elm);  
     110               if (!elm.getContext && typeof G_vmlCanvasManager != 'undefined') { 
     111                    elm = G_vmlCanvasManager.initElement(elm); 
     112               } 
     113               return elm; 
     114          }; 
     115           
     116          // interpret the (string) argument 
     117          var o = (options || "").toLowerCase(); 
     118          var radius = parseInt((o.match(/(\d+)px/)||[])[1]) || null; // corner width 
     119          var bg_color = ((o.match(/(#[0-9a-f]+)/)||[])[1]);  // strip color 
     120          if (radius == null) { radius = "auto"; } 
     121           
     122          var edges = { T:0, B:1 }; 
     123     var opts = { 
     124          tl:  /top|tl/.test(o),        
     125          tr:  /top|tr/.test(o), 
     126          bl:  /bottom|bl/.test(o),     
     127          br:  /bottom|br/.test(o) 
     128     }; 
     129     if ( !opts.tl && !opts.tr && !opts.bl && !opts.br) { 
     130          opts = { tl:1, tr:1, bl:1, br:1 }; 
    106131        } 
    107     for(i=0;i<el.childNodes.length;i++){ 
    108         if(el.childNodes[i].nodeType==1){ 
    109             el.childNodes[i].style.borderLeft="1px solid "+bc; 
    110             el.childNodes[i].style.borderRight="1px solid "+bc; 
    111             } 
    112         } 
    113     } 
    114 el.passed=true; 
    115 } 
    116      
    117 function AddTop(el,bk,color,bc,cn){ 
    118 var i,lim=4,d=CreateEl("b"); 
    119  
    120 if(cn.indexOf("s")>=0) lim=2; 
    121 if(bc) d.className="artop"; 
    122 else d.className="rtop"; 
    123 d.style.backgroundColor=bk; 
    124 for(i=1;i<=lim;i++){ 
    125     var x=CreateEl("b"); 
    126     x.className=cn + i; 
    127     x.style.backgroundColor=color; 
    128     if(bc) x.style.borderColor=bc; 
    129     d.appendChild(x); 
    130     } 
    131 el.style.paddingTop=0; 
    132 el.insertBefore(d,el.firstChild); 
    133 } 
    134  
    135 function AddBottom(el,bk,color,bc,cn){ 
    136 var i,lim=4,d=CreateEl("b"); 
    137  
    138 if(cn.indexOf("s")>=0) lim=2; 
    139 if(bc) d.className="artop"; 
    140 else d.className="rtop"; 
    141 d.style.backgroundColor=bk; 
    142 for(i=lim;i>0;i--){ 
    143     var x=CreateEl("b"); 
    144     x.className=cn + i; 
    145     x.style.backgroundColor=color; 
    146     if(bc) x.style.borderColor=bc; 
    147     d.appendChild(x); 
    148     } 
    149 el.style.paddingBottom=0; 
    150 el.appendChild(d); 
    151 } 
    152  
    153 function CreateEl(x){ 
    154 if(isXHTML) return(document.createElementNS('http://www.w3.org/1999/xhtml',x)); 
    155 else return(document.createElement(x)); 
    156 } 
    157  
    158 function getElementsBySelector(selector){ 
    159 var i,selid="",selclass="",tag=selector,f,s=[],objlist=[]; 
    160  
    161 if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag" 
    162     s=selector.split(" "); 
    163     var fs=s[0].split("#"); 
    164     if(fs.length==1) return(objlist); 
    165     f=document.getElementById(fs[1]); 
    166     if(f) return(f.getElementsByTagName(s[1])); 
    167     return(objlist); 
    168     } 
    169 if(selector.indexOf("#")>0){ //id selector like "tag#id" 
    170     s=selector.split("#"); 
    171     tag=s[0]; 
    172     selid=s[1]; 
    173     } 
    174 if(selid!=""){ 
    175     f=document.getElementById(selid); 
    176     if(f) objlist.push(f); 
    177     return(objlist); 
    178     } 
    179 if(selector.indexOf(".")>0){  //class selector like "tag.class" 
    180     s=selector.split("."); 
    181     tag=s[0]; 
    182     selclass=s[1]; 
    183     } 
    184 var v=document.getElementsByTagName(tag);  // tag selector like "tag" 
    185 if(selclass=="") 
    186     return(v); 
    187 for(i=0;i<v.length;i++){ 
    188     if(v[i].className.indexOf(selclass)>=0){ 
    189         objlist.push(v[i]); 
    190         } 
    191     } 
    192 return(objlist); 
    193 } 
    194  
    195 function Mix(c1,c2){ 
    196 var i,step1,step2,x,y,r=new Array(3); 
    197 if(c1.length==4)step1=1; 
    198 else step1=2; 
    199 if(c2.length==4) step2=1; 
    200 else step2=2; 
    201 for(i=0;i<3;i++){ 
    202     x=parseInt(c1.substr(1+step1*i,step1),16); 
    203     if(step1==1) x=16*x+x; 
    204     y=parseInt(c2.substr(1+step2*i,step2),16); 
    205     if(step2==1) y=16*y+y; 
    206     r[i]=Math.floor((x*50+y*50)/100); 
    207     } 
    208 return("#"+r[0].toString(16)+r[1].toString(16)+r[2].toString(16)); 
    209 } 
     132       
     133          return this.each(function() { 
     134 
     135               var elm = $(this); 
     136               var hover = /hover/.test(o); 
     137                
     138               if (hover) { 
     139                     
     140                    options = options.replace(/hover/i, ""); 
     141                     
     142                    elm.hover(function(){ 
     143                         $(this).addClass('jrcHover'); 
     144                         $(this).corner(options); 
     145                    },function(){ 
     146                         $(this).removeClass('jrcHover');    
     147                         $(this).corner(options); 
     148                    }); 
     149                     
     150               } 
     151                
     152               if ($.browser.msie) {  
     153 
     154                    // give element 'haslayout' 
     155                    elm.css('zoom','1'); 
     156                    // give the child elements 'haslayout' 
     157                    elm.children().css('zoom','1'); 
     158                     
     159                    if (elm.css('height') == 'auto') elm.height(elm.height()); 
     160                     
     161                    // msie6 rendering bugs :( 
     162                    if ($.browser.msie && typeof document.body.style.maxHeight == "undefined") { 
     163                         if (elm.width()%2 != 0) { elm.width(elm.width()+1); } 
     164                         if (elm.height()%2 != 0) { elm.height(elm.height()+1); } 
     165                         if (elm.css('lineHeight') != 'normal' && elm.height() < elm.css('lineHeight')) { 
     166                              elm.css('lineHeight', elm.height()); 
     167                         } 
     168                         if (elm.css('lineHeight') == 'normal') elm.css('lineHeight','1'); // dont ask 
     169                    } 
     170               } 
     171                
     172               var arr = new Array(elm.get(0).offsetHeight,elm.get(0).offsetWidth); 
     173               if (elm.height() != 0) arr[arr.length] = elm.height(); 
     174               if (elm.width() != 0) arr[arr.length] = elm.width(); 
     175               var widthheight_smallest = getMin(arr); 
     176                
     177               // the size of the corner is not defined... 
     178               if (radius == "auto") { 
     179                    radius = widthheight_smallest/2; 
     180                    if (radius > 10) { radius = 10; } 
     181               } 
     182 
     183               // the size of the corner can't be to high 
     184               if (radius > widthheight_smallest/2) {  
     185                    radius = (widthheight_smallest/2);  
     186               } 
     187                
     188               radius = Math.floor(radius); 
     189                
     190               // some css thats required in order to position the canvas elements 
     191               if (elm.css('position') == 'static') {  
     192                    elm.css('position','relative');  
     193               // only needed for ie6 and (ie7 in Quirks mode) , CSS1Compat == Strict mode 
     194               } else if (elm.css('position') == 'fixed' && $.browser.msie && !(document.compatMode == 'CSS1Compat' && typeof document.body.style.maxHeight != "undefined")) {  
     195                    elm.css('position','absolute'); 
     196               } 
     197               elm.css('overflow','visible');  
     198                
     199               // get border width 
     200               var border_t = getCSSint(this, 'borderTopWidth'); 
     201               var border_r = getCSSint(this, 'borderRightWidth'); 
     202               var border_b = getCSSint(this, 'borderBottomWidth'); 
     203               var border_l = getCSSint(this, 'borderLeftWidth'); 
     204                
     205               // get the lowest borderwidth of the corners in use 
     206               var bordersWidth = new Array(); 
     207               if (opts.tl || opts.tr) { bordersWidth.push(border_t); } 
     208               if (opts.br || opts.tr) { bordersWidth.push(border_r); } 
     209               if (opts.br || opts.bl) { bordersWidth.push(border_b); } 
     210               if (opts.bl || opts.tl) { bordersWidth.push(border_l); } 
     211                
     212               var borderswidth_smallest = getMin(bordersWidth); 
     213                
     214               // creat the canvas elements and position them 
     215               var p_top = 0-border_t; 
     216               var p_right = 0-border_r; 
     217               var p_bottom = 0-border_b; 
     218               var p_left = 0-border_l;  
     219                
     220               // remove old stuff 
     221               elm.children("canvas.cornercanvas").remove(); 
     222 
     223               if (opts.tl) { var tl = $(creatCanvas(this,radius)).css({left:p_left,top:p_top}).get(0); } 
     224               if (opts.tr) { var tr = $(creatCanvas(this,radius)).css({right:p_right,top:p_top}).get(0); } 
     225               if (opts.bl) { var bl = $(creatCanvas(this,radius)).css({left:p_left,bottom:p_bottom}).get(0); } 
     226               if (opts.br) { var br = $(creatCanvas(this,radius)).css({right:p_right,bottom:p_bottom}).get(0); } 
     227                
     228               // get the background color of parent element 
     229               if (bg_color == undefined) { 
     230                    var current_p = elm.parent(); 
     231                    var bg = current_p.css('background-color'); 
     232                    while((bg == "transparent" || bg == "rgba(0, 0, 0, 0)") && (typeof current_p == 'object') && !current_p.is("html")) { 
     233                         bg = current_p.css('background-color'); 
     234                         current_p = current_p.parent(); 
     235                    } 
     236                     
     237               } else { 
     238                    bg = bg_color; 
     239               } 
     240 
     241               if (bg == "transparent" || bg == "rgba(0, 0, 0, 0)") { bg = "#ffffff"; } 
     242                
     243               if (opts.tl) { drawRoundCornerCanvasShape(tl,radius,'tl',bg,borderswidth_smallest,elm.css('borderTopColor')); } 
     244               if (opts.tr) { drawRoundCornerCanvasShape(tr,radius,'tr',bg,borderswidth_smallest,elm.css('borderTopColor')); } 
     245               if (opts.bl) { drawRoundCornerCanvasShape(bl,radius,'bl',bg,borderswidth_smallest,elm.css('borderBottomColor')); } 
     246               if (opts.br) { drawRoundCornerCanvasShape(br,radius,'br',bg,borderswidth_smallest,elm.css('borderBottomColor')); } 
     247                
     248               elm.addClass('roundCornersParent'); 
     249                     
     250          });   
     251     }; 
     252      
     253     $.fn.corner = _corner; 
     254      
     255})(jQuery); 
Note: See TracChangeset for help on using the changeset viewer.

Sites map