source: prototipo_portal_2018/prototipo/static/js/docsDraggable.js @ 327fd70

Last change on this file since 327fd70 was 327fd70, checked in by José Sulbarán <jsulbaran@…>, 7 years ago

Se agrego nuevas funciones de sing

  • Property mode set to 100644
File size: 3.5 KB
Line 
1
2
3var __PDF_DOC,
4  __CURRENT_PAGE,
5  __TOTAL_PAGES,
6  __PAGE_RENDERING_IN_PROGRESS = 0,
7  __CANVAS = $('#pdf-canvas2').get(0),
8  __CANVAS_CTX = __CANVAS.getContext('2d'),
9  __id = "",
10  __NUMBER = 0,
11  __CLICK = 0;
12
13 $("#pdf-canvas2").hide();
14function showPDF2(pdf_url) {
15  $("#pdf-loader2").show();
16
17  PDFJS.getDocument({ url: pdf_url }).then(function(pdf_doc) {
18    __PDF_DOC = pdf_doc;
19    __TOTAL_PAGES = __PDF_DOC.numPages;
20   
21    // Hide the pdf loader and show pdf container in HTML
22    $("#pdf-loader2").hide();
23    $("#pdf-contents2").show();
24    $("#pdf-total-pages2").text(__TOTAL_PAGES);
25
26    // Show the
27      showPage2(1);
28 
29  }).catch(function(error) {
30    // If error re-show the upload button
31    $("#pdf-loader2").hide();
32    $("#upload-button2").show();
33   
34    alert(error.message);
35  });;
36}
37
38function showPage2(page_no) {
39  __PAGE_RENDERING_IN_PROGRESS = 1;
40  __CURRENT_PAGE = page_no;
41
42  // Disable Prev & Next buttons while page is being loaded
43  $("#pdf-next2, #pdf-prev2").attr('disabled', 'disabled');
44
45  // While page is being rendered hide the canvas and show a loading message
46  $("#pdf-canvas2").hide();
47  $("#page-loader2").show();
48
49  // Update current page in HTML
50  $("#pdf-current-page2").text(page_no);
51 
52  VALOR_PAGE = page_no;
53 
54  // Fetch the page
55  __PDF_DOC.getPage(page_no).then(function(page) {
56    // As the canvas is of a fixed width we need to set the scale of the viewport accordingly
57
58
59    var scale_required = __CANVAS.width / page.getViewport(1).width;
60
61    // Get viewport of the page at required scale
62    var viewport = page.getViewport(scale_required);
63
64    // Set canvas height
65
66    __CANVAS.height = viewport.height;
67
68
69    var renderContext = {
70      canvasContext: __CANVAS_CTX,
71      viewport: viewport
72    };
73
74
75    // Render the page contents in the canvas
76    page.render(renderContext).then(function() {
77      __PAGE_RENDERING_IN_PROGRESS = 0;
78
79      // Re-enable Prev & Next buttons
80      $("#pdf-next2, #pdf-prev2").removeAttr('disabled');
81
82      // Show the canvas and hide the page loader
83      $("#page-loader2").hide();
84
85        __id = __CANVAS.toDataURL()
86       
87      var viewdimen = page.getViewport(1); 
88
89      $("#container1").attr("style", "background-image: url('"+__id+"');background-size: cover; background-repeat: no-repeat;  height:"+viewdimen.height+"px; width:"+viewdimen.width+"px");     
90
91
92    });
93  });
94
95
96}
97
98// Upon click this should should trigger click on the #file-to-upload file input element
99// This is better than showing the not-good-looking file input element
100$("#upload-button2").on('click', function() {
101  //$("#img").removeAttr('src');
102  //$("#img").removeAttr('class');
103  //$(".cropper-container").remove();
104  $("#pdf-main-container2").hide(); 
105  $("#pdf-main-container").show(); 
106
107  $("#file-sign-ft_Vble").trigger('click');
108
109});
110
111// When user chooses a PDF file
112$("#file-sign-ft_Vble").on('change', function() {
113
114  // Validate whether PDF
115    if(['application/pdf'].indexOf($("#file-sign-ft_Vble").get(0).files[0].type) == -1) {
116        alert('Error : Not a PDF');
117        return;
118    }
119
120  // Send the object url of the pdf
121  showPDF2(URL.createObjectURL($("#file-sign-ft_Vble").get(0).files[0]));
122
123  if (__CLICK == 0){
124      $('#firmar-documento').attr("disabled","disabled").show();
125      $('#texto').show();
126      __CLICK += 1;
127  }
128
129});
130
131// Previous page of the PDF
132$("#pdf-prev2").on('click', function() {
133  if(__CURRENT_PAGE != 1)
134    showPage2(--__CURRENT_PAGE);
135});
136
137// Next page of the PDF
138$("#pdf-next2").on('click', function() {
139   
140
141  if(__CURRENT_PAGE != __TOTAL_PAGES)
142   
143    showPage2(++__CURRENT_PAGE);
144
145});
146
147
Note: See TracBrowser for help on using the repository browser.