.net 2.0 WebPart

  • WebPartManager: This control manages the current display mode, i.e., it allows you to switch between browse mode, design mode, edit mode, etc. It also allows you to change the current scope from user to shared view. The control does not provide any user interface per se; you have to build the UI yourself, and then call the WebPartManager's method to change the display mode, or to programmatically add Web Parts on the page. There must be one and only one WebPartManager on the page, and it must be declared before any other control listed here; otherwise, you will get a runtime exception.

  • WebPartZone: This control defines an area where Web Parts can be added programmatically, or dragged and dropped at runtime by the user. They are generally put inside table cells or <div> containers, which define the page's layout.

管理:
  • CatalogZone: This control defines a region that will contain particular Web Parts (listed below) that create the catalog of Web Parts, declared on the page or already present on the page. This area is invisible until the page enters the catalog display mode.

  • DeclarativeCatalogPart: This Web Part must be placed within the CatalogZone, and when the page is in catalog mode it shows a list of Web Parts declared at design time, and allows the user to insert one or more of them into a selected Web Part zone.

  • PageCatalogPart: This Web Part must be placed within the CatalogZone, and when the page is in catalog mode it displays a list of Web Parts already present on the page but closed, and therefore not currently visible.

  • ImportCatalogPart: This Web Part allows you to import a Web Part from a configuration file saved on the user's local computer, which is uploaded to the server. The file contains the URL of the Web Part to insert on the page, and the values for its properties. The file is generated by the Export command of the Web Part's menu. Note that the export is disabled by default, and must be explicitly enabled (covered later).

编辑:
  • EditorZone: This control defines a region that will contain particular Web Parts (listed below) that create the editor of Web Parts. This area is invisible until the page enters the edit display mode, and the Edit command for a specific Web Part is clicked.

  • AppearanceEditorPart: This Web Part must be placed within the EditorZone, and allows you to edit the Web Part's properties related to its appearance, such as its title, the chrome type, and the size.

  • BehaviorEditorPart: This Web Part must be placed within the EditorZone, and allows you to edit the Web Part's properties related to its behavior, such as whether the Web Part can be closed, minimized, or moved from one Web Part zone to another, and the URL to which users are redirected when they click the Web Part's title bar.

  • LayoutEditorPart: This Web Part must be placed within the EditorZone, and allows you to edit the Web Part's properties related to its layout, such as its state (minimized or opened) and the zone where it is located.

  • PropertyGridEditorPart: This Web Part must be placed within the EditorZone, and allows you to edit all the custom properties that have the WebBrowsable attribute. A default user interface is automatically built according to the type of the property. For example, Boolean properties are rendered as a checkbox, enumerations are displayed in a DropDownList, and other types are edited by means of a textbox. If you don't like the standard UI for a particular property, however, you could build your own editor and associate it to the property. A custom editor is just a custom control that inherits from EditorPart. On the Web Part, you must override the WebBrowsableObject property and the CreateEditorParts method, which returns the collection of custom editor parts to show in the EditorZone.

关联:
  • ConnectionsZone: This Web Part creates the UI for connecting two Web Parts; one acts as a provider and the other as a consumer for the value being exchanged. The UI is displayed only when the page's display mode is correct.

示例代码:
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/webparts/default.aspx

代码分析

1. 客户端代码分析

<!--  WebPartZone 和 ZoneTemplate 目标代码层次 -->
< table  id ="WebPartZone2"  cellspacing ="0"  cellpadding ="0"  border ="0" >< tr >< td >
   
< table  id ="WebPart_UserControl1"  class ="WebPartZone2_0"  cellspacing ="0"  cellpadding ="2"  border ="0"  style ="width:100%;" >
</ table ></ td ></ tr >< table >

< script  type ="text/javascript" >
<!--
var __wpmExportWarning='This Web Part Page has been personalized. As a result, one or more Web Part properties may contain confidential information. Make sure the properties contain information that is safe for others to read. After exporting this Web Part, view properties in the Web Part description file (.WebPart) by using a text editor such as Microsoft Notepad.';var __wpmCloseProviderWarning='You are about to close this Web Part.  It is currently providing data to other Web Parts, and these connections will be deleted if this Web Part is closed.  To close this Web Part, click OK.  To keep this Web Part, click Cancel.';var __wpmDeleteWarning='You are about to permanently delete this Web Part.  Are you sure you want to do this?  To delete this Web Part, click OK.  To keep this Web Part, click Cancel.';// -->
</ script >

<!--  供拖拉使用的层 -->
< div  id ="WebPartManager1___Drag"  style ="display:none; position:absolute; z-index: 32000; filter:alpha(opacity=75)" ></ div >
< script  type ="text/javascript" >

__wpm 
= new WebPartManager();
__wpm.overlayContainerElement 
= document.getElementById('WebPartManager1___Drag');
__wpm.personalizationScopeShared 
= false;

var zoneElement;
var zoneObject;

//加载 WebPartZone 和 ZoneTemplate 信息;
//
加载 ZoneTemplate 时,会给其element增加捕捉拖拽事件,具体参考function WebPart(...)
zoneElement = document.getElementById('WebPartZone1');
if (zoneElement != null{
    zoneObject 
= __wpm.AddZone(zoneElement, 'WebPartZone1'truetrue'Blue');
}

zoneElement 
= document.getElementById('WebPartZone2');
if (zoneElement != null{
    zoneObject 
= __wpm.AddZone(zoneElement, 'WebPartZone2'truetrue'Blue');
    zoneObject.AddWebPart(document.getElementById(
'WebPart_UserControl1'), document.getElementById('WebPartTitle_UserControl1'), true);
    zoneObject.AddWebPart(document.getElementById(
'WebPart_gwpTextInputControl1'), document.getElementById('WebPartTitle_gwpTextInputControl1'), true);
    zoneObject.AddWebPart(document.getElementById(
'WebPart_gwpTextInputControl2'), document.getElementById('WebPartTitle_gwpTextInputControl2'), true);
}

</ script >

<!--  设置ZoneTemplate的样式 -->
< script  type ="text/javascript" >
var menuWebPart_UserControl1Verbs = new WebPartMenu(document.getElementById('WebPart_UserControl1Verbs'), document.getElementById('WebPart_UserControl1VerbsPopup'), document.getElementById('WebPart_UserControl1VerbsMenu'));
menuWebPart_UserControl1Verbs.itemStyle 
= '';
menuWebPart_UserControl1Verbs.itemHoverStyle 
= '';
menuWebPart_UserControl1Verbs.labelHoverColor 
= '';
menuWebPart_UserControl1Verbs.labelHoverClassName 
= '';
</ script >
< script  type ="text/javascript" >
var menuWebPart_gwpTextInputControl1Verbs = new WebPartMenu(document.getElementById('WebPart_gwpTextInputControl1Verbs'), document.getElementById('WebPart_gwpTextInputControl1VerbsPopup'), document.getElementById('WebPart_gwpTextInputControl1VerbsMenu'));
menuWebPart_gwpTextInputControl1Verbs.itemStyle 
= '';
menuWebPart_gwpTextInputControl1Verbs.itemHoverStyle 
= '';
menuWebPart_gwpTextInputControl1Verbs.labelHoverColor 
= '';
menuWebPart_gwpTextInputControl1Verbs.labelHoverClassName 
= '';
</ script >
< script  type ="text/javascript" >
var menuWebPart_gwpTextInputControl2Verbs = new WebPartMenu(document.getElementById('WebPart_gwpTextInputControl2Verbs'), document.getElementById('WebPart_gwpTextInputControl2VerbsPopup'), document.getElementById('WebPart_gwpTextInputControl2VerbsMenu'));
menuWebPart_gwpTextInputControl2Verbs.itemStyle 
= '';
menuWebPart_gwpTextInputControl2Verbs.itemHoverStyle 
= '';
menuWebPart_gwpTextInputControl2Verbs.labelHoverColor 
= '';
menuWebPart_gwpTextInputControl2Verbs.labelHoverClassName 
= '';
</ script >

2. 拖拽相关的JS代码分析

1.所有的 ZoneTemplate 加载时已经定义其事件动作
 webPartTitleElement.style.cursor = "move";
        webPartTitleElement.attachEvent("onmousedown", WebPart_OnMouseDown);
        webPartElement.attachEvent("ondragstart", WebPart_OnDragStart);
        webPartElement.attachEvent("ondrag", WebPart_OnDrag);
        webPartElement.attachEvent("ondragend", WebPart_OnDragEnd);
2.  onmousedown
当鼠标点击到ZoneTemplate的Title时,找到 ZoneTemplate 所在的table元素,设置到__wpm.draggedWebPart,开始调用 __wpm.DragDrop()(WebPartManager_DragDrop)
   WebPartManager_DragDrop
   调用__wpm.draggedWebPart元素的 dragDrop 去触发 ondragstart 事件。同时document.selection.empty();

3. WebPart_OnDragStart
 调用 WebPartManager_InitiateWebPartDragDrop 调整ZoneTemplate位置,增加当前webPartElement的复制到overlayContainerElement中(overlayContainerElement.appendChild(webPartElement.cloneNode(true)))。
 增加事件document.body.attachEvent("ondragover", Zone_OnDragOver);
       Zone_OnDragOver用于当拖拽到合适的位置时画高亮线的
 
4.WebPart_OnDrag(WebPartManager_ContinueWebPartDragDrop)
根据 location 坐标修改拖拽层style的位置信息

5.WebPart_OnDragEnd(WebPartManager_CompleteWebPartDragDrop)
  this.overlayContainerElement.removeChild(this.overlayContainerElement.firstChild);
 this.overlayContainerElement.style.display = "none";
 设置参数,提交页面

JS代码:

var  __wpm  =   null ;
function  Point(x, y)  {
    
this.x = x;
    
this.y = y;
}

function  __wpTranslateOffset(x, y, offsetElement, relativeToElement, includeScroll)  {
    
while ((typeof(offsetElement) != "undefined"&& (offsetElement != null&& (offsetElement != relativeToElement)) {
        x 
+= offsetElement.offsetLeft;
        y 
+= offsetElement.offsetTop;
        
var tagName = offsetElement.tagName;
        
if ((tagName != "TABLE"&& (tagName != "BODY")) {
            x 
+= offsetElement.clientLeft;
            y 
+= offsetElement.clientTop;
        }

        
if (includeScroll && (tagName != "BODY")) {
            x 
-= offsetElement.scrollLeft;
            y 
-= offsetElement.scrollTop;
        }

        offsetElement 
= offsetElement.offsetParent;
    }

    
return new Point(x, y);
}

function  __wpGetPageEventLocation(event, includeScroll)  {
    
if ((typeof(event) == "undefined"|| (event == null)) {
        event 
= window.event;
    }

    
return __wpTranslateOffset(event.offsetX, event.offsetY, event.srcElement, null, includeScroll);
}

function  __wpClearSelection()  {
    document.selection.empty();
}

function  WebPart(webPartElement, webPartTitleElement, zone, zoneIndex, allowZoneChange)  {
    
this.webPartElement = webPartElement;
    
this.allowZoneChange = allowZoneChange;
    
this.zone = zone;
    
this.zoneIndex = zoneIndex;
    
this.title = ((typeof(webPartTitleElement) != "undefined"&& (webPartTitleElement != null)) ?
        webPartTitleElement.innerText : 
"";
    webPartElement.__webPart 
= this;
    
if ((typeof(webPartTitleElement) != "undefined"&& (webPartTitleElement != null)) {
        webPartTitleElement.style.cursor 
= "move";
        webPartTitleElement.attachEvent(
"onmousedown", WebPart_OnMouseDown);
        webPartElement.attachEvent(
"ondragstart", WebPart_OnDragStart);
        webPartElement.attachEvent(
"ondrag", WebPart_OnDrag);
        webPartElement.attachEvent(
"ondragend", WebPart_OnDragEnd);
    }

    
this.UpdatePosition = WebPart_UpdatePosition;
    
this.Dispose = WebPart_Dispose;
}

function  WebPart_Dispose()  {
    
this.webPartElement.__webPart = null    
}

function  WebPart_OnMouseDown()  {
    
var currentEvent = window.event;
    
var draggedWebPart = WebPart_GetParentWebPartElement(currentEvent.srcElement);
    
if ((typeof(draggedWebPart) == "undefined"|| (draggedWebPart == null)) {
        
return;
    }

    document.selection.empty();
    
try {
        __wpm.draggedWebPart 
= draggedWebPart;
        __wpm.DragDrop();
    }

    
catch (e) {
        __wpm.draggedWebPart 
= draggedWebPart;
        window.setTimeout(
"__wpm.DragDrop()"0);
    }

    currentEvent.returnValue 
= false;
    currentEvent.cancelBubble 
= true;
}

function  WebPart_OnDragStart()  {
    
var currentEvent = window.event;
    
var webPartElement = currentEvent.srcElement;
    
if ((typeof(webPartElement.__webPart) == "undefined"|| (webPartElement.__webPart == null)) {
        currentEvent.returnValue 
= false;
        currentEvent.cancelBubble 
= true;
        
return;
    }

    
var dataObject = currentEvent.dataTransfer;
    dataObject.effectAllowed 
= __wpm.InitiateWebPartDragDrop(webPartElement);
}

function  WebPart_OnDrag()  {
    __wpm.ContinueWebPartDragDrop();
}

function  WebPart_OnDragEnd()  {
    __wpm.CompleteWebPartDragDrop();
}

function  WebPart_GetParentWebPartElement(containedElement)  {
    
var elem = containedElement;
    
while ((typeof(elem.__webPart) == "undefined"|| (elem.__webPart == null)) {
        elem 
= elem.parentElement;
        
if ((typeof(elem) == "undefined"|| (elem == null)) {
            
break;
        }

    }

    
return elem;
}

function  WebPart_UpdatePosition()  {
    
var location = __wpTranslateOffset(00this.webPartElement, nullfalse);
    
this.middleX = location.x + this.webPartElement.offsetWidth / 2;
    
this.middleY = location.y + this.webPartElement.offsetHeight / 2;
}

function  Zone(zoneElement, zoneIndex, uniqueID, isVertical, allowLayoutChange, highlightColor)  {
    
var webPartTable = null;
    
if (zoneElement.rows.length == 1{
        webPartTableContainer 
= zoneElement.rows[0].cells[0];
    }

    
else {
        webPartTableContainer 
= zoneElement.rows[1].cells[0];
    }

    
var i;
    
for (i = 0; i < webPartTableContainer.childNodes.length; i++{
        
var node = webPartTableContainer.childNodes[i];
        
if (node.tagName == "TABLE"{
            webPartTable 
= node;
            
break;
        }

    }

    
this.zoneElement = zoneElement;
    
this.zoneIndex = zoneIndex;
    
this.webParts = new Array();
    
this.uniqueID = uniqueID;
    
this.isVertical = isVertical;
    
this.allowLayoutChange = allowLayoutChange;
    
this.allowDrop = false;
    
this.webPartTable = webPartTable;
    
this.highlightColor = highlightColor;
    
this.savedBorderColor = (webPartTable != null? webPartTable.style.borderColor : null;
    
this.dropCueElements = new Array();
    
if (webPartTable != null{
        
if (isVertical) {
            
for (i = 0; i < webPartTable.rows.length; i += 2{
                
this.dropCueElements[i / 2= webPartTable.rows[i].cells[0].childNodes[0];
            }

        }

        
else {
            
for (i = 0; i < webPartTable.rows[0].cells.length; i += 2{
                
this.dropCueElements[i / 2= webPartTable.rows[0].cells[i].childNodes[0];
            }

        }

    }

    
this.AddWebPart = Zone_AddWebPart;
    
this.GetWebPartIndex = Zone_GetWebPartIndex;
    
this.ToggleDropCues = Zone_ToggleDropCues;
    
this.UpdatePosition = Zone_UpdatePosition;
    
this.Dispose = Zone_Dispose;
    webPartTable.__zone 
= this;
    webPartTable.attachEvent(
"ondragenter", Zone_OnDragEnter);
    webPartTable.attachEvent(
"ondrop", Zone_OnDrop);
}

function  Zone_Dispose()  {
    
for (var i = 0; i < this.webParts.length; i++{
        
this.webParts[i].Dispose();
    }

    
this.webPartTable.__zone = null;
}

function  Zone_OnDragEnter()  {
    
var handled = __wpm.ProcessWebPartDragEnter();
    
var currentEvent = window.event;
    
if (handled) {
        currentEvent.returnValue 
= false;
        currentEvent.cancelBubble 
= true;
    }

}

function  Zone_OnDragOver()  {
    
var handled = __wpm.ProcessWebPartDragOver();
    
var currentEvent = window.event;
    
if (handled) {
        currentEvent.returnValue 
= false;
        currentEvent.cancelBubble 
= true;
    }

}

function  Zone_OnDrop()  {
    
var handled = __wpm.ProcessWebPartDrop();
    
var currentEvent = window.event;
    
if (handled) {
        currentEvent.returnValue 
= false;
        currentEvent.cancelBubble 
= true;
    }

}

function  Zone_GetParentZoneElement(containedElement)  {
    
var elem = containedElement;
    
while ((typeof(elem.__zone) == "undefined"|| (elem.__zone == null)) {
        elem 
= elem.parentElement;
        
if ((typeof(elem) == "undefined"|| (elem == null)) {
            
break;
        }

    }

    
return elem;
}

function  Zone_AddWebPart(webPartElement, webPartTitleElement, allowZoneChange)  {
    
var webPart = null;
    
var zoneIndex = this.webParts.length;
    
if (this.allowLayoutChange && __wpm.IsDragDropEnabled()) {
        webPart 
= new WebPart(webPartElement, webPartTitleElement, this, zoneIndex, allowZoneChange);
    }

    
else {
        webPart 
= new WebPart(webPartElement, nullthis, zoneIndex, allowZoneChange);
    }

    
this.webParts[zoneIndex] = webPart;
    
return webPart;
}

function  Zone_ToggleDropCues(show, index, ignoreOutline)  {
    
if (ignoreOutline == false{
        
this.webPartTable.style.borderColor = (show ? this.highlightColor : this.savedBorderColor);
    }

    
if (index == -1{
        
return;
    }

    
var dropCue = this.dropCueElements[index];
    
if (dropCue && dropCue.style) {
        
if (dropCue.style.height == "100%" && !dropCue.webPartZoneHorizontalCueResized) {
            
var oldParentHeight = dropCue.parentElement.clientHeight;
            
var realHeight = oldParentHeight - 10;
            dropCue.style.height 
= realHeight + "px";
            
var dropCueVerticalBar = dropCue.getElementsByTagName("DIV")[0];
            
if (dropCueVerticalBar && dropCueVerticalBar.style) {
                dropCueVerticalBar.style.height 
= dropCue.style.height;
                
var heightDiff = (dropCue.parentElement.clientHeight - oldParentHeight);
                
if (heightDiff) {
                    dropCue.style.height 
= (realHeight - heightDiff) + "px";
                    dropCueVerticalBar.style.height 
= dropCue.style.height;
                }

            }

            dropCue.webPartZoneHorizontalCueResized 
= true;
        }

        dropCue.style.visibility 
= (show ? "visible" : "hidden");
    }

}

function  Zone_GetWebPartIndex(location)  {
    
var x = location.x;
    
var y = location.y;
    
if ((x < this.webPartTableLeft) || (x > this.webPartTableRight) ||
        (y 
< this.webPartTableTop) || (y > this.webPartTableBottom)) {
        
return -1;
    }

    
var vertical = this.isVertical;
    
var webParts = this.webParts;
    
var webPartsCount = webParts.length;
    
for (var i = 0; i < webPartsCount; i++{
        
var webPart = webParts[i];
        
if (vertical) {
            
if (y < webPart.middleY) {
                
return i;
            }

        }

        
else {
            
if (x < webPart.middleX) {
                
return i;
            }

        }

    }

    
return webPartsCount;
}

function  Zone_UpdatePosition()  {
    
var topLeft = __wpTranslateOffset(00this.webPartTable, nullfalse);
    
this.webPartTableLeft = topLeft.x;
    
this.webPartTableTop = topLeft.y;
    
this.webPartTableRight = (this.webPartTable != null? topLeft.x + this.webPartTable.offsetWidth : topLeft.x;
    
this.webPartTableBottom = (this.webPartTable != null? topLeft.y + this.webPartTable.offsetHeight : topLeft.y;
    
for (var i = 0; i < this.webParts.length; i++{
        
this.webParts[i].UpdatePosition();
    }

}

function  WebPartDragState(webPartElement, effect)  {
    
this.webPartElement = webPartElement;
    
this.dropZoneElement = null;
    
this.dropIndex = -1;
    
this.effect = effect;
    
this.dropped = false;
}

function  WebPartMenu(menuLabelElement, menuDropDownElement, menuElement)  {
    
this.menuLabelElement = menuLabelElement;
    
this.menuDropDownElement = menuDropDownElement;
    
this.menuElement = menuElement;
    
this.menuLabelElement.__menu = this;
    
this.menuLabelElement.attachEvent('onclick', WebPartMenu_OnClick);
    
this.menuLabelElement.attachEvent('onkeypress', WebPartMenu_OnKeyPress);
    
this.menuLabelElement.attachEvent('onmouseenter', WebPartMenu_OnMouseEnter);
    
this.menuLabelElement.attachEvent('onmouseleave', WebPartMenu_OnMouseLeave);
    
if ((typeof(this.menuDropDownElement) != "undefined"&& (this.menuDropDownElement != null)) {
        
this.menuDropDownElement.__menu = this;
    }

    
this.menuItemStyle = "";
    
this.menuItemHoverStyle = "";
    
this.popup = null;
    
this.hoverClassName = "";
    
this.hoverColor = "";
    
this.oldColor = this.menuLabelElement.style.color;
    
this.oldTextDecoration = this.menuLabelElement.style.textDecoration;
    
this.oldClassName = this.menuLabelElement.className;
    
this.Show = WebPartMenu_Show;
    
this.Hide = WebPartMenu_Hide;
    
this.Hover = WebPartMenu_Hover;
    
this.Unhover = WebPartMenu_Unhover;
    
this.Dispose = WebPartMenu_Dispose;
    
var menu = this;
    window.attachEvent(
'onunload'function() { menu.Dispose(); });
}

function  WebPartMenu_Dispose()  {
    
this.menuLabelElement.__menu = null;
    
this.menuDropDownElement.__menu = null;
}

function  WebPartMenu_Show()  {
    
if ((typeof(__wpm.menu) != "undefined"&& (__wpm.menu != null)) {
        __wpm.menu.Hide();
    }

    
var menuHTML =
        
"<html><head><style>" +
        
"a.menuItem, a.menuItem:Link { display: block; padding: 1px; text-decoration: none; " + this.itemStyle + " }" +
        
"a.menuItem:Hover { " + this.itemHoverStyle + " }" +
        
"</style><body scroll="no" style="border: none; margin: 0; padding: 0;" οndragstart="window.event.returnValue=false;" οnclick="popup.hide()">" +
        
this.menuElement.innerHTML +
        
"<body></html>";
    
var width = 16;
    
var height = 16;
    
this.popup = window.createPopup();
    __wpm.menu 
= this;
    
var popupDocument = this.popup.document;
    popupDocument.write(menuHTML);
    
this.popup.show(00, width, height);
    
var popupBody = popupDocument.body;
    width 
= popupBody.scrollWidth;
    height 
= popupBody.scrollHeight;
    
if (width < this.menuLabelElement.offsetWidth) {
        width 
= this.menuLabelElement.offsetWidth + 16;
    }

    
if (this.menuElement.innerHTML.indexOf("progid:DXImageTransform.Microsoft.Shadow"!= -1{
        popupBody.style.paddingRight 
= "4px";
    }

    popupBody.__wpm 
= __wpm;
    popupBody.__wpmDeleteWarning 
= __wpmDeleteWarning;
    popupBody.__wpmCloseProviderWarning 
= __wpmCloseProviderWarning;
    popupBody.popup 
= this.popup;
    
this.popup.hide();
    
this.popup.show(0this.menuLabelElement.offsetHeight, width, height, this.menuLabelElement);
}

function  WebPartMenu_Hide()  {
    
if (__wpm.menu == this{
        __wpm.menu 
= null;
        
if ((typeof(this.popup) != "undefined"&& (this.popup != null)) {
            
this.popup.hide();
            
this.popup = null;
        }

    }

}

function  WebPartMenu_Hover()  {
    
if (this.labelHoverClassName != ""{
        
this.menuLabelElement.className = this.menuLabelElement.className + " " + this.labelHoverClassName;
    }

    
if (this.labelHoverColor != ""{
        
this.menuLabelElement.style.color = this.labelHoverColor;
    }

}

function  WebPartMenu_Unhover()  {
    
if (this.labelHoverClassName != ""{
        
this.menuLabelElement.style.textDecoration = this.oldTextDecoration;
        
this.menuLabelElement.className = this.oldClassName;
    }

    
if (this.labelHoverColor != ""{
        
this.menuLabelElement.style.color = this.oldColor;
    }

}

function  WebPartMenu_OnClick()  {
    
var menu = window.event.srcElement.__menu;
    
if ((typeof(menu) != "undefined"&& (menu != null)) {
        window.event.returnValue 
= false;
        window.event.cancelBubble 
= true;
        menu.Show();
    }

}

function  WebPartMenu_OnKeyPress()  {
    
if (window.event.keyCode == 13{
        
var menu = window.event.srcElement.__menu;
        
if ((typeof(menu) != "undefined"&& (menu != null)) {
            window.event.returnValue 
= false;
            window.event.cancelBubble 
= true;
            menu.Show();
        }

    }

}

function  WebPartMenu_OnMouseEnter()  {
    
var menu = window.event.srcElement.__menu;
    
if ((typeof(menu) != "undefined"&& (menu != null)) {
        menu.Hover();
    }

}

function  WebPartMenu_OnMouseLeave()  {
    
var menu = window.event.srcElement.__menu;
    
if ((typeof(menu) != "undefined"&& (menu != null)) {
        menu.Unhover();
    }

}

function  WebPartManager()  {
    
this.overlayContainerElement = null;
    
this.zones = new Array();
    
this.dragState = null;
    
this.menu = null;
    
this.draggedWebPart = null;
    
this.AddZone = WebPartManager_AddZone;
    
this.IsDragDropEnabled = WebPartManager_IsDragDropEnabled;
    
this.DragDrop = WebPartManager_DragDrop;
    
this.InitiateWebPartDragDrop = WebPartManager_InitiateWebPartDragDrop;
    
this.CompleteWebPartDragDrop = WebPartManager_CompleteWebPartDragDrop;
    
this.ContinueWebPartDragDrop = WebPartManager_ContinueWebPartDragDrop;
    
this.ProcessWebPartDragEnter = WebPartManager_ProcessWebPartDragEnter;
    
this.ProcessWebPartDragOver = WebPartManager_ProcessWebPartDragOver;
    
this.ProcessWebPartDrop = WebPartManager_ProcessWebPartDrop;
    
this.ShowHelp = WebPartManager_ShowHelp;
    
this.ExportWebPart = WebPartManager_ExportWebPart;
    
this.Execute = WebPartManager_Execute;
    
this.SubmitPage = WebPartManager_SubmitPage;
    
this.UpdatePositions = WebPartManager_UpdatePositions;
    window.attachEvent(
"onunload", WebPartManager_Dispose);
}

function  WebPartManager_Dispose()  {
    
for (var i = 0; i < __wpm.zones.length; i++{
        __wpm.zones[i].Dispose();
    }

}

function  WebPartManager_AddZone(zoneElement, uniqueID, isVertical, allowLayoutChange, highlightColor)  {
    
var zoneIndex = this.zones.length;
    
var zone = new Zone(zoneElement, zoneIndex, uniqueID, isVertical, allowLayoutChange, highlightColor);
    
this.zones[zoneIndex] = zone;
    
return zone;
}

function  WebPartManager_IsDragDropEnabled()  {
    
return ((typeof(this.overlayContainerElement) != "undefined"&& (this.overlayContainerElement != null));
}

function  WebPartManager_DragDrop()  {
    
if ((typeof(this.draggedWebPart) != "undefined"&& (this.draggedWebPart != null)) {
        
var tempWebPart = this.draggedWebPart;
        
this.draggedWebPart = null;
        tempWebPart.dragDrop();
        window.setTimeout(
"__wpClearSelection()"0);
    }

}

function  WebPartManager_InitiateWebPartDragDrop(webPartElement)  {
    
var webPart = webPartElement.__webPart;
    
this.UpdatePositions();
    
this.dragState = new WebPartDragState(webPartElement, "move");
    
var location = __wpGetPageEventLocation(window.event, true);
    
var overlayContainerElement = this.overlayContainerElement;
    overlayContainerElement.style.left 
= location.x - webPartElement.offsetWidth / 2;
    overlayContainerElement.style.top 
= location.y + 4 + (webPartElement.clientTop ? webPartElement.clientTop : 0);
    overlayContainerElement.style.display 
= "block";
    overlayContainerElement.style.width 
= webPartElement.offsetWidth;
    overlayContainerElement.style.height 
= webPartElement.offsetHeight;
    overlayContainerElement.appendChild(webPartElement.cloneNode(
true));
    
if (webPart.allowZoneChange == false{
        webPart.zone.allowDrop 
= true;
    }

    
else {
        
for (var i = 0; i < __wpm.zones.length; i++{
            
var zone = __wpm.zones[i];
            
if (zone.allowLayoutChange) {
                zone.allowDrop 
= true;
            }

        }

    }

    document.body.attachEvent(
"ondragover", Zone_OnDragOver);
    
return "move";
}

function  WebPartManager_CompleteWebPartDragDrop()  {
    
var dragState = this.dragState;
    
this.dragState = null;
    
if ((typeof(dragState.dropZoneElement) != "undefined"&& (dragState.dropZoneElement != null)) {
        dragState.dropZoneElement.__zone.ToggleDropCues(
false, dragState.dropIndex, false);
    }

    document.body.detachEvent(
"ondragover", Zone_OnDragOver);
    
for (var i = 0; i < __wpm.zones.length; i++{
        __wpm.zones[i].allowDrop 
= false;
    }

    
this.overlayContainerElement.removeChild(this.overlayContainerElement.firstChild);
    
this.overlayContainerElement.style.display = "none";
    
if ((typeof(dragState) != "undefined"&& (dragState != null&& (dragState.dropped == true)) {
        
var currentZone = dragState.webPartElement.__webPart.zone;
        
var currentZoneIndex = dragState.webPartElement.__webPart.zoneIndex;
        
if ((currentZone != dragState.dropZoneElement.__zone) ||
            ((currentZoneIndex 
!= dragState.dropIndex) &&
             (currentZoneIndex 
!= (dragState.dropIndex - 1)))) {
            
var eventTarget = dragState.dropZoneElement.__zone.uniqueID;
            
var eventArgument = "Drag:" + dragState.webPartElement.id + ":" + dragState.dropIndex;
            
this.SubmitPage(eventTarget, eventArgument);
        }

    }

}

function  WebPartManager_ContinueWebPartDragDrop()  {
    
var dragState = this.dragState;
    
if ((typeof(dragState) != "undefined"&& (dragState != null)) {
        
var style = this.overlayContainerElement.style;
        
var location = __wpGetPageEventLocation(window.event, true);
        style.left 
= location.x - dragState.webPartElement.offsetWidth / 2;
        style.top 
= location.y + 4 + (dragState.webPartElement.clientTop ? dragState.webPartElement.clientTop : 0);
    }

}

function  WebPartManager_Execute(script)  {
    
if (this.menu) {
        
this.menu.Hide();
    }

    
var scriptReference = new Function(script);
    
return (scriptReference() != false);
}

function  WebPartManager_ProcessWebPartDragEnter()  {
    
var dragState = __wpm.dragState;
    
if ((typeof(dragState) != "undefined"&& (dragState != null)) {
        
var currentEvent = window.event;
        
var newDropZoneElement = Zone_GetParentZoneElement(currentEvent.srcElement);
        
if ((typeof(newDropZoneElement.__zone) == "undefined"|| (newDropZoneElement.__zone == null||
            (newDropZoneElement.__zone.allowDrop 
== false)) {
            newDropZoneElement 
= null;
        }

        
var newDropIndex = -1;
        
if ((typeof(newDropZoneElement) != "undefined"&& (newDropZoneElement != null)) {
            newDropIndex 
= newDropZoneElement.__zone.GetWebPartIndex(__wpGetPageEventLocation(currentEvent, false));
            
if (newDropIndex == -1{
                newDropZoneElement 
= null;
            }

        }

        
if (dragState.dropZoneElement != newDropZoneElement) {
            
if ((typeof(dragState.dropZoneElement) != "undefined"&& (dragState.dropZoneElement != null)) {
                dragState.dropZoneElement.__zone.ToggleDropCues(
false, dragState.dropIndex, false);
            }

            dragState.dropZoneElement 
= newDropZoneElement;
            dragState.dropIndex 
= newDropIndex;
            
if ((typeof(newDropZoneElement) != "undefined"&& (newDropZoneElement != null)) {
                newDropZoneElement.__zone.ToggleDropCues(
true, newDropIndex, false);
            }

        }

        
else if (dragState.dropIndex != newDropIndex) {
            
if (dragState.dropIndex != -1{
                dragState.dropZoneElement.__zone.ToggleDropCues(
false, dragState.dropIndex, false);
            }

            dragState.dropIndex 
= newDropIndex;
            
if ((typeof(newDropZoneElement) != "undefined"&& (newDropZoneElement != null)) {
                newDropZoneElement.__zone.ToggleDropCues(
true, newDropIndex, false);
            }

        }

        
if ((typeof(dragState.dropZoneElement) != "undefined"&& (dragState.dropZoneElement != null)) {
            currentEvent.dataTransfer.effectAllowed 
= dragState.effect;
        }

        
return true;
    }

    
return false;
}

function  WebPartManager_ProcessWebPartDragOver()  {
    
var dragState = __wpm.dragState;
    
var currentEvent = window.event;
    
var handled = false;
    
if ((typeof(dragState) != "undefined"&& (dragState != null&&
        (
typeof(dragState.dropZoneElement) != "undefined"&& (dragState.dropZoneElement != null)) {
        
var dropZoneElement = Zone_GetParentZoneElement(currentEvent.srcElement);
        
if ((typeof(dropZoneElement) != "undefined"&& (dropZoneElement != null&& (dropZoneElement.__zone.allowDrop == false)) {
            dropZoneElement 
= null;
        }

        
if (((typeof(dropZoneElement) == "undefined"|| (dropZoneElement == null)) &&
            (
typeof(dragState.dropZoneElement) != "undefined"&& (dragState.dropZoneElement != null)) {
            dragState.dropZoneElement.__zone.ToggleDropCues(
false, __wpm.dragState.dropIndex, false);
            dragState.dropZoneElement 
= null;
            dragState.dropIndex 
= -1;
        }

        
else if ((typeof(dropZoneElement) != "undefined"&& (dropZoneElement != null)) {
            
var location = __wpGetPageEventLocation(currentEvent, false);
            
var newDropIndex = dropZoneElement.__zone.GetWebPartIndex(location);
            
if (newDropIndex == -1{
                dropZoneElement 
= null;
            }

            
if (dragState.dropZoneElement != dropZoneElement) {
                
if ((dragState.dropIndex != -1|| (typeof(dropZoneElement) == "undefined"|| (dropZoneElement == null)) {
                    dragState.dropZoneElement.__zone.ToggleDropCues(
false, __wpm.dragState.dropIndex, false);
                }

                dragState.dropZoneElement 
= dropZoneElement;
            }

            
else {
                dragState.dropZoneElement.__zone.ToggleDropCues(
false, dragState.dropIndex, true);
            }

            dragState.dropIndex 
= newDropIndex;
            
if ((typeof(dropZoneElement) != "undefined"&& (dropZoneElement != null)) {
                dropZoneElement.__zone.ToggleDropCues(
true, newDropIndex, false);
            }

        }

        handled 
= true;
    }

    
if ((typeof(dragState) == "undefined"|| (dragState == null||
        (
typeof(dragState.dropZoneElement) == "undefined"|| (dragState.dropZoneElement == null)) {
        currentEvent.dataTransfer.effectAllowed 
= "none";
    }

    
return handled;
}

function  WebPartManager_ProcessWebPartDrop()  {
    
var dragState = this.dragState;
    
if ((typeof(dragState) != "undefined"&& (dragState != null)) {
        
var currentEvent = window.event;
        
var dropZoneElement = Zone_GetParentZoneElement(currentEvent.srcElement);
        
if ((typeof(dropZoneElement) != "undefined"&& (dropZoneElement != null&& (dropZoneElement.__zone.allowDrop == false)) {
            dropZoneElement 
= null;
        }

        
if ((typeof(dropZoneElement) != "undefined"&& (dropZoneElement != null&& (dragState.dropZoneElement == dropZoneElement)) {
            dragState.dropped 
= true;
        }

        
return true;
    }

    
return false;
}

function  WebPartManager_ShowHelp(helpUrl, helpMode)  {
    
if ((typeof(this.menu) != "undefined"&& (this.menu != null)) {
        
this.menu.Hide();
    }

    
if (helpMode == 0 || helpMode == 1{
        
if (helpMode == 0{
            
var dialogInfo = "edge: Sunken; center: yes; help: no; resizable: yes; status: no";
            window.showModalDialog(helpUrl, 
null, dialogInfo);
        }

        
else {
            window.open(helpUrl, 
null"scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=no,location=no");
        }

    }

    
else if (helpMode == 2{
        window.location 
= helpUrl;
    }

}

function  WebPartManager_ExportWebPart(exportUrl, warn, confirmOnly)  {
    
if (warn == true && __wpmExportWarning.length > 0 && this.personalizationScopeShared != true{
        
if (confirm(__wpmExportWarning) == false{
            
return false;
        }

    }

    
if (confirmOnly == false{
        window.location 
= exportUrl;
    }

    
return true;
}

function  WebPartManager_UpdatePositions()  {
    
for (var i = 0; i < this.zones.length; i++{
        
this.zones[i].UpdatePosition();
    }

}

function  WebPartManager_SubmitPage(eventTarget, eventArgument)  {
    
if ((typeof(this.menu) != "undefined"&& (this.menu != null)) {
        
this.menu.Hide();
    }

    __doPostBack(eventTarget, eventArgument);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值