рефакторинг

This commit is contained in:
vgoma 2017-11-30 12:30:47 +03:00
parent e6bfea656d
commit 1f684aa888
3 changed files with 705 additions and 728 deletions

1256
dist/crypto-pro.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -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 {