diff --git a/action.php b/action.php
index 2401d51a18fe7c2f9fdb6cf8fcbc087ff92e7212..0ee9b23c6a2635f74f50bcbfe7ea66f88fa702a2 100644
--- a/action.php
+++ b/action.php
@@ -343,24 +343,18 @@ if ($action === 'addComment') {
$visibility = required_param('visibility', PARAM_ALPHA);
$isquestion = required_param('isquestion', PARAM_INT);
- $imgcounter = substr_count($extracted_content, '<img');
- $maxFileCount = get_config('mod_pdfannotator', 'maxfiles');
- if($imgcounter > $maxFileCount) {
- echo json_encode(['status' => 'error', 'type' => "maxfile", 'maxFileCount' => $maxFileCount]);
- } else {
- // Insert the comment into the mdl_pdfannotator_comments table and get its record id.
- $comment = pdfannotator_comment::create($documentid, $annotationid, $extracted_content, $visibility, $isquestion, $cm, $context);
+ // Insert the comment into the mdl_pdfannotator_comments table and get its record id.
+ $comment = pdfannotator_comment::create($documentid, $annotationid, $extracted_content, $visibility, $isquestion, $cm, $context);
- // If successful, create a comment array and return it as json.
- if ($comment) {
- $myrenderer = $PAGE->get_renderer('mod_pdfannotator');
- $templatable = new comment($comment, $cm, $context);
- $data = $templatable->export_for_template($myrenderer);
+ // If successful, create a comment array and return it as json.
+ if ($comment) {
+ $myrenderer = $PAGE->get_renderer('mod_pdfannotator');
+ $templatable = new comment($comment, $cm, $context);
+ $data = $templatable->export_for_template($myrenderer);
- echo json_encode($data);
- } else {
- echo json_encode(['status' => '-1']);
- }
+ echo json_encode($data);
+ } else {
+ echo json_encode(['status' => '-1']);
}
}
@@ -442,18 +436,11 @@ if ($action === 'editComment') {
$commentid = required_param('commentId', PARAM_INT);
$content = required_param('content', PARAM_RAW);
- $regex = ["/?time=[0-9]*|/", '"'];
+ $regex = "/?time=[0-9]*/";
$extracted_content = str_replace($regex, "", $content);
- $imgcounter = substr_count($extracted_content, "<img");
- $maxFileCount = get_config('mod_pdfannotator', 'maxfiles');
- if($imgcounter > $maxFileCount) {
- echo json_encode(['status' => 'error:maxfile', 'maxFileCount' => $maxFileCount]);
- } else {
- $data = pdfannotator_comment::update($commentid, $extracted_content, $editanypost, $context);
- echo json_encode($data);
- }
-
+ $data = pdfannotator_comment::update($commentid, $extracted_content, $editanypost, $context);
+ echo json_encode($data);
}
/* * ****************************************** Vote for a comment ****************************************** */
diff --git a/constants.php b/constants.php
index 803c5a87859b86913d5450e7cdf97a06f0a37b49..b0ccee908dbc0545c4c008d5a1da550d14105708 100644
--- a/constants.php
+++ b/constants.php
@@ -39,3 +39,8 @@ define('LATEX_TO_PNG_GOOGLE_API', 1);
* Prefix needed for encode64 images
*/
define('IMAGE_PREFIX', 'data:image/png;base64,');
+
+/**
+ * Editor unlimited files variable
+ */
+define('PDFANNOTATOR_EDITOR_UNLIMITED_FILES', -1);
diff --git a/lang/en/pdfannotator.php b/lang/en/pdfannotator.php
index 48861ce99880c24654ae77cac9698fd6017d17e9..77a3609504c93366dea4af44c9bd6ef04d71eae1 100644
--- a/lang/en/pdfannotator.php
+++ b/lang/en/pdfannotator.php
@@ -113,8 +113,8 @@ $string['error:hideComment'] = "An error has occured while trying to hide the co
$string['error:markasread'] = 'The item could not be marked as read.';
$string['error:markasunread'] = 'The item could not be marked as unread.';
$string['error:markcorrectanswer'] = 'An error has occured while marking the answer as correct.';
-$string['error:maximalfilenumber_created'] = 'Your comment cannot be created, because it exceeds the maximum number of files. You can attach at most {$a} file(s) to a single comment.';
-$string['error:maximalfilenumber_edited'] = 'Your comment cannot be edited, because it exceeds the maximum number of files. You can attach at most {$a} file(s) to a single comment.';
+$string['error:maximalsizeoffile_created'] = 'Your comment cannot be created, because it exceeds the maximum size of files. You can attach file(s) with at most {$a} to a single comment.';
+$string['error:maximalsizeoffile_edited'] = 'Your comment cannot be edited, because it exceeds the maximum size of files. You can attach file(s) with at most {$a} to a single comment.';
$string['error:missingAnnotationtype'] = 'Annotationtype does not exists. Possibly the entry in table pdfannotator_annotationtypes is missing.';
$string['error:openingPDF'] = 'An error occurred while opening the PDF file.';
$string['error:openprintview'] = 'An error has occured while trying to open the pdf in Acrobat Reader.';
@@ -213,8 +213,6 @@ $string['markCorrect'] = 'Mark as correct';
$string['markhidden'] = 'Hide';
$string['markSolved'] = 'Close question';
$string['markUnsolved'] = 'Reopen question';
-$string['maxfiles'] = 'Maximal number of file';
-$string['maxfiles_help'] = 'Maximal number of file per comment uploaded by users.';
$string['maximumfilesize'] = 'Maximum file size';
$string['maximumfilesize_help'] = 'Files uploaded by users may be up to this size.';
$string['me'] = 'me';
diff --git a/lib.php b/lib.php
index 03542f7d05de2463d4ebf953f82e3fc9f6dabbed..6aca97734314093c19346eb45e89ae3c77f0ca4d 100644
--- a/lib.php
+++ b/lib.php
@@ -774,10 +774,23 @@ function mod_pdfannotator_output_fragment_edit_comment_form($args) {
$context = context_module::instance($args['cmid']);
$html = '';
- $draftitemid = pdfannotator_data_preprocessing($context, 'editarea' . $args['commentid'], 'editor-editcomment-inputs' . $args['commentid'], 1);
+ $draftitemid = pdfannotator_data_preprocessing($context, 'editarea' . $args['commentid'], 'editor-editcomment-inputs' . $args['commentid'], 0);
$comment = $DB->get_record('pdfannotator_comments', ['id' => $args['commentid']]);
$html = pdfannotator_file_prepare_draft_area($draftitemid, $context->id, 'mod_pdfannotator', 'post',
$args['commentid'], pdfannotator_get_editor_options($context), $comment->content);
return $html;
}
+
+function mod_pdfannotator_output_fragment_open_editor($args) {
+ global $DB;
+ $context = context_module::instance($args['cmid']);
+
+ $data = pdfannotator_data_preprocessing($context, 'id_pdfannotator_content', "editor-commentlist-inputs", 0);
+ file_prepare_draft_area($draftitemid, $context->id, 'mod_pdfannotator', 'post', 0, pdfannotator_get_editor_options($context));
+
+ $out = html_writer::empty_tag('input', ['type' => 'hidden', 'class' => 'pdfannotator_' . $args['section'] . '_editoritemid', 'name' => 'input_value_editor', 'value' => $data['draftItemId']]);
+ $out .= html_writer::empty_tag('input', ['type' => 'hidden', 'class' => 'pdfannotator_' . $args['section'] . '_editorformat', 'name' => 'input_value_editor', 'value' => $data['editorFormat']]);
+
+ return $out;
+}
diff --git a/locallib.php b/locallib.php
index 2c5bc396bdf6f2c94ff737506e8f5dccb358b0a3..a178ad12824534767cf01928c32a24f719418231 100644
--- a/locallib.php
+++ b/locallib.php
@@ -31,6 +31,7 @@ require_once("$CFG->libdir/filelib.php");
require_once("$CFG->libdir/resourcelib.php");
require_once("$CFG->dirroot/mod/pdfannotator/lib.php");
require_once($CFG->dirroot . '/repository/lib.php');
+require_once($CFG->dirroot . '/mod/pdfannotator/constants.php');
/**
* Display embedded pdfannotator file.
@@ -87,15 +88,18 @@ function pdfannotator_display_embed($pdfannotator, $cm, $course, $file, $page =
$capabilities->usedrawing = has_capability('mod/pdfannotator:usedrawing', $context);
$capabilities->useprint = has_capability('mod/pdfannotator:printdocument', $context);
$capabilities->useprintcomments = has_capability('mod/pdfannotator:printcomments', $context);
+ // 3. Comment editor setting.
+ $editorsettings = new stdClass();
+ $editorsettings->active_editor = explode(',', get_config('core', 'texteditors'))[0];
- $params = [$cm, $documentobject, $context->id, $USER->id, $capabilities, $toolbarsettings, $page, $annoid, $commid];
+ $params = [$cm, $documentobject, $context->id, $USER->id, $capabilities, $toolbarsettings, $page, $annoid, $commid, $editorsettings];
$PAGE->requires->js_init_call('adjustPdfannotatorNavbar', null, true);
$PAGE->requires->js_init_call('startIndex', $params, true);
// The renderer renders the original index.php / takes the template and renders it.
$myrenderer = $PAGE->get_renderer('mod_pdfannotator');
echo $myrenderer->render_index(new index($pdfannotator, $capabilities, $file));
$PAGE->requires->js_init_call('checkOnlyOneCheckbox', null, true);
- pdfannotator_data_preprocessing($context, 'id_pdfannotator_content', "editor-commentlist-inputs");
+ //pdfannotator_data_preprocessing($context, 'id_pdfannotator_content', "editor-commentlist-inputs");
$PAGE->requires->js_init_call('checkOnlyOneCheckbox', null, true);
pdfannotator_print_intro($pdfannotator, $cm, $course);
@@ -107,7 +111,7 @@ function pdfannotator_display_embed($pdfannotator, $cm, $course, $file, $page =
function pdfannotator_get_image_options_editor() {
$image_options = new \stdClass();
$image_options->maxbytes = get_config('mod_pdfannotator', 'maxbytes');
- $image_options->maxfiles = get_config('mod_pdfannotator', 'maxfiles');
+ $image_options->maxfiles = PDFANNOTATOR_EDITOR_UNLIMITED_FILES;
$image_options->autosave = false;
$image_options->env = 'editor';
$draftitemid = file_get_unused_draft_itemid();
@@ -120,7 +124,7 @@ function pdfannotator_get_editor_options($context) {
$options = [
'atto:toolbar' => get_config('mod_pdfannotator', 'attobuttons'),
'maxbytes' => get_config('mod_pdfannotator', 'maxbytes'),
- 'maxfiles' => get_config('mod_pdfannotator', 'maxfiles'),
+ 'maxfiles' => PDFANNOTATOR_EDITOR_UNLIMITED_FILES,
'return_types' => 15,
'enable_filemanagement' => true,
'removeorphaneddrafts' => false,
@@ -237,10 +241,12 @@ function pdfannotator_data_preprocessing($context, $textarea, $classname, $draft
// advimage plugin
$image_options = (object)initialise_filepicker($args);
$image_options->maxbytes = get_config('mod_pdfannotator', 'maxbytes');
- $image_options->maxfiles = get_config('mod_pdfannotator', 'maxfiles');
+ $image_options->maxfiles = PDFANNOTATOR_EDITOR_UNLIMITED_FILES;
$image_options->autosave = false;
$image_options->env = 'editor';
- $draftitemid = file_get_unused_draft_itemid();
+ if (!$draftitemid) {
+ $draftitemid = file_get_unused_draft_itemid();
+ }
$image_options->itemid = $draftitemid;
$editor->use_editor($textarea, $options, ['image' => $image_options]);
}
@@ -248,11 +254,15 @@ function pdfannotator_data_preprocessing($context, $textarea, $classname, $draft
// Add draftitemid and editorformat into input-tags.
$editorformat = editors_get_preferred_format(FORMAT_HTML);
- $PAGE->requires->js_init_call('inputDraftItemID', [$draftitemid, (int)$editorformat, $classname]);
+ //$PAGE->requires->js_init_call('inputDraftItemID', [$draftitemid, (int)$editorformat, $classname]);
- return $draftitemid;
+ return ['draftItemId' => $draftitemid, 'editorFormat' => $editorformat, 'className' => $classname];
}
+/**
+ * Same function as core, however we need to add files into the existing draft area!
+ *
+ */
function pdfannotator_file_prepare_draft_area(&$draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null) {
global $CFG, $USER, $CFG, $DB;
@@ -267,11 +277,7 @@ function pdfannotator_file_prepare_draft_area(&$draftitemid, $contextid, $compon
$usercontext = \context_user::instance($USER->id);
$fs = get_file_storage();
- if (empty($draftitemid)) {
- // create a new area and copy existing files into
- $draftitemid = file_get_unused_draft_itemid();
- }
- $file_record = array('contextid'=>$usercontext->id, 'component'=>'user', 'filearea'=>'draft', 'itemid'=>$draftitemid);
+ $file_record = ['contextid'=>$usercontext->id, 'component'=>'user', 'filearea'=>'draft', 'itemid'=>$draftitemid];
if (!is_null($itemid) and $files = $fs->get_area_files($contextid, $component, $filearea, $itemid)) {
foreach ($files as $file) {
if ($file->is_directory() and $file->get_filepath() === '/') {
@@ -364,7 +370,6 @@ function pdfannotator_get_annotationtype_name($typeid) {
function pdfannotator_handle_latex($context, string $subject) {
global $CFG;
- require_once($CFG->dirroot . '/mod/pdfannotator/constants.php');
$latexapi = get_config('mod_pdfannotator', 'latexapi');
// Look for these formulae: $$ ... $$, \( ... \) and \[ ... \]
diff --git a/settings.php b/settings.php
index 8b8b668aa0a16a4589ac10c320f8aec88b82a3b5..3dec4a61b4a3a4cc1b887783d5355ce24524572f 100644
--- a/settings.php
+++ b/settings.php
@@ -87,8 +87,4 @@ screen = fullscreen';
$settings->add($element);
}
- $settings->add(new admin_setting_configtext('mod_pdfannotator/maxfiles',
- new lang_string('maxfiles', 'pdfannotator'),
- new lang_string('maxfiles_help', 'pdfannotator'), 20, PARAM_INT));
-
}
diff --git a/shared/index.js b/shared/index.js
index 032bd99fdaed27cff84262f0fa315353a96a2319..35e1124c8a384dcb5caf3a7e3772dd3aca60bcfe 100644
--- a/shared/index.js
+++ b/shared/index.js
@@ -39,7 +39,7 @@
//SOFTWARE.
//
//R: The first parameter has to be Y, because it is a default YUI-object, because moodle gives this object first.
-function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _toolbarSettings, _page = 1,_annoid = null,_commid = null){ // 3. parameter war mal _fileid
+function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _toolbarSettings, _page = 1,_annoid = null,_commid = null, _editorSettings){ // 3. parameter war mal _fileid
// Require amd modules.
require(['jquery','core/templates','core/notification','mod_pdfannotator/jspdf', 'core/fragment'], function($,templates,notification,jsPDF, Fragment) {
@@ -283,12 +283,6 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
}else if (data.status == -1){
notification.alert(M.util.get_string('error','pdfannotator'),M.util.get_string('missingAnnotation','pdfannotator'),'ok');
return false;
- } else if (data.status === "error" && data.type === "maxfile") {
- notification.addNotification({
- message: M.util.get_string('error:maximalfilenumber_created','pdfannotator', data.maxFileCount),
- type: "error"
- });
- return false;
} else {
notification.addNotification({
message: M.util.get_string('error:addComment','pdfannotator'),
@@ -1554,22 +1548,22 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
// Comment annotations
(function (window, document) {
- var commentList = document.querySelector('#comment-wrapper .comment-list-container'); // to be found in index.php
- var commentForm = document.querySelector('#comment-wrapper .comment-list-form'); // to be found in index.php
- var commentText = commentForm.querySelector('#id_pdfannotator_content'); // Plain text editor.
- // We will need this to reset the typed text for other editors.
- var editorArea = commentForm.querySelector('#id_pdfannotator_contenteditable'); // Atto editor.
- if (!editorArea) { // TinyMCE editor.
- var iframe = document.getElementById("myarea_ifr");
- if (iframe) {
- editorArea = iframe.contentWindow.document.getElementById("tinymce");
- }
- }
- // Function checks whether the target annotation type allows comments
- function supportsComments(target) {
- var type = target.getAttribute('data-pdf-annotate-type');
- return ['point', 'highlight', 'area', 'strikeout'].indexOf(type) > -1;
- }
+ var commentList = document.querySelector('#comment-wrapper .comment-list-container'); // to be found in index.php
+ var commentForm = document.querySelector('#comment-wrapper .comment-list-form'); // to be found in index.php
+ var commentText = commentForm.querySelector('#id_pdfannotator_content'); // Plain text editor.
+ // We will need this to reset the typed text for other editors.
+ var editorArea = commentForm.querySelector('#id_pdfannotator_contenteditable'); // Atto editor.
+ if (!editorArea) { // TinyMCE editor.
+ var iframe = document.getElementById("myarea_ifr");
+ if (iframe) {
+ editorArea = iframe.contentWindow.document.getElementById("tinymce");
+ }
+ }
+ // Function checks whether the target annotation type allows comments
+ function supportsComments(target) {
+ var type = target.getAttribute('data-pdf-annotate-type');
+ return ['point', 'highlight', 'area', 'strikeout'].indexOf(type) > -1;
+ }
/*
@@ -1578,12 +1572,12 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
*
* @return {Element}
*/
- function insertComments(comments, markCommentid = undefined) {
+ function insertComments(comments, markCommentid = undefined) {
if(!comments) {
return false;
}
if(!comments.comments){
- comments = {comments: [comments]};
+ comments = {comments: [comments]};
}
(function(templates, data) {
@@ -1595,8 +1589,8 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
} else {
templates.replaceNodeContents('.comment-list-container', html, js);
}
-
- }).then(function() {
+
+ }).then(function(e) {
data.comments.forEach(function(comment) {
createVoteHandler(comment);
createEditFormHandler(comment);
@@ -1614,14 +1608,11 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
let element = document.querySelector(selector);
renderMathJax(element);
});
- // fixCommentForm();
-
- //$("#comment_"+comment.uuid+" chat-message-p:contains('"+pattern+"')").addClass('mark');
- //$("chat-message+:contains('text')").addClass('mark');
+
//if the target has the attribute markCommentid a specific comment should be marked with an red border
//after 3 sec the border should disappear
if(markCommentid !== undefined && markCommentid !== null){
- // document.querySelector('#comment_'+markCommentid).style.cssText = "border:3px solid red !important";
+ // document.querySelector('#comment_'+markCommentid).style.cssText = "border:3px solid red !important";
$('#comment_'+markCommentid).addClass('mark');
markCommentid = undefined;
setTimeout(function(){
@@ -1631,14 +1622,14 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
},3000);
}else{
// Otherwise the inputfield of the form should be focused.
- commentText.focus();
+ commentText.focus();
}
}); // add a catch
}
})(templates, comments);
return true;
- }
+ }
function createSolvedHandler(comment){
var button = $('#comment_'+comment.uuid+' .comment-solve-a');
@@ -1789,7 +1780,7 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
if (editForm.style.display === "none") {
editForm.style.display = "block";
text.innerHTML = "";
-
+
var isEmptyContent = false;
// Add an event handler to the form for submitting any changes to the database.
editForm.onsubmit = function (e) {
@@ -1799,6 +1790,22 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
if(commentEditContentElements.innerText.replace('/\n/g', '').trim() === '') {
isEmptyContent = true;
}
+ if(imgContents) {
+ imgContents.forEach(img => {
+ if(img.size > maxFile) {
+ setTimeout(function(){
+ notification.addNotification({
+ message: M.util.get_string('','pdfannotator'),
+ type: "error"
+ });
+ let notificationpanel = document.getElementById("user-notifications");
+ while (notificationpanel.hasChildNodes()) {
+ notificationpanel.removeChild(notificationpanel.firstChild);
+ }
+ }, 5000);
+ }
+ });
+ }
var temp = commentEditContentElements.querySelectorAll('p')[0];
if(temp) {
if (temp.innerText.replace('/\n/g', '').trim() === '' && imgContents.length === 0) {
@@ -1828,16 +1835,12 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
newContent = data.newContent;
text.innerHTML = newContent;
comment.content = newContent;
+ editArea = newContent;
renderMathJax(text);
notification.addNotification({
message: M.util.get_string('successfullyEdited', 'pdfannotator'),
type: "success"
});
- } else if (data.status === "error:maxfile") {
- notification.addNotification({
- message: M.util.get_string('error:maximalfilenumber_edited','pdfannotator', data.maxFileCount),
- type: "error"
- });
} else {
notification.addNotification({
message: M.util.get_string('error:editComment','pdfannotator'),
@@ -1869,29 +1872,14 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
editForm.style.display = "none";
text.innerHTML = comment.displaycontent;
renderMathJax(text);
- }
+ }
}
// Create an element for click.
var editButton = $('#editButton'+comment.uuid);
// Add an event handler to the click element that opens a textarea and fills it with the current comment.
editButton.click(function(e) {
- if(!editorExists) {
- let args = {'commentid': comment.uuid, 'cmid': _cm.id};
- let fragmentPromise = Fragment.loadFragment('mod_pdfannotator', 'edit_comment_form', _contextId, args);
- fragmentPromise.done(function(html, js) {
- templates.runTemplateJS(js);
- return html;
- }).fail(notification.exception)
- .then(function(html) {
- var editareaEditable = document.querySelectorAll(`#editarea${comment.uuid}editable`)[0];
- editareaEditable.innerHTML = '';
- editareaEditable.innerHTML = html;
- editorExists = true;
- handleClickIfEditorExists();
- });
- } else {
- handleClickIfEditorExists();
- }
+ UI.loadEditor('editcomment', 'edit', comment.uuid);
+ handleClickIfEditorExists();
});
}
@@ -1988,9 +1976,9 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
}
$('#comment-wrapper h4')[0].innerHTML = title;
- commentList.innerHTML = '';
- commentForm.style.display = 'inherit';
-
+ commentList.innerHTML = '';
+ commentForm.style.display = 'inherit';
+
var button1 = document.getElementById('allQuestions'); // to be found in index template
button1.style.display = 'inline';
var button2 = document.getElementById('questionsOnThisPage'); // to be found in index template
@@ -2019,12 +2007,13 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
document.querySelector('#commentSubmit').disabled = false;
return false;
}
- _2.default.getStoreAdapter().addComment(documentId, annotationId, commentContentElements.innerHTML, commentVisibility, isquestion)
+ _2.default.getStoreAdapter().addComment(documentId, annotationId, commentContentElements.innerHTML, commentVisibility, isquestion)
.then(insertComments)
.then(function (success) {
if (!success) {
return false;
}
+ UI.loadEditor('content');
document.querySelector('#commentSubmit').disabled = false;
commentText.value = '';
if(editorArea) {
@@ -2033,19 +2022,21 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
commentText.focus();
}).catch(function(err){
notification.addNotification({
- message: M.util.get_string('error:addComment','pdfannotator'),
- type: "error"
+ message: M.util.get_string('error:addComment','pdfannotator'),
+ type: "error"
});
console.error(M.util.get_string('error:addComment', 'pdfannotator'));
});
- return false; // Prevents page reload via POST to enable asynchronous loading
- };
-
+ return false; // Prevents page reload via POST to enable asynchronous loading
+ };
+
+ //render comments
//render comments
- insertComments(comments, target.markCommentid);
-
- }, function (err){
+ //render comments
+ insertComments(comments, target.markCommentid);
+
+ }, function (err){
commentList.innerHTML = '';
commentForm.style.display = 'none';
commentForm.onsubmit = null;
@@ -3995,7 +3986,7 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
} else {
clickedElement = '';
}
- if(clickedElement && editorNodes.querySelector(clickedElement)) {
+ if(clickedElement && editorNodes && editorNodes.querySelector(clickedElement)) {
return;
}
//If moodle Modal beeing clicked.
@@ -5094,7 +5085,8 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
var _shortText = __webpack_require__(39);
var _newAnnotations = __webpack_require__(40);
var _ajaxloader=__webpack_require__(36);
- exports.default={addEventListener:_event.addEventListener,removeEventListener:_event.removeEventListener,fireEvent:_event.fireEvent,disableEdit:_edit.disableEdit,enableEdit:_edit.enableEdit,disablePen:_pen.disablePen,enablePen:_pen.enablePen,setPen:_pen.setPen,disablePoint:_point.disablePoint,enablePoint:_point.enablePoint,disableRect:_rect.disableRect,enableRect:_rect.enableRect,disableText:_text.disableText,enableText:_text.enableText,setText:_text.setText,createPage:_page.createPage,renderPage:_page.renderPage,showLoader:_ajaxloader.showLoader,hideLoader:_ajaxloader.hideLoader,pickAnnotation:_pickAnno.pickAnnotation, renderQuestions:_questionsRenderer.renderQuestions, renderAllQuestions: _questionsRenderer.renderAllQuestions, shortenTextDynamic:_shortText.shortenTextDynamic, mathJaxAndShortenText:_shortText.mathJaxAndShortenText, loadNewAnnotations : _newAnnotations.load};
+ var _commentWrapper=__webpack_require__(35);
+ exports.default={addEventListener:_event.addEventListener,removeEventListener:_event.removeEventListener,fireEvent:_event.fireEvent,disableEdit:_edit.disableEdit,enableEdit:_edit.enableEdit,disablePen:_pen.disablePen,enablePen:_pen.enablePen,setPen:_pen.setPen,disablePoint:_point.disablePoint,enablePoint:_point.enablePoint,disableRect:_rect.disableRect,enableRect:_rect.enableRect,disableText:_text.disableText,enableText:_text.enableText,setText:_text.setText,createPage:_page.createPage,renderPage:_page.renderPage,showLoader:_ajaxloader.showLoader,hideLoader:_ajaxloader.hideLoader,pickAnnotation:_pickAnno.pickAnnotation, renderQuestions:_questionsRenderer.renderQuestions, renderAllQuestions: _questionsRenderer.renderAllQuestions, shortenTextDynamic:_shortText.shortenTextDynamic, mathJaxAndShortenText:_shortText.mathJaxAndShortenText, loadNewAnnotations : _newAnnotations.load, loadEditor: _commentWrapper.loadEditor};
module.exports=exports['default'];
/***/},
/** 29 */
@@ -5808,6 +5800,7 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
deleteUndefinedPin();
[textarea,data] = (0,_commentWrapper.openComment)(e,handleCancelClick,handleSubmitClick,handleToolbarClick,handleSubmitBlur,'pin');
renderPin();
+ _commentWrapper.loadEditor('content');
}
// Reset dragging to false.
@@ -5925,7 +5918,7 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
}
function initializeAnnotationTouchscreen(rect,svg,coordinates){
var clientX=(0,_utils.roundDigits)(coordinates.x,4);
- var clientY=(0,_utils.roundDigits)(coordinates.y,4);
+ var clientY=(0,_utils.roundDigits)(coordinates.y,4);
return Object.assign({type:'point'},(0,_utils.scaleDown)(svg,{x:clientX-((0,_utils.roundDigits)(rect.left,4)),y:clientY-((0,_utils.roundDigits)(rect.top,4))}));
}
/**
@@ -6186,10 +6179,12 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
}
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);
+ _commentWrapper.loadEditor('content');
[textarea,data] = (0,_commentWrapper.openComment)(e,handleCancelClick,handleSubmitClick,handleToolbarClick,handleSubmitBlur,_type);
}else if((rectsSelection=getSelectionRects()) && _type!=='area'){
renderRect(_type,[].concat(_toConsumableArray(rectsSelection)).map(function(r){return{top:r.top,left:r.left,width:r.width,height:r.height};}),null);
+ _commentWrapper.loadEditor('content');
[textarea,data] = (0,_commentWrapper.openComment)(e,handleCancelClick,handleSubmitClick,handleToolbarClick,handleSubmitBlur,_type);
}else{
enableRect(_type);
@@ -6339,7 +6334,8 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
}else if(type==='strikeout'){
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-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){
return;
@@ -6358,7 +6354,6 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
}
return annotation;
}
-
/**
* Save a rect annotation
@@ -6401,7 +6396,8 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
document.querySelector('.toolbar').removeEventListener('click',handleToolbarClick);
//simulate an click on cursor
document.querySelector('button.cursor').click();
- (0,_commentWrapper.showCommentsAfterCreation)(annotation.uuid);
+ (0,_commentWrapper.showCommentsAfterCreation)(annotation.uuid);
+ //_commentWrapper.loadEditor('content');
})
.catch(function(){
//if there is an error in addComment, the annotation should be deleted!
@@ -6776,6 +6772,7 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
exports.closeComment = closeComment;
exports.showCommentsAfterCreation = showCommentsAfterCreation;
exports.openCommentTouchscreen = openCommentTouchscreen;
+ exports.loadEditor = loadEditor;
var _PDFJSAnnotate=__webpack_require__(1);
var _event=__webpack_require__(4);
var _PDFJSAnnotate2=_interopRequireDefault(_PDFJSAnnotate);
@@ -6955,6 +6952,77 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
textarea.focus();
return [textarea,data];
}
+
+ /**
+ *
+ * @param {type} section is a part of class name of editor input: pdfannotator_${section}_editoritemid, pdfannotator_${section}_editorFormat. It could be
+ */
+ function loadEditor(section, action='add', uuid=0){
+ _ajaxloader.showLoader('.editor-loader-placeholder');
+ let addCommentEditor = document.querySelectorAll('#add_comment_editor_wrapper').length;
+ let editCommentEditor = document.querySelectorAll('#edit_comment_editor_wrapper').length;
+ // If one of the Moodle Editor is active, then remove it from DOM and reappend the textarea for editor needs and the input fields.
+ if(addCommentEditor > 0 && action === "add") {
+ templates.render('mod_pdfannotator/add_comment_editor')
+ .then(function(html, js) {
+ let commentListForm = document.querySelectorAll('#comment-list-form')[0];
+ commentListForm.appendChild(html);
+ return html;
+ })
+ .catch(notification.exception)
+ .then(function(html) {
+ $('input').remove('[name="input_value_editor"]');
+ let args = {'section': section, 'cmid': _cm.id};
+ Fragment.loadFragment('mod_pdfannotator', 'open_editor', _contextId, args)
+ .done(function(html, js) {
+ _ajaxloader.hideLoader('.editor-loader-placeholder');
+ if (!html) {
+ throw new TypeError("Invalid HMTL Input");
+ }
+ templates.replaceNode(document.getElementById('editor-commentlist-inputs'), html, js);
+ return html;
+ }.bind(this))
+ .catch(notification.exception);
+ });
+ } else if(editCommentEditor > 0 && action === "edit") {
+ templates.render('mod_pdfannotator/edit_comment_editor')
+ .then(function(html, js) {
+ let editForm = document.querySelectorAll(`edit${uuid}`)[0];
+ editForm.appendChild(html);
+ return html;
+ })
+ .catch(notification.exception)
+ .then(function() {
+ $('input').remove('[name="input_value_editor"]');
+ let args = {'section': section, 'cmid': _cm.id};
+ Fragment.loadFragment('mod_pdfannotator', 'open_editor', _contextId, args)
+ .done(function(html, js) {
+ _ajaxloader.hideLoader('.editor-loader-placeholder');
+ if (!html) {
+ throw new TypeError("Invalid HMTL Input");
+ }
+ templates.replaceNode(document.getElementById('editor-commentlist-inputs'), html, js);
+ return html;
+ }.bind(this))
+ .catch(notification.exception);
+ });
+ } else {
+ // nothing to do.
+ }
+
+ /* $('input').remove('[name="input_value_editor"]');
+ let args = {'section': section, 'cmid': _cm.id};
+ Fragment.loadFragment('mod_pdfannotator', 'open_editor', _contextId, args)
+ .done(function(html, js) {
+ _ajaxloader.hideLoader('.editor-loader-placeholder');
+ if (!html) {
+ throw new TypeError("Invalid HMTL Input");
+ }
+ templates.replaceNode(document.getElementById('editor-commentlist-inputs'), html, js);
+ return html;
+ }.bind(this))
+ .catch(notification.exception) */
+ }
/***/},
/* 36 *//*OWN Module! To show and hide ajaxloader*/
@@ -6970,10 +7038,10 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
* hides the loading animation
* @returns {undefined}
*/
- function hideLoader(){
+ function hideLoader(selector='.comment-list-container'){
let loader = document.querySelector('#ajaxLoaderCreation');
if(loader !== null){
- let commentContainer = document.querySelector('.comment-list-container');
+ let commentContainer = document.querySelector(`${selector}`);
commentContainer.removeChild(loader);
}
}
@@ -6982,8 +7050,8 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
* Shows an loading animation in the comment wrapper
* @returns {undefined}
*/
- function showLoader(){
- let commentContainer = document.querySelector('.comment-list-container');
+ function showLoader(selector='.comment-list-container'){
+ let commentContainer = document.querySelector(`${selector}`);
commentContainer.innerHTML = '';
let img = document.createElement('img');
img.id = "ajaxLoaderCreation";
diff --git a/shared/locallib.js b/shared/locallib.js
index 5c1a9de6e7077fc0aca90d816a5fd89a7c5a001a..bc75be5d828c5c69bad36dc53d8a87d0de36b83e 100644
--- a/shared/locallib.js
+++ b/shared/locallib.js
@@ -224,30 +224,4 @@ function checkOnlyOneCheckbox( Y ) {
}
});
}
-}
-
-
-/**
- * Input draftitemid to the input-tag in comment_list_form.
- */
- function inputDraftItemID(Y, draftitemid, editorformat, classname) {
- let elem = document.getElementsByClassName(classname);
- for (let editorwrap of elem) {
- let match = '';
- if(classname.match('editcomment')) {
- match = 'editcomment';
- } else if (classname.match('commentlist')) {
- match = 'content';
- } else {
- return false;
- }
- if(editorwrap.getElementsByClassName(`pdfannotator_${match}_editoritemid`).length === 0) {
- let sibling1 = `<input class="pdfannotator_${match}_editoritemid" type="hidden" value=${draftitemid}>`
- editorwrap.insertAdjacentHTML("afterend", sibling1);
- }
- if(editorwrap.getElementsByClassName('pdfannotator_${match}_editorformat').length === 0) {
- let sibling2 = `<input class="pdfannotator_${match}_editorformat" id="menupdfannotator_${match}_editorformat" type="hidden" value=${editorformat}>`;
- editorwrap.insertAdjacentHTML("afterend", sibling2);
- }
- };
}
\ No newline at end of file
diff --git a/styles.css b/styles.css
index 8ab8c73fea5cb0b8e9ac525b24ef3ddefa1588c1..4195952ce0d3b38faaad08e4dfb4aee5d20d7e78 100644
--- a/styles.css
+++ b/styles.css
@@ -1248,4 +1248,8 @@ header, section, footer, aside, nav, main, article, figure {
.path-mod-pdfannotator [contenteditable] {
-webkit-user-select: text;
user-select: text;
+}
+
+.path-mod-pdfannotator #id_pdfannotator_content {
+ display: none !important;
}
\ No newline at end of file
diff --git a/templates/add_comment_editor.mustache b/templates/add_comment_editor.mustache
new file mode 100644
index 0000000000000000000000000000000000000000..22a56a4f82fa3ee75727885aa340f528f55e6368
--- /dev/null
+++ b/templates/add_comment_editor.mustache
@@ -0,0 +1,5 @@
+<div id="add_comment_editor_wrapper"> {{! necessary for atto-editor }}
+ <textarea id="id_pdfannotator_content" placeholder="{{# str }} addAComment, pdfannotator {{/ str }}" cols="40" rows="3"></textarea>
+ <div id="editor-commentlist-inputs"></div>
+ <div class="editor-loader-placeholder"></div>
+</div>
\ No newline at end of file
diff --git a/templates/comment.mustache b/templates/comment.mustache
index d9fb718d1e9997c1bc74ce8870502d7e388fc3a2..ff781d1e3ba2bc5d98c82506555647e048116d8b 100644
--- a/templates/comment.mustache
+++ b/templates/comment.mustache
@@ -57,9 +57,10 @@
{{#displayhidden}}<span id="taghidden{{uuid}}" class="tag tag-info">{{# str }} hiddenforparticipants, pdfannotator {{/ str }}</span>{{/displayhidden}}
<form id="edit{{ uuid }}" class="edit-comment-form" style="display:none;">
- <div> {{! necessary for atto-editor }}
+ <div id="editor_edit_wrapper"> {{! necessary for atto-editor }}
<textarea id="editarea{{ uuid }}" placeholder="" cols="40" rows="3">{{{ displaycontent }}}</textarea>
<div class="editor-editcomment-inputs{{ uuid }}"></div>
+ <div class="editor-loader-placeholder"></div>
</div>
<input id="commentSubmit" class="owner btn btn-primary mb-1" type="submit" value="{{# str }} editButton, pdfannotator {{/ str }}">
<input id="commentCancel" class="owner btn btn-secondary mb-1" type="reset" value="{{# str }} cancelButton, pdfannotator {{/ str }}" >
diff --git a/templates/edit_comment_editor.mustache b/templates/edit_comment_editor.mustache
new file mode 100644
index 0000000000000000000000000000000000000000..2abb33320d6f6c3023cf6b9eaefb276bda381d23
--- /dev/null
+++ b/templates/edit_comment_editor.mustache
@@ -0,0 +1,5 @@
+<div id="edit_comment_editor_wrapper"> {{! necessary for atto-editor }}
+ <textarea id="editarea{{ uuid }}" placeholder="" cols="40" rows="3">{{{ displaycontent }}}</textarea>
+ <div class="editor-editcomment-inputs{{ uuid }}"></div>
+ <div class="editor-loader-placeholder"></div>
+</div>
\ No newline at end of file
diff --git a/templates/index.mustache b/templates/index.mustache
index f43d627e1bc0a38f81ad2192e843e1a47ea2dc8f..658d8954bc5218b76a382c6586fa5bccfaaf00c0 100644
--- a/templates/index.mustache
+++ b/templates/index.mustache
@@ -129,9 +129,10 @@
</div>
<form id="comment-list-form" class="comment-list-form" style="display:none;">
- <div> {{! necessary for atto-editor }}
+ <div id="editor_wrapper"> {{! necessary for atto-editor }}
<textarea id="id_pdfannotator_content" placeholder="{{# str }} addAComment, pdfannotator {{/ str }}" cols="40" rows="3"></textarea>
- <div class="editor-commentlist-inputs"></div>
+ <div id="editor-commentlist-inputs"></div>
+ <div class="editor-loader-placeholder"></div>
</div>
<div id="anonymousDiv" class="row-fluid row">
<input type="checkbox" name="visibility" value="anonymous" id="anonymousCheckbox" class="pdfannotator-radio" style="width:auto;"><label id="anonymousLabel" for="anonymousCheckbox">{{# str }} sendAnonymous, pdfannotator {{/ str }}</label>
diff --git a/version.php b/version.php
index 2182b1cb6c1b26c46e7d1655b3e4493aa39e7ea6..10465647309ce96f061d50f7f198cdb7e76d21f9 100644
--- a/version.php
+++ b/version.php
@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'mod_pdfannotator';
-$plugin->version = 2022090600;
+$plugin->version = 2022090800;
$plugin->release = 'PDF Annotator v1.4 release 11';
$plugin->requires = 2021051700;
$plugin->maturity = MATURITY_STABLE;