Browse Source

auto-pretty javascript files

master
Jan Koppe 11 months ago
parent
commit
fe31939806
Signed by: j <post@jankoppe.de> GPG Key ID: BE935B0735A2129B
4 changed files with 5009 additions and 4192 deletions
  1. +4932
    -4114
      shared/index.js
  2. +27
    -28
      shared/locallib.js
  3. +46
    -46
      shared/overview.js
  4. +4
    -4
      shared/statistic.js

+ 4932
- 4114
shared/index.js
File diff suppressed because it is too large
View File


+ 27
- 28
shared/locallib.js View File

@@ -2,7 +2,7 @@
* @package mod_pdfannotator
* @copyright 2018 RWTH Aachen, Rabea de Groot and Ahmad Obeid (see README.md)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*
*/

function addDropdownNavigation(Y, __capabilities, __cmid) {
@@ -10,12 +10,12 @@ function addDropdownNavigation(Y, __capabilities, __cmid) {
// Select the general overview tab.
let tabs = document.getElementsByClassName('nav-link');
var overviewtab;
for (var tab in tabs){
if(tabs[tab].innerHTML === M.util.get_string('overview', 'pdfannotator')){
for (var tab in tabs) {
if (tabs[tab].innerHTML === M.util.get_string('overview', 'pdfannotator')) {
overviewtab = tabs[tab];
break;
}
}
}
overviewtab.classList.add('mydropbtn');

// Create a dropdown navigation menu.
@@ -46,11 +46,11 @@ function addDropdownNavigation(Y, __capabilities, __cmid) {
}
if (__capabilities.viewreports) {
var nav4 = document.createElement('a');
var img4 = "<div><span class='media-left'><i class='icon fa fa-flag fa-fw'></i></span> "; //"<div><span class='media-left'><img src='" + M.util.image_url('flagged', 'pdfannotator') + "'></span> ";
var img4 = "<div><span class='media-left'><i class='icon fa fa-flag fa-fw'></i></span> "; // "<div><span class='media-left'><img src='" + M.util.image_url('flagged', 'pdfannotator') + "'></span> ";
nav4.href = 'view.php?action=overviewreports&id=' + __cmid;
nav4.innerHTML = img4 + "<span class='media-body'>" + M.util.get_string('reportstab', 'pdfannotator') + "</span>";
dropdown.appendChild(nav4);
var nav5 = document.createElement('a');
var img5 = "<div><span class='media-left'><i class='icon fa fa-archive fa-fw'></i></span> ";
nav5.href = 'view.php?action=overviewrecyclebin&id=' + __cmid;
@@ -59,41 +59,40 @@ function addDropdownNavigation(Y, __capabilities, __cmid) {
}

overviewtab.parentNode.append(dropdown);
// Add an event listener (for opening the dropdown) to the overview tab.
let mouseOverDropdownContent = false;
// Hover on overview-tab => show dropdown
overviewtab.addEventListener("mouseover", function(){
if(!dropdown.classList.contains('show')){
overviewtab.addEventListener("mouseover", function() {
if (!dropdown.classList.contains('show')) {
dropdown.classList.add('show');
}
}
});
// Leaving overview-tab => hide dropdown. But not if hover on dropdown!
overviewtab.addEventListener("mouseleave", function(){
setTimeout(function(){
if(!mouseOverDropdownContent) {
overviewtab.addEventListener("mouseleave", function() {
setTimeout(function() {
if (!mouseOverDropdownContent) {
$('#pdfannotator_dropdownnav').removeClass('show');
}
},0);
}, 0);
});
$('#pdfannotator_dropdownnav').mouseenter(function(){
mouseOverDropdownContent=true;
$('#pdfannotator_dropdownnav').mouseenter(function() {
mouseOverDropdownContent = true;
});
$('#pdfannotator_dropdownnav').mouseleave(function(){
$('#pdfannotator_dropdownnav').mouseleave(function() {
$('#pdfannotator_dropdownnav').removeClass('show');
mouseOverDropdownContent=false;
mouseOverDropdownContent = false;
});

}

}


function renderMathJax() {
var counter = 0;
let mathjax = function () {
let mathjax = function() {
if (typeof (MathJax) !== "undefined") {
MathJax.Hub.Queue(['Typeset', MathJax.Hub]);
} else if (counter < 30) {
@@ -123,11 +122,11 @@ function fixCommentForm() {

fixForm(top, fixedTop, oldWidth);

$(window).scroll(function (event) {
$(window).scroll(function(event) {
fixForm(top, fixedTop, oldWidth);
});

$(window).resize(function (event) {
$(window).resize(function(event) {
// Adjust width if form is fixed.
if ($('#comment-list-form').hasClass('fixtool')) {
$('#comment-list-form').removeClass('fixtool');
@@ -164,8 +163,8 @@ function closeComment() {
var oldHeight = -1;
function makeFullScreen() {
document.querySelector('body').classList.toggle('fullscreenWrapper');
//if it is now in fullscreen, the image should be the collapse fullscreen image
//else it should be the fullscreen image
// If it is now in fullscreen, the image should be the collapse fullscreen image
// else it should be the fullscreen image
if (document.querySelector('body').classList.contains('fullscreenWrapper')) {
oldHeight = document.querySelector('#body-wrapper').style.height;
let img = document.querySelector('img[title="' + M.util.get_string('fullscreen', 'pdfannotator') + '"]');
@@ -184,4 +183,4 @@ function makeFullScreen() {
document.querySelector('#body-wrapper').style.height = oldHeight;
}
}
;

+ 46
- 46
shared/overview.js View File

@@ -16,9 +16,9 @@
*/
function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper function that is called by teacher-/studentview controller.

require(['jquery', 'core/templates', 'core/notification'], function ($, templates, notification) {
require(['jquery', 'core/templates', 'core/notification'], function($, templates, notification) {

/************************** 1. Call initialising functions **************************/
/** ************************ 1. Call initialising functions **************************/

styleTableReset();
addDropdownNavigation(null, __capabilities, __cmid);
@@ -30,15 +30,15 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
addEventListenerForHidingAnswers();
addEventListenerForDisplayingAnswers();
addEventListenerForUnsubscribing();
shortenTextOverview();
renderMathJax();

/************************** 2. Function definitions **************************/
/** ************************ 2. Function definitions **************************/

/**
* Function reduces the extra white space for the 'reset table' option added after table sort
*
*
* @returns {undefined}
*/
function styleTableReset() {
@@ -49,9 +49,9 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
}
}

/**This function adds a select option for choosing the number of tablerows to be displayed
/** This function adds a select option for choosing the number of tablerows to be displayed
* per page.
*
*
* @returns {undefined}
*/
function letUserSelectNumberOfItemsPerPage() {
@@ -59,11 +59,11 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
// 1. Create a selection element.
var itemsPerPage = document.createElement("SELECT");
itemsPerPage.setAttribute("id", "itemsPerPage");
let option0 = document.createElement("OPTION");
option0.value = 5;
option0.text = 5;
let option1 = document.createElement("OPTION");
option1.value = 10;
option1.text = 10;
@@ -80,7 +80,7 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
if (endpos === null || endpos == -1) {
endpos = query.length;
}
let pastchoice = query.slice(pos+14, endpos);
let pastchoice = query.slice(pos + 14, endpos);
if (pastchoice === '5') {
option0.selected = true;
} else if (pastchoice === '10') {
@@ -128,7 +128,7 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
var oldpath = window.location.pathname + window.location.search;
var newurl = '';
if (oldpath.includes('itemsperpage')) {
let activepage = document.getElementsByClassName("page-item active");
if (activepage !== null && activepage.nextSibling == null && select.value == 10) {
let pos2 = query.indexOf('&page=');
@@ -136,7 +136,7 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
} else {
newurl = window.location.pathname + query.slice(0, pos) + '&itemsperpage=' + select.value;
}
} else {
newurl = oldpath + '&itemsperpage=' + select.value;
}
@@ -152,11 +152,11 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
function addEventListenerForHidingReports() {

var hide = document.getElementsByClassName("report-recycle");
for (i = 0; i < hide.length; i++) {
(function (innerI) {
hide[innerI].addEventListener("click", function () {
(function(innerI) {
hide[innerI].addEventListener("click", function() {
var annotatorid = this.getAttribute("data-annotator");
var openannotator = __annotatorid;

@@ -164,7 +164,7 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
type: "POST",
url: "action.php",
data: {"documentId": annotatorid, "reportid": this.id, "openannotator": openannotator, "action": 'markReportAsSeen', sesskey: M.cfg.sesskey}
}).then(function (data) {
}).then(function(data) {
console.log('data: ', data);
data = JSON.parse(data);

@@ -191,9 +191,9 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
});
console.error(M.util.get_string('error:hide', 'pdfannotator'));
} else {
}
setTimeout(function () {
setTimeout(function() {
let notificationpanel = document.getElementById("user-notifications");
while (notificationpanel.hasChildNodes()) {
notificationpanel.removeChild(notificationpanel.firstChild);
@@ -214,10 +214,10 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
function addEventListenerForHidingAnswers() {

var hide = document.getElementsByClassName("comment-recycle");
for (i = 0; i < hide.length; i++) {
(function (innerI) {
hide[innerI].addEventListener("click", function () {
(function(innerI) {
hide[innerI].addEventListener("click", function() {
var annotatorid = this.getAttribute("data-annotator");
var openannotator = __annotatorid;
var answerid = hide[innerI].id;
@@ -226,7 +226,7 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
type: "POST",
url: "action.php",
data: {"documentId": annotatorid, "answerid": answerid, "openannotator": openannotator, "action": 'markAnswerAsSeen', sesskey: M.cfg.sesskey}
}).then(function (data) {
}).then(function(data) {

data = JSON.parse(data);

@@ -263,7 +263,7 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
});
console.error(M.util.get_string('error:putinrecyclebin', 'pdfannotator'));
}
setTimeout(function () {
setTimeout(function() {
let notificationpanel = document.getElementById("user-notifications");
while (notificationpanel.hasChildNodes()) {
notificationpanel.removeChild(notificationpanel.firstChild);
@@ -286,8 +286,8 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
var hide = document.getElementsByClassName("report-redisplay");

for (i = 0; i < hide.length; i++) {
(function (innerI) {
hide[innerI].addEventListener("click", function () {
(function(innerI) {
hide[innerI].addEventListener("click", function() {
var button = this;
var annotatorid = button.getAttribute("data-annotator");
var openannotator = __annotatorid;
@@ -297,7 +297,7 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
type: "POST",
url: "action.php",
data: {"documentId": annotatorid, "reportid": reportid, "openannotator": openannotator, "action": 'markReportAsUnseen', sesskey: M.cfg.sesskey}
}).then(function (data) {
}).then(function(data) {

data = JSON.parse(data);

@@ -322,7 +322,7 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
});
console.error(M.util.get_string('error:show', 'pdfannotator'));
}
setTimeout(function () {
setTimeout(function() {
let notificationpanel = document.getElementById("user-notifications");
while (notificationpanel.hasChildNodes()) {
notificationpanel.removeChild(notificationpanel.firstChild);
@@ -345,9 +345,9 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
var hidden = document.getElementsByClassName("comment-redisplay");

for (i = 0; i < hidden.length; i++) {
(function (innerI) {
hidden[innerI].addEventListener("click", function () {
(function(innerI) {
hidden[innerI].addEventListener("click", function() {
var button = this;
var answerid = (button.id).slice(7);
var annotatorid = button.getAttribute("data-annotator");
@@ -357,7 +357,7 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
type: "POST",
url: "action.php",
data: {"documentId": annotatorid, "answerid": answerid, "openannotator": openannotator, "action": 'markAnswerAsUnseen', sesskey: M.cfg.sesskey}
}).then(function (data) {
}).then(function(data) {

data = JSON.parse(data);

@@ -394,7 +394,7 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
});
console.error(M.util.get_string('error:show', 'pdfannotator'));
}
setTimeout(function () {
setTimeout(function() {
let notificationpanel = document.getElementById("user-notifications");
while (notificationpanel.hasChildNodes()) {
notificationpanel.removeChild(notificationpanel.firstChild);
@@ -417,23 +417,23 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
var unsubscribeButtons = document.getElementsByClassName("comment-subscribe");

for (i = 0; i < unsubscribeButtons.length; i++) {
(function (innerI) {
unsubscribeButtons[innerI].addEventListener("click", function () {
(function(innerI) {
unsubscribeButtons[innerI].addEventListener("click", function() {
var annotationid = unsubscribeButtons[innerI].id;
annotationid = annotationid.slice(11);
return $.ajax({
type: "POST",
url: "action.php",
data: {"documentId": __annotatorid, "annotationid": annotationid, "action": 'unsubscribeQuestion', sesskey: M.cfg.sesskey} // documentID is a dummy passed on pro forma.
}).then(function (data) {
data: {"documentId": __annotatorid, "annotationid": annotationid, "action": 'unsubscribeQuestion', sesskey: M.cfg.sesskey} // DocumentID is a dummy passed on pro forma.
}).then(function(data) {
data = JSON.parse(data);

if (data.status === "success") {
// 1. Hide answers to the question unsubscribed (There will be at least 1).
let items = document.getElementsByClassName(data.annotationid);
for (let i = 0; i < items.length; i++) {
(function (innerI) {
(function(innerI) {
items[innerI].parentNode.parentNode.style.setProperty('display', 'none', 'important');
})(i);
}
@@ -450,7 +450,7 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
});
console.error(M.util.get_string('error:unsubscribe', 'pdfannotator'));
}
setTimeout(function () {
setTimeout(function() {
let notificationpanel = document.getElementById("user-notifications");
while (notificationpanel.hasChildNodes()) {
notificationpanel.removeChild(notificationpanel.firstChild);
@@ -494,12 +494,12 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
* @returns {undefined}
*/
function shortenTextOverview() {
require(['jquery'], function ($) {
require(['jquery'], function($) {
var showChar = 120;
var ellipsestext = "...";
var moretext = M.util.get_string('showmore', 'pdfannotator');
var lesstext = M.util.get_string('showless', 'pdfannotator');
$('.more').each(function () {
$('.more').each(function() {
var content = this.innerText;
var widthParent = $(this).parent()[0].offsetWidth;
if (widthParent === 0) {
@@ -534,7 +534,7 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
i3 = -1;
}
if (i3 > -1 && i3 < showChar) {
x = content.indexOf('$$', i3 + 1) + 4
x = content.indexOf('$$', i3 + 1) + 4;
showChar = Math.max(showChar, x);
}
if (showChar === content.length) {
@@ -551,7 +551,7 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu

});

$(".morelink").click(function () {
$(".morelink").click(function() {
if ($(this).hasClass("less")) {
$(this).removeClass("less");
$(this).html(moretext);
@@ -568,7 +568,7 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu

function renderMathJax() {
var counter = 0;
let mathjax = function () {
let mathjax = function() {
if (typeof (MathJax) !== "undefined") {
MathJax.Hub.Queue(['Typeset', MathJax.Hub]);
} else if (counter < 10) {
@@ -579,5 +579,5 @@ function startOverview(Y, __annotatorid, __cmid, __capabilities) { // Wrapper fu
};
mathjax();
}
}

+ 4
- 4
shared/statistic.js View File

@@ -4,7 +4,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

//R: The first parameter has to be Y, because it is a default YUI-object (demanded by moodle)
// R: The first parameter has to be Y, because it is a default YUI-object (demanded by moodle)
function setCharts(Y, names, otherquestions, myquestions, otheranswers, myanswers) {
Highcharts.setOptions({
colors: ['rgb(0,84,159)', 'rgb(142,186,229)', 'rgb(87,171,39)', 'rgb(184,214,152)']
@@ -36,12 +36,12 @@ function setCharts(Y, names, otherquestions, myquestions, otheranswers, myanswer
},
tooltip: {
headerFormat: '<b>{point.key}</b><br/>',
pointFormat: '{series.name}: {point.y}<br/>'+M.util.get_string('total', 'pdfannotator')+': {point.stackTotal}'
pointFormat: '{series.name}: {point.y}<br/>' + M.util.get_string('total', 'pdfannotator') + ': {point.stackTotal}'
},
legend: {
// reversed: true,
// Reversed: true,
itemWidth: 225
// layout: 'vertical'
// Layout: 'vertical'
},
series: [{
name: M.util.get_string('myquestions', 'pdfannotator'),


Loading…
Cancel
Save