Client-side global scripts
This section describes using client-side global scripts.
Registering client-side global scripts
Client-side global scripts must be loaded into the browser, if they are not there already, at the same time the layout's client script is loaded.
To let the system know that a global script will be needed, go to the Portal Manager and add references. By right-clicking on the layout and selecting
, you can get a dialog showing the current client script references. Add references to global scripts as necessary.Any client-side scripting can have references to client-side global scripts. However, you cannot have a reference to client-side layout scripts.
Calling client-side global scripts
During the editing of your client-side layout script, you can get IntelliSense help by adding this reference to the top of your script:
/// <reference path="GlobalScripts/YourGlobalScript.js"
/>
This allows Visual Studio to provide IntelliSense for the APIs that are in the client-side global script (if it has been provided by the author of the global script).
To get access to the methods in a client-side global script, use this API:
var layoutGlobalScript =
context.NewGlobalScript("layout");
If the script has not already been loaded, it will be loaded at that time, if possible. If references were not created appropriately, a warning will be written to the diagnostics. If the load fails, an error will be written.
When you access
layoutGlobalScript
, you can see the IntelliSense for
the functions available in that global script if the author provided them.
Once the global script has been loaded, your methods are available in the variable:
var retval = layoutGlobalScript.yourMethodA(parms);
retval = layoutGlobalScript.yourMethodB(parms);
For more information on IntelliSense, see: http://msdn.microsoft.com/EN-US/library/hh542722(VS.110).aspx.
Creating global scripts
Global scripts can reference other global scripts. You can get IntelliSense help by adding a reference to the top of your script:
/// <reference path="GlobalScripts/XXXXXX.js"
/>
This allows Visual Studio to provide IntelliSense for the APIs that are in the referenced client-side global script (if it has been provided by the author).
There are two required parts and one optional part to a global script. The function declarations and the functions are required and the optional part is IntelliSense support.
The function declarations look like this:
this['z'] = z;
this['y'] = y;
You must store each function that you want to make public (available to callers) in the special 'this' variable.
Next, you can simply declare all of the functions, both public and private in the normal way:
function y(parms){...}
function z(parms){...}
The optional part is the IntelliSense. When a global script is created in the Portal Manager, a template is provided with stubs to assist in creating a global script with IntelliSense.
The global script must include this declaration, where
<LayoutName>
is replaced with the actual name of
the global layout:
function <LayoutName<() { }
The public functions must have this declaration defined to support provide IntelliSense:
<LayoutName>.prototype.PublicMethod1 = function (context, parms) {
/// <summary>
/// Do something.
/// </summary>
/// <param name="parms" type="SomeType"></param>
/// <returns type="SomeType"></returns>
}