Compartilhar via


Vwa.VwaControl.removeHandler Method

Applies to: SharePoint Server 2010

Removes an event handler from the Visio Web Access control.

var value = VwaControl.removeHandler(String eventName, Function eventHandler)

Parameters

eventName The name of the event to remove a handler for.

eventHandler The ECMAScript (JavaScript, JScript) function to call when eventName is raised, added by a previous call to the addHandler method.

Return Value

Void Returns nothing.

Remarks

The value of eventName must be one of the following:

  • diagramcomplete

  • diagramerror

  • shapemouseenter

  • shapemouseleave

  • shapeselectionchanged

If you pass a value that is not valid for eventName, the Visio Web Access control returns an eventNotFound error.

For more information about how to add a Visio Web Access Web Part to a SharePoint Web Parts page, see Customizing Visio Web Drawings in the Visio Web Access Web Part.

Example

The following example adds a handler to the Vwa.shapeselectionchanged event. When the event is raised, the code sample gets the hyperlinks applied to the shape that raised the event and then displays them in the Content Editor Web Part.

<script type="text/javascript">

document.write("Hyperlinks contained in this shape:");
document.write("<div id='shapelinks'></div>");

// Declare the global variables for the Visio Web Access Web Part, the active page in the Web Part,
// the shapes on the active page, and the <div> tag in the Content Editor Web Part.
var vwaControl;
var vwaPage;
var vwaShapes;
var linkList;

// Add a handler to the AJAX Sys.Application.load event.
Sys.Application.add_load(onApplicationLoad)

// Capture a reference to the current session of the Visio Web Access Web Part.
function onApplicationLoad() {
    try{
            vwaControl= new Vwa.VwaControl(getVWAWebPartID());
            vwaControl.addHandler("diagramcomplete", onDiagramComplete);
    }
    catch(err){
        alert(err);
    }
}

// Search the SharePoint page to get the WebPartID# for the Visio Web Access Web Part.
function getVWAWebPartID() {
    
    // Get a NodesList of all the div tags on the page. 
    var divArray = document.getElementsByTagName("div");
    var webPartElementID;
    
    // Iterate through the NodesList to get the node with the class attribute "VisioWebAccess."
    for (var i = 0; i < divArray.length; i++) {
        var node = divArray[i];
        
        // Return the first instance of the Visio Web Access Web Part.
        if (node.className == "VisioWebAccess") {
            webPartElementID = node.parentNode.parentNode.id;
            break;
        }
    }
    return webPartElementID;
}

// Capture references to global variables and add handler functions to events.
function onDiagramComplete(){
    try{
        // Set the vwaPage and vwaShapes variables to the active page and the shapes collection on that page, respectively.
        vwaPage = vwaControl.getActivePage();
        vwaShapes = vwaPage.getShapes();
        linkList = document.getElementById("shapelinks");

        // Remove the handler from the shape selection changed event and then add it back to the event.
        vwaControl.removeHandler("shapeselectionchanged", onShapeSelectionChanged);
        vwaControl.addHandler("shapeselectionchanged", onShapeSelectionChanged);
        
    }
    catch(err){
        alert(err);
    }
}

// Get the hyperlinks from a shape when the selection changes and display them in the Content Editor Web Part.
function onShapeSelectionChanged(source, args){
    try{
        // Clear any displayed links from the Content Editor Web Part.
        linkList.innerHTML = "";

        // Get the array of hyperlinks from the selected shape.
        var vwaShape = vwaShapes.getItemById(args);
        var newURLArray = vwaShape.getHyperlinks();

        // Check to see whether the shape has any hyperlinks.
        if (newURLArray.length > 0) {
            
            // Iterate through all the links applied to the shape.
            for (var i = 0; i < newURLArray.length; i++) {
                
                // Get the anonymous object from the array.
                currLink = newURLArray[i];

                // Get the URL for the hyperlink.
                var newURL = currLink.value;
                var newLink;
                var newText;

                // Check if the link goes to another page in the drawing.
                if (newURL.indexOf("vdw") >= 0) {
                    
                    // Create a paragraph element for a link to a page.
                    newLink = document.createElement("p");

                }
                else {
                    
                    // Create a hyperlink element for a link to a web address.
                    newLink = document.createElement("a");
                    newLink.setAttribute("href", newURL);
                    newLink.setAttribute("target", "_blank");
                }

                // Check whether there is a description for the hyperlink.
                if (currLink.description) {
                    newText = document.createTextNode(currLink.description);
                }
                else {
                    newText = document.createTextNode(newURL);
                }

                // Add the link, link text, and a line break to the <div> tag in the Content Editor Web Part.
                var lineBreak = document.createElement("br");
                linkList.appendChild(newLink);
                newLink.appendChild(newText);
                linkList.appendChild(lineBreak);

            }
        }
    }
    catch(err){
          alert(err);
    }
}

</script>

See Also

Reference

Vwa.VwaControl Class

Vwa.VwaControl Class Methods

Concepts

Vwa.VwaControl Class Events