LacunaWebPKI.init example (with defaultError and notInstalled)

by Lacuna Software

HTML

<script src="https://get.webpkiplugin.com/Scripts/LacunaWebPKI/lacuna-web-pki-2.7.0.js"></script>
<form>
    <button id="startButton" type="button">Start</button>
</form>
<div id="logPanel">
</div>
<div id="notInstalledPanel" style="display: none;">
    <span id="notInstalledMsg"></span><br/>
    <a id="installLink" href="#">Click here</a> to go to the installation page.
</div>

CSS

#notInstalledPanel {
    border: 1px solid #000;
    padding: 0.5em;
    background-color: #f0f0f0;
}

JavaScript

// ------------------------------------------------------------------------------------------
// LacunaWebPKI.init example (with defaultError and notInstalled)

var pki = new LacunaWebPKI('ARQAKi5sYWN1bmFzb2Z0d2FyZS5jb20AAAABbtx62HIMKuzsfnr4jYNsKQGSzIAKyp/s7F9rcRRI+ZnFUNSZBVg3t5NZU0dVB4W8wxaT+wDpeCeBfkjVlrRlzB0EG/m8LW2V3Qojf6Gbd/W74YC/wv4Ndp0pb2UEbGMfZiTZupgukF9dZYA/lG5/fywZqBLvBkYhNOEIGNDrCHLOvz8kgaELqxdTOd/L7ojBLTsCxArv4HykiNawRZ+CSy4HOYAAD6UmsCuOYKbnQ6JMS4wfAX+Llz4SikopDNjqJDYlYbTDuDSDhGGgk3ZS3t0esJysB803BVG/mhnasr7fip8Pdnw3U4Pdk1mlZ6irpH0koULy6nOB6tyXH08nnQ==');

function onStart() {
    log('Initializing component ...');
    pki.init({
        ready: onWebPkiReady,
        notInstalled: onWebPkiNotInstalled,
        defaultFail: onWebPkiFail
    });
}

function onWebPkiNotInstalled(status, message) {
    $('#notInstalledMsg').html(message);
    $('#notInstalledPanel').show();
}

function onGoToInstallPage() {
    pki.redirectToInstallPage();
}

function onWebPkiReady() {
    log('Component is ready to go!');
}

function log(msg) {
  $('#logPanel').append('<p>' + msg + '</p>');
}

function onWebPkiFail(ex) {
    log('Web PKI error from ' + ex.origin + ': ' + ex.message + '(' + ex.code +')');
    alert(ex.message);
}

$(function() {
  $('#startButton').click(onStart);
  $('#installLink').click(onGoToInstallPage);
});