增强的广告飘浮与定位广告.

n久以前的
样式表

<?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:variable name="linkAddr">
       <xsl:choose>
        <xsl:when test="LimitTime/TimeSlice and LimitTime/TimeSlice/BeginTime and LimitTime/TimeSlice/BeginTime!='' and LimitTime/TimeSlice/EndTime!=''">/Frame/FloatAD/FloatControl.aspx?id=<xsl:value-of select="./Id" /></xsl:when>
        <xsl:otherwise>
         <xsl:value-of select="LinkAddr"/>
        </xsl:otherwise>
       </xsl:choose>
      </xsl:variable>
      <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 != ''">
    var iPosLeft = (window.screen.availWidth - <xsl:value-of select="$popupWidth"/>)/2;
    var iPosTop  = (window.screen.availHeight - <xsl:value-of select="$popupHeight"/>)/2;
    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,'left="+iPosLeft+",top="+iPosTop+",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;
     this.objPoint = document.createElement("&lt;img src='" + srcFile + "' height='" + height + "' width='" + width + "' style='cursor:hand'/>");
     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;
   var iPosLeft = (window.screen.availWidth - popupWidth)/2;
   var iPosTop  = (window.screen.availHeight - popupHeight)/2;
   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="+iPosLeft+",top="+iPosTop+",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>

配置文件
<?xml version="1.0" encoding="GB2312"?>
<Config>
  <AD>
    <Id>1</Id>
    <!--是否可用-->
    <Enabled>true</Enabled>
    <!--浮动类型1为随机浮动,2为定点浮动-->
    <FloatType>1</FloatType>
    <!--文件类型包括swf,或(image)各种web支持的图片格式,图片格式不用设置高度,宽度-->
    <FileType>image</FileType>
    <PhotoURL>/Popup/kaoshilogo.gif</PhotoURL>
    <LinkAddr>/HR/Investigation/StandbyInvesList.aspx</LinkAddr>
    <PopupHeight>
    </PopupHeight>
    <PopupWidth>
    </PopupWidth>
    <PhotoTop>100</PhotoTop>
    <PhotoLeft>20</PhotoLeft>
    <PhotoHeight>274</PhotoHeight>
    <PhotoWidth>60</PhotoWidth>
    <LimitTime>
      <TimeSlice>
        <BeginTime>8:00</BeginTime>
        <EndTime>11:30</EndTime>
      </TimeSlice>
      <TimeSlice>
        <BeginTime>13:00</BeginTime>
        <EndTime>16:00</EndTime>
      </TimeSlice>
    </LimitTime>
  </AD>
  <AD>
    <Id>4</Id>
    <Enabled>true</Enabled>
    <FloatType>1</FloatType>
    <FileType>image</FileType>
    <PhotoURL>/popup/pic-diaocha-005.gif</PhotoURL>
    <LinkAddr>/Running/Project/InnovationAddForIndex.aspx</LinkAddr>
    <PopupHeight>450</PopupHeight>
    <PopupWidth>700</PopupWidth>
    <PhotoTop>50</PhotoTop>
    <PhotoLeft>50</PhotoLeft>
    <PhotoHeight>77</PhotoHeight>
    <PhotoWidth>87</PhotoWidth>
    <LimitTime>
      <TimeSlice>
        <BeginTime>8:00</BeginTime>
        <EndTime>9:00</EndTime>
      </TimeSlice>
      <TimeSlice>
        <BeginTime>10:00</BeginTime>
        <EndTime>12:00</EndTime>
      </TimeSlice>
    </LimitTime>
  </AD>
</Config>
Advertisements
此条目发表在Xml/Xslt分类目录。将固定链接加入收藏夹。

发表评论

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

WordPress.com Logo

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