定点广告与漂浮广告

配置文件 XML 内容
 
<?xml version="1.0" encoding="GB2312"?> 
<Config>
 <AD>
  <!--是否可用-->
  <Enabled>true</Enabled>
  <!--浮动类型1为随机浮动,2为定点浮动-->
  <FloatType>1</FloatType>
  <!--文件类型包括swf,或(image)各种web支持的图片格式,图片格式不用设置高度,宽度-->
  <FileType>swf</FileType>
  <PhotoURL>http://image2.sina.com.cn/dy/ad/cmad120x250a.swf</PhotoURL>
  <LinkAddr>http://user.7host.com/ioriwellings/</LinkAddr>
  <PopupHeight></PopupHeight>
  <PopupWidth></PopupWidth>
  <PhotoTop>100</PhotoTop>
  <PhotoLeft>20</PhotoLeft>
  <PhotoHeight>250</PhotoHeight>
  <PhotoWidth>120</PhotoWidth>
 </AD>
 
 <AD>
  <!--是否可用-->
  <Enabled>true</Enabled>
  <!--浮动类型1为随机浮动,2为定点浮动-->
  <FloatType>2</FloatType>
  <!--文件类型包括swf,或(image)各种web支持的图片格式,图片格式不用设置高度,宽度-->
  <FileType>image</FileType>
  <PhotoURL>http://www.sanhaostreet.com/imagesindex/indexnew_shop.jpg</PhotoURL>
  <LinkAddr>http://user.7host.com/ioriwellings/</LinkAddr>
  <PopupHeight>250</PopupHeight>
  <PopupWidth>120</PopupWidth>
  <PhotoTop>100</PhotoTop>
  <PhotoLeft>20</PhotoLeft>
  <PhotoHeight>90</PhotoHeight>
  <PhotoWidth>90</PhotoWidth>
 </AD>
 
 <AD>
  <!--是否可用-->
  <Enabled>true</Enabled>
  <!--浮动类型1为随机浮动,2为定点浮动-->
  <FloatType>1</FloatType>
  <!--文件类型包括swf,或(image)各种web支持的图片格式-->
  <FileType>image</FileType>
  <PhotoURL>http://image2.sina.com.cn/dy/temp/119/2003-12-30/U40P1T119D21F2656DT20050814120827.gif</PhotoURL>
  <LinkAddr>http://user.7host.com/ioriwellings/</LinkAddr>
  <PopupHeight>250</PopupHeight>
  <PopupWidth>120</PopupWidth>
  <!--仅适用于定点浮动-->
  <PhotoTop>100</PhotoTop>
  <PhotoLeft>750</PhotoLeft>
  <PhotoHeight>90</PhotoHeight>
  <PhotoWidth>90</PhotoWidth>
  <!--结速-->
 </AD> 
</Config>
转换文件 XSLT内容:
<?xml version="1.0" encoding="GB2312"?>
<!--作者:杨林 at 2005-08-?? -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="html"/>
 
 <xsl:template match="/Config">
  
  <xsl:if test="AD/FloatType[.=1][../Enabled='true']">
   <xsl:call-template name="getCodeOfFloat"/>
  </xsl:if>
  
  <xsl:if test="AD/FloatType[.=2][../Enabled='true']">
   <xsl:call-template name="getCodeOfPosition"/>
  </xsl:if>
  
  <script language="javascript">
   <xsl:for-each select="AD">
    <xsl:if test="Enabled and not(Enabled='false')">
      <xsl:call-template name="runCode">
       <xsl:with-param name="photoURL" select="PhotoURL"/>
       <xsl:with-param name="fileType" select="FileType"/>
       <xsl:with-param name="photoHeight" select="PhotoHeight"/>
       <xsl:with-param name="photoWidth" select="PhotoWidth"/>
       <xsl:with-param name="linkAddr" select="LinkAddr"/>
       <xsl:with-param name="zIndex" select="ZIndex"/>
       <xsl:with-param name="floatType" select="FloatType"/>
       <xsl:with-param name="photoTop" select="PhotoTop"/>
       <xsl:with-param name="photoLeft" select="PhotoLeft"/>
       <xsl:with-param name="popupHeight" select="PopupHeight"/>
       <xsl:with-param name="popupWidth" select="PopupWidth"/>
      </xsl:call-template>  
     
    </xsl:if>
   </xsl:for-each>
  </script>
  
 </xsl:template>
 
 <xsl:template name="runCode">
 
  <xsl:param name="photoURL"/>
  <xsl:param name="fileType"/>
  <xsl:param name="photoHeight"/>
  <xsl:param name="photoWidth"/>
  <xsl:param name="linkAddr"/>
  <xsl:param name="zIndex"/>
  <xsl:param name="floatType"/>
  <xsl:param name="photoTop"/>
  <xsl:param name="photoLeft"/>
  <xsl:param name="popupHeight"/>
  <xsl:param name="popupWidth"/>
  <xsl:if test="$floatType and $floatType=1">
   //执行漂浮广告,挂接到onload事件上;
   <xsl:if test="$popupHeight='' or $popupWidth=''">
    window.attachEvent("onload",function(){new randFly(<xsl:value-of select="$photoHeight"/>,<xsl:value-of select="$photoWidth"/>,"<xsl:value-of select="$photoURL"/>",2,35,"window.open('<xsl:value-of select="$linkAddr"/>')"<xsl:if test="$fileType='swf'">,"swf"</xsl:if>);});
   </xsl:if>
   <xsl:if test="$popupHeight != '' and $popupWidth != ''">
    window.attachEvent("onload",function(){new randFly(<xsl:value-of select="$photoHeight"/>,<xsl:value-of select="$photoWidth"/>,"<xsl:value-of select="$photoURL"/>",2,35,"window.open('<xsl:value-of select="$linkAddr"/>',null,'top=0,left=0,height=<xsl:value-of select="$popupHeight"/>,width=<xsl:value-of select="$popupWidth"/>')"<xsl:if test="$fileType='swf'">,"swf"</xsl:if>);});
   </xsl:if>
  </xsl:if>
  
  <xsl:if test="$floatType and $floatType=2">
   //调用定点广告实例方法;
   <xsl:if test="$popupHeight='' or $popupWidth=''">
    new PositionAD(<xsl:value-of select="$photoTop"/>,<xsl:value-of select="$photoLeft"/>,<xsl:value-of select="$photoHeight"/>,<xsl:value-of select="$photoWidth"/>,"<xsl:value-of select="$photoURL"/>","<xsl:value-of select="$linkAddr"/>","<xsl:value-of select="$fileType"/>").myload();
   </xsl:if>
   <xsl:if test="$popupHeight != '' and $popupWidth != ''">
    new PositionAD(<xsl:value-of select="$photoTop"/>,<xsl:value-of select="$photoLeft"/>,<xsl:value-of select="$photoHeight"/>,<xsl:value-of select="$photoWidth"/>,"<xsl:value-of select="$photoURL"/>","<xsl:value-of select="$linkAddr"/>","<xsl:value-of select="$fileType"/>","<xsl:value-of select="$popupHeight"/>","<xsl:value-of select="$popupWidth"/>").myload();
   </xsl:if>
  </xsl:if>
   
 </xsl:template>
 
 <xsl:template name="getCodeOfFloat">
  <script language="javascript">
  var randFlyCount = 0;
  var randFlyCollection = new Array();
  randFly.pause = function(){}
  
  //定义漂浮广告对象;
  function randFly(height,width,obj,flyAmount,flyDelay,command,fileType)
  {
   if(typeof obj == "undefined")
   {
    alert("Error");
    return;
   }
   this._ID = randFlyCount++;
   this.objPoint = obj;
   this._amount = flyAmount;
   this._delay  = flyDelay;
   this._command   = command;
   this._setTime;
   this._dirX;
   this._dirY;
   this._stepX;
   this._stepY;
   //实例启动函数;
   this.init = function()
   {
    var srcFile = this.objPoint;
    if(typeof fileType != "undefined" && fileType=="swf"){
     var strSwf = "&lt;EMBED src='"+srcFile+"' height='"+height+"' width='"+width+"' quality='high' TYPE='application/x-shockwave-flash'>&lt;/EMBED>";
     this.objPoint = document.body.appendChild(document.createElement(strSwf));
    }else{
     this.objPoint = new Image();
     this.objPoint.src = srcFile;
     document.body.appendChild(this.objPoint);//生成广告html实体;
    }
    with(this.objPoint)
    {
     style.position = "absolute";
     style.cursor = "hand";
     style.top = (document.body != null)? (document.body.clientHeight - offsetHeight) / 2 : 0;
     style.left = (document.body != null)? (document.body.clientWidth - offsetWidth) / 2 : 0;
     setAttribute("cID",this._ID);//自定义属性;
     setAttribute("reflectClass",this);//自定义属性;
     attachEvent("onclick",new Function(this._command));
     attachEvent("onmouseover",this.pause);//设置鼠标停留事件;
     attachEvent("onmouseout",this.restart);//设置鼠标移出事件;
    }
    this._stepX = this._amount;
    this._stepY = this._amount;
    this._dirX  = rBool();
    this._dirY  = rBool();
    randFlyCollection.push(this);
    this.start();
   }
   
   //方向调整函数;
   this.start = function()
   {
    if(this._dirX == true)
    {
     if(this.objPoint.offsetLeft + this._stepX + this.objPoint.offsetWidth &lt; document.body.scrollLeft+document.body.clientWidth)
     {      
      this.objPoint.style.left = this.objPoint.offsetLeft + this._stepX;
     }
     else
     {
      this.objPoint.style.left = this.objPoint.offsetLeft - this._stepX
      this._dirX = false;
     }
    }
    else
    {
     if(this.objPoint.offsetLeft - this._stepX > 0)
     {
      this.objPoint.style.left = this.objPoint.offsetLeft - this._stepX;
     }
     else
     {
      this.objPoint.style.left = this.objPoint.offsetLeft + this._stepX;
      this._dirX = true;
     }
    }
    if(this._dirY == true)
    {    
     if(this.objPoint.offsetTop + this._stepY + this.objPoint.offsetHeight &lt; document.body.scrollTop+document.body.clientHeight)
     {      
      this.objPoint.style.top = this.objPoint.offsetTop + this._stepY;
     }
     else
     {
      this.objPoint.style.top = this.objPoint.offsetTop - this._stepX
      this._dirY = false;
     }
    }
    else
    {
     if(this.objPoint.offsetTop - this._stepY > 0)
     {
      this.objPoint.style.top = this.objPoint.offsetTop - this._stepY;
     }
     else
     {
      this.objPoint.style.top = this.objPoint.offsetTop + this._stepY;
      this._dirY = true;
     }
    } 
    this._setTime = setTimeout("randFlyCollection["+this.objPoint.cID+"].start()",this._delay);
   }
   this.pause = function()
   {
    clearTimeout(event.srcElement.reflectClass._setTime);
   }
   this.restart = function()
   {
    event.srcElement.reflectClass.start();
   }
   this.init();
  }
  function rBool()
  {
   return (Math.random() > 0.5)? true : false;
  } 
  
  window.attachEvent("onerror",function(){window.event.returnValue=false;return false;});
  </script>
 </xsl:template>
 
 <xsl:template name="getCodeOfPosition">
 
  <script language="javascript">
 
  var positionID = 0;
  var objCollection = new Array();
  //定义定点广告对象;
  function PositionAD(top,left,height,width,photoUrl,photoLink,type,popupHeight,popupWidth){
   var imgTop = top;
   var imgLeft = left;
   var imgHeight = height;
   var imgWidth = width;
   
   this._id = positionID++;
   objCollection.push(this);
   //定位初始化;
   this.myload = function myload()
   {
    eval("myright"+this._id).style.top = document.body.scrollTop+imgTop;
    eval("myright"+this._id).style.left = imgLeft;
    this.mymove();
   }
   //始终定位函数;
   this.mymove = function mymove()
   {
    eval("myright"+this._id).style.top = document.body.scrollTop+imgTop;
    eval("myright"+this._id).style.left = document.body.scrollLeft+imgLeft;
    setTimeout("objCollection["+this._id+"].myload()",50)
   }
   
   //输出广告html;
   if(type == "image")
    document.write("&lt;div id=myright"+this._id+" style='position: absolute;visibility: visible;z-index:10'>&lt;img border='0' src='"+photoUrl+"' style='cursor:hand' onclick=window.open('"+photoLink+"',null,'left=0,top=0,height="+popupHeight+",width="+popupWidth+"')>&lt;/div>");
   
   if(type == "swf")
    document.write("&lt;div id=myright"+this._id+" style='position: absolute;visibility: visible;z-index:10' onclick=window.open('"+photoLink+"','','')>&lt;EMBED src='"+photoUrl+"' height='"+imgHeight+"' width='"+imgWidth+"' quality='high' TYPE='application/x-shockwave-flash'>&lt;/EMBED>&lt;/div>");
  } 
  
  </script>
 </xsl:template>
 
</xsl:stylesheet> 
Advertisements
此条目发表在Xml/Xslt分类目录。将固定链接加入收藏夹。

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

You are commenting using your WordPress.com account. Log Out /  更改 )

Google+ photo

You are commenting using your Google+ account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

w

Connecting to %s