From 197747f707ed6532dce4e25e55b3f48acf2b843d Mon Sep 17 00:00:00 2001 From: "hendrik.donath" <Donath@itc.rwth-aachen.de> Date: Fri, 19 Mar 2021 14:51:18 +0100 Subject: [PATCH] Fixed text annotation not showing and not working on mobile devices --- shared/index.js | 37 ++++++++++++++++++++++++++++--------- styles.css | 5 +++++ templates/index.mustache | 2 +- version.php | 2 +- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/shared/index.js b/shared/index.js index 060b6c8..5e00dc9 100644 --- a/shared/index.js +++ b/shared/index.js @@ -6321,15 +6321,17 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting var input=void 0; var pos = void 0; var _textSize=void 0; - var _textColor=void 0;/** + var _textColor=void 0; + var svg=void 0; + var rect=void 0;/** * Handle document.mouseup event * * * @param {Event} e The DOM event to handle */function handleDocumentMouseup(e){ // betrifft textbox - if(input||!(0,_utils.findSVGAtPoint)(e.clientX,e.clientY)){ + if(input||!(svg=(0,_utils.findSVGAtPoint)(e.clientX,e.clientY))){ return; - } + } let scrollTop = window.pageYOffset; input=document.createElement('input'); input.setAttribute('id','pdf-annotate-text-input'); @@ -6344,10 +6346,14 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting input.addEventListener('keyup',handleInputKeyup); document.body.appendChild(input); input.focus(); + rect=svg.getBoundingClientRect(); pos = {x: e.clientX, y: e.clientY }; - }/** + } + /** * Handle input.blur event - */function handleInputBlur(){saveText();}/** + */function handleInputBlur(){ + saveText(); + }/** * Handle input.keyup event * * @param {Event} e The DOM event to handle @@ -6359,14 +6365,14 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting var clientX=parseInt(pos.x,10); //text size additional to y to render the text right under the mouse click var clientY=parseInt(pos.y,10); - var svg=(0,_utils.findSVGAtPoint)(clientX,clientY); + //var svg=(0,_utils.findSVGAtPoint)(clientX,clientY); if(!svg){ return{v:void 0}; } var _getMetadata=(0,_utils.getMetadata)(svg); var documentId=_getMetadata.documentId; var pageNumber=_getMetadata.pageNumber; - var rect=svg.getBoundingClientRect(); + var annotation=Object.assign({type:'textbox',size:_textSize,color:_textColor,content:input.value.trim()},(0,_utils.scaleDown)(svg,{x:(0,_utils.roundDigits)(clientX-rect.left,4),y:(0,_utils.roundDigits)(clientY-rect.top,4),width:(0,_utils.roundDigits)(input.offsetWidth,4),height:(0,_utils.roundDigits)(input.offsetHeight,4)})); _PDFJSAnnotate2.default.getStoreAdapter().addAnnotation(documentId,pageNumber,annotation) .then(function(annotation){ @@ -6393,9 +6399,22 @@ function startIndex(Y,_cm,_documentObject,_userid,_capabilities, _toolbarSetting * @param {String} textColor The color of the text */function setText(){var textSize=arguments.length<=0||arguments[0]===undefined?12:arguments[0];var textColor=arguments.length<=1||arguments[1]===undefined?'000000':arguments[1];_textSize=parseInt(textSize,10);_textColor=textColor;}/** * Enable text behavior - */function enableText(){if(_enabled){return;}_enabled=true;document.getElementById('content-wrapper').classList.add('cursor-text');document.addEventListener('mouseup',handleDocumentMouseup);}/** + */function enableText(){ + if(_enabled){ + return; + } + _enabled=true; + document.getElementById('content-wrapper').classList.add('cursor-text'); + document.addEventListener('mouseup',handleDocumentMouseup); + }/** * Disable text behavior - */function disableText(){if(!_enabled){return;}_enabled=false;document.getElementById('content-wrapper').classList.remove('cursor-text');document.removeEventListener('mouseup',handleDocumentMouseup);} + */function disableText(){ + if(!_enabled){return; + } + _enabled=false; + document.getElementById('content-wrapper').classList.remove('cursor-text'); + document.removeEventListener('mouseup',handleDocumentMouseup); + } /***/}, /* 34 */ /***/function(module,exports,__webpack_require__){ diff --git a/styles.css b/styles.css index c515833..418ed21 100644 --- a/styles.css +++ b/styles.css @@ -860,4 +860,9 @@ header, section, footer, aside, nav, main, article, figure { .path-mod-pdfannotator .pdfannotator-statistic #chart-container { min-height: 500px; +} + +.toolbaritem .pdfannotator_text { + display: inline-block; + visibility: visible; } \ No newline at end of file diff --git a/templates/index.mustache b/templates/index.mustache index 62fbfa0..c583313 100644 --- a/templates/index.mustache +++ b/templates/index.mustache @@ -16,7 +16,7 @@ {{#usestudenttextbox}} <span class="toolbaritem"> - <button class="text" type="button" title="{{# str }} text, pdfannotator {{/ str }}" data-tooltype="text">{{# pix }}text_color_picker,pdfannotator, {{# str }} text, pdfannotator {{/ str }} {{/ pix}}</button> + <button class="pdfannotator_text text" type="button" title="{{# str }} text, pdfannotator {{/ str }}" data-tooltype="text">{{# pix }}text_color_picker,pdfannotator, {{# str }} text, pdfannotator {{/ str }} {{/ pix}}</button> <select class="text-size"></select> <div class="text-color"></div> </span> diff --git a/version.php b/version.php index 236c605..a8c7720 100644 --- a/version.php +++ b/version.php @@ -25,6 +25,6 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'mod_pdfannotator'; // Full name of the plugin (used for diagnostics). -$plugin->version = 2021030505; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2021031902; // The current module version (Date: YYYYMMDDXX). $plugin->release = 'PDF Annotator v1.4 release 5'; $plugin->requires = 2016112900; // Requires this Moodle version. -- GitLab