source: prototipo_portal_2018/prototipo/static/js/docsDraggable.js @ 0500480

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

Se modificaron las bottones y las funcionalidades de draggable

  • Property mode set to 100644
File size: 3.6 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  $("#pagepdf").val(page_no);
52 
53  // Fetch the page
54  __PDF_DOC.getPage(page_no).then(function(page) {
55    // As the canvas is of a fixed width we need to set the scale of the viewport accordingly
56
57
58    var scale_required = __CANVAS.width / page.getViewport(1).width;
59
60    // Get viewport of the page at required scale
61    var viewport = page.getViewport(scale_required);
62
63    // Set canvas height
64
65    __CANVAS.height = viewport.height;
66
67
68    var renderContext = {
69      canvasContext: __CANVAS_CTX,
70      viewport: viewport
71    };
72
73
74    // Render the page contents in the canvas
75    page.render(renderContext).then(function() {
76      __PAGE_RENDERING_IN_PROGRESS = 0;
77
78      // Re-enable Prev & Next buttons
79      $("#pdf-next2, #pdf-prev2").removeAttr('disabled');
80
81      // Show the canvas and hide the page loader
82      $("#page-loader2").hide();
83
84        __id = __CANVAS.toDataURL()
85       
86      var viewdimen = page.getViewport(1);
87      console.log( "Width: " + viewdimen.width + ", Height: " + viewdimen.height);     
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-to-upload2").trigger('click');
108
109});
110
111// When user chooses a PDF file
112$("#file-to-upload2").on('change', function() {
113
114  // Validate whether PDF
115    if(['application/pdf'].indexOf($("#file-to-upload2").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-to-upload2").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.