mirror of
https://github.com/crypto-pro-web/crypto-pro-js.git
synced 2024-11-24 00:55:00 +03:00
рефакторинг
This commit is contained in:
parent
e6bfea656d
commit
1f684aa888
1256
dist/crypto-pro.js
vendored
1256
dist/crypto-pro.js
vendored
File diff suppressed because it is too large
Load Diff
2
dist/crypto-pro.js.map
vendored
2
dist/crypto-pro.js.map
vendored
File diff suppressed because one or more lines are too long
59
src/index.js
59
src/index.js
@ -1,47 +1,36 @@
|
|||||||
var bowser = require('bowser/bowser'),
|
|
||||||
browserInfo = bowser._detect(navigator.userAgent),
|
|
||||||
global = Function('return this')(),
|
|
||||||
canPromise = Boolean(global.Promise),
|
|
||||||
canAsync,
|
|
||||||
cadesplugin,
|
|
||||||
cryptoService,
|
|
||||||
_errorMsg = '',
|
|
||||||
_isLoaded = false,
|
|
||||||
_onLoadCbQueue = [];
|
|
||||||
|
|
||||||
global.allow_firefox_cadesplugin_async = browserInfo.firefox && browserInfo.version >= 52;
|
|
||||||
|
|
||||||
require('../vendor/cadesplugin_api');
|
require('../vendor/cadesplugin_api');
|
||||||
|
|
||||||
cadesplugin = global.cadesplugin;
|
var global = Function('return this')(),
|
||||||
|
canPromise = Boolean(global.Promise),
|
||||||
|
cadesplugin = global.cadesplugin,
|
||||||
|
cryptoService = require('./api'),
|
||||||
|
errorMsg = '',
|
||||||
|
loadedPlugin = false,
|
||||||
|
onLoadCallbacs = [],
|
||||||
|
|
||||||
canAsync = Boolean(cadesplugin.CreateObjectAsync);
|
execOnloadQueue = function execOnloadQueue() {
|
||||||
|
onLoadCallbacs.forEach(function (callback) {
|
||||||
cryptoService = require('./api');
|
|
||||||
|
|
||||||
function execOnloadQueue() {
|
|
||||||
_onLoadCbQueue.forEach(function (callback) {
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
|
|
||||||
function passToWaitOnLoad(callback) {
|
passToWaitOnLoad = function passToWaitOnLoad(callback) {
|
||||||
if (Object.prototype.toString.call(callback) === '[object Function]') {
|
if (Object.prototype.toString.call(callback) === '[object Function]') {
|
||||||
_onLoadCbQueue.push(callback);
|
onLoadCallbacs.push(callback);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
function callOnLoad(method) {
|
callOnLoad = function callOnLoad(method) {
|
||||||
_isLoaded ? method() : passToWaitOnLoad(method);
|
loadedPlugin ? method() : passToWaitOnLoad(method);
|
||||||
}
|
},
|
||||||
|
|
||||||
function finishLoading() {
|
finishLoading = function finishLoading() {
|
||||||
_isLoaded = true;
|
loadedPlugin = true;
|
||||||
|
|
||||||
execOnloadQueue();
|
execOnloadQueue();
|
||||||
}
|
},
|
||||||
|
|
||||||
function call() {
|
call = function call() {
|
||||||
var args = Array.prototype.slice.call(arguments),
|
var args = Array.prototype.slice.call(arguments),
|
||||||
methodName = args.shift();
|
methodName = args.shift();
|
||||||
|
|
||||||
@ -49,8 +38,8 @@ function call() {
|
|||||||
callOnLoad(function () {
|
callOnLoad(function () {
|
||||||
var method;
|
var method;
|
||||||
|
|
||||||
if (_errorMsg) {
|
if (errorMsg) {
|
||||||
reject(_errorMsg);
|
reject(errorMsg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +53,7 @@ function call() {
|
|||||||
method.apply(null, args).then(resolve, reject);
|
method.apply(null, args).then(resolve, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
if (cadesplugin) {
|
if (cadesplugin) {
|
||||||
// Уровень отладки (LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_ERROR)
|
// Уровень отладки (LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_ERROR)
|
||||||
@ -72,7 +61,7 @@ if (cadesplugin) {
|
|||||||
|
|
||||||
if (canPromise) {
|
if (canPromise) {
|
||||||
cadesplugin.then(finishLoading, function () {
|
cadesplugin.then(finishLoading, function () {
|
||||||
_errorMsg = 'КриптоПРО ЭЦП Browser Plug-In не доступен';
|
errorMsg = 'КриптоПРО ЭЦП Browser Plug-In не доступен';
|
||||||
finishLoading();
|
finishLoading();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user