LacunaWebPKI: complete example (with jQuery and extra UI components)

HTML

<script src="https://rawgit.com/malsup/blockui/316f6e5d76a33266970778e80507149d9ef6a02d/jquery.blockUI.js"></script>
<script src="https://get.webpkiplugin.com/Scripts/LacunaWebPKI/lacuna-web-pki-2.5.0.js"></script>
<div id="signatureControlsPanel">
    <select id="certificateSelect"></select>
    <button id="refreshButton" type="button">Refresh</button><br/><br/>
    <button id="signFileButton" type="button">Sign Dummy File</button>
</div>
<div id="dialog">
    <p id="dialogMessage"></p>
</div>
<div id="blockPanel">
</div>

CSS

#signatureControlsPanel {
    margin-top: 1em;
    display: none;
}
#blockPanel {
    display: none;
    padding: 0.5em;
}

JavaScript

// ------------------------------------------------------------------------------------------
// LacunaWebPKI: complete example (with jQuery and extra UI components)

var signatureProcessId = null;

var pki = new LacunaWebPKI({
    "format": 1,
    "allowedDomains": [
        "jsfiddle.net",
        "webpki.lacunasoftware.com"
    ],
    "expiration": null,
    "signature": "ClKvO1J22vAD+YmfANiKQLbcLE1lNraPKCel6tRM+ZxR+h6M/crtJYRRVGGz7hrdbM0Y0mfTu15RMYGqQMi1QNZS6GrT4vNzIayv552Fl0EFWQA7jWlctUwfYoHRHVEnCNx9YGXDiA9+yDoGlVwgTR7fjzNeS3Fen1MVIyKBF464gN0JvdiCRJMI47JGVDkPmKjcrYIvJs6y5Lg25RW4ZnBKVruS+HR2s3k8ZrV4y4RCQE4UYMKbukF9vsF+JqAEifRlPq2xLcrNdxBveVDSXS/LRHAcrZrMM+Iw4A79jl0ngWPcy+CwinAhT+3dxVo5ZWMRQFpmTkylEMDvTjV9wQ=="
});

function start() {
    log('Checking component installation ...');
    blockUI.start('Initializing Web PKI ...');
    pki.init({
        ready: onWebPkiReady,
        redirectUrl: 'https://www.google.com',
        notInstalled: onWebPkiNotInstalled,
        defaultError: onWebPkiError
    });
}

function onWebPkiError(message, error, origin) {
    blockUI.stop();
    log('Web PKI error originated at ' + origin + ': ' + error);
    showModal('Error', 'Web PKI error: ' + message);
}

function onWebPkiNotInstalled (status, message) {
    log('Installation NOT ok: ' + message);
    blockUI.stop();
    showModal('Message', message + '<br/><br/>Click OK to go to installation page', function() {
        pki.redirectToInstallPage();
    });
}

function onWebPkiReady () {
    log('Component ready.');
    blockUI.message('Loading certificates ...');
    loadCertificates();
}

function refresh() {
    blockUI.start('Loading certificates ...');
    loadCertificates();
}

function loadCertificates() {
    log('Listing certificates ...');
    pki.listCertificates().success(function (certificates) {
        log('Certificates listed.');
        var select = $('#certificateSelect');
        $.each(certificates, function() {
            select.append(
              ...