source: prototipo_portal_2018/prototipo/static/js/docsDraggable.js @ 747e744

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

Creado directorio prototipo con fuentes de la modificación del portal para establecer la ubicación de la firma visible

  • Property mode set to 100644
File size: 4.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
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
86      $("#container1").attr("style", "background-image: url('"+__id+"')")
87
88    });
89  });
90
91
92}
93
94// Upon click this should should trigger click on the #file-to-upload file input element
95// This is better than showing the not-good-looking file input element
96$("#upload-button2").on('click', function() {
97  //$("#img").removeAttr('src');
98  //$("#img").removeAttr('class');
99  //$(".cropper-container").remove();
100  $("#file-to-upload2").trigger('click');
101
102});
103
104// When user chooses a PDF file
105$("#file-to-upload2").on('change', function() {
106
107  // Validate whether PDF
108    if(['application/pdf'].indexOf($("#file-to-upload2").get(0).files[0].type) == -1) {
109        alert('Error : Not a PDF');
110        return;
111    }
112
113
114
115  // Send the object url of the pdf
116  showPDF2(URL.createObjectURL($("#file-to-upload2").get(0).files[0]));
117
118});
119
120// Previous page of the PDF
121$("#pdf-prev2").on('click', function() {
122  if(__CURRENT_PAGE != 1)
123    showPage2(--__CURRENT_PAGE);
124});
125
126// Next page of the PDF
127$("#pdf-next2").on('click', function() {
128   
129
130  if(__CURRENT_PAGE != __TOTAL_PAGES)
131   
132    showPage2(++__CURRENT_PAGE);
133
134});
135
136
137var transferred = false;
138$('.text').draggable({
139    connectToSortable: $('#container1'),
140    helper: 'clone',
141    start: function(event, ui)
142    {
143        $(this).hide();
144    },
145    stop: function(event, ui)
146    {
147
148        if(!transferred) {
149            $(this).show();
150        }
151        else{ 
152       
153            $(this).remove();
154            transferred = false;
155        }
156    }
157});
158
159
160function InicializarObjectoPositicion(){
161  var container = document.getElementById('container1'),
162    element = document.getElementsByClassName('text')[0];
163 
164  // options
165  var options = {
166    limit: container,
167    setCursor: true
168  };
169
170  // initialize drag
171  new Draggable(element, options); 
172
173}
174
175
176function NuevoObjectoInicial(){
177
178  var num = 0;
179  $( ".text" ).draggable({ 
180    containment: '#container1',
181    scroll: false,
182    stop: function(event, ui)
183      {
184       
185        num+= 1;
186        if (num == 1){
187          $("#submenu2 #submenu2 .text").hide();
188          $('#dataX').val(0);
189          $('#dataY').val(0);
190        }else{
191          $('#dataX').val(ui.position['left']);
192          $('#dataY').val(ui.position['top']);
193        }
194       
195      },
196   
197  });
198}
199
200$('#container1').sortable({
201    receive: function(event, ui)
202    { 
203       
204        transferred = true;
205        InicializarObjectoPositicion()
206        NuevoObjectoInicial();
207
208       
209    }
210});
Note: See TracBrowser for help on using the repository browser.