Fix for widget

This commit is contained in:
Jane Adelmann 2022-06-14 18:33:28 +03:00
parent e1b7ea48a3
commit 8187645ee1
No known key found for this signature in database
GPG Key ID: 4CCF39DF30B8AF72
2 changed files with 55 additions and 36 deletions

87
lib.php
View File

@ -330,47 +330,66 @@ window.plagiarism_check_full_report = function (action, token) {
form.submit(); form.submit();
}; };
require([], function () { require(['jquery'], function ($) {
$(function () {
var spans = window.document.getElementsByClassName('plagiarism-pchkorg-widget'); var spans = window.document.getElementsByClassName('plagiarism-pchkorg-widget');
for (var span of spans) { for (var s in spans) {
for (var classname of span.classList) { var span = spans[s];
if (classname.includes('plagiarism-pchkorg-widget-id-')) { if (span) {
var id = classname.replace('plagiarism-pchkorg-widget-id-', ''); for (var c in span.classList) {
if (id) { var classname = span.classList[c];
for (var data of window.plagiarism_check_data) { if (classname && classname.includes('plagiarism-pchkorg-widget-id-')) {
if (data.id == id) { var id = classname.replace('plagiarism-pchkorg-widget-id-', '');
var a = document.createElement('a'); if (id) {
a.setAttribute('href', '#'); for (var d in window.plagiarism_check_data) {
a.setAttribute('title', data.title); var data = window.plagiarism_check_data[d];
a.style.padding = '5px 3px'; if (data && data.id == id) {
a.style.textDecoration = 'none'; var a = document.createElement('a');
a.style.backgroundColor = data.color; a.setAttribute('href', '#');
a.style.color = 'black'; a.setAttribute('title', data.title);
a.style.cursor = 'pointer'; a.setAttribute('data-id', data.id);
a.style.borderRadius = '3px 3px 3px 3px'; a.style.padding = '5px 3px';
a.style.margin = '4px'; a.style.textDecoration = 'none';
a.style.display = 'inline-block'; a.style.backgroundColor = data.color;
a.onclick = function() { a.style.color = 'black';
window.plagiarism_check_full_report(data.action, data.token); a.style.cursor = 'pointer';
return false; a.style.borderRadius = '3px 3px 3px 3px';
}; a.style.margin = '4px';
var label = document.createTextNode(data.label); a.style.display = 'inline-block';
var img = document.createElement('img'); var label = document.createTextNode(data.label);
img.setAttribute('alt', 'PlagiarismCheck.org'); var img = document.createElement('img');
img.setAttribute('src', data.image); img.setAttribute('alt', 'PlagiarismCheck.org');
img.setAttribute('width', '20'); img.setAttribute('src', data.image);
a.appendChild(img); img.setAttribute('width', '20');
a.appendChild(label); a.appendChild(img);
span.appendChild(a); a.appendChild(label);
break; span.appendChild(a);
break;
}
} }
} }
break;
} }
break;
} }
} }
} }
});"
$(window.document.body).on('click', '.plagiarism-pchkorg-widget', function(e) {
var id = $(e.target).closest('a').attr('data-id')
if (id) {
for (var d in window.plagiarism_check_data) {
var data = window.plagiarism_check_data[d];
if (data && data.id == id) {
window.plagiarism_check_full_report(data.action, data.token);
break;
}
}
}
return false;
})
});
});
"
); );
} }

View File

@ -26,9 +26,9 @@ defined('MOODLE_INTERNAL') || die();
if (!isset($plugin)) { if (!isset($plugin)) {
$plugin = new stdClass(); $plugin = new stdClass();
} }
$plugin->version = 2022060211; $plugin->version = 2022061418;
$plugin->requires = 2020061501; // Requires Moodle 3.9 . $plugin->requires = 2020061501; // Requires Moodle 3.9 .
$plugin->release = 'v3.9.5'; $plugin->release = 'v3.9.6';
$plugin->component = 'plagiarism_pchkorg'; $plugin->component = 'plagiarism_pchkorg';
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;
$plugin->dependencies = array( $plugin->dependencies = array(