LacunaWebPKI.configure example

by Lacuna Software

HTML

<script src="https://webpki.lacunasoftware.com/Scripts/LacunaWebPKI/lacuna-web-pki-1.3.3.js"></script>
<form>
    <button id="startButton" type="button">Start</button>
    <button id="forceErrorButton" type="button" disabled>Force error</button>
    <button id="changeCallbackButton" type="button" disabled>Change default error callback</button>
</form>
<div id="logPanel">
</div>

JavaScript

// ------------------------------------------------------------------------------------------
// LacunaWebPKI.configure example

// In this example, we'll be using the configure method to change the initially configured
// default error callback (the actual call to the configure method is in the bottom of the code,
// in the onChangeCallback function).

// This is the callback that will be initially configured
function errorCallback1(message, error, origin) {
    log('errorCallback1 called! Now try changing the default error callback.');
}

// This is the callback that will be later configured
function errorCallback2(message, error, origin) {
    log('errorCallback2 called!');
}

// We instantiate a LacunaWebPKI object passing a reference to errorCallback1 as the default error callback
var myLicense = {
    "format": 1,
    "allowedDomains": [
        "jsfiddle.net",
        "webpki.lacunasoftware.com"
    ],
    "expiration": null,
    "signature": "ClKvO1J22vAD+YmfANiKQLbcLE1lNraPKCel6tRM+ZxR+h6M/crtJYRRVGGz7hrdbM0Y0mfTu15RMYGqQMi1QNZS6GrT4vNzIayv552Fl0EFWQA7jWlctUwfYoHRHVEnCNx9YGXDiA9+yDoGlVwgTR7fjzNeS3Fen1MVIyKBF464gN0JvdiCRJMI47JGVDkPmKjcrYIvJs6y5Lg25RW4ZnBKVruS+HR2s3k8ZrV4y4RCQE4UYMKbukF9vsF+JqAEifRlPq2xLcrNdxBveVDSXS/LRHAcrZrMM+Iw4A79jl0ngWPcy+CwinAhT+3dxVo5ZWMRQFpmTkylEMDvTjV9wQ=="
    };
var pki = new LacunaWebPKI({
    license: myLicense,
    defaultError: errorCallback1 // <-- here's the reference
});

// When the Start button is called, we'll run the component verification. If all is OK, we'll enable
// the other buttons
function onStart() {
    log('Checking component installation ...');
    pki.checkInstalled({
        installed: function() {
            log('Component detected. Now try causing an error.');
            $("#forceErrorButton").removeAttr("disabled");
            $("#changeCallbackButton").removeAttr("disabled");
        },
        notInstalled: function(status, message) {
            log(message);
        }
    });
}

// When the...