Skip to content
Snippets Groups Projects
Commit 17233cd9 authored by hendrik.donath's avatar hendrik.donath Committed by Friederike Schwager
Browse files

fixed an error that saved the strikeout and highlight annotation on wrong positions.

parent 8edc8a9b
No related branches found
No related tags found
No related merge requests found
...@@ -5908,6 +5908,8 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting ...@@ -5908,6 +5908,8 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting
var data=void 0; var data=void 0;
var rectsSelection = void 0; var rectsSelection = void 0;
var rectObj; var rectObj;
var _svg=void 0;
var rect=void 0;
/** /**
* Get the current window selection as rects * Get the current window selection as rects
* *
...@@ -5937,11 +5939,10 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting ...@@ -5937,11 +5939,10 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting
* *
* @param {Event} e The DOM event to handle * @param {Event} e The DOM event to handle
*/function handleDocumentMousedown(e){ */function handleDocumentMousedown(e){
var svg=void 0; if(!(_svg=(0,_utils.findSVGAtPoint)(e.clientX,e.clientY))|| _type!=='area'){
if(_type!=='area'||!(svg=(0,_utils.findSVGAtPoint)(e.clientX,e.clientY))){
return; return;
} }
var rect=svg.getBoundingClientRect(); rect=_svg.getBoundingClientRect();
originY=e.clientY; originY=e.clientY;
originX=e.clientX; originX=e.clientX;
overlay=document.createElement('div'); overlay=document.createElement('div');
...@@ -5950,7 +5951,7 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting ...@@ -5950,7 +5951,7 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting
overlay.style.left=originX-rect.left+'px'; overlay.style.left=originX-rect.left+'px';
overlay.style.border='3px solid '+_utils.BORDER_COLOR; overlay.style.border='3px solid '+_utils.BORDER_COLOR;
overlay.style.borderRadius='3px'; overlay.style.borderRadius='3px';
svg.parentNode.appendChild(overlay); _svg.parentNode.appendChild(overlay);
document.addEventListener('mousemove',handleDocumentMousemove); document.addEventListener('mousemove',handleDocumentMousemove);
(0,_utils.disableUserSelect)(); (0,_utils.disableUserSelect)();
} }
...@@ -5966,8 +5967,8 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting ...@@ -5966,8 +5967,8 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting
return false; return false;
}); });
} }
var svg=void 0;
if(_type!=='area'||!(svg=(0,_utils.findSVGAtPoint)(e.touches[0].clientX,e.touches[0].clientY))){ if(!(_svg=(0,_utils.findSVGAtPoint)(e.touches[0].clientX,e.touches[0].clientY)) || _type!=='area'){
return; return;
} }
// Disable scrolling on the page. // Disable scrolling on the page.
...@@ -5975,7 +5976,7 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting ...@@ -5975,7 +5976,7 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting
document.getElementById('content-wrapper').style.overflow = 'hidden'; document.getElementById('content-wrapper').style.overflow = 'hidden';
document.body.style.overflow = 'hidden'; document.body.style.overflow = 'hidden';
   
var rect=svg.getBoundingClientRect(); rect=_svg.getBoundingClientRect();
originY=e.touches[0].clientY; originY=e.touches[0].clientY;
originX=e.touches[0].clientX; originX=e.touches[0].clientX;
overlay=document.createElement('div'); overlay=document.createElement('div');
...@@ -5984,7 +5985,7 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting ...@@ -5984,7 +5985,7 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting
overlay.style.left=originX-rect.left+'px'; overlay.style.left=originX-rect.left+'px';
overlay.style.border='3px solid '+_utils.BORDER_COLOR; overlay.style.border='3px solid '+_utils.BORDER_COLOR;
overlay.style.borderRadius='3px'; overlay.style.borderRadius='3px';
svg.parentNode.appendChild(overlay); _svg.parentNode.appendChild(overlay);
document.addEventListener('touchmove',handleDocumentTouchmove); document.addEventListener('touchmove',handleDocumentTouchmove);
(0,_utils.disableUserSelect)(); (0,_utils.disableUserSelect)();
...@@ -5996,8 +5997,7 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting ...@@ -5996,8 +5997,7 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting
* *
* @param {Event} e The DOM event to handle * @param {Event} e The DOM event to handle
*/function handleDocumentMousemove(e){ */function handleDocumentMousemove(e){
var svg=overlay.parentNode.querySelector('svg.annotationLayer'); // var rect=_svg.getBoundingClientRect();
var rect=svg.getBoundingClientRect();
if(originX+(e.clientX-originX)<rect.right){ if(originX+(e.clientX-originX)<rect.right){
overlay.style.width=e.clientX-originX+'px'; overlay.style.width=e.clientX-originX+'px';
} }
...@@ -6008,8 +6008,7 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting ...@@ -6008,8 +6008,7 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting
   
// Handle document.touchmove event // Handle document.touchmove event
function handleDocumentTouchmove(e){ function handleDocumentTouchmove(e){
var svg=overlay.parentNode.querySelector('svg.annotationLayer'); // var rect=_svg.getBoundingClientRect();
var rect=svg.getBoundingClientRect();
if(originX+(e.touches[0].clientX-originX)<rect.right){ if(originX+(e.touches[0].clientX-originX)<rect.right){
overlay.style.width=e.touches[0].clientX-originX+'px'; overlay.style.width=e.touches[0].clientX-originX+'px';
} }
...@@ -6044,8 +6043,7 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting ...@@ -6044,8 +6043,7 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting
enableRect(_type); enableRect(_type);
return; return;
} }
var _svg=overlay.parentNode.querySelector('svg.annotationLayer'); // var rect=_svg.getBoundingClientRect();
var rect=_svg.getBoundingClientRect();
renderRect(_type,[{top:parseInt(overlay.style.top,10)+rect.top,left:parseInt(overlay.style.left,10)+rect.left,width:parseInt(overlay.style.width,10),height:parseInt(overlay.style.height,10)}],null); renderRect(_type,[{top:parseInt(overlay.style.top,10)+rect.top,left:parseInt(overlay.style.left,10)+rect.left,width:parseInt(overlay.style.width,10),height:parseInt(overlay.style.height,10)}],null);
[textarea,data] = (0,_commentWrapper.openComment)(e,handleCancelClick,handleSubmitClick,handleToolbarClick,handleSubmitBlur,_type); [textarea,data] = (0,_commentWrapper.openComment)(e,handleCancelClick,handleSubmitClick,handleToolbarClick,handleSubmitBlur,_type);
...@@ -6078,7 +6076,7 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting ...@@ -6078,7 +6076,7 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting
return; return;
} }
var _svg=overlay.parentNode.querySelector('svg.annotationLayer'); var _svg=overlay.parentNode.querySelector('svg.annotationLayer');
var rect=_svg.getBoundingClientRect(); // var rect=_svg.getBoundingClientRect();
renderRect(_type,[{top:parseInt(overlay.style.top,10)+rect.top,left:parseInt(overlay.style.left,10)+rect.left,width:parseInt(overlay.style.width,10),height:parseInt(overlay.style.height,10)}],null); renderRect(_type,[{top:parseInt(overlay.style.top,10)+rect.top,left:parseInt(overlay.style.left,10)+rect.left,width:parseInt(overlay.style.width,10),height:parseInt(overlay.style.height,10)}],null);
[textarea,data] = (0,_commentWrapper.openComment)(e,handleCancelClick,handleSubmitClick,handleToolbarClick,handleSubmitBlur,_type); [textarea,data] = (0,_commentWrapper.openComment)(e,handleCancelClick,handleSubmitClick,handleToolbarClick,handleSubmitBlur,_type);
...@@ -6107,11 +6105,9 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting ...@@ -6107,11 +6105,9 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting
function handleSubmitClick(e){ function handleSubmitClick(e){
var rects=void 0; var rects=void 0;
if(_type!=='area'&&(rects=rectsSelection)){ if(_type!=='area'&&(rects=rectsSelection)){
var svg=(0,_utils.findSVGAtPoint)(rects[0].left,rects[0].top);
saveRect(_type,[].concat(_toConsumableArray(rects)).map(function(r){return{top:r.top,left:r.left,width:r.width,height:r.height};}),null,e); saveRect(_type,[].concat(_toConsumableArray(rects)).map(function(r){return{top:r.top,left:r.left,width:r.width,height:r.height};}),null,e);
}else if(_type==='area'&&overlay){ }else if(_type==='area'&&overlay){
var _svg=overlay.parentNode.querySelector('svg.annotationLayer'); // var rect=_svg.getBoundingClientRect();
var rect=_svg.getBoundingClientRect();
saveRect(_type,[{top:parseInt(overlay.style.top,10)+rect.top,left:parseInt(overlay.style.left,10)+rect.left,width:parseInt(overlay.style.width,10),height:parseInt(overlay.style.height,10)}],null,e); saveRect(_type,[{top:parseInt(overlay.style.top,10)+rect.top,left:parseInt(overlay.style.left,10)+rect.left,width:parseInt(overlay.style.width,10),height:parseInt(overlay.style.height,10)}],null,e);
} }
return false; return false;
...@@ -6154,13 +6150,13 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting ...@@ -6154,13 +6150,13 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting
} }
function renderRect(type,rects,color){ function renderRect(type,rects,color){
var svg=(0,_utils.findSVGAtPoint)(rects[0].left,rects[0].top); rect=_svg.getBoundingClientRect();
var _getMetadata=(0,_utils.getMetadata)(svg); var _getMetadata=(0,_utils.getMetadata)(_svg);
documentId=_getMetadata.documentId; documentId=_getMetadata.documentId;
pageNumber=_getMetadata.pageNumber; pageNumber=_getMetadata.pageNumber;
var annotation = initializeAnnotation(type,rects,'rgb(255,237,0)',svg); var annotation = initializeAnnotation(type,rects,'rgb(255,237,0)',_svg);
rectObj = [svg,annotation]; rectObj = [_svg,annotation];
(0,_appendChild2.default)(svg,annotation); (0,_appendChild2.default)(_svg,annotation);
} }
/** /**
* This function deletes all annotations which data-pdf-annotate-id is undefined. An annotation is undefined, if it is only temporarily displayed. * This function deletes all annotations which data-pdf-annotate-id is undefined. An annotation is undefined, if it is only temporarily displayed.
...@@ -6179,7 +6175,6 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting ...@@ -6179,7 +6175,6 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting
var node=void 0; var node=void 0;
var annotation=void 0; var annotation=void 0;
if(!svg){return;} if(!svg){return;}
var boundingRect=svg.getBoundingClientRect();
if(!color){ if(!color){
if(type==='highlight'){ if(type==='highlight'){
color='rgb(142,186,229)'; color='rgb(142,186,229)';
...@@ -6187,17 +6182,17 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting ...@@ -6187,17 +6182,17 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting
color='rgb(0,84,159)'; color='rgb(0,84,159)';
} }
}// Initialize the annotation }// Initialize the annotation
annotation={type:type,color:color,rectangles:[].concat(_toConsumableArray(rects)).map(function(r){var offset=0;if(type==='strikeout'){offset=r.height/2;}return(0,_utils.scaleDown)(svg,{y:r.top+offset-boundingRect.top,x:r.left-boundingRect.left,width:r.width,height:r.height});}).filter(function(r){return r.width>0&&r.height>0&&r.x>-1&&r.y>-1;})};// Short circuit if no rectangles exist annotation={type:type,color:color,rectangles:[].concat(_toConsumableArray(rects)).map(function(r){var offset=0;if(type==='strikeout'){offset=r.height/2;}return(0,_utils.scaleDown)(svg,{y:r.top+offset-rect.top,x:r.left-rect.left,width:r.width,height:r.height});}).filter(function(r){return r.width>0&&r.height>0&&r.x>-1&&r.y>-1;})};// Short circuit if no rectangles exist
if(annotation.rectangles.length===0){ if(annotation.rectangles.length===0){
return; return;
}// Special treatment for area as it only supports a single rect }// Special treatment for area as it only supports a single rect
if(type==='area'){ if(type==='area'){
var rect=annotation.rectangles[0]; var _rect=annotation.rectangles[0];
delete annotation.rectangles; delete annotation.rectangles;
annotation.x=(0,_utils.roundDigits)(rect.x,4); annotation.x=(0,_utils.roundDigits)(_rect.x,4);
annotation.y=(0,_utils.roundDigits)(rect.y,4); annotation.y=(0,_utils.roundDigits)(_rect.y,4);
annotation.width=(0,_utils.roundDigits)(rect.width,4); annotation.width=(0,_utils.roundDigits)(_rect.width,4);
annotation.height=(0,_utils.roundDigits)(rect.height,4); annotation.height=(0,_utils.roundDigits)(_rect.height,4);
}else{ }else{
annotation.rectangles = annotation.rectangles.map(function(elem, index, array){ annotation.rectangles = annotation.rectangles.map(function(elem, index, array){
return {x:(0,_utils.roundDigits)(elem.x,4),y:(0,_utils.roundDigits)(elem.y,4),width:(0,_utils.roundDigits)(elem.width,4),height:(0,_utils.roundDigits)(elem.height,4)}; return {x:(0,_utils.roundDigits)(elem.x,4),y:(0,_utils.roundDigits)(elem.y,4),width:(0,_utils.roundDigits)(elem.width,4),height:(0,_utils.roundDigits)(elem.height,4)};
...@@ -6214,9 +6209,8 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting ...@@ -6214,9 +6209,8 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting
* @param {Array} rects The rects to use for annotation * @param {Array} rects The rects to use for annotation
* @param {String} color The color of the rects * @param {String} color The color of the rects
*/function saveRect(type,rects,color,e){ */function saveRect(type,rects,color,e){
var svg=(0,_utils.findSVGAtPoint)(rects[0].left,rects[0].top); var annotation = initializeAnnotation(type,rects,color,_svg);
var annotation = initializeAnnotation(type,rects,color,svg); var _getMetadata=(0,_utils.getMetadata)(_svg);
var _getMetadata=(0,_utils.getMetadata)(svg);
var documentId=_getMetadata.documentId; var documentId=_getMetadata.documentId;
var pageNumber=_getMetadata.pageNumber; var pageNumber=_getMetadata.pageNumber;
var content=textarea.value.trim(); var content=textarea.value.trim();
...@@ -6247,7 +6241,7 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting ...@@ -6247,7 +6241,7 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting
//get Old rectangles because of scrolling //get Old rectangles because of scrolling
annotation.rectangles = rectObj[1].rectangles; annotation.rectangles = rectObj[1].rectangles;
   
(0,_appendChild2.default)(svg,annotation); (0,_appendChild2.default)(_svg,annotation);
document.querySelector('.toolbar').removeEventListener('click',handleToolbarClick); document.querySelector('.toolbar').removeEventListener('click',handleToolbarClick);
//simulate an click on cursor //simulate an click on cursor
document.querySelector('button.cursor').click(); document.querySelector('button.cursor').click();
......
...@@ -25,6 +25,6 @@ ...@@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->component = 'mod_pdfannotator'; // Full name of the plugin (used for diagnostics). $plugin->component = 'mod_pdfannotator'; // Full name of the plugin (used for diagnostics).
$plugin->version = 2021020400; // The current module version (Date: YYYYMMDDXX). $plugin->version = 2021021600; // The current module version (Date: YYYYMMDDXX).
$plugin->release = 'PDF Annotator v1.4 release 5'; $plugin->release = 'PDF Annotator v1.4 release 5';
$plugin->requires = 2016112900; // Requires this Moodle version. $plugin->requires = 2016112900; // Requires this Moodle version.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment