blob: b5fa13609806fecdbe4ef76dcfc92fcbfaaa3aa4 [file] [log] [blame]
j1c53f822020-06-07 15:32:06 -07001<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <title>JSDoc: Source: core.js</title>
6
7 <script src="scripts/prettify/prettify.js"> </script>
8 <script src="scripts/prettify/lang-css.js"> </script>
9 <!--[if lt IE 9]>
10 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11 <![endif]-->
12 <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13 <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
14</head>
15
16<body>
17
18<div id="main">
19
20 <h1 class="page-title">Source: core.js</h1>
21
22
23
24
25
26
27 <section>
28 <article>
29 <pre class="prettyprint source linenums"><code>/**
30 * @file DTPS Core functions and module loader
31 * @author jottocraft
32 * @version v2.9.1
33 *
34 * @copyright Copyright (c) 2018-2020 jottocraft. All rights reserved.
35 * @license GPL-2.0-only
36 */
37
38//Make sure DTPS isn't already loading
39if (typeof dtps !== "undefined") throw "Error: DTPS is already loading";
40
41/**
42 * Global DTPS object
43 * All global DTPS functions and variables are stored in this object
44 *
45 * @global
46 * @namespace dtps
47 * @property {number} ver Comparable version number
48 * @property {string} readableVer Formatted semantic version number
49 * @property {Class[]} classes DTPS classes array
50 * @property {string} baseURL The base URL that DTPS is being loaded from
51 * @property {boolean} unstable This is true if loading an unstable version of DTPS
52 * @property {string|undefined} popup Popup to show when loaded. Either undefined (no popup), "firstrun", or "changelog".
53 * @property {User} user Current user, fetched with dtps.init
54 * @property {number|string} selectedClass The selected class number, or "dash" if the dashboard is selected. Set when the first screen is loaded in dtps.init.
55 * @property {string} selectedContent The selected class content/tab. Set when the first class content is loaded. Defaults to "stream".
56 * @property {number|undefined} bgTimeout Background transition timeout when switching between classes
57 * @property {DashboardItem[]} dashboardItems Array of items that can be shown on the dashboard
58 * @property {DashboardItem[]} leftDashboard Items on the left side of the dashboard based on dtps.dashboardItems and user prefrences. Set in dtps.loadDashboardPrefs.
59 * @property {DashboardItem[]} rightDashboard Items on the right side of the dashboard based on dtps.dashboardItems and user prefrences. Set in dtps.loadDashboardPrefs.
60 */
61var dtps = {
62 ver: 291,
63 readableVer: "v2.9.1 (beta)",
64 classes: [],
65 baseURL: document.currentScript.src.split('/')[0] + '//' + document.currentScript.src.split('/')[2],
66 unstable: true || window.localStorage.dtpsLoaderPref == "canary" || window.localStorage.dtpsLoaderPref == "debugging" || String(document.currentScript.src).includes("http://localhost"),
67 dashboardItems: [
68 {
69 name: "Calendar",
70 id: "dtps.calendar",
71 icon: "event",
72 supportsCompactMode: false,
73 size: 100,
74 defaultSide: "left"
75 }, {
76 name: "Updates [NYI]",
77 id: "dtps.updates",
78 icon: "construction",
79 supportsCompactMode: true,
80 size: 80,
81 defaultSide: "left"
82 }, {
83 name: "Due Today",
84 id: "dtps.dueToday",
85 icon: "check_circle_outline",
86 size: 20,
87 defaultSide: "right"
88 }, {
89 name: "Upcoming Assignments",
90 id: "dtps.upcoming",
91 icon: "view_stream",
92 supportsCompactMode: true,
93 size: 250,
94 defaultSide: "right"
95 }
96 ]
97};
98
99//Load jQuery ASAP
100jQuery.getScript("https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js");
101
102//Fluid UI theme listener (for changing background color)
103document.addEventListener("fluidTheme", function (data) {
104 if (dtps.oldTheme !== data.detail) {
105 //Theme has changed
106 dtps.oldTheme = data.detail;
107
108 //Update background gradient
109 var next = window.getComputedStyle(document.getElementsByClassName("background")[0]).getPropertyValue("--grad")
110 if (dtps.selectedClass !== "dash") next = "linear-gradient(to bottom right, " + (dtps.classes[dtps.selectedClass] &amp;&amp; dtps.classes[dtps.selectedClass].color) + ", var(--background))"
111 if (dtps.selectedClass !== "dash") $('body').removeClass('dashboard');
112 $(".background").css("background", next);
113
114 //Re-run chroma
115 dtps.chroma();
116 }
117});
118
119/**
120 * Debugging shortcut for getting the selected class. This should only be used in the web inspector and not in actual code.
121 *
122 * @return {object|undefined} The selected class
123 */
124dtps.class = function () {
125 return dtps.classes[dtps.selectedClass]
126}
127
128/**
129 * Checks if a Date is today
130 *
131 * @param {Date} date Date string to check
132 */
133dtps.isToday = function(date) {
134 var today = new Date();
135 var d1 = new Date(date);
136
137 return d1.getFullYear() === today.getFullYear() &amp;&amp;
138 d1.getMonth() === today.getMonth() &amp;&amp;
139 d1.getDate() === today.getDate();
140}
141
142/**
143 * Fetches and displays the DTPS changelog modal
144 *
145 * @param onlyIfNewVersion True if the changelog should only show if this is a new version
146 */
147dtps.changelog = function (onlyIfNewVersion) {
148 //Fetch latest changelog from GitHub releases
149 jQuery.getScript("https://cdnjs.cloudflare.com/ajax/libs/showdown/1.8.6/showdown.min.js", function () {
150 markdown = new showdown.Converter();
151 jQuery.getJSON("https://api.github.com/repos/jottocraft/dtps/releases/latest", function (data) {
152 //Convert changelog to HTML and render in the changelog card
153 var changelogHTML = markdown.makeHtml(data.body);
154 jQuery(".card.changelog").html(`&lt;i onclick="fluid.cards.close('.card.changelog')" class="material-icons close">close&lt;/i>` + changelogHTML);
155
156 if (!onlyIfNewVersion) {
157 //Show changelog
158 fluid.cards.close(".card.focus");
159 fluid.cards(".card.changelog");
160 } else if (Number(data.tag_name.replace(/[^0-9]/g, '')) > Number(window.localStorage.dtps)) {
161 //Show changelog if this is a new(er) version
162 localStorage.setItem('dtps', data.tag_name.replace(/[^0-9]/g, ''));
163
164 if (!data.tag_name.includes("s")) {
165 //s in tag_name means a silent release
166 fluid.cards.close(".card.focus");
167 fluid.cards(".card.changelog");
168 }
169 }
170 });
171 });
172};
173
174/**
175 * Logs debugging messages
176 *
177 * @param {string} msg The debugging message to log
178 */
179dtps.log = function (msg) {
180 console.debug("[DTPS] ", msg);
181}
182
183
184/**
185 * Shows an error message alert and logs to console
186 *
187 * @param {string} msg The error to display
188 * @param {string} [devNotes] Technical error details displayed in a smaller font
189 * @param {Error} [err] An error object to log to the console
190 */
191dtps.error = function (msg, devNotes, err) {
192 var formattedDevNotes = "";
193 if (devNotes) {
194 formattedDevNotes = '&lt;div style="font-size: 12px; color: var(--secText, gray); margin-top: 10px;">' + devNotes + '&lt;/div>';
195 }
196 fluid.alert("Error", msg + formattedDevNotes, "error");
197 console.error("[DTPS !!ERROR!!]", devNotes + ": ", err);
198}
199
200/**
201 * Renders "Welcome to Project DTPS" screen on the first run
202 */
203dtps.firstrun = function () {
204 //Set latest changelog version to current version
205 window.localStorage.setItem('dtps', dtps.ver);
206
207 //Welcome to Power+ screen HTML
208 jQuery(".card.changelog").html(/*html*/`
209 &lt;h3 style="margin-bottom: 0px;">Welcome to Power+&lt;/h3>
210 &lt;h5 style="color: var(--secText); font-weight: bold; font-size: 22px;">${dtps.readableVer}&lt;/h5>
211
212 &lt;div class="welcomeSection">
213 &lt;i class="material-icons">dashboard&lt;/i>
214 &lt;h5>${dtpsLMS.gradebook ? "Manage your coursework and grades" : "Manage your coursework"}&lt;/h5>
215 &lt;p>Power+ organizes all of your coursework so you can easily see what you need to do next. The dashboard shows upcoming assignments, recent grades, and announcements.
216 ${dtpsLMS.gradebook ? `Power+ includes a gradebook designed for ${dtpsLMS.name} to help you understand your grades.` : ``}&lt;/p>
217 &lt;/div>
218
219 &lt;div class="welcomeSection">
220 &lt;i class="material-icons">security&lt;/i>
221 &lt;h5>Privacy&lt;/h5>
222 &lt;p>Power+ does not collect any information. All of the data used in Power+ is fetched directly from ${dtpsLMS.shortName} and is never sent anywhere else.
223 User preferences, grade history, and other Power+ data is stored locally on your computer and is not associated with your ${dtpsLMS.shortName} account.&lt;/p>
224 &lt;/div>
225
226 &lt;div class="welcomeSection">
227 &lt;i class="material-icons">error_outline&lt;/i>
228 &lt;h5>Power+ is not official&lt;/h5>
229 &lt;p>Assignment information, grades, and other content displayed in Power+ are not official. Power+ is neither created nor endorsed by ${dtpsLMS.legalName}.
230 Power+ may have bugs that could cause it to display inaccurate information. Use Power+ at your own risk.&lt;/p>
231 &lt;/div>
232
233 &lt;br />
234 &lt;div onclick="window.localStorage.setItem('dtpsInstalled', 'true'); fluid.cards.close('.card.changelog');" class="btn">
235 &lt;i class="material-icons">arrow_forward&lt;/i> Continue
236 &lt;/div>
237 `);
238
239 //Show Welcome to Power+ card
240 fluid.cards.close(".card.focus");
241 fluid.cards(".card.changelog", "stayOpen");
242};
243
244/**
245 * Renders the Power+ loading screen
246 */
247dtps.renderLoadingScreen = function () {
248 if (!window.dtpsPreLoader) {
249 //Only show the loader if the extension hasn't already shown it
250 jQuery("body").append(/*html*/`
251 &lt;div id="dtpsNativeOverlay" style="position: fixed; top: 0px; left: 0px; width: 100vw; height: 100vh; z-index: 999; background: #191919; text-align: center; z-index: 999; transition: opacity 0.2s;">
252 &amp;nbsp;
253 &lt;img style="height: 100px; margin-top: 132px;" src="https://i.imgur.com/eiTE2sW.png" />
254 &lt;div class="spinner" style="margin-top: 300px;">&lt;/div>
255 &lt;style>body { overflow: hidden !important; } .spinner { width: 40px; height: 40px; margin: 40px auto; background-color: gray; border-radius: 100%; -webkit-animation: sk-scaleout 1.0s infinite ease-in-out; animation: sk-scaleout 1.0s infinite ease-in-out; } @-webkit-keyframes sk-scaleout { 0% { -webkit-transform: scale(0) } 100% { -webkit-transform: scale(1.0); opacity: 0; } } @keyframes sk-scaleout { 0% { -webkit-transform: scale(0); transform: scale(0); } 100% { -webkit-transform: scale(1.0); transform: scale(1.0); opacity: 0; } }&lt;/style>
256 &lt;/div>
257 `);
258 }
259}
260
261/**
262 * Load all external JavaScript libraries
263 *
264 * @param {function} cb Callback function
265 */
266dtps.JS = function (cb) {
267 //Moment &amp; Fullcalendar are used for the calendar on the dashboard
268 jQuery.getScript("https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js", function () {
269 jQuery.getScript("https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.9.0/fullcalendar.min.js")
270 });
271
272 //Fuse.js is used for search
273 jQuery.getScript('https://cdnjs.cloudflare.com/ajax/libs/fuse.js/3.3.0/fuse.min.js');
274
275 //jQuery UI for dashboard settings page
276 jQuery.getScript('https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js');
277
278 //Tinycolor used for Fluid UI acrylic &amp; color manipulation
279 jQuery.getScript("https://cdn.jottocraft.com/tinycolor.js", () => {
280 //dtao/nearest-color is used for finding the nearest class color
281 jQuery.getScript("https://cdn.jottocraft.com/nearest-color.dtao.js", () => {
282 //Fluid UI for core UI elements
283 jQuery.getScript('https://cdn.jottocraft.com/fluid/v4.min.js', cb);
284 })
285 });
286}
287
288/**
289 * Load all DTPS CSS files
290 */
291dtps.CSS = function () {
292 jQuery("&lt;link/>", {
293 rel: "stylesheet",
294 type: "text/css",
295 href: "https://cdn.jottocraft.com/fluid/v4.min.css",
296 class: "dtpsHeadItem"
297 }).appendTo("head");
298
299 jQuery("&lt;link/>", {
300 rel: "stylesheet",
301 type: "text/css",
302 href: dtps.baseURL + "/dtps.css",
303 class: "dtpsHeadItem"
304 }).appendTo("head");
305
306 jQuery("&lt;link/>", {
307 rel: "stylesheet",
308 type: "text/css",
309 href: "https://fonts.googleapis.com/css?family=Material+Icons+Outlined",
310 class: "dtpsHeadItem"
311 }).appendTo("head");
312
313 jQuery("&lt;link/>", {
314 rel: "stylesheet",
315 type: "text/css",
316 href: "https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.9.0/fullcalendar.min.css",
317 class: "dtpsHeadItem"
318 }).appendTo("head");
319
320 jQuery("&lt;link/>", {
321 rel: "stylesheet",
322 type: "text/css",
323 href: "https://fonts.googleapis.com/icon?family=Material+Icons+Extended",
324 class: "dtpsHeadItem"
325 }).appendTo("head");
326
327 jQuery("&lt;link/>", {
328 rel: "stylesheet",
329 type: "text/css",
330 href: "https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css",
331 class: "dtpsHeadItem"
332 }).appendTo("head");
333}
334
335/**
336 * Starts DTPS (entrypoint function)
337 */
338dtps.init = function () {
339 //Initial log
340 dtps.log("Starting DTPS " + dtps.readableVer + "...");
341
342 //Check for LMS config
343 if (!window.dtpsLMS) {
344 throw "Error: No DTPS LMS configuration found";
345 }
346
347 //Determine if changelog should be shown
348 if (Number(window.localStorage.dtps) &lt; dtps.ver) {
349 dtps.log("New release");
350 dtps.popup = "changelog";
351 }
352
353 //Determine if this is the first time loading DTPS
354 if (window.localStorage.dtpsInstalled !== "true") {
355 dtps.popup = "firstrun";
356 }
357
358 //Render loading screen
359 dtps.renderLoadingScreen();
360
361 //Fluid UI settings
362 fluidThemes = [["midnight", "tome"], ["rainbow"]];
363 fluidAutoLoad = false;
364
365 //Default selected content
366 dtps.selectedContent = "stream";
367
368 //Begin loading CSS
369 dtps.CSS();
370
371 //Begin loading static DTPS HTML
372 dtps.render();
373
374 //Fetch user and class data
375 dtpsLMS.fetchUser().then(data => {
376 dtps.user = data;
377
378 return dtpsLMS.fetchClasses();
379 }).then((rawClasses) => {
380 return new Promise(resolve => {
381 if (dtpsLMS.institutionSpecific &amp;&amp; dtpsLMS.updateClasses) {
382 //Using an institution-specific script, make any nessasary changes and return updated classes
383 var updatedClasses = dtpsLMS.updateClasses(rawClasses);
384
385 resolve(updatedClasses);
386 } else {
387 //No institution-specific script, return classes as-is
388 resolve(rawClasses);
389 }
390 });
391 }).then(classData => {
392 //Store classData to dtps.classes
393 dtps.classes = classData;
394
395 //Fetch JavaScript modules
396 dtps.JS(() => {
397 //Define DTPS class color pallete
398 var nearestCourseColor = nearestColor.from({
399 //Primary color shades
400 red: "#cc4747",
401 brown: "#9a4429",
402 orange: "#ce734e",
403 pumpkin: "#c58535",
404 yellow: "#b58f38",
405 yellowGreen: "#7c9630",
406 green: "#439a47",
407 oceanGreen: "#339a70",
408 keppel: "#40b5c3",
409 skyBlue: "#40a4d6",
410 blue: "#2d72a0",
411 purple: "#985cab",
412 magenta: "#bd3e69",
413 pink: "#ec7ca5",
414 gray: "#888888",
415 //Dark color shades
416 gold: "#94652a",
417 darkRed: "#943f3f",
418 darkBlue: "#485182",
419 darkPurple: "#6f4882",
420 darkGreen: "#3d7358",
421 //Light color shades
422 lightOrange: "#ea7a44",
423 lightRed: "#e07f7f",
424 lightBlue: "#76c1e6",
425 lightPurple: "#978fd6",
426 lightGreen: "#7ebb95",
427 lightBrown: "#928871"
428 });
429
430 //Loop over each class to update the color and check for grade calculation
431 dtps.classes.forEach(course => {
432 course.color = course.color ? nearestCourseColor(course.color).value : "gray";
433
434 if (dtpsLMS.calculateGrade) {
435 //This LMS/Institution supports grade calculation, show loading indicator for grade
436 //Grade will be calculated once assignments are fetched
437
438 course.letter = "..."; //Setting this to ... shows the loading indicator
439 course.grade = undefined;
440 }
441 });
442
443 //Fluid UI screens
444 fluid.defaultScreen = "dashboard";
445 fluid.screens.dashboard = dtps.baseURL + "/scripts/assignments.js";
446 fluid.screens.stream = dtps.baseURL + "/scripts/assignments.js";
447 fluid.screens.modules = dtps.baseURL + "/scripts/assignments.js";
448 fluid.screens.pages = dtps.baseURL + "/scripts/pages-discussions.js";
449 fluid.screens.discussions = dtps.baseURL + "/scripts/pages-discussions.js";
450
451 if (dtpsLMS.gradebook) {
452 //Handle LMS gradebook
453 fluid.screens.gradebook = dtps.showLMSGradebook;
454 } else if (dtpsLMS.genericGradebook) {
455 //Generic gradebook script
456 fluid.screens.gradebook = dtps.baseURL + "/scripts/generic-gradebook.js";
457 }
458
459 //Begin fetching class assignments
460 dtps.classes.forEach((course, courseIndex) => {
461 dtpsLMS.fetchAssignments(course.id).then((rawAssignments) => {
462 return new Promise(resolve => {
463 if (dtpsLMS.institutionSpecific &amp;&amp; dtpsLMS.updateAssignments) {
464 //Using an institution-specific script, make any nessasary changes and return updated assignments
465 var updatedAssignments = dtpsLMS.updateAssignments(rawAssignments);
466
467 resolve(updatedAssignments);
468 } else {
469 //No institution-specific script, return assignments as-is
470 resolve(rawAssignments);
471 }
472 });
473 }).then(assignments => {
474 //Store assignments in the class
475 course.assignments = assignments;
476
477 //Add class props to assignments
478 course.assignments.forEach(assignment => {
479 assignment.class = courseIndex;
480 });
481
482 //Calculate class grade if supported
483 if (dtpsLMS.calculateGrade) {
484 let gradeCalcResults = dtpsLMS.calculateGrade(course, assignments);
485
486 if (gradeCalcResults) {
487 //This class has a grade
488
489 //Set course letter and grade to grade calc results
490 course.letter = gradeCalcResults.letter;
491 course.grade = gradeCalcResults.grade;
492
493 //Save raw results object to the course so it can be accessed by the gradebook
494 course.gradeCalculation = gradeCalcResults;
495 } else {
496 //No grade for this class
497 course.letter = null;
498 course.grade = null;
499 }
500
501 //Force re-render sidebar to show grades only if the user isn't on pages or discussions
502 if ((dtps.selectedContent !== "pages") &amp;&amp; (dtps.selectedContent !== "discuss")) {
503 dtps.showClasses(true);
504 }
505 }
506
507 //Grade history and gradebook
508 if (course.letter &amp;&amp; (course.letter !== "...")) {
509 //Enable gradebook for this class
510 course.hasGradebook = true;
511
512 //Save grade history
513 dtps.logGrades(courseIndex);
514
515 //If the class is selected, call dtps.presentClass again to show the grades tab
516 if (courseIndex == dtps.selectedClass) {
517 dtps.presentClass(courseIndex);
518
519 //If the gradebook is selected, reload the gradebook
520 if (dtps.selectedContent == "grades") {
521 fluid.screen('gradebook', dtps.classes[courseIndex].id);
522 }
523 }
524 } else {
525 //This class doesn't have a gradebook, exit gradebook if selected
526 if ((courseIndex == dtps.selectedClass) &amp;&amp; (dtps.selectedContent == "grades")) {
527 fluid.screen('stream', dtps.classes[courseIndex].id);
528 }
529 }
530
531 //Re-render screen if the dashboard or stream is selected
532 if ((dtps.selectedClass == "dash") || (dtps.selectedContent == "stream")) {
533 fluid.screen();
534 }
535 });
536 });
537
538 //Render remaining HTML
539 dtps.renderLite();
540
541 //Render initial screen
542 fluid.screen();
543
544 //Load popup if needed
545 if (dtps.popup == "firstrun") {
546 dtps.firstrun();
547 } else if (dtps.popup == "changelog") {
548 //Changelog will only show if the release notes are on GitHub
549 dtps.changelog(true);
550 }
551 });
552 }).catch(function (err) {
553 //Web request error
554 console.error("[DTPS] Error fetching user and classes at dtps.init", err);
555
556 //404 Error means the user isn't logged in
557 if (err.status == 404) {
558 //Redirect to login page
559 window.location.href = "/?dtpsLogin=true";
560 } else {
561 dtps.error("Failed to get user and/or course data", "Exception in promise @ dtps.init");
562 }
563 });
564
565 //Load dashboard prefrences
566 dtps.loadDashboardPrefs();
567}
568
569/**
570 * 12 hour time formatter
571 *
572 * @param {Date} date The date to format
573 * @return {string} Formatted time string in 12hr format
574 */
575dtps.ampm = function (date) {
576 var hours = date.getHours();
577 var minutes = date.getMinutes();
578 var ampm = hours >= 12 ? 'pm' : 'am';
579 hours = hours % 12;
580 hours = hours ? hours : 12; // the hour '0' should be '12'
581 minutes = minutes &lt; 10 ? '0' + minutes : minutes;
582 var strTime = hours + ':' + minutes + ' ' + ampm;
583 return strTime;
584}
585
586/**
587 * Formats a date to a readable date string
588 *
589 * @param {Date} date The date to format
590 * @return {string} Formatted date string in DAY MONTH DATE, HH:MM AMPM format
591 */
592dtps.formatDate = function (date) {
593 if (date) {
594 return new Date(date).toDateString().slice(0, -5) + ", " + dtps.ampm(new Date(date));
595 } else {
596 return "";
597 }
598}
599
600/**
601 * Adjusts the height of an iFrame to match its content
602 *
603 * @param {string} iframeID The ID of the iFrame element to adjust
604 */
605dtps.iframeLoad = function (iframeID) {
606 var iFrame = document.getElementById(iframeID);
607 if (iFrame) {
608 iFrame.height = "";
609 iFrame.height = iFrame.contentWindow.document.body.scrollHeight + "px";
610 }
611}
612
613/**
614 * Clears all DTPS data
615 */
616dtps.clearData = function () {
617 if (window.confirm("Clearing Power+ data will clear all local user data stored by Power+. This should be done if it is a new semester / school year or if you are having issues with Power+. Are you sure you want to clear all your Power+ data?")) {
618 window.localStorage.clear()
619 window.alert("Power+ data cleared")
620 }
621}
622
623/**
624 * Runs Razer Chroma RGB effects for the selected content
625 *
626 * @todo Pending v3 rewrite
627 */
628dtps.chroma = function () {
629 if (fluid.chroma) {
630 if (fluid.chroma.on) {
631 var classVar = "--light"
632 if ($("body").hasClass("dark")) classVar = "--norm"
633 if ($("body").hasClass("midnight")) classVar = "--dark"
634 if (dtps.selectedClass !== "dash") {
635 var dark = "white";
636 var lighting = JSON.parse(`[
637 [null,null,null,` + (dtps.selectedContent == "stream" ? '"white","white","white","white"' : "null,null,null,null") + `,` + (dtps.selectedContent == "pages" ? '"white","white","white","white"' : "null,null,null,null") + `,` + (dtps.selectedContent == "grades" ? '"white","white","white","white"' : "null,null,null,null") + `,null,null,null,null,null,null,null],
638 [null,null,` + (dtps.classes[dtps.selectedClass].grade >= 10 ? `"` + dark + `"` : 0) + `,` + (dtps.classes[dtps.selectedClass].grade >= 20 ? `"` + dark + `"` : 0) + `,` + (dtps.classes[dtps.selectedClass].grade >= 30 ? `"` + dark + `"` : 0) + `,` + (dtps.classes[dtps.selectedClass].grade >= 40 ? `"` + dark + `"` : 0) + `,` + (dtps.classes[dtps.selectedClass].grade >= 50 ? `"` + dark + `"` : 0) + `,
639 ` + (dtps.classes[dtps.selectedClass].grade >= 60 ? `"` + dark + `"` : 0) + `,` + (dtps.classes[dtps.selectedClass].grade >= 70 ? `"` + dark + `"` : 0) + `,` + (dtps.classes[dtps.selectedClass].grade >= 80 ? `"` + dark + `"` : 0) + `,` + (dtps.classes[dtps.selectedClass].grade >= 90 ? `"` + dark + `"` : 0) + `,` + (dtps.classes[dtps.selectedClass].grade >= 100 ? `"` + dark + `"` : 0) + `,null,null,null,null,null,null,null,null,null,null],
640 [null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],
641 [null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],
642 [null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],
643 [null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]]`)
644 var ele = $(".background")[0];
645 if ($(".class." + dtps.selectedClass)[0] !== undefined) ele = $(".class." + dtps.selectedClass)[0];
646 fluid.chroma.effect(tinycolor(getComputedStyle(ele).getPropertyValue(classVar)).saturate(70).toHexString(), lighting);
647 } else {
648 var ele = $(".background")[0];
649 if ($(".class.dash")[0] !== undefined) ele = $(".class.dash")[0];
650 fluid.chroma.static(getComputedStyle(ele).getPropertyValue(classVar));
651 }
652 }
653 }
654}
655
656/**
657 * Renders the class list in the sidebar
658 *
659 * @param {boolean} [override] True if the sidebar should be forcefully re-rendered
660 */
661dtps.showClasses = function (override) {
662 //Array of class HTML for the sidebar
663 dtps.classlist = [];
664
665 for (var i = 0; i &lt; dtps.classes.length; i++) {
666 //Determine letter grade HTML
667 var letterGradeHTML = "";
668 if (dtps.classes[i].letter) letterGradeHTML = dtps.classes[i].letter;
669 if (dtps.classes[i].letter == null) letterGradeHTML = "--";
670 if (dtps.classes[i].letter == "...") letterGradeHTML = `&lt;div class="spinner" style="background-color: var(--norm); margin: -2px -13px">&lt;/div>`; //Show loading indicator for ...
671
672 //Add class HTML to array
673 dtps.classlist.push(/*html*/`
674 &lt;div
675 onclick="${'dtps.selectedClass = ' + i}"
676 class="${'class item ' + i + ' ' + (dtps.selectedClass == i ? " active" : "")}"
677 style="${'--classColor: ' + dtps.classes[i].color}"
678 >
679 &lt;span class="label name">${dtps.classes[i].subject}&lt;/span>
680 &lt;div ${dtps.classes[i].letter == null ? `style="letter-spacing:2px;"` : ""} class="icon grade val">
681 ${letterGradeHTML}
682 &lt;/div>
683 &lt;/div>
684 `);
685 }
686
687 //Only render HTML if the sidebar doesn't already have the classes rendered, or if override is true
688 if (!jQuery(".sidebar .class.dash")[0] || override) {
689 jQuery(".sidebar").html(/*html*/`
690 &lt;div class="bigLogo" style="text-align: center; margin: 10px 0 20px;">
691 &lt;img style="width: 28px; margin-right: 7px; vertical-align: middle;" src="${dtps.baseURL + "/gh-pages/icon.svg"}" />
692 &lt;h4 style="color: var(--text); display: inline-block; font-size: 28px; vertical-align: middle; margin: 0px;">Power+&lt;/h4>
693 &lt;/div>
694
695 &lt;img class="logo" src="${dtps.baseURL + "/gh-pages/favicon.png"}" />
696
697 &lt;div class="items">
698
699 &lt;div onclick="dtps.selectedClass = 'dash';" class="class item main dash ${dtps.selectedClass == "dash" ? "active" : ""}">
700 &lt;span class="label name">Dashboard&lt;/span>
701 &lt;div class="icon">&lt;i class="material-icons">dashboard&lt;/i>&lt;/div>
702 &lt;/div>
703
704 &lt;div class="divider">&lt;/div>
705
706 ${dtps.classlist.join("")}
707 &lt;/div>
708
709 &lt;div onclick="$('body').toggleClass('collapsedSidebar'); if ($('body').hasClass('collapsedSidebar')) { $(this).children('i').html('keyboard_arrow_right'); } else {$(this).children('i').html('keyboard_arrow_left');}" init="true" class="collapse">
710 &lt;i class="material-icons">keyboard_arrow_left&lt;/i>
711 &lt;/div>
712 `);
713
714 //Change view to stream if coming from pages or discussions, since those tabs change the sidebar
715 if ((dtps.selectedContent == "pages") || (dtps.selectedContent == "discuss")) {
716 //Show stream
717 fluid.screen('stream', dtps.classes[dtps.selectedClass].id);
718 }
719
720 //Class onclick listener
721 $(".class:not(.overrideClass)").click(function (event) {
722 dtps.presentClass(dtps.selectedClass);
723
724 //Load class content based on what's selected
725 if ((dtps.selectedContent == "stream") &amp;&amp; dtps.classes[dtps.selectedClass]) {
726 fluid.screen("stream", dtps.classes[dtps.selectedClass].id);
727 }
728
729 if ((dtps.selectedContent == "moduleStream") &amp;&amp; dtps.classes[dtps.selectedClass]) {
730 fluid.screen("modules", dtps.classes[dtps.selectedClass].id);
731 }
732
733 if ((dtps.selectedContent == "grades") &amp;&amp; dtps.classes[dtps.selectedClass]) {
734 if (dtps.classes[dtps.selectedClass].hasGradebook) {
735 fluid.screen("gradebook", dtps.classes[dtps.selectedClass].id);
736 } else {
737 fluid.screen("stream", dtps.classes[dtps.selectedClass].id);
738 }
739 }
740
741 if (dtps.selectedClass == "dash") {
742 fluid.screen("dashboard");
743 }
744 });
745 }
746}
747
748/**
749 * Renders the class header (color, name, tabs, etc.) and sets the class as the selected class
750 *
751 * @param {number|string} classNum The class number to load or "dash" if loading the dashboard
752 */
753dtps.presentClass = function (classNum) {
754 //Set classNum as selected class
755 dtps.selectedClass = classNum;
756
757 //Set dashboard body class for CSS styles
758 if (classNum == "dash") {
759 $('body').addClass('dashboard');
760 } else {
761 $('body').removeClass('dashboard');
762 }
763
764 //Update RGB keyboard lighting effects
765 dtps.chroma();
766
767 //Set the default imageURL to an empty PNG to make the CSS transition work
768 var imageURL = "https://i.imgur.com/SpqHCNo.png";
769
770 if (fluid.get("pref-hideClassImages") !== "true") {
771 //Class images are not disabled
772 if (dtps.classes[classNum] &amp;&amp; dtps.classes[classNum].image) {
773 //Class has image
774 imageURL = dtps.classes[classNum].image;
775 }
776 }
777
778 //Run CSS animation for class transition
779 $(".background").addClass("trans");
780 $(".cover.image").css("background-image", 'url("' + imageURL + '")');
781 $(".background").css("opacity", '0.90');
782 $(".background").css("filter", 'none');
783
784 //Clear any existing background animation timeout
785 clearTimeout(dtps.bgTimeout);
786
787 //Set 500ms transition
788 dtps.bgTimeout = setTimeout(function () {
789 //Set theme to something random to force the theme change listener to update
790 dtps.oldTheme = "squidward theme park";
791 document.dispatchEvent(new CustomEvent('fluidTheme'));
792
793 //Remove transition
794 $(".background").removeClass("trans");
795 }, 500);
796
797 //Set background color
798 if (dtps.classes[classNum]) {
799 $(".background").css("--classColor", dtps.classes[classNum].color);
800 }
801
802 //Remove active class from other classes in the sidebar, add the active class to the selected class
803 $(".class." + classNum).siblings().removeClass("active");
804 $(".class." + classNum).addClass("active");
805
806 //Update title to show class name
807 //If the dashboard is selected, this is just "Dashboard". Otherwise, this is Class.subject
808 $("#headText").html(classNum == "dash" ? "Dashboard" : dtps.classes[classNum] &amp;&amp; dtps.classes[classNum].subject);
809
810 //If the class doesn't exist, hide the tabs
811 //Otherwise, show the tabs
812 if (!dtps.classes[classNum]) {
813 $(".header .btns").hide();
814 } else {
815 $(".header .btns").show();
816 }
817
818 if (dtps.classes[classNum]) {
819 //Show pages tab if the class supports it, otherwise, hide it
820 if (dtps.classes[classNum].pages) {
821 $(".btns .btn.pages").show();
822 } else {
823 $(".btns .btn.pages").hide();
824 }
825
826 //Show pages tab if the class supports it, otherwise, hide it
827 if (dtps.classes[classNum].discussions) {
828 $(".btns .btn.discuss").show();
829 } else {
830 $(".btns .btn.discuss").hide();
831 }
832
833 //Show gradebook if the LMS and the class supports it, otherwise, hide it
834 if ((dtpsLMS.genericGradebook || dtpsLMS.gradebook) &amp;&amp; dtps.classes[classNum].hasGradebook) {
835 $(".btns .btn.grades").show();
836 } else {
837 $(".btns .btn.grades").hide();
838 }
839
840 //Hide tabs if only one tab is visible
841 if ($("#dtpsTabBar .btn:visible").length &lt; 2) {
842 $("#dtpsTabBar").hide();
843 }
844 }
845}
846
847/**
848 * Shows the gradebook using HTML from dtpsLMS.gradebook
849 *
850 * @param {string} classID Class ID
851 */
852dtps.showLMSGradebook = function (classID) {
853 //Get class index and set as selected class
854 var classNum = dtps.classes.map(course => course.id).indexOf(classID);
855 dtps.selectedClass = classNum;
856
857 //Set stream as the selected content
858 dtps.selectedContent = "grades";
859 $("#dtpsTabBar .btn").removeClass("active");
860 $("#dtpsTabBar .btn.grades").addClass("active");
861
862 //Load class color, name, etc.
863 dtps.presentClass(classNum);
864
865 //Ensure classes are shown in the sidebar
866 dtps.showClasses();
867
868 if (classNum == -1) {
869 //Class does not exist
870 dtps.error("The selected class doesn't exist", "classNum check failed @ dtps.showLMSGradebook");
871 }
872
873 //Show loading indicator
874 jQuery(".classContent").html(`&lt;div class="spinner">&lt;/div>`);
875
876 dtpsLMS.gradebook(dtps.classes[classNum]).then(html => {
877 $(".classContent").html(html);
878 }).catch(function (err) {
879 dtps.error("Could not load the gradebook", "Caught promise rejection @ dtps.showLMSGradebook", err);
880 });
881}
882
883/**
884 * Stores grade data locally for the previous grade feature
885 *
886 * @param classNum Class number to log grade
887 */
888dtps.logGrades = function (classNum) {
889 /*
890 Grade change vars:
891 gradeHistory-ID: current|previous (e.g. "A|B+" represents a change of B+ -> A)
892 if there is only one grade, it is the current one
893 */
894 if (window.localStorage.getItem("gradeHistory-" + dtps.classes[classNum].id)) {
895 var savedCurrent = window.localStorage.getItem("gradeHistory-" + dtps.classes[classNum].id).split("|")[0];
896 var savedPrevious = window.localStorage.getItem("gradeHistory-" + dtps.classes[classNum].id).split("|")[1];
897
898 if (savedCurrent !== dtps.classes[classNum].letter) {
899 //Grade change
900 window.localStorage.setItem("gradeHistory-" + dtps.classes[classNum].id, dtps.classes[classNum].letter + "|" + savedCurrent);
901 dtps.classes[classNum].previousLetter = savedCurrent;
902 }
903
904 if ((savedCurrent == dtps.classes[classNum].letter) &amp;&amp; savedPrevious) {
905 //Previous grade is already saved
906 dtps.classes[classNum].previousLetter = savedPrevious;
907 }
908 } else {
909 //No history yet, store current grade
910 window.localStorage.setItem("gradeHistory-" + dtps.classes[classNum].id, dtps.classes[classNum].letter);
911 }
912}
913
914/**
915 * Opens the settings page
916 */
917dtps.settings = function () {
918 //Render dashboard HTML if not already loaded
919 if ($("#leftDashboardColumn").attr("loaded") !== "true") {
920 //Returns dashboard item HTML from a dashboard item array
921 function dashboardHTML(dashboardArray) {
922 return dashboardArray.map(dashboardItem => {
923 return /*html*/`
924 &lt;div dashboardItem-id="${dashboardItem.id}" style="height: ${dashboardItem.size * 1.7 + 50}px" class="dashboardItem">
925 &lt;h5>
926 &lt;i class="material-icons">${dashboardItem.icon}&lt;/i>
927 &lt;span>${dashboardItem.name}&lt;/span>
928 &lt;/h5>
929
930 ${dashboardItem.supportsCompactMode ? /*html*/`
931 &lt;div class="compactModeSwitch">
932 &lt;div dashboardItem-id="${dashboardItem.id}" onclick="$(this).toggleClass('active'); dtps.saveDashboardPrefs();"
933 class="switch ${dashboardItem.compact ? "active" : ""}">&lt;span class="head">&lt;/span>&lt;/div>
934 &lt;div class="label">&lt;i class="material-icons">view_compact&lt;/i> Compact mode (NYI)&lt;/div>
935 &lt;/div>
936 ` : ``}
937 &lt;/div>
938 `;
939 }).join("");
940 }
941
942 //Render dashboard items
943 $("#leftDashboardColumn").html(dashboardHTML(dtps.leftDashboard));
944 $("#rightDashboardColumn").html(dashboardHTML(dtps.rightDashboard));
945
946 //Make dashboard items sortable
947 $(".dashboardColumn").sortable({
948 connectWith: ".dashboardColumn",
949 update: function (e, ui) {
950 dtps.saveDashboardPrefs();
951 }
952 });
953
954 //Store loaded state to prevent reloading dashboard items
955 $("#leftDashboardColumn").attr("loaded", "true");
956 }
957
958 fluid.modal('.settingsCard');
959}
960
961/**
962 * Saves dashboard prefrences
963 */
964dtps.saveDashboardPrefs = function () {
965 var dashboardPrefs = [];
966
967 //Add dashboard items
968 for (var i = 0; i &lt; $(".dashboardColumn").children().length; i++) {
969 //Get HTML item
970 var child = $($(".dashboardColumn").children()[i]);
971
972 //Add item to dashboardPrefs array
973 dashboardPrefs.push({
974 id: child.attr("dashboardItem-id"),
975 side: child.parent().attr("id").includes("left") ? "left" : "right",
976 compact: child.find(".switch") &amp;&amp; child.find(".switch").hasClass("active")
977 });
978 }
979
980 //Save to local storage
981 window.localStorage.setItem("dtpsDashboardItems", JSON.stringify(dashboardPrefs));
982
983 //Reload dashboard items
984 dtps.loadDashboardPrefs();
985}
986
987/**
988 * Loads dashboard prefrences
989 */
990dtps.loadDashboardPrefs = function() {
991 //Define left and right dashboard columns
992 dtps.leftDashboard = [];
993 dtps.rightDashboard = [];
994
995 //Add items to dashboard columns
996 if (window.localStorage.dtpsDashboardItems) {
997 //Add from user prefs
998
999 //Parse JSON
1000 var dashboardPref = JSON.parse(window.localStorage.dtpsDashboardItems);
1001
1002 //Generate arrays of dashboard item IDs
1003 var dashboardIDs = dtps.dashboardItems.map(item => item.id);
1004
1005 //Add items to dashboard according to prefs
1006 dashboardPref.forEach(dashboardItemPref => {
1007 if (dashboardIDs.includes(dashboardItemPref.id)) {
1008 //Get item index based on dashboardIDs array
1009 var itemIndex = dashboardIDs.indexOf(dashboardItemPref.id);
1010
1011 //Get item from dtps.dashboardItems array
1012 var dashboardItem = dtps.dashboardItems[itemIndex];
1013
1014 //Set compact mode
1015 if (dashboardItemPref.compact) {
1016 dashboardItem.compact = true;
1017 }
1018
1019 //Add item to dashboard
1020 if (dashboardItemPref.side == "left") {
1021 dtps.leftDashboard.push(dashboardItem);
1022 } else if (dashboardItemPref.side == "right") {
1023 dtps.rightDashboard.push(dashboardItem);
1024 }
1025 }
1026 });
1027 } else {
1028 //Add from defaults
1029 dtps.dashboardItems.forEach(dashboardItem => {
1030 if (dashboardItem.defaultSide == "left") {
1031 dtps.leftDashboard.push(dashboardItem);
1032 } else if (dashboardItem.defaultSide == "right") {
1033 dtps.rightDashboard.push(dashboardItem);
1034 }
1035 })
1036 }
1037}
1038
1039/**
1040 * Renders initial static DTPS HTML
1041 */
1042dtps.render = function () {
1043 //Remove all existing link tags and LMS head content
1044 $("link:not(.dtpsHeadItem)").remove();
1045 $("head *:not(.dtpsHeadItem)").remove();
1046
1047 //Set default body classes
1048 $("body").attr("class", "dark showThemeWindows hasSidebar dashboard");
1049
1050 //Set document title and favicon
1051 document.title = "Power+";
1052 jQuery("&lt;link/>", {
1053 rel: "shortcut icon",
1054 type: "image/png",
1055 href: dtps.baseURL + "/gh-pages/favicon.png"
1056 }).appendTo("head");
1057
1058 //Remove existing LMS HTML (excluding Power+ loading screen HTML)
1059 jQuery("body *:not(#dtpsNativeOverlay):not(#dtpsNativeOverlay *)").remove();
1060
1061 //Render HTML
1062 jQuery("body").append(/*html*/`
1063 &lt;div style="line-height: 0;" class="sidebar acrylicMaterial">&lt;/div>
1064
1065 &lt;!-- Header background elements -->
1066 &lt;div class="cover image">&lt;/div>
1067 &lt;div class="background">&lt;/div>
1068
1069 &lt;!-- Header with class name and tabs -->
1070 &lt;div class="header">
1071 &lt;p id="timeRemaining" style="position: absolute;top:${dtps.unstable ? "2px" : "14px"};margin-left: 20px;">&lt;/p>
1072 ${dtps.unstable ? `&lt;p style="position: absolute;top: 45px;margin-left: 20px; color: #ff6e6e; background-color: black; font-size: 12px;">THIS IS AN UNSTABLE VERSION OF POWER+. USE AT YOUR OWN RISK.&lt;/p>` : ""}
1073
1074 &lt;h2 id="headText">Dashboard&lt;/h2>
1075
1076 &lt;!-- Class tabs. Each button has init=true to prevent Fluid UI from automatically managing their states -->
1077 &lt;div style="display: none;" id="dtpsTabBar" class="btns row tabs">
1078 &lt;button init="true" onclick="fluid.screen('stream', dtps.classes[dtps.selectedClass].id);" class="btn stream">
1079 &lt;i class="material-icons">library_books&lt;/i>
1080 Coursework
1081 &lt;/button>
1082 &lt;button init="true" onclick="fluid.screen('discussions', dtps.classes[dtps.selectedClass].id);" class="btn discuss">
1083 &lt;i class="material-icons">forum&lt;/i>
1084 Discussions
1085 &lt;/button>
1086 &lt;button init="true" onclick="fluid.screen('pages', dtps.classes[dtps.selectedClass].id);" class="btn pages">
1087 &lt;i class="material-icons">insert_drive_file&lt;/i>
1088 Pages
1089 &lt;/button>
1090 &lt;button init="true" onclick="fluid.screen('gradebook', dtps.classes[dtps.selectedClass].id);" class="btn grades">
1091 &lt;i class="material-icons">assessment&lt;/i>
1092 ${dtpsLMS.gradebook ? "Grades" : "Gradebook"}
1093 &lt;/button>
1094 &lt;/div>
1095 &lt;/div>
1096
1097 &lt;!-- Class content area -->
1098 &lt;div class="classContent">
1099 &lt;div class="spinner">&lt;/div>
1100 &lt;/div>
1101
1102 &lt;!-- Settings card (its inner HTML is added later) -->
1103 &lt;div style="height: calc(100vh - 50px); overflow: auto !important;" class="card withnav focus close container settingsCard">&lt;/div>
1104
1105 &lt;!-- Toolbar (the thing at the top-right with your name, profile picture, and buttons. its inner HTML is also added later) -->
1106 &lt;div class="toolbar items">&lt;/div>
1107
1108 &lt;!-- Changelog card -->
1109 &lt;div style="border-radius: 30px;" class="card focus changelog close container">
1110 &lt;i onclick="fluid.cards.close('.card.changelog')" class="material-icons close">close&lt;/i>
1111 &lt;h3>What's new in Power+&lt;/h3>
1112 &lt;h5>Loading...&lt;/h5>
1113 &lt;/div>
1114
1115 &lt;!-- General details card for assignments, outcomes, class info, etc. -->
1116 &lt;div style="border-radius: 30px;" class="card focus details close container">
1117 &lt;i onclick="fluid.cards.close('.card.details')" class="material-icons close">close&lt;/i>
1118 &lt;p>An error occured&lt;/p>
1119 &lt;/div>
1120
1121 &lt;!-- General iFrame card (with white background) -->
1122 &lt;div style="border-radius: 30px; top: 50px; background-color: white; color: black;" class="card focus close moduleURL container">
1123 &lt;i style="color: black !important;" onclick="fluid.cards.close('.card.moduleURL'); $('#moduleIFrame').attr('src', '');" class="material-icons close">close&lt;/i>
1124 &lt;br />&lt;br />
1125 &lt;iframe style="width: 100%; height: calc(100vh - 175px); border: none;" id="moduleIFrame">&lt;/iframe>
1126 &lt;/div>
1127 `);
1128}
1129
1130/**
1131 * Renders basic content after the user has been loaded
1132 */
1133dtps.renderLite = function () {
1134 //Add hideGrades body class if enabled and preference listener
1135 if (fluid.get("pref-hideGrades") == "true") { jQuery('body').addClass('hidegrades'); }
1136 document.addEventListener("pref-hideGrades", function (e) {
1137 if (e.detail == "true") {
1138 //hideGrades has been enabled, add class to body to hide grades via CSS
1139 jQuery('body').addClass('hidegrades');
1140 } else {
1141 //hideGrades has been disabled, remove class from body to show grades
1142 jQuery('body').removeClass('hidegrades');
1143 }
1144 });
1145
1146 //Render settings card
1147 jQuery(".card.settingsCard").html(/*html*/`
1148 &lt;i onclick="fluid.cards.close('.card.settingsCard')" class="material-icons close">close&lt;/i>
1149
1150 &lt;div class="sidenav" style="position: fixed; height: calc(100% - 50px); border-radius: 20px 0px 0px 20px;">
1151 &lt;div class="title">
1152 &lt;img src="${dtps.baseURL + "/gh-pages/icon.svg"}" style="width: 50px;vertical-align: middle;padding: 7px; padding-top: 14px;" />
1153 &lt;div style="vertical-align: middle; display: inline-block;">
1154 &lt;h5 style="font-weight: bold;display: inline-block;vertical-align: middle;">Power+&lt;/h5>
1155 &lt;p>${dtps.readableVer}&lt;/p>
1156 &lt;/div>
1157 &lt;/div>
1158
1159 &lt;div onclick="$('.abtpage').hide();$('.abtpage.settings').show();" class="item active">
1160 &lt;i class="material-icons">settings&lt;/i> Settings
1161 &lt;/div>
1162 &lt;div onclick="$('.abtpage').hide();$('.abtpage.dashboard').show();" class="item">
1163 &lt;i class="material-icons">dashboard&lt;/i> Dashboard
1164 &lt;/div>
1165 &lt;div onclick="$('.abtpage').hide();$('.abtpage.about').show(); if ($('body').hasClass('sudo')) { $('.advancedOptions').show(); $('.advOp').hide(); } else { $('.advancedOptions').hide(); $('.advOp').show(); }" class="item abt">
1166 &lt;i class="material-icons">info&lt;/i> About
1167 &lt;/div>
1168 &lt;/div>
1169
1170 &lt;div style="min-height: 100%" class="content">
1171 &lt;div class="abtpage settings">
1172 &lt;h5>Settings&lt;/h5>
1173
1174 &lt;br />
1175 &lt;p>Theme&lt;/p>
1176
1177 &lt;div>
1178 &lt;div class="btns row themeSelector">&lt;/div>
1179
1180 &lt;br />&lt;br />
1181 &lt;p>Grades&lt;/p>
1182
1183 &lt;div onclick="fluid.set('pref-hideGrades')" class="switch pref-hideGrades">&lt;span class="head">&lt;/span>&lt;/div>
1184 &lt;div class="label">&lt;i class="material-icons">visibility_off&lt;/i> Hide class grades&lt;/div>
1185 &lt;/div>
1186
1187 &lt;br />&lt;br />
1188 &lt;p>Classes&lt;/p>
1189
1190 &lt;div>
1191 &lt;div onclick="fluid.set('pref-fullNames')" class="switch pref-fullNames">&lt;span class="head">&lt;/span>&lt;/div>
1192 &lt;div class="label">&lt;i class="material-icons">title&lt;/i> Show full class names (requires reload)&lt;/div>
1193
1194 &lt;br />&lt;br />
1195 &lt;div onclick="fluid.set('pref-hideClassImages')" class="switch pref-hideClassImages">&lt;span class="head">&lt;/span>&lt;/div>
1196 &lt;div class="label">&lt;i class="material-icons">image&lt;/i> Hide class images&lt;/div>
1197
1198 &lt;div class="razerChroma" style="display: none;">
1199 &lt;br />&lt;br />
1200 &lt;div onclick="fluid.set('pref-chromaEffects')" class="switch pref-chromaEffects">&lt;span class="head">&lt;/span>&lt;/div>
1201 &lt;div class="label">&lt;img style="width: 26px;vertical-align: middle;margin-right: 2px;" src="https://i.imgur.com/FLwviAM.png" class="material-icons" /> Razer Chroma Effects (beta)&lt;/div>
1202 &lt;/div>
1203 &lt;/div>
1204
1205 ${window.localStorage.githubCanary || window.localStorage.dtpsDebuggingPort ? /*html*/`
1206 &lt;br />&lt;br />
1207 &lt;p>&lt;b>Prerelease testing&lt;/b>&lt;/p>
1208
1209 &lt;div>
1210 &lt;div class="btns row small">
1211 &lt;button
1212 onclick="window.localStorage.setItem('dtpsLoaderPref', 'prod')"
1213 class="btn ${window.localStorage.dtpsLoaderPref != "canary" &amp;&amp; window.localStorage.dtpsLoaderPref != "debugging" ? "active" : ""}">
1214 &lt;i class="material-icons">label&lt;/i> Production
1215 &lt;/button>
1216 ${window.localStorage.githubCanary ? /*html*/`
1217 &lt;button
1218 onclick="window.localStorage.setItem('dtpsLoaderPref', 'canary')"
1219 class="btn ${window.localStorage.dtpsLoaderPref == "canary" ? "active" : ""}">
1220 &lt;i class="material-icons">build_circle&lt;/i> Canary
1221 &lt;/button>
1222 ` : ``}
1223 ${window.localStorage.dtpsDebuggingPort ? /*html*/`
1224 &lt;button
1225 onclick="window.localStorage.setItem('dtpsLoaderPref', 'debugging')"
1226 class="btn ${window.localStorage.dtpsLoaderPref == "debugging" ? "active" : ""}">
1227 &lt;i class="material-icons">bug_report&lt;/i> Debugging
1228 &lt;/button>
1229 ` : ``}
1230 &lt;/div>
1231 &lt;/div>
1232 ` : ``}
1233
1234 &lt;/div>
1235
1236 &lt;div style="display: none;" class="abtpage dashboard">
1237 &lt;h5>Dashboard&lt;/h5>
1238
1239 &lt;br />
1240
1241 &lt;div id="leftDashboardColumn" class="dashboardColumn">&lt;/div>
1242
1243 &lt;div id="rightDashboardColumn" class="dashboardColumn">&lt;/div>
1244
1245 &lt;/div>
1246
1247 &lt;div style="display: none;" class="abtpage about">
1248 &lt;h5>About&lt;/h5>
1249
1250 &lt;div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
1251 &lt;img src="${dtps.baseURL + "/gh-pages/icon.svg"}" style="height: 50px; margin-right: 10px; vertical-align: middle; margin-top: 20px;" />
1252
1253 &lt;div style="display: inline-block; vertical-align: middle;">
1254 &lt;h4 style="font-weight: bold; font-size: 32px; margin-bottom: 0px;">Power+&lt;/h4>
1255 &lt;div style="font-size: 16px; margin-top: 5px;">
1256 ${dtps.readableVer}
1257 &lt;div class="buildInfo" style="display: inline-block;margin: 0px 5px;font-size: 12px;cursor: pointer;">&lt;/div>
1258 &lt;/div>
1259 &lt;/div>
1260
1261 &lt;div style="margin-top: 15px; margin-bottom: 7px;">&lt;a onclick="dtps.changelog();" style="color: var(--lightText); margin: 0px 5px;" href="#">&lt;i class="material-icons" style="vertical-align: middle">update&lt;/i> Changelog&lt;/a>
1262 &lt;a onclick="if (window.confirm('Are you sure you want to uninstall Power+? The extension will be removed and all of your Power+ data will be erased. If you use the Power+ bookmarklet, you will have to remove that yourself.')) { document.dispatchEvent(new CustomEvent('extensionData', { detail: 'extensionUninstall' })); window.localStorage.clear(); window.alert('Power+ has been uninstalled. Reload the page to go back to ${dtpsLMS.shortName}.') }" style="color: var(--lightText); margin: 0px 5px;" href="#">&lt;i class="material-icons" style="vertical-align: middle">delete_outline&lt;/i> Uninstall&lt;/a>
1263 &lt;a style="color: var(--lightText); margin: 0px 5px;" href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=***REMOVED***&amp;item_name=Donate+to+Power%2B&amp;currency_code=USD&amp;source=url">&lt;i class="material-icons" style="vertical-align: middle">attach_money&lt;/i> Donate&lt;/a>
1264 &lt;a style="color: var(--lightText); margin: 0px 5px;" href="mailto:[email protected]">&lt;i class="material-icons" style="vertical-align: middle">email&lt;/i> Contact&lt;/a>
1265 &lt;/div>
1266 &lt;/div>
1267
1268 &lt;div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
1269 &lt;img src="${dtps.user.photoURL}" style="height: 50px; margin-right: 10px; vertical-align: middle; margin-top: 20px; border-radius: 50%;" />
1270
1271 &lt;div style="display: inline-block; vertical-align: middle;">
1272 &lt;h4 style="font-weight: bold; font-size: 32px; margin-bottom: 0px;">${dtps.user.name} &lt;span style="font-size: 12px;">${dtps.user.id}&lt;/span>&lt;/h4>
1273 &lt;/div>
1274
1275 &lt;div style="margin-top: 15px; margin-bottom: 7px;">
1276 &lt;a style="color: var(--lightText); margin: 0px 5px;" href="/logout">&lt;i class="material-icons" style="vertical-align: middle">exit_to_app&lt;/i> Logout&lt;/a>
1277 &lt;/div>
1278 &lt;/div>
1279
1280 &lt;div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
1281 &lt;img src="${dtpsLMS.logo}" style="height: 50px; margin-right: 10px; vertical-align: middle; margin-top: 20px; border-radius: 50%; background: #ee5034;" />
1282
1283 &lt;div style="display: inline-block; vertical-align: middle;">
1284 &lt;h4 style="font-weight: bold; font-size: 32px; margin-bottom: 0px;">${dtpsLMS.name}&lt;/h4>
1285 ${dtpsLMS.description ? `
1286 &lt;div style="font-size: 16px; margin-top: 5px;">${dtpsLMS.description}&lt;/div>
1287 ` : ``}
1288 &lt;/div>
1289
1290 &lt;div style="margin-top: 15px; margin-bottom: 7px;">
1291 &lt;a style="color: var(--lightText); margin: 0px 5px;" href="${dtpsLMS.source}">&lt;i class="material-icons" style="vertical-align: middle">code&lt;/i> LMS integration source code&lt;/a>
1292 &lt;/div>
1293 &lt;/div>
1294
1295 &lt;div class="card advancedOptions" style="padding: 8px 16px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px; display: none;">
1296 &lt;div style="display: inline-block; vertical-align: middle;">
1297 &lt;h4 style="font-weight: bold; font-size: 28px; margin-bottom: 0px;">Advanced Options&lt;/h4>
1298 &lt;/div>
1299
1300 &lt;div style="margin-top: 15px; margin-bottom: 7px;">
1301 &lt;a style="color: var(--lightText); margin: 0px 5px;" onclick="dtps.clearData();" href="#">&lt;i class="material-icons" style="vertical-align: middle">refresh&lt;/i> Reset Power+&lt;/a>
1302 &lt;a style="color: var(--lightText); margin: 0px 5px;" href="https://github.com/jottocraft/dtps/issues/new/choose">&lt;i class="material-icons" style="vertical-align: middle">bug_report&lt;/i> Bug Report / Feedback&lt;/a>
1303 &lt;/div>
1304 &lt;/div>
1305
1306 &lt;br />
1307 &lt;p style="cursor: pointer; color: var(--secText, gray)" onclick="$('.advancedOptions').show(); $(this).hide();" class="advOp">Show advanced options&lt;/p>
1308
1309 &lt;div style="text-align: center; padding: 50px 0px;">
1310 &lt;img style="height: 45px; margin-right: 20px; vertical-align: middle;" src="https://cdn.jottocraft.com/images/footerImage.png" />
1311 &lt;h5 style="display: inline-block; vertical-align: middle;">jottocraft&lt;/h5>
1312 &lt;p>(c) jottocraft 2018-2020. All rights reserved.&amp;nbsp;&amp;nbsp;&lt;a href="https://github.com/jottocraft/dtps">source code&lt;/a>&amp;nbsp;&amp;nbsp;&lt;a href="https://github.com/jottocraft/dtps/blob/master/LICENSE">license&lt;/a>&lt;/p>
1313 &lt;/div>
1314 &lt;/div>
1315 &lt;/div>
1316 `);
1317
1318 //Render toolbar (the thing with the name and settings button at the top-right)
1319 jQuery(".toolbar.items").html(/*html*/`
1320 &lt;div style="text-align: right;">
1321 &lt;h4 style="font-size: 22px;">${dtps.user.name}&lt;/h4>
1322 &lt;img src="${dtps.user.photoURL}" style="height: 34px; margin: 0px; margin-right: 10px; border-radius: 50%; vertical-align: middle;" />
1323 &lt;/div>
1324
1325 &lt;div style="margin-top: 5px; display: inline-block; text-align: right; float: right;">
1326 &lt;div onclick="window.location.href = '/';" class="itemButton">&lt;i class="material-icons">exit_to_app&lt;/i> Go to ${dtpsLMS.shortName || dtpsLMS.name}&lt;/div>
1327 ${dtps.unstable ? `&lt;div onclick="window.open('https://github.com/jottocraft/dtps/issues/new/choose')" class="itemButton">&lt;i class="material-icons">feedback&lt;/i> Feedback&lt;/div>` : ""}
1328 &lt;div onclick="dtps.settings();" class="itemButton">&lt;i class="material-icons">settings&lt;/i> Settings&lt;/div>
1329 &lt;/div>
1330 `);
1331
1332 //Begin loading chroma effects
1333 if (fluid.chroma) {
1334 dtps.chromaProfile = {
1335 title: "Power+",
1336 description: "Razer Chroma effects for Power+ (beta)",
1337 author: "jottocraft",
1338 domain: "powerplus.app"
1339 }
1340 fluid.chroma.supported(function (res) {
1341 if (res) {
1342 //Razer Synapse installed
1343 $(".razerChroma").show();
1344
1345 //Razer Chroma pref
1346 if (fluid.get("pref-chromaEffects") == "true") { if (!fluid.chroma.on) { fluid.chroma.init(dtps.chromaProfile, () => fluid.chroma.static(getComputedStyle($(".background")[0]).getPropertyValue("--dark"))); } }
1347 document.addEventListener("pref-chromaEffects", function (e) {
1348 if (String(e.detail) == "true") { if (!fluid.chroma.on) { fluid.chroma.init(dtps.chromaProfile, () => fluid.chroma.static(getComputedStyle($(".background")[0]).getPropertyValue("--dark"))); } } else { fluid.chroma.disable(); }
1349 })
1350 }
1351 })
1352 }
1353
1354 //Load Fluid UI
1355 fluid.onLoad();
1356
1357 //Render sidebar
1358 dtps.showClasses();
1359
1360 //Load header background gradient
1361 document.dispatchEvent(new CustomEvent('fluidTheme'));
1362
1363 //Remove loading screen styles
1364 jQuery("#dtpsNativeOverlay style").remove();
1365
1366 //Fade out loading screen
1367 jQuery("#dtpsNativeOverlay").css("opacity", "0");
1368
1369 //Remove loading screen after the animation is complete
1370 setTimeout(() => jQuery("#dtpsNativeOverlay").remove(), 200);
1371}
1372
1373//Start loading DTPS
1374dtps.init();
1375
1376//LMS Integration documentation -------------------------------------------------------------------------------------
1377
1378/**
1379 * @namespace dtpsLMS
1380 * @description Global DTPS LMS integration object. All LMS-related tasks, such as fetching data, are handled by this object. This is always loaded first. Please read the guide docs for instructions on implementing a custom LMS.
1381 * @global
1382 * @property {string} name Full LMS name
1383 * @property {string} [shortName] Short LMS name
1384 * @property {string} legalName Legal name (or names) to show in the "Welcome to Power+" disclaimer
1385 * @property {string} [description] A short description of the LMS integration provided
1386 * @property {string} logo LMS logo image URL
1387 * @property {string} url URL to the LMS' website
1388 * @property {string} source URL to the LMS integration's source code
1389 * @property {boolean} [institutionSpecific] True if the LMS is designed for a specific institution
1390 * @property {boolean} [preferRubricGrades] True if DTPS should prefer rubric grades for assignments
1391 * @property {boolean} [genericGradebook] True if DTPS should show the generic gradebook. Ignored if dtpsLMS.gradebook defined.
1392 */
1393
1394/**
1395 * @name dtpsLMS.fetchUser
1396 * @description [REQUIRED] Fetches user data from the LMS
1397 * @kind function
1398 * @return {Promise&lt;User>} A promise which resolves to a User object
1399 */
1400
1401/**
1402* @name dtpsLMS.fetchClasses
1403* @description [REQUIRED] Fetches class data from the LMS
1404* @kind function
1405* @return {Promise&lt;Class[]>} A promise which resolves to an array of Class objects
1406*/
1407
1408/**
1409* @name dtpsLMS.fetchAssignments
1410* @description [REQUIRED] Fetches assignment data for a course from the LMS
1411* @kind function
1412* @param {string} classID The class ID to fetch assignments for
1413* @return {Promise&lt;Assignment[]>} A promise which resolves to an array of Assignment objects
1414*/
1415
1416/**
1417* @name dtpsLMS.fetchDiscussionThreads
1418* @description [OPTIONAL] Fetches discussion threads for a course from the LMS
1419* @kind function
1420* @param {string} classID The class ID to fetch discussion threads for
1421* @return {Promise&lt;DiscussionThread[]>} A promise which resolves to an array of Discussion Thread objects
1422*/
1423
1424/**
1425* @name dtpsLMS.fetchDiscussionPosts
1426* @description [REQUIRED IF dtpsLMS.fetchDiscussionThreads IS IMPLEMENTED] Fetches discussion posts in a thread from the LMS
1427* @kind function
1428* @param {string} classID The class ID to fetch discussion posts for
1429* @param {string} threadID The discussion thread ID to fetch discussion posts for
1430* @return {Promise&lt;DiscussionPost[]>} A promise which resolves to an array of Discussion Post objects
1431*/
1432
1433/**
1434* @name dtpsLMS.fetchPages
1435* @description [OPTIONAL] Fetches pages for a course from the LMS
1436* @kind function
1437* @param {string} classID The class ID to fetch pages for
1438* @return {Promise&lt;Page[]>} A promise which resolves to an array of Page objects
1439*/
1440
1441/**
1442* @name dtpsLMS.fetchPageContent
1443* @description [REQUIRED IF dtpsLMS.fetchPages IS IMPLEMENTED] Fetches content for a page from the LMS
1444* @kind function
1445* @param {string} classID The class ID to fetch page content for
1446* @param {string} pageID The page ID to fetch page content for
1447* @return {Promise&lt;string>} A promise which resolves to the page's content as HTML
1448*/
1449
1450/**
1451* @name dtpsLMS.gradebook
1452* @description [OPTIONAL] Renders custom gradebook HTML for unique grading systems or for a more tailored experience. The gradebook only shows for classes with a grade and with at least 1 assignment.
1453* @kind function
1454* @param {Class} course Class to render the gradebook for. If custom grade calculation is enabled (dtpsLMS.calculateGrade), those results can be accessed at course.gradeCalculation.
1455* @return {Promise&lt;string>} A promise which resolves to HTML to render for the class gradebook
1456*/
1457
1458/**
1459* @name dtpsLMS.calculateGrade
1460* @description [OPTIONAL] Calculates class grades with a custom grade calculation formula. Used for unique grading systems.
1461* @kind function
1462* @param {Class} course Class to calculate grades for [DO NOT USE COURSE.ASSIGNMENTS to access assignments for grade calculation. Use the assignments parameter instead.]
1463* @param {Assignment[]} assignments Assignments used for grade calculation. Use this instead of course.assignments for hypothetical/what-if grade calculation.
1464* @return {undefined|object} The letter grade should be returned in the "letter" property as a string and the percentage in the "grade" property as a number. Other custom properties can be set if they need to be accessed by dtpsLMS.gradebook. Return undefined if there is no grade for the class.
1465*/
1466
1467/**
1468* @name dtpsLMS.updateAssignments
1469* @description [OPTIONAL, INSTITUTION ONLY] This function can be implemented by institution-specific scripts to loop through and override assignment data returned by the LMS.
1470* @kind function
1471* @param {Assignment[]} assignments Original assignments array
1472* @return {Assignment[]} Updated assignments array
1473*/
1474
1475/**
1476* @name dtpsLMS.updateClasses
1477* @description [OPTIONAL, INSTITUTION ONLY] This function can be implemented by institution-specific scripts to loop through and override class data returned by the LMS.
1478* @kind function
1479* @param {Class[]} classes Original classes array
1480* @return {Class[]} Updated classes array
1481*/
1482
1483//Type definitions -------------------------------------------------------------------------------------
1484
1485/**
1486 * @typedef {string} Date
1487 * @description A date string recognized by {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse|Date.parse}
1488 */
1489
1490/**
1491 * @typedef {Object} User
1492 * @description Defines user objects in DTPS
1493 * @property {string} name User name
1494 * @property {string} id User ID
1495 * @property {string} photoURL User photo URL
1496 */
1497
1498/**
1499* @typedef {Object} Class
1500* @description Defines class objects in DTPS
1501* @property {string} name Name of the class
1502* @property {string} id Class ID
1503* @property {number} num Index of the class in the dtps.classes array
1504* @property {string} subject Class subject
1505* @property {Assignment[]} assignments Class assignments. Assume assignments are still loading if this is undefined. The class has no assignments if this is an empty array. Loaded in dtps.init.
1506* @property {DiscussionThread[]|boolean} [discussions] Class discussion threads. Assume this class supports discussions, but not yet loaded, if this is true and that the class has no threads if this is an empty array. For LMSs that do not support discussions, either keep it undefined or set it to false.
1507* @property {Page[]|boolean} [pages] Class pages. Assume this class supports the pages feature, but not yet loaded, if true and that the class has no pages if this is an empty array. For LMSs that do not support pages, either keep it undefined or set it to false.
1508* @property {string} [newDiscussionThreadURL] A URL the user can visit to create a new discussion thread in this class
1509* @property {string} [syllabus] Class syllabus HTML
1510* @property {string} [description] Class description HTML
1511* @property {number} [numStudents] Number of students in the class
1512* @property {string} [term] Class term
1513* @property {string} [color] Class color
1514* @property {number} [grade] Current percentage grade in the class
1515* @property {string} [letter] Current letter grade in the class
1516* @property {string} [previousLetter] Automatically managed by DTPS. The previous letter grade in this class, based on local grade history.
1517* @property {string} [image] URL to the class background image
1518* @property {User} [teacher] Class teacher
1519* @property {boolean} [hasGradebook] Automatically managed by DTPS. True if the class should show the gradebook tab.
1520* @property {object} [gradeCalculation] Automatically managed by DTPS. If custom grade calculation is implemented, this will be the results from custom grade calculation returned by dtpsLMS.calculateGrade.
1521*/</code></pre>
1522 </article>
1523 </section>
1524
1525
1526
1527
1528</div>
1529
1530<nav>
1531 <h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="dtps.html">dtps</a></li><li><a href="dtpsLMS.html">dtpsLMS</a></li></ul><h3><a href="global.html">Global</a></h3>
1532</nav>
1533
1534<br class="clear">
1535
1536<footer>
1537 Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.4</a> on Sun Jun 07 2020 14:02:58 GMT-0700 (Pacific Daylight Time)
1538</footer>
1539
1540<script> prettyPrint(); </script>
1541<script src="scripts/linenumber.js"> </script>
1542</body>
1543</html>