rounded_corners.inc.js.tmp

来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· TMP 代码 · 共 1,115 行 · 第 1/4 页

TMP
1,115
字号
                                  newCorner.style.borderRight  = this.borderString;                                  newCorner.style.borderBottom = this.borderString;                                  newCorner.style.left         = this.borderWidth + "px"                                  newCorner.style.backgroundPosition = "-" + (botMaxRadius + this.borderWidth) + "px -" + (this.boxHeight + (botMaxRadius + this.borderWidth)) + "px";                                  break;                          }                      }                  }                  else                  {                      /*                      PERFORMANCE NOTE:                      If more than one corner is requested and a corner has been already                      created for the same radius then that corner will be used as a master and cloned.                      The pixel bars will then be repositioned to form the new corner type.                      All new corners start as a bottom right corner.                      */                      //alert(masterCorners["boxId: "+ cc]+ cc);                      /*if(cc == "tr"){                      	  if(masterCorners[this.settings[cc].radius])                      	  	var newCorner = masterCorners[this.settings["tr"].radius].cloneNode(true);                      	  //alert("cloning tr");                      }else if(cc == "br"){                          if(masterCorners[this.settings[cc].radius])                      	  	var newCorner = masterCorners[this.settings["br"].radius].cloneNode(true);                      	  //alert("cloning br");                      }*/                                            if(masterCorners[this.settings[cc].radius] && cc == "tl"){                      	  var newCorner = masterCorners[this.settings["tr"].radius].cloneNode(true);                      }else if(masterCorners[this.settings[cc].radius] && cc == "bl"){                      	  var newCorner = masterCorners[this.settings["br"].radius].cloneNode(true);                      }else{                          // Yes, we need to create a new corner                          var newCorner = document.createElement("DIV");                          newCorner.style.height = this.settings[cc].radius + "px";                          newCorner.style.width  = this.settings[cc].radius + "px";                          newCorner.style.position = "absolute";                          newCorner.style.fontSize = "1px";                          newCorner.style.overflow = "hidden";                          // THE FOLLOWING BLOCK OF CODE CREATES A ROUNDED CORNER                          // ---------------------------------------------------- TOP                          // Get border radius                          var borderRadius = parseInt(this.settings[cc].radius - this.borderWidth);                          // Cycle the x-axis                          for(var intx = 0, j = this.settings[cc].radius; intx < j; intx++)                          {                              // Calculate the value of y1 which identifies the pixels inside the border                              if((intx +1) >= borderRadius)                                var y1 = -1;                              else                                var y1 = (Math.floor(Math.sqrt(Math.pow(borderRadius, 2) - Math.pow((intx+1), 2))) - 1);                              // Only calculate y2 and y3 if there is a border defined                              if(borderRadius != j)                              {                                  if((intx) >= borderRadius)                                    var y2 = -1;                                  else                                    var y2 = Math.ceil(Math.sqrt(Math.pow(borderRadius,2) - Math.pow(intx, 2)));                                  if((intx+1) >= j)                                    var y3 = -1;                                  else                                    var y3 = (Math.floor(Math.sqrt(Math.pow(j ,2) - Math.pow((intx+1), 2))) - 1);                              }                              // Calculate y4                              if((intx) >= j)                                var y4 = -1;                              else                                var y4 = Math.ceil(Math.sqrt(Math.pow(j ,2) - Math.pow(intx, 2)));                              // Draw bar on inside of the border with foreground colour                              if(y1 > -1) this.drawPixel(intx, 0, this.boxColour, 100, (y1+1), newCorner, -1, this.settings[cc].radius,cc);                              // Only draw border/foreground antialiased pixels and border if there is a border defined                              if(borderRadius != j)                              {                                  // Cycle the y-axis                                  for(var inty = (y1 + 1); inty < y2; inty++)                                  {                                      // Draw anti-alias pixels                                      if(this.settings.antiAlias)                                      {                                          // For each of the pixels that need anti aliasing between the foreground and border colour draw single pixel divs                                          if(this.backgroundImage != "")                                          {                                              var borderFract = (pixelFraction(intx, inty, borderRadius) * 100);                                              if(borderFract < 30)                                              {										      		this.drawPixel(intx, inty, this.borderColour, 100, 1, newCorner, 0, this.settings[cc].radius,myobj);                                              }else{									                this.drawPixel(intx, inty, this.borderColour, 100, 1, newCorner, -1, this.settings[cc].radius,myobj);                                              }                                          }                                          else                                          {                                              var pixelcolour = BlendColour(this.boxColour, this.borderColour, pixelFraction(intx, inty, borderRadius));                                              this.drawPixel(intx, inty, pixelcolour, 100, 1, newCorner, 0, this.settings[cc].radius, myobj);                                          }                                      }                                  }                                  // Draw bar for the border                                  if(this.settings.antiAlias)                                  {                                      if(y3 >= y2)                                      {                                         if (y2 == -1) y2 = 0;                                         this.drawPixel(intx, y2, this.borderColour, 100, (y3 - y2 + 1), newCorner, 0, 0,myobj);                                      }                                  }                                  else                                  {                                      if(y3 >= y1)                                      {                                          this.drawPixel(intx, (y1 + 1), this.borderColour, 100, (y3 - y1), newCorner, 0, 0,myobj);                                      }                                  }                                  // Set the colour for the outside curve                                  var outsideColour = this.borderColour;                              }                              else                              {                                  // Set the coour for the outside curve                                  var outsideColour = this.boxColour;                                  var y3 = y1;                              }                              // Draw aa pixels?                              if(this.settings.antiAlias)                              {                                  // Cycle the y-axis and draw the anti aliased pixels on the outside of the curve                                  for(var inty = (y3 + 1); inty < y4; inty++)                                  {                                      // For each of the pixels that need anti aliasing between the foreground/border colour & background draw single pixel divs                                      this.drawPixel(intx, inty, outsideColour, (pixelFraction(intx, inty , j) * 100), 1, newCorner, ((this.borderWidth > 0)? 0 : -1), this.settings[cc].radius,myobj);                                  }                              }                          }                          // END OF CORNER CREATION                          // ---------------------------------------------------- END                          // We now need to store the current corner in the masterConers array                          masterCorners[this.settings[cc].radius] = newCorner.cloneNode(true);                      }                      /*                      Now we have a new corner we need to reposition all the pixels unless                      the current corner is the bottom right.                      */                      if(cc != "br")                      {                          // Loop through all children (pixel bars)                          for(var t = 0, k = newCorner.childNodes.length; t < k; t++)                          {                              // Get current pixel bar                              var pixelBar = newCorner.childNodes[t];                              // Get current top and left properties                              var pixelBarTop    = parseInt(pixelBar.style.top.substring(0, pixelBar.style.top.indexOf("px")));                              var pixelBarLeft   = parseInt(pixelBar.style.left.substring(0, pixelBar.style.left.indexOf("px")));                              var pixelBarHeight = parseInt(pixelBar.style.height.substring(0, pixelBar.style.height.indexOf("px")));                              // Reposition pixels                              if(cc == "tl" || cc == "bl"){                                  pixelBar.style.left = this.settings[cc].radius -pixelBarLeft -1 + "px"; // Left                              }                              if(cc == "tr" || cc == "tl"){                                  pixelBar.style.top =  this.settings[cc].radius -pixelBarHeight -pixelBarTop + "px"; // Top                              }                              switch(cc)                              {                                  case "tr":                                      pixelBar.style.backgroundPosition  = "-" + Math.abs((this.boxWidth - this.settings[cc].radius + this.borderWidth) + pixelBarLeft) + "px -" + Math.abs(this.settings[cc].radius -pixelBarHeight -pixelBarTop - this.borderWidth) + "px";                                      break;                                  case "tl":                                      pixelBar.style.backgroundPosition = "-" + Math.abs((this.settings[cc].radius -pixelBarLeft -1)  - this.borderWidth) + "px -" + Math.abs(this.settings[cc].radius -pixelBarHeight -pixelBarTop - this.borderWidth) + "px";                                      break;                                  case "bl":                                      pixelBar.style.backgroundPosition = "-" + Math.abs((this.settings[cc].radius -pixelBarLeft -1) - this.borderWidth) + "px -" + Math.abs((this.boxHeight + this.settings[cc].radius + pixelBarTop) -this.borderWidth) + "px";                                      break;                              }                          }                      }                  }                  if(newCorner)                  {                      // Position the container                      switch(cc)                      {                          case "tl":                            if(newCorner.style.position == "absolute") newCorner.style.top  = "0px";                            if(newCorner.style.position == "absolute") newCorner.style.left = "0px";                            if(this.topContainer) this.topContainer.appendChild(newCorner);                            break;                          case "tr":                            if(newCorner.style.position == "absolute") newCorner.style.top  = "0px";                            if(newCorner.style.position == "absolute") newCorner.style.right = "0px";                            if(this.topContainer) this.topContainer.appendChild(newCorner);                            break;                          case "bl":                            if(newCorner.style.position == "absolute") newCorner.style.bottom  = "0px";                            if(newCorner.style.position == "absolute") newCorner.style.left = "0px";                            if(this.bottomContainer) this.bottomContainer.appendChild(newCorner);                            break;                          case "br":                            if(newCorner.style.position == "absolute") newCorner.style.bottom   = "0px";                            if(newCorner.style.position == "absolute") newCorner.style.right = "0px";                            if(this.bottomContainer) this.bottomContainer.appendChild(newCorner);                            break;                      }                  }              }          }          /*          The last thing to do is draw the rest of the filler DIVs.          We only need to create a filler DIVs when two corners have          diffrent radiuses in either the top or bottom container.          */          // Find out which corner has the biiger radius and get the difference amount          var radiusDiff = new Array();          radiusDiff["t"] = Math.abs(this.settings.tl.radius - this.settings.tr.radius)          radiusDiff["b"] = Math.abs(this.settings.bl.radius - this.settings.br.radius);          for(z in radiusDiff)          {              // FIX for prototype lib              if(z == "t" || z == "b")              {                  if(radiusDiff[z])                  {                      // Get the type of corner that is the smaller one                      var smallerCornerType = ((this.settings[z + "l"].radius < this.settings[z + "r"].radius)? z +"l" : z +"r");                      // First we need to create a DIV for the space under the smaller corner                      var newFiller = document.createElement("DIV");                      newFiller.style.height = radiusDiff[z] + "px";                      newFiller.style.width  =  this.settings[smallerCornerType].radius+ "px"                      newFiller.style.position = "absolute";                      newFiller.style.fontSize = "1px";                      newFiller.style.overflow = "hidden";                      newFiller.style.backgroundColor = this.boxColour;                      //newFiller.style.backgroundColor = get_random_color();                      // Position filler                      switch(smallerCornerType)                      {                          case "tl":                              newFiller.style.bottom = "0px";                              newFiller.style.left   = "0px";                              newFiller.style.borderLeft = this.borderString;                              this.topContainer.appendChild(newFiller);                              break;                          case "tr":                              newFiller.style.bottom = "0px";                              newFiller.style.right  = "0px";                              newFiller.style.borderRight = this.borderString;                              this.topContainer.appendChild(newFiller);                              break;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?