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');
|
||||
|
||||
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);
|
||||
|
||||
cryptoService = require('./api');
|
||||
|
||||
function execOnloadQueue() {
|
||||
_onLoadCbQueue.forEach(function (callback) {
|
||||
execOnloadQueue = function execOnloadQueue() {
|
||||
onLoadCallbacs.forEach(function (callback) {
|
||||
callback();
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
function passToWaitOnLoad(callback) {
|
||||
passToWaitOnLoad = function passToWaitOnLoad(callback) {
|
||||
if (Object.prototype.toString.call(callback) === '[object Function]') {
|
||||
_onLoadCbQueue.push(callback);
|
||||
onLoadCallbacs.push(callback);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
function callOnLoad(method) {
|
||||
_isLoaded ? method() : passToWaitOnLoad(method);
|
||||
}
|
||||
callOnLoad = function callOnLoad(method) {
|
||||
loadedPlugin ? method() : passToWaitOnLoad(method);
|
||||
},
|
||||
|
||||
function finishLoading() {
|
||||
_isLoaded = true;
|
||||
finishLoading = function finishLoading() {
|
||||
loadedPlugin = true;
|
||||
|
||||
execOnloadQueue();
|
||||
}
|
||||
},
|
||||
|
||||
function call() {
|
||||
call = function call() {
|
||||
var args = Array.prototype.slice.call(arguments),
|
||||
methodName = args.shift();
|
||||
|
||||
@ -49,8 +38,8 @@ function call() {
|
||||
callOnLoad(function () {
|
||||
var method;
|
||||
|
||||
if (_errorMsg) {
|
||||
reject(_errorMsg);
|
||||
if (errorMsg) {
|
||||
reject(errorMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -64,7 +53,7 @@ function call() {
|
||||
method.apply(null, args).then(resolve, reject);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (cadesplugin) {
|
||||
// Уровень отладки (LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_ERROR)
|
||||
@ -72,7 +61,7 @@ if (cadesplugin) {
|
||||
|
||||
if (canPromise) {
|
||||
cadesplugin.then(finishLoading, function () {
|
||||
_errorMsg = 'КриптоПРО ЭЦП Browser Plug-In не доступен';
|
||||
errorMsg = 'КриптоПРО ЭЦП Browser Plug-In не доступен';
|
||||
finishLoading();
|
||||
});
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user