aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web/src/main/webapp/assets/js/dragNdrop.js
diff options
context:
space:
mode:
authorThomas Felber <felber@student.tugraz.at>2015-07-12 11:17:20 -1000
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2015-07-13 09:50:07 +0200
commitcb363884c6fe3cffb3d4ea1b06675c4caeec5d98 (patch)
tree59a21dcca5f4c495e72bded2c061be47d7ce0036 /pdf-as-web/src/main/webapp/assets/js/dragNdrop.js
parent3042a3f75fdcf09852799b50b554c71b6c9e393b (diff)
downloadpdf-as-4-cb363884c6fe3cffb3d4ea1b06675c4caeec5d98.tar.gz
pdf-as-4-cb363884c6fe3cffb3d4ea1b06675c4caeec5d98.tar.bz2
pdf-as-4-cb363884c6fe3cffb3d4ea1b06675c4caeec5d98.zip
introduced statusobject to app.js, file get reqeust parameter now gets handled within app.js and not in viewer.js anymore. fixed a bug where a placed signature would dissappear if the user scrolls too far away. updated some stylesheets. parent and child frame dont talk via postmessage anymore, instead functionality of the DOM is used. added porject report / documentation
Diffstat (limited to 'pdf-as-web/src/main/webapp/assets/js/dragNdrop.js')
-rw-r--r--pdf-as-web/src/main/webapp/assets/js/dragNdrop.js54
1 files changed, 35 insertions, 19 deletions
diff --git a/pdf-as-web/src/main/webapp/assets/js/dragNdrop.js b/pdf-as-web/src/main/webapp/assets/js/dragNdrop.js
index b66073e6..940804bd 100644
--- a/pdf-as-web/src/main/webapp/assets/js/dragNdrop.js
+++ b/pdf-as-web/src/main/webapp/assets/js/dragNdrop.js
@@ -9,11 +9,6 @@ function registerEventListeners() {
var locale = "EN";
var connector = "mobilebku";
- window.addEventListener("message", function receiveMessage(evt) {
- var iframewindow = document.getElementById("iFrame");
- iframewindow.contentWindow.postMessage(file, "*");
- }, false);
-
$(document).bind("dragover", function(evt) {
evt.preventDefault();
});
@@ -49,12 +44,10 @@ function registerEventListeners() {
evt.preventDefault();
evt.stopPropagation();
unhighlightDropzone();
-
var files = evt.originalEvent.dataTransfer.files;
if(files == null || files.length === 0) {
return;
}
-
file = files[0];
previewFile();
});
@@ -65,7 +58,6 @@ function registerEventListeners() {
if(files == null || files.length === 0) {
return;
}
-
file = files[0];
previewFile(file);
});
@@ -83,31 +75,34 @@ function registerEventListeners() {
});
}
+//
+//Creates an PDF.js instance within the PDF preview section and displays
+//the user selected PDF document.
+//
function previewFile() {
clearContentDiv();
createIframe();
}
+//
+//Calls the sign servlet with the provided file and the provided connector and locale
+//
function sign(file, connector, locale) {
if(file == null) {
alert("No file selected");
return
}
-
var fd = new FormData();
fd.append("source", "internal");
fd.append("pdf-file", file);
fd.append("connector", connector);
fd.append("locale", locale);
- signature_overlay = $("#iFrame").contents().find(".cl_signature");
- if(signature_overlay.length > 0) {
- var sig_pos_x = $("#iFrame").contents().find(".cl_signature").attr("data-pos-x");
- var sig_pos_y = $("#iFrame").contents().find(".cl_signature").attr("data-pos-y");
- var sig_pos_p = $("#iFrame").contents().find(".cl_signature").attr("data-page");
- fd.append("sig-pos-x", sig_pos_x);
- fd.append("sig-pos-y", sig_pos_y);
- fd.append("sig-pos-p", sig_pos_p);
+ ifr = document.getElementById('iFrame').contentWindow;
+ if(ifr.isSignaturePlaced()) { //Signature has been manually placed
+ fd.append("sig-pos-x", ifr.global_status.getSignature().posx);
+ fd.append("sig-pos-y", ifr.global_status.getSignature().posy);
+ fd.append("sig-pos-p", ifr.global_status.getSignature().page);
}
$.ajax({
@@ -117,24 +112,45 @@ function sign(file, connector, locale) {
contentType: false,
type: "POST",
success: function(response) {
- $("html").empty();
- $("html").html(response);
+ $("#fade").remove();
+ $("#popup").remove();
+ var fade_div = "<div id='fade' class='black_overlay'></div>";
+ var popup_div = "<div id='popup' class='white_content'><a href='javascript:void(0)' id='closelink'>Close</a><div id='resp'></div></div>"
+ $("body").append(fade_div);
+ $("body").append(popup_div);
+ $("#resp").html(response);
+ $("#closelink").bind("click", function(evt) {
+ $("#fade").remove();
+ $("#popup").remove();
+ });
}
});
}
+//
+//Changes color if the user drags a file over the dropzone
+//
function highlightDropzone() {
$("#dropzone").css("background", "#D8FFD8");
}
+//
+//Changes color back to original, if the user stops dragging a file over the dropzone (or drops the file)
+//
function unhighlightDropzone() {
$("#dropzone").css("background", "#E8F4FF");
}
+//
+//Removes all content that is inside of the PDF Preview section
+//
function clearContentDiv() {
$("#content").empty();
}
+//
+//Inserts an Iframe with a PDF.js instance into the PDF Preview section
+//
function createIframe() {
$("#content").append("<iframe src='assets/js/pdf.js/web/viewer.html' height='863px' width='800px' id='iFrame'></iframe>");
}