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

Last change on this file since e35a1b8 was e35a1b8, checked in by Antonio Araujo <aaraujo@…>, 7 years ago

Corrección de error en ubicación de caja de referencia de firma.

  • Property mode set to 100644
File size: 4.7 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
12 $("#pdf-canvas2").hide();
13function showPDF2(pdf_url) {
14  $("#pdf-loader2").show();
15
16  PDFJS.getDocument({ url: pdf_url }).then(function(pdf_doc) {
17    __PDF_DOC = pdf_doc;
18    __TOTAL_PAGES = __PDF_DOC.numPages;
19   
20    // Hide the pdf loader and show pdf container in HTML
21    $("#pdf-loader2").hide();
22    $("#pdf-contents2").show();
23    $("#pdf-total-pages2").text(__TOTAL_PAGES);
24
25    // Show the
26      showPage2(1);
27 
28  }).catch(function(error) {
29    // If error re-show the upload button
30    $("#pdf-loader2").hide();
31    $("#upload-button2").show();
32   
33    alert(error.message);
34  });;
35}
36
37function showPage2(page_no) {
38  __PAGE_RENDERING_IN_PROGRESS = 1;
39  __CURRENT_PAGE = page_no;
40
41  // Disable Prev & Next buttons while page is being loaded
42  $("#pdf-next2, #pdf-prev2").attr('disabled', 'disabled');
43
44  // While page is being rendered hide the canvas and show a loading message
45  $("#pdf-canvas2").hide();
46  $("#page-loader2").show();
47
48  // Update current page in HTML
49  $("#pdf-current-page2").text(page_no);
50  $("#pagepdf").val(page_no);
51 
52  // Fetch the page
53  __PDF_DOC.getPage(page_no).then(function(page) {
54    // As the canvas is of a fixed width we need to set the scale of the viewport accordingly
55
56
57    var scale_required = __CANVAS.width / page.getViewport(1).width;
58
59    // Get viewport of the page at required scale
60    var viewport = page.getViewport(scale_required);
61
62    // Set canvas height
63
64    __CANVAS.height = viewport.height;
65
66
67    var renderContext = {
68      canvasContext: __CANVAS_CTX,
69      viewport: viewport
70    };
71
72
73    // Render the page contents in the canvas
74    page.render(renderContext).then(function() {
75      __PAGE_RENDERING_IN_PROGRESS = 0;
76
77      // Re-enable Prev & Next buttons
78      $("#pdf-next2, #pdf-prev2").removeAttr('disabled');
79
80      // Show the canvas and hide the page loader
81      $("#page-loader2").hide();
82
83        __id = __CANVAS.toDataURL()
84       
85      var viewdimen = page.getViewport(1);
86      console.log( "Width: " + viewdimen.width + ", Height: " + viewdimen.height);     
87     
88      $("#container1").attr("style", "background-image: url('"+__id+"');background-size: cover; background-repeat: no-repeat;  height:"+(viewdimen.height)+"px; width:"+(viewdimen.width)+"px");
89     
90
91    });
92  });
93
94
95}
96
97// Upon click this should should trigger click on the #file-to-upload file input element
98// This is better than showing the not-good-looking file input element
99$("#upload-button2").on('click', function() {
100  //$("#img").removeAttr('src');
101  //$("#img").removeAttr('class');
102  //$(".cropper-container").remove();
103  $("#file-to-upload2").trigger('click');
104
105});
106
107// When user chooses a PDF file
108$("#file-to-upload2").on('change', function() {
109
110  // Validate whether PDF
111    if(['application/pdf'].indexOf($("#file-to-upload2").get(0).files[0].type) == -1) {
112        alert('Error : Not a PDF');
113        return;
114    }
115
116
117
118  // Send the object url of the pdf
119  showPDF2(URL.createObjectURL($("#file-to-upload2").get(0).files[0]));
120
121});
122
123// Previous page of the PDF
124$("#pdf-prev2").on('click', function() {
125  if(__CURRENT_PAGE != 1)
126    showPage2(--__CURRENT_PAGE);
127});
128
129// Next page of the PDF
130$("#pdf-next2").on('click', function() {
131   
132
133  if(__CURRENT_PAGE != __TOTAL_PAGES)
134   
135    showPage2(++__CURRENT_PAGE);
136
137});
138
139
140var transferred = false;
141$('.text').draggable({
142    connectToSortable: $('#container1'),
143    helper: 'clone',
144    start: function(event, ui)
145    {
146        $(this).hide();
147    },
148    stop: function(event, ui)
149    {
150
151        if(!transferred) {
152            $(this).show();
153        }
154        else{ 
155       
156            $(this).remove();
157            transferred = false;
158        }
159    }
160});
161
162
163function InicializarObjectoPositicion(){
164  var container = document.getElementById('container1'),
165    element = document.getElementsByClassName('text')[0];
166 
167  // options
168  var options = {
169    limit: container,
170    setCursor: true
171  };
172
173  // initialize drag
174  new Draggable(element, options); 
175
176}
177
178
179function NuevoObjectoInicial(){
180
181  var num = 0;
182  $( ".text" ).draggable({ 
183    containment: '#container1',
184    scroll: false,
185    stop: function(event, ui)
186      {
187       
188        num+= 1;
189        if (num == 1){
190          $("#submenu2 #submenu2 .text").hide();
191          $('#dataX').val(0);
192          $('#dataY').val(0);
193        }else{
194          $('#dataX').val(ui.position['left']);
195          $('#dataY').val(ui.position['top']);
196        }
197       
198      },
199   
200  });
201}
202
203$('#container1').sortable({
204    receive: function(event, ui)
205    { 
206       
207        transferred = true;
208        InicializarObjectoPositicion()
209        NuevoObjectoInicial();
210
211       
212    }
213});
Note: See TracBrowser for help on using the repository browser.