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 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.
Some functions return a Promise() which enables simpler asynchronous coding and supports use of
async
in code.
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.10.1.js" type="text/javascript"></script>
-
Initialise the library in the document ready/window loaded event handler, and initialise printing parameters. For example, with jQuery and to check the license was accepted before making calls:
<script type="text/javascript"> // Note: It is assumed that attribute based configuration on the script elements // has been used. $(window).load(async () => { try { await MeadCo.ScriptX.InitAsync(); 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(async () => { MeadCo.ScriptX.Printing.PrintHTML("http://www.meadroid.com", false); showPrintingModal(); await MeadCo.ScriptX.WaitForSpoolingComplete(); hidePrintingModal(); }); } catch (e) { console.error(e); alert("Error while printing: " + e.message); } }); </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.