Configuring Shared JavaScript Libraries
You can take all existing scripts of significant size and complexity and re-factor them into a JavaScript library. You can put the library reference into script files, and replace any existing inline blocks of code with calls to the library. For example, the Activity OnSave JavaScript file might change to something like the following:
<script type="text/javascript" language="javascript" src="ExampleActivity.js"></script><script type="text/javascript"> function onSave () { return oActivityHandler.onSave ( "Activity" /** vs. Attendee Call */, "SampleDrop|PromoItem|ProductDetailed" /* requires signature */, "SampleRequest" /* does not require signature **/,......); } </script>
Using JavaScript libraries allows you to eliminate code duplication and build JavaScript unit tests. If you decide to use JavaScript libraries, then note the following:
- You can enter scripts into the Swift MEAPâ„¢ Server. For more information, see "Uploading a JavaScript Library to the Server".
- You must keep the Event Handler within inline event scripts rather than the .js file.
You must change the script header to reference the specific library as follows:
<html><head><title>YOURPRODUCT</title> <script src="SwiftMEAP/callsampledrop.js" type="text/javascript" language="javascript"></script> <script type="text/javascript" language="javascript" src="callsampledrop.js"></ script> <script type="text/javascript"></script></head><body></body></html>
where:
- src is the location of the script library, relative to the subfolder
- type is always equal to "text/javascript"
- language is always equal to "javascript"