This repository has been archived by the owner on May 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache-and-show-rubrics.js.php
64 lines (59 loc) · 2.06 KB
/
cache-and-show-rubrics.js.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
require_once __DIR__ . '/common.inc.php';
?>
var canvashack = {
cacheRubric: function(url) {
"use strict";
var http = new XMLHttpRequest();
var rubrics = document.getElementById('rubrics');
var assignment = document.location.href;
var params =
'assignment=' + encodeURIComponent(assignment) + '&' +
'rubrics=' + encodeURIComponent(rubrics.outerHTML);
http.open('POST', url, true);
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {
if (http.readyState === 4 && http.status === 200) {
if (http.responseText == 'success') {
alert('Your rubric has been cached.');
} else {
alert('There was a problem caching your rubric.');
}
}
};
http.send(params);
},
showRubric: function(url) {
"use strict";
var assignment = document.location.href;
if (!/.*\/courses\/\d+\/assignments\/\d+$/.test(assignment)) {
return;
}
function displayCache() {
if (http.readyState === 4 && http.status === 200 && http.responseText.length > 0) {
var rubrics = document.createElement('div');
/*
* assumes we only want to append cached rubrics to
* assignments that are turned in via LTI tool (since those
* are the assignments where you can't already see the
* rubric)
*/
var tool = $('.tool_content_wrapper')[0];
if (tool !== undefined) {
tool.parentNode.insertBefore(rubrics, tool);
rubrics.outerHTML = http.responseText;
rubrics.style.display = 'block';
}
}
}
var url = '<?= $pluginMetadata['PLUGIN_URL'] ?>/show-rubrics.php';
var http = new XMLHttpRequest();
var params = 'assignment=' + encodeURIComponent(assignment);
http.open('POST', url);
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
http.addEventListener('load', displayCache);
http.send(params);
}
};