1. Place a ScriptEditor webpart on the same page that has the Visio webpart
2. Paste the following code into the webpart:
<script type="text/javascript">
// Declare global variables.
var vwaControl;
var vwaPage;
var vwaShapes;
var currentShape;
Sys.Application.add_load(onApplicationLoad)
// 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;
}
//Apply the handlers in the "OnLoad" event, for we need this each time we click a Shape
function onApplicationLoad()
{
vwaControl= new Vwa.VwaControl(getVWAWebPartID());
vwaControl.addHandler("diagramcomplete", onDiagramComplete);
vwaControl.addHandler("shapeselectionchanged", ClickIt);
vwaControl.addHandler("shapemouseenter", getShape);
vwaControl.addHandler("shapemouseleave", unselectShape);
}
//This is the "MouseEnter" event that fires when you enter/hover a Shape
getShape = function (source, args)
{
currentShape=null;
currentShape=vwaShapes.getItemById(args) ;
}
//This is the "MouseLeave" event that fires when the mousecursor leaves/unselects the shape
unselectShape = function (source, args)
{
currentShape=null ;
}
//The event that fires when a diagram is loaded
function onDiagramComplete() {
try {
vwaPage = vwaControl.getActivePage();
vwaShapes = vwaPage.getShapes();
currentShape=null;
}
catch (err) {
//alert(err);
}
}
//The function that enables the single click!
function ClickIt()
{
if (currentShape != null)
{
var drawingURL = vwaControl.getDiagramUrl();
while(drawingURL.indexOf('%20')>0)
{
drawingURL=drawingURL.replace('%20',' ');
}
vwaPage = vwaControl.getActivePage();
var vwaPageName = vwaPage.getId();
var n=currentShape.getHyperlinks();
if (n.length>0 )
{
vwaPages = vwaControl.getAllPageIds();
var pageCount = vwaPages.length;
// Get page ID from array of pages IDs.
for (var i = 0; i < pageCount; i++)
{
vwaPageId = vwaPages[i];
//Set variable PageName to the URL of the Shape
vwaPageName=n[0].value;
//Clean up the URL
while(vwaPageName.indexOf('%20')>0)
{
vwaPageName=vwaPageName.replace('%20',' ');
}
//If the PageID exists in the PageName (URL of the Shape)
if (vwaPageName.indexOf(vwaPages[i])>0)
{
//HERE IT IS!! OPEN THE SHAPE WITH A SINGLE CLICK!!!
//By using "OpenDiagram" instead of "setActivePage" the Shape gets deselected after the click!
vwaControl.openDiagram(drawingURL, i);
//Call "onApplicationLoad" to set the handlers again for the 'new' Diagram
onApplicationLoad();
break;
}
}
}
}
}
</script>