$(function () {
'use strict';
function registerIframeCallbacksWhenReady() {
$('.nexus-iframe').on('load', registerIframeCallbacksOnce);
}
function registerIframeCallbacksOnce() {
registerIframeCallbacks();
$('.nexus-iframe').off('load', registerIframeCallbacksOnce);
}
function registerIframeCallbacks() {
iFrameResize({
messageCallback: function (messageData) {
if (typeof messageData !== 'undefined'
&& typeof messageData.message !== 'undefined') {
if (messageData.message.event === 'submitForm') {
// "nexus-iframe" is about to reload
// Hide the iframe and show the loading indicator
} else if (messageData.message.event === 'log') {
handleLogMessage(messageData.message);
}
}
},
resizedCallback: function () {
// "nexus-iframe" has initialized completely
// Show the iframe and hide the loading indicator
},
}, '.nexus-iframe');
}
function handleLogMessage(message) {
// State that the authentication process is currently in (see below for details)
console.log('message.state ' + message.state);
// Text that is being presented to the user, if applicable
console.log(' .text ' + message.text);
if (message.state === 'requesterror') {
// Possibly more specific error reason from the Ajax request, if applicable
console.log(' .ajaxReason ' + message.ajaxReason);
// HTTP response status code for the Ajax request, if applicable
console.log(' .httpStatus ' + message.httpStatus);
// HTTP response body for the erroneous Ajax request, if applicable
console.log(' .httpResponse ' + message.httpResponse);
}
/*
Possible "log" event states:
initerror An error was received by the server upon loading the page;
this error will be shown to the user
requesterror A request to the server couldn't be completed normally;
an "initerror" state will follow
autostart An attempt will be made to automatically launch the
BankID app on this device
startfailed The BankID app was not started on this mobile device in the
allotted time; the user will be allowed to enter their
personal number manually
continue Waiting for the user to launch their BankID app manually
started A BankID app was launched following the "autostart" state, but the
app has not yet found a usable BankID profile on the device
sign Waiting for the user to authenticate with their BankID profile
done Authentication completed, either successfully or not;
if unsuccessful, an "initerror" state will follow
*/
}
registerIframeCallbacksWhenReady();
});
// The actual iframe:
// <iframe class="nexus-iframe" width="260" scrolling="no" src="{Method URL}"></iframe> |