Some of you have started developing mashups with the new Visio Web Access web part that is available in SharePoint 2010 Enterprise and as you have noticed there is not a lot of sample code available that demonstrate best practices or even a common function library containing even the most basic helper functions.
To make use of this library I simply upload it as a document to my SharePoint site where I will be developing mashups using the VWA control. Here you can see that I have placed the JS file in the SiteAssets folder on my SharePoint site using SharePoint Designer 2010.
Once the library file is uploaded to my SharePoint site I can simple reference the JS file in any page using the standard script tag as shown:
With a reference to the JS file I can now simply call functions directly from this references library as if the source was contained directly in my page.
You can also copy the content of the vwalib.js file and paste it directly into the script on your web part page.
If you are not familiar with building mashups using the VWA web part check out this article published by the Visio product team.
At this point my function library does not contain very much functionality at all, but I wanted to release it because the two methods that it does contain will be helpful to anyone building mashups with the VWA control.
findVWAControlId() – this function simply returns the ID of the first VWA control on the page, ex. “WebPartWPQ3”. This is a very important function because as you add web parts to a web part page, SharePoint assigns a unique Id to that instance of the web part. This Id is required to get the instance of the VWA control object on the page. Now you can certainly hard code this Id in your script to get the instance of the control ( vwaControl = new Vwa.VwaControl(‘WebPartWPQ3’); ) but this makes your code not very portable and if you make changes to the layout of the web part page you might need to fix this Id.
getVWAControl() – this function calls findVWAControlId() and uses the Id that is returned to get the instance of the VWA control object on the page. Once you have the instance of the VWA control object you can then start making calls to the VWA objects and connect to the VWA control events.
If you have ideas or functions that you would like to see included in this library please feel free to email me at email@example.com.
For more details on the mashup API for the VWA control, take a look at these articles:
Objects in the Visio Services ECMAScript API
This article provides a nice overview of the object model for the VWA control.
This set of articles provides detailed information on the VWA objects, methods, and properties.