jquery-assinadordigitaldiscus
Version:
Plugin jQuery para comunicação com o Assinador Digital - Discus Tecnologia
23 lines • 2.88 kB
JavaScript
/**
* The MIT License (MIT)
* Copyright (c) 2016 Discus Tecnologia.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
!function($){function sendToSigner(jqObj,authkey,obj,urlService,isFile){for(var lenFiles=$(jqObj)[0].files.length,i=0;i<lenFiles;i++){var formData=new FormData;isFile||formData.append("tosign",$(jqObj)[0].files[i]),formData.append("authkey",authkey),isFile&&formData.append("file",$(jqObj)[0].files[i]),$.ajax({url:urlService,type:"POST",data:formData,processData:!1,contentType:!1,xhrFields:{responseType:"blob"},success:function(blob,status,xhr){"function"==typeof obj.success&&obj.success(blob)},error:function(xhr,textStatus){"function"==typeof obj.error&&obj.error(xhr.status,xhr.statusText)}})}}$.fn.extend({signPDF:function(authkey,obj){var urlService="http://localhost:5820/";return this.each(function(){sendToSigner(this,authkey,obj,urlService,!0)})},verifyPDF:function(authkey,obj,showValidator){var urlService="http://localhost:5820/validapkcs7/pdf/"+(showValidator?"show_validator":"");return this.each(function(){sendToSigner(this,authkey,obj,urlService,!0)})},verifyData:function(authkey,obj,showValidator){var urlService="http://localhost:5820/validapkcs7/"+(showValidator?"show_validator":"");return this.each(function(){sendToSigner(this,authkey,obj,urlService,!0)})}}),$.signData=function(data,authkey,obj){var urlService="http://localhost:5820/dados/";sendToSigner($({files:[data]}),authkey,obj,urlService,!1)},$.signerIsActive=function(callback){$.ajax({url:"http://localhost:5820",type:"GET",timeout:1e3,success:function(data,status,xhr){"function"==typeof callback&&callback(200==xhr.status)},error:function(){"function"==typeof callback&&callback(!1)}})},$.signerIsActiveSync=function(){return 200==$.ajax({type:"GET",url:"http://localhost:5820",async:!1}).statusCode().status}}(jQuery);