mirror of
				https://github.com/crypto-pro-web/crypto-pro-js.git
				synced 2025-10-31 06:13:22 +03:00 
			
		
		
		
	рефакторинг
This commit is contained in:
		
							parent
							
								
									e6bfea656d
								
							
						
					
					
						commit
						1f684aa888
					
				
							
								
								
									
										1314
									
								
								dist/crypto-pro.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1314
									
								
								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
											
										
									
								
							
							
								
								
									
										117
									
								
								src/index.js
									
									
									
									
									
								
							
							
						
						
									
										117
									
								
								src/index.js
									
									
									
									
									
								
							| @ -1,70 +1,59 @@ | ||||
| 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) { | ||||
|         callback(); | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| function passToWaitOnLoad(callback) { | ||||
|     if (Object.prototype.toString.call(callback) === '[object Function]') { | ||||
|         _onLoadCbQueue.push(callback); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| function callOnLoad(method) { | ||||
|     _isLoaded ? method() : passToWaitOnLoad(method); | ||||
| } | ||||
| 
 | ||||
| function finishLoading() { | ||||
|     _isLoaded = true; | ||||
| 
 | ||||
|     execOnloadQueue(); | ||||
| } | ||||
| 
 | ||||
| function call() { | ||||
|     var args = Array.prototype.slice.call(arguments), | ||||
|         methodName = args.shift(); | ||||
| 
 | ||||
|     return new Promise(function (resolve, reject) { | ||||
|         callOnLoad(function () { | ||||
|             var method; | ||||
| 
 | ||||
|             if (_errorMsg) { | ||||
|                 reject(_errorMsg); | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             method = cryptoService[methodName]; | ||||
| 
 | ||||
|             if (!method) { | ||||
|                 reject('Метод "' + methodName + '" не доступен'); | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             method.apply(null, args).then(resolve, reject); | ||||
|     execOnloadQueue = function execOnloadQueue() { | ||||
|         onLoadCallbacs.forEach(function (callback) { | ||||
|             callback(); | ||||
|         }); | ||||
|     }); | ||||
| } | ||||
|     }, | ||||
| 
 | ||||
|     passToWaitOnLoad = function passToWaitOnLoad(callback) { | ||||
|         if (Object.prototype.toString.call(callback) === '[object Function]') { | ||||
|             onLoadCallbacs.push(callback); | ||||
|         } | ||||
|     }, | ||||
| 
 | ||||
|     callOnLoad = function callOnLoad(method) { | ||||
|         loadedPlugin ? method() : passToWaitOnLoad(method); | ||||
|     }, | ||||
| 
 | ||||
|     finishLoading = function finishLoading() { | ||||
|         loadedPlugin = true; | ||||
| 
 | ||||
|         execOnloadQueue(); | ||||
|     }, | ||||
| 
 | ||||
|     call = function call() { | ||||
|         var args = Array.prototype.slice.call(arguments), | ||||
|             methodName = args.shift(); | ||||
| 
 | ||||
|         return new Promise(function (resolve, reject) { | ||||
|             callOnLoad(function () { | ||||
|                 var method; | ||||
| 
 | ||||
|                 if (errorMsg) { | ||||
|                     reject(errorMsg); | ||||
|                     return; | ||||
|                 } | ||||
| 
 | ||||
|                 method = cryptoService[methodName]; | ||||
| 
 | ||||
|                 if (!method) { | ||||
|                     reject('Метод "' + methodName + '" не доступен'); | ||||
|                     return; | ||||
|                 } | ||||
| 
 | ||||
|                 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
	 vgoma
						vgoma