Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 2025121500 v1.5.9
* version increment
* fix items perpage dropdown + overview table styling
* overview page crash fix + table styling
* accessibility enhancement: tab title set to coursename and instance name
* close sidebars in fullscreen mode
* fix comment section in mobile view
* colorpicker feature for highlighter implemented

## 2025070803 v1.5.9
* fix images not being displayed in comments
* remove explicit mathjax calls for rendering
Expand Down
2 changes: 1 addition & 1 deletion controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@
$stringman = get_string_manager();
$strings = $stringman->load_component_strings('pdfannotator', 'en'); // Method gets the strings of the language files.
$PAGE->requires->strings_for_js(array_keys($strings), 'pdfannotator'); // Method to use the language-strings in javascript.
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/locallib.js?ver=00008"));
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/locallib.js?ver=00009"));
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/statistic.js?ver=0004"));
$myrenderer = $PAGE->get_renderer('mod_pdfannotator');
$capabilities = new stdClass();
Expand Down
61 changes: 57 additions & 4 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ function pdfannotator_display_embed($pdfannotator, $cm, $course, $file, $page =
// Load and execute the javascript files.
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/pdf.js?ver=00002"));
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/textclipper.js"));
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/index.js?ver=00043"));
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/locallib.js?ver=00008"));
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/index.js?ver=00044"));
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/locallib.js?ver=00009"));

// Pass parameters from PHP to JavaScript.

Expand Down Expand Up @@ -984,7 +984,7 @@ function pdfannotator_prepare_overviewpage($cmid, $myrenderer, $taburl, $action,
$strings = $stringman->load_component_strings('pdfannotator', 'en'); // Method gets the strings of the language files.
$PAGE->requires->strings_for_js(array_keys($strings), 'pdfannotator'); // Method to use the language-strings in javascript.
// 1.3 Add the javascript file that determines the dynamic behaviour of the page.
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/locallib.js?ver=00008"));
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/locallib.js?ver=00009"));
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/overview.js?ver=00004"));

// 1.4 Check user capabilities to view the different categories.
Expand Down Expand Up @@ -1666,6 +1666,35 @@ function pdfannotator_print_questions($questions, $thiscourse, $urlparams, $curr

// Define flexible table.
$table = new questionstable($url, $showdropdown);
$questioncount = count($questions);

$pages = $table->pdfannotator_build_pagesize_options($questioncount);

// Ensure current value is valid
if (!isset($pages[$itemsperpage])) {
$itemsperpage = 5;
}

// Render dropdown
echo html_writer::start_div('pdfannotator-pagesize-wrapper');

echo html_writer::tag('label',
get_string('itemsperpage', 'pdfannotator'),
['for' => 'pdfannotator-pagesize']
);

echo html_writer::select(
$pages, // options
'perpage', // name
$itemsperpage, // selected
false, // no empty option
[
'id' => 'pdfannotator-pagesize',
'onchange' => "location.href='{$url->out(false)}&itemsperpage=' + this.value"
]
);

echo html_writer::end_div();
$table->setup();
// $table->pageable(false);
// Sort the entries of the table according to time or number of votes.
Expand All @@ -1682,6 +1711,7 @@ function pdfannotator_print_questions($questions, $thiscourse, $urlparams, $curr
}
} else {
$table->pagesize($itemsperpage, $questioncount);
$table->set_attribute('data-force-pagesize', 1);
for ($i = $offset; $i < $questioncount; $i++) {
$question = $questions[$i];
if ($itemsperpage === 0) {
Expand Down Expand Up @@ -1856,7 +1886,30 @@ function pdfannotator_questionstable_add_row($thiscourse, $table, $question, $ur
if (isset($question->displayhidden)) {
$classname = 'dimmed_text';
}
$content = "<a href=$question->link class='more'>$question->content</a>";
$link = new moodle_url($question->link);

// 1. Get plain text only
$fulltext = trim(strip_tags($question->content));

// 2. Collapse newlines and whitespace (CRITICAL for JS)
$fulltext = preg_replace('/\s+/', ' ', $fulltext);

// 3. Limit length to prevent JS infinite loops
$preview = mb_substr($fulltext, 0, 180);

if (mb_strlen($fulltext) > 180) {
$preview .= '…';
}

// 4. Escape for safe output
$preview = format_string($preview);

// 5. Build safe clickable link
$content = html_writer::link(
$link,
$preview,
['class' => 'more']
);
$pdfannotatorname = $question->pdfannotatorname;

$data = array($content, $author . '<br>' . $time, $question->votes, $question->answercount, $lastanswered, $pdfannotatorname);
Expand Down
27 changes: 27 additions & 0 deletions model/overviewtable.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public function setup() {
TABLE_VAR_PAGE => 'page', // This is used for pagination in the tables.
TABLE_VAR_RESET => 'treset'
)));
// ensure paging is enabled
$this->pageable(true);

// ensure baseurl exists BEFORE parent::setup()
if (empty($this->baseurl)) {
$this->define_baseurl(new moodle_url('/'));
}
parent::setup();
}
/**
Expand All @@ -54,6 +61,26 @@ public function setup() {
public static function wrap($string) {
return "<span class='text'>$string</span>";
}
function pdfannotator_build_pagesize_options(int $questioncount) {
$pages = [5 => 5]; // always include 5

if ($questioncount > 10) { $pages[10] = 10; }
if ($questioncount > 25) { $pages[25] = 25; }
if ($questioncount > 50) { $pages[50] = 50; }
if ($questioncount > 100) { $pages[100] = 100; }
if ($questioncount > 200) { $pages[200] = 200; }
if ($questioncount > 500) { $pages[500] = 500; }

$pages[-1] = get_string('all');

return $pages;
}

public function finish_html() {
error_log('overviewtable::finish_html called id=' . ($this->attributes['id'] ?? 'unknown') . ' pagesize=' . ($this->pagesize ?? 'n/a'));
// call parent
parent::finish_html();
}

}
/**
Expand Down
Loading
Loading