⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 popupwin.cs

📁 h 大噶
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;

namespace AspNetForums.Controls
{
  /// <summary>
  /// Popup window control
  /// </summary>
  [DefaultProperty("Message"),ToolboxData("<{0}:PopupWin runat=server></{0}:PopupWin>")]
  [Designer(typeof(PopupWinDesigner))]
  public class PopupWin : System.Web.UI.WebControls.WebControl, IPostBackEventHandler
  {
    #region Private variables, constants and constructor
		
    private string msg,fullmsg,divDesign,cntStyle,sPopup,spopStyle,
      cntStyleN,cntStyleI,aStyle,aCommands,hdrStyle,title,closeHtml;

    private string popupBackground,popupBorderDark,popupBorderLight,
      cntBorderDark,cntBorderLight,cntBackground,gradientStart,
      gradientEnd,textColor,xButton,xButtonOver,sLink,sTarget;

    private PopupColorStyle clrStyle;
    private PopupDocking popDock;
    private PopupAction popAction;

    int xOffset,yOffset,iSpeed=20; 
    Size winSize;
    bool winScroll=true,bAutoShow=true,bDragDrop=false,bShowLink=true;

    int iHide,startTime;

    const string sScript=@"<script type=""text/javascript"">
      //<![CDATA[
        var [id]oldonloadHndlr=window.onload, [id]popupHgt, [id]actualHgt, [id]tmrId=-1, [id]resetTimer;
        var [id]titHgt, [id]cntDelta, [id]tmrHide=-1, [id]hideAfter=[hide], [id]hideAlpha, [id]hasFilters=[ie];
        var [id]nWin, [id]showBy=null, [id]dxTimer=-1, [id]popupBottom, [id]oldLeft;
        var [id]nText,[id]nMsg,[id]nTitle,[id]bChangeTexts=false;
        window.onload=[id]espopup_winLoad;

        var [id]oldonscrollHndr=window.onscroll;
        window.onscroll=[id]espopup_winScroll;
        [id]nText=""[popup]"";

        function [id]espopup_winScroll()
        {
          if ([id]oldonscrollHndr!=null) [id]oldonscrollHndr();
          if ([id]tmrHide!=-1)
          {
            el=document.getElementById('[id]');
            el.style.display='none'; el.style.display='block';
          }
        }

        function [id]espopup_ShowPopup(show)
        {
          if ([id]dxTimer!=-1) { el.filters.blendTrans.stop(); }

          if (([id]tmrHide!=-1) && ((show!=null) && (show==[id]showBy)))
          {
            clearInterval([id]tmrHide);
            [id]tmrHide=setInterval([id]espopup_tmrHideTimer,[id]hideAfter);
            return;
          }
          if ([id]tmrId!=-1) return;
          [id]showBy=show;

          elCnt=document.getElementById('[id]_content')
          elTit=document.getElementById('[id]_header');
          el=document.getElementById('[id]');
          el.style.left=[id]oldLeft;
          el.style.top='';
          el.style.filter='';

          if ([id]tmrHide!=-1) clearInterval([id]tmrHide); [id]tmrHide=-1;

          document.getElementById('[id]_header').style.display='none';
          document.getElementById('[id]_content').style.display='none';

          if (navigator.userAgent.indexOf('Opera')!=-1)
            el.style.bottom=(document.body.scrollHeight*1-document.body.scrollTop*1
                            -document.body.offsetHeight*1+1*[id]popupBottom)+'px';
          
          if ([id]bChangeTexts)
          {
            [id]bChangeTexts=false;
            document.getElementById('[id]aCnt').innerHTML=[id]nMsg;
            document.getElementById('[id]titleEl').innerHTML=[id]nTitle;
          }

          [id]actualHgt=0; el.style.height=[id]actualHgt+'px';
          el.style.visibility='';
          if (![id]resetTimer) el.style.display='';
          [id]tmrId=setInterval([id]espopup_tmrTimer,([id]resetTimer?[stime]:20));
        }

        function [id]espopup_winLoad()
        {
          if ([id]oldonloadHndlr!=null) [id]oldonloadHndlr();

          elCnt=document.getElementById('[id]_content')
          elTit=document.getElementById('[id]_header');
          el=document.getElementById('[id]');
					[id]oldLeft=el.style.left;
          [id]popupBottom=el.style.bottom.substr(0,el.style.bottom.length-2);
          
          [id]titHgt=elTit.style.height.substr(0,elTit.style.height.length-2);
          [id]popupHgt=el.style.height;
          [id]popupHgt=[id]popupHgt.substr(0,[id]popupHgt.length-2); [id]actualHgt=0;
          [id]cntDelta=[id]popupHgt-(elCnt.style.height.substr(0,elCnt.style.height.length-2));

          if ([autoshow])
          {
            [id]resetTimer=true;
            [id]espopup_ShowPopup(null);
          }
        }

        function [id]espopup_tmrTimer()
        {
          el=document.getElementById('[id]');
          if ([id]resetTimer)
          {
            el.style.display='';
            clearInterval([id]tmrId); [id]resetTimer=false;
            [id]tmrId=setInterval([id]espopup_tmrTimer,[speed]);
          }
          [id]actualHgt+=5;
          if ([id]actualHgt>=[id]popupHgt)
          {
            [id]actualHgt=[id]popupHgt; clearInterval([id]tmrId); [id]tmrId=-1;
            document.getElementById('[id]_content').style.display='';
            if ([id]hideAfter!=-1) [id]tmrHide=setInterval([id]espopup_tmrHideTimer,[id]hideAfter);
          }
          if ([id]titHgt<[id]actualHgt-6)
            document.getElementById('[id]_header').style.display='';
          if (([id]actualHgt-[id]cntDelta)>0)
          {
            elCnt=document.getElementById('[id]_content')
            elCnt.style.display='';
            elCnt.style.height=([id]actualHgt-[id]cntDelta)+'px';
          }
          el.style.height=[id]actualHgt+'px';
        }
        
        function [id]espopup_tmrHideTimer()
        {
          clearInterval([id]tmrHide); [id]tmrHide=-1;
          el=document.getElementById('[id]');
          if ([id]hasFilters)
          {
            backCnt=document.getElementById('[id]_content').innerHTML;
            backTit=document.getElementById('[id]_header').innerHTML;
            document.getElementById('[id]_content').innerHTML='';
            document.getElementById('[id]_header').innerHTML='';
            el.style.filter='blendTrans(duration=1)';
            el.filters.blendTrans.apply();
            el.style.visibility='hidden';
            el.filters.blendTrans.play();
            document.getElementById('[id]_content').innerHTML=backCnt;
            document.getElementById('[id]_header').innerHTML=backTit;
            
            [id]dxTimer=setInterval([id]espopup_dxTimer,1000);
          }
          else el.style.visibility='hidden';
        }
        
        function [id]espopup_dxTimer()
        {
          clearInterval([id]dxTimer); [id]dxTimer=-1;
        }
     
        function [id]espopup_Close()
        {
          if ([id]tmrId==-1)
          {
            el=document.getElementById('[id]');
            el.style.filter='';
            el.style.display='none';
            if ([id]tmrHide!=-1) clearInterval([id]tmrHide); [id]tmrHide=-1;
            [sclose]
          }
        }
    
        function [id]espopup_ShowWindow()
        {
          [slink]
          if ([id]nWin!=null) [id]nWin.close();
          [id]nWin=window.open('','[id]nWin','[winstyle], '+
            'menubar=no, resizable=no, status=no, toolbar=no, location=no');
          [id]nWin.document.write([id]nText);
        }

        var [id]mousemoveBack,[id]mouseupBack;
        var [id]ofsX,[id]ofsY;
        function [id]espopup_DragDrop(e)
        {
          [id]mousemoveBack=document.body.onmousemove;
          [id]mouseupBack=document.body.onmouseup;
          ox=(e.offsetX==null)?e.layerX:e.offsetX;
          oy=(e.offsetY==null)?e.layerY:e.offsetY;
          [id]ofsX=ox; [id]ofsY=oy;

          document.body.onmousemove=[id]espopup_DragDropMove;
          document.body.onmouseup=[id]espopup_DragDropStop;
          if ([id]tmrHide!=-1) clearInterval([id]tmrHide);
        }

        function [id]espopup_DragDropMove(e)
        {
          el=document.getElementById('[id]');          
          if (e==null&&event!=null)
          {
            el.style.left=(event.clientX*1+document.body.scrollLeft-[id]ofsX)+'px';
            el.style.top=(event.clientY*1+document.body.scrollTop-[id]ofsY)+'px';
            event.cancelBubble=true;
          }
          else
          {
            el.style.left=(e.pageX*1-[id]ofsX)+'px';
            el.style.top=(e.pageY*1-[id]ofsY)+'px';
            e.cancelBubble=true;
          }
          if ((event.button&1)==0) [id]espopup_DragDropStop();
        }

        function [id]espopup_DragDropStop()
        {
          document.body.onmousemove=[id]mousemoveBack;
          document.body.onmouseup=[id]mouseupBack;
        }

      //]]>
      </script>";
  
    /// <summary>
    /// Initialize script, styles and colors
    /// </summary>
    public PopupWin()
    {
      // {0} = E5EDFA - popupBackground  
      // {1} = 455690 - popupBorderDark  
      // {2} = A6B4CF - popupBorderLight 
      // {3} = 728EB8 - cntBorderDark    
      // {4} = B9C9EF - cntBorderLight   
      // {5} = E9EFF9 - cntBackground    
      // {6} = E0E9F8 - gradientStart    
      // {7} = FFFFFF - gradientEnd      
      // {8} = 1F336B - textColor        
      // {9} = 6A87B2 - xButton          
      // {10}= 45638F - xButtonOver      

      divDesign=@"background:#{0}; border-right:1px solid #{1}; border-bottom:1px solid #{1};
                  border-left:1px solid #{2}; border-top:1px solid #{2}; position:absolute;
                  z-index:9999; ";

      cntStyle=@"border-left:1px solid #{3}; border-top:1px solid #{3};
                 border-bottom:1px solid #{4}; border-right:1px solid #{4};
                 background:#{5}; padding:2px; overflow:hidden; text-align:center;
                 filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,
                 StartColorStr='#FF{6}', EndColorStr='#FF{7}');";
      cntStyleI=@"position:absolute; left:2px; width:{0}px; top:20px; height:{1}px;";
      cntStyleN=@"position:absolute; left:2px; width:{0}px; top:20px; height:{1}px;";
                 
      aStyle=@"font:12px arial,sans-serif; color:#{8}; text-decoration:none;";
      aCommands=@"onmouseover=""style.textDecoration='underline';""
                  onmouseout=""style.textDecoration='none';""
                  href=""[cmd]""";

      hdrStyle=@"position:absolute; left:2px; width:[wid]px; top:2px; height:14px;
                 filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,
                 StartColorStr='#FF{6}', EndColorStr='#FF{7}');";

      title="Title here";
      msg="Message to show in popup";
      fullmsg="Text to display in new window.";

      closeHtml=@"<span style=""position:absolute; right:0px; top:0px; cursor:pointer; color:#{9}; font:bold 12px arial,sans-serif; 
                  position:absolute; right:3px;""
                  onclick=""[id]espopup_Close()""
                  onmousedown=""event.cancelBubble=true;""
                  onmouseover=""style.color='#{10}';""
                  onmouseout=""style.color='#{9}';"">X</span>";

      sPopup="<head><title>{1}</title><style type=\\\"text/css\\\">{2}</style></head>"+
        "<body><h1>{1}</h1><p>{0}</p></body>";

      spopStyle="body {"+
        "    background:#[gs]; padding:5px;"+
        "    filter:progid:DXImageTransform.Microsoft.Gradient("+
        "     GradientType=0,StartColorStr='#FF[gs]', EndColorStr='#FF[ge]');"+
        "  }"+
        "  h1 {"+
        "    font:bold 16px arial,sans-serif; color:#[clr]; "+
        "    text-align:center; margin:0px;"+
        "  }"+
        "  p {"+
        "    font:14px arial,sans-serif; color:#[clr];"+
        "  }";

      ColorStyle=PopupColorStyle.Blue;
      xOffset=yOffset=15; popDock=PopupDocking.BottomRight;
      iHide=5000; winSize=new Size(400,250);
      Width=new Unit("200px");
      Height=new Unit("100px");
      startTime=1000;
      popAction=PopupAction.MessageWindow;
    }
    
    #endregion
    #region Properties

    
    /// <summary>
    /// Get or set type of action
    /// </summary>
    [Category("Action"),Description("Type of action (after link is clicked).")]
    public PopupAction ActionType
    {
      get { return popAction; }
      set { popAction=value; }
    }


    /// <summary>
    /// Get or set text to display in new window 
    /// (when user clicked on popup window)
    /// </summary>
    [Bindable(true),Category("Action"),Description("This text will be displayed in new window.")]
    public string Text
    {
      get { return fullmsg; }
      set { fullmsg=value.Replace("\\","\\\\").Replace("\"","\\\""); }
    }


    /// <summary>
    /// Get or set adress/javascript to open when link is clicked
    /// </summary>
    [Bindable(true),Category("Action"),Description("Adress/javascript to open when link is clicked.")]
    public string Link
    {
      get { return sLink; }
      set { sLink=value; }
    }


    /// <summary>
    /// Get or set target for specified link
    /// </summary>
    [Bindable(true),Category("Action"),Description("Target for specified link.")]
    public string LinkTarget
    {
      get { return sTarget; }
      set { sTarget=value; }
    }


    /// <summary>
    /// Get or set predefined color style
    /// </summary>
    [Category("Design"),Description("Predefined color style.")]
    public PopupColorStyle ColorStyle
    {
      get { return clrStyle; }
      set
      {
        clrStyle=value;
        switch(clrStyle)
        {
          case PopupColorStyle.Blue:
            textColor="1F336B";
            xButtonOver=popupBorderDark="455690";
            xButton=cntBorderDark="728EB8";
            popupBorderLight=cntBorderLight="B9C9EF";
            popupBackground=cntBackground=gradientStart="E0E9F8";
            gradientEnd="FFFFFF";
            break;

          case PopupColorStyle.Violet:
            textColor="200040";
            xButtonOver=popupBorderDark="400080";
            xButton=cntBorderDark="7D5AA0";
            popupBorderLight=cntBorderLight="B9AAC8";
            popupBackground=cntBackground=gradientStart="D2C8DC";
            gradientEnd="FFFFFF";
            break;

          case PopupColorStyle.Green:
            textColor="004000";
            xButtonOver=popupBorderDark="008000";
            xButton=cntBorderDark="5AA05A";
            popupBorderLight=cntBorderLight="AAC8AA";
            popupBackground=cntBackground=gradientStart="C8DCC8";
            gradientEnd="FFFFFF";
            break;

          case PopupColorStyle.Red:
            textColor="400000";
            xButtonOver=popupBorderDark="800000";
            xButton=cntBorderDark="A05A5A";
            popupBorderLight=cntBorderLight="C8AAAA";
            popupBackground=cntBackground=gradientStart="DCC8C8";
            gradientEnd="FFFFFF";
            break;


			default: //blue
				textColor="1F336B";
				xButtonOver=popupBorderDark="455690";
				xButton=cntBorderDark="728EB8";
				popupBorderLight=cntBorderLight="B9C9EF";
				popupBackground=cntBackground=gradientStart="E0E9F8";
				gradientEnd="FFFFFF";
				break;
        }
      }
    }


    /// <summary>
    /// Get or set message to display in popup window
    /// </summary>
    [Bindable(true),Category("Texts"),Description("Message in popup.")]
    public string Message
    {
      get { return msg; }
      set { msg=value; }
    }


    /// <summary>
    /// Get or set title to display in popup window and new window
    /// </summary>
    [Bindable(true),Category("Texts"),Description("Title of popup element and new window.")]
    public string Title
    {
      get { return title; }
      set { title=value; }
    }


    /// <summary>
    /// Get or set ligh Gradient color
    /// </summary>

⌨️ 快捷键说明

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