MeadCoScriptXJS Library
Introduction
The ScriptX.Services Client Library delivers an emulation of the ScriptX.Addon API in javascript to any browser with javascript enabled.
The emulation level is excellent though there are some necessary, but small, differences between the implementations, in particular the emulation of asynchronous behaviours.
The MeadCoScriptXJS Library library delivers two useful and significant simplifications for coding:
Single functions that encapsulate the differences between ScriptX.Addon and ScriptX.Services enabling a single code base to work with both.
Some operations that require a few lines of script are wrapped into a more usable form in a single function call.
These libraries are used throughout our samples to illustrate 'single source' across all versions and implementations of ScriptX. It is free to use and deploy, and works with both free and licensed ScriptX.Addon and all implementations of ScriptX.Services. Obviously use of licensed functionality on ScriptX.Addon still requires a license.
Download
The library is available on GitHub in source form: MeadCoScriptXJS Library (open source with an MIT license).
Please see the Github repo for packaging options, which include CDN, NPM and Nuget.
Using the library
-
To use the library, download it from a suitable source and add it to your project or reference via a CDN.
-
Link to the implementation file, this will be meadco-scriptx-{version}.js in documents using ScriptX. For example:
<script src="/scripts/meadco-scriptx-1.9.0.js" type="text/javascript"></script>
-
Initialise the library in the document ready/window loaded event handler, and initialise printing parameters. For example, for basic usage when using jQuery:
<script type="text/javascript"> $(function () { if (MeadCo.ScriptX.Init()) { MeadCo.ScriptX.Printing.header = "MeadCo's ScriptX&b:&p of &P:&bBasic Printing Sample"; MeadCo.ScriptX.Printing.footer = "The de facto standard for advanced web-based printing"; MeadCo.ScriptX.Printing.orientation = "landscape"; $("#btnprint").click(function () { MeadCo.ScriptX.PrintPage(false); }); } }); </script>
Or, with jQuery and licensed usage and to check the license was accepted before making calls:
<script type="text/javascript"> // do not use document.ready() as the license // may still be loading (on older browsers aka IE6) $(window).load(function () { if (MeadCo.ScriptX.Init()) { if (MeadCo.Licensing.IsLicensed()) { MeadCo.ScriptX.Printing.SetMarginMeasure(2); with (MeadCo.ScriptX.Printing) { header = "MeadCo's ScriptX&b:&p of &P:&bPrinting Sample"; footer = "The de facto standard for advanced web-based printing"; orientation = "landscape"; topMargin = 1; leftMargin = 1; } $("#btnprint").click(function () { MeadCo.ScriptX.Printing.PrintHTML("http://www.meadroid.com", false); }); } else { MeadCo.Licensing.ReportError("This sample requires a license."); } } }); </script>
Summary of features in the library
- The namespace MeadCo.ScriptX contains a number of useful functions for initialising the library and accessing commonly required functionality.
- The namespace MeadCo.Licensing contains functionality for checking that a license was accepted.
- The object MeadCo.ScriptX.Utils is the ‘factory’ object.
- The object MeadCo.ScriptX.Printing is the ‘factory.printing’ object.