Skip to content

Commit

Permalink
Merge pull request #518 from matematikk-mooc/KURSP-1159-one-theme
Browse files Browse the repository at this point in the history
Kursp 1159 one theme
  • Loading branch information
madsenandreas authored Apr 18, 2024
2 parents b7f7b30 + 4f0c040 commit 8b38338
Show file tree
Hide file tree
Showing 23 changed files with 142 additions and 358 deletions.
115 changes: 115 additions & 0 deletions src/js/account-theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import LoginDirectLink from '../vue/components/login-choice/LoginDirectLink.vue';
import { createApp } from 'vue';
import utilRoot from './utilRoot';

var udirDesignLoaded;


jQuery.extend({
getScript: function (url, callback) {
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = url;

// Handle Script loading
{
var done = false;

// Attach handlers for all browsers
script.onload = script.onreadystatechange = function () {
if (
!done &&
(!this.readyState ||
this.readyState == "loaded" ||
this.readyState == "complete")
) {
done = true;
if (callback) callback();

// Handle memory leak in IE
script.onload = script.onreadystatechange = null;
}
};
}

head.appendChild(script);

// We handle everything using the script element injection
return undefined;
},
});

jQuery(document).ready(function ($) {
console.log("START.");

var redirected = false;

// Redirect if necessary
if (document.location.pathname == "/search/all_courses" && document.location.search.includes('?enroll_code')) {
window.location.href = '/courses' + document.location.search;
redirected = true;
} else if (document.location.pathname == "/login/canvas") {
if (document.referrer.includes("/logout")) {
window.location.href = '/search/all_courses';
redirected = true;
} else if (!document.referrer.includes("/login/canvas")) {
$(".ic-Login").hide();
$("#f1_container").hide(); // Small screens
redirected = utilRoot.redirectFeideAuthIfEnrollReferrer();
if (!redirected) {
if (!document.location.search.includes("normalLogin=1")) {
document.getElementById('wrapper').remove();
let parent = document.getElementById('application');
let login = document.createElement('div');
login.id = 'login-component';
let customLogin = createApp(LoginDirectLink);
parent.appendChild(login);
customLogin.mount("#login-component");
} else {
$(".ic-Login").show();
$("#f1_container").show(); // Small screens
}
}
}
} else if (document.location.pathname == "/courses") {
redirected = utilRoot.redirectToEnrollIfCodeParamPassed();
} else if (document.location.href.indexOf('?login_success=1') != -1) {
window.location.href = '/search/all_courses';
} else if (document.location.pathname == "/") {
setTimeout(function () {
if (!$(".ic-DashboardCard__header_hero").length) {
let html = `
<div class="card card-body">
<h3>Er det tomt her?</h3>
<p>Dersom du har valgt å logge inn med Feide og ikke finner innholdet ditt kan det hende det er fordi du
vanligvis har logget på med en annen bruker ved å bruke epost og passord. Logg ut og inn igjen ved å benytte "Ikke Feide" - knappen.
</p>
<img src="${SERVER}bitmaps/nyinnlogging.png" width="70%" alt="Ny innloggingsskjerm"/>
</div>
`;
document.getElementById('dashboard-activity').insertAdjacentHTML('beforebegin', html);
}
}, 1000)
}

if (!redirected) {
if (window.udirDesignLoaded === undefined) {
window.udirDesignLoaded = true;
console.log("Loading udir design.");

var filename = SERVER + DESIGNCSS;

var fileref = document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
fileref.onload = (_) => {
$.getScript(SERVER + DESIGNJS);
}
document.getElementsByTagName("head")[0].appendChild(fileref)
} else {
console.log("Udir design already loaded.");
}
}

});
2 changes: 1 addition & 1 deletion src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jQuery(function($) {
if (document.location.search === '?mmpf') {
mmooc.powerFunctions.show(parentId);
} else {
window.location.href = '/courses?design=udir';
window.location.href = '/courses';
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/js/modules/courselist.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default (function () {
var myCoursesWithSettings = util.mapCourseSettings(courses, allCoursesSettings.result);

if (courses.length == 0) {
window.location.href = "/search/all_courses?design=udir";
window.location.href = "/search/all_courses";
} else {


Expand Down
4 changes: 1 addition & 3 deletions src/js/modules/coursepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ export default (function() {
showCourseInvitation: function () {
if (!util.isAuthenticated()) {
var enrollButton = $(".course_enrollment_link");
var linkToSelectedCourse = window.location.href.split('/');
var selectedCourseId = linkToSelectedCourse[linkToSelectedCourse.length - 1];

if (enrollButton) {
enrollButton.text('Enroll this course');
enrollButton.click(function (e) {
e.preventDefault();
window.location.href = '/search/all_courses' + '?design=udir' + '#' + selectedCourseId;
window.location.href = '/search/all_courses';
})
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/js/modules/enroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import LoggedInLandingPage from "../../vue/pages/LoggedInLandingPage.vue";
import NotLoggedInPage from "../../vue/pages/NotLoggedInPage.vue";
import api from "../api/api";
import { createApp } from "vue/dist/vue.runtime.esm-bundler.js";
import { hrefQueryString } from "../settingsRoot";
import kpasApi from "../api/kpas-api";
import settings from "../settings";
import util from "./util";
Expand Down Expand Up @@ -60,7 +59,7 @@ export default (function () {
if ($this.hasClass('btn-primary')){
var _href = $this.attr("href");
}else {
var _href = $this.attr("href") + hrefQueryString;
var _href = $this.attr("href");
}

const urlParamsObj = utilRoot.urlParamsToObject();
Expand Down
6 changes: 2 additions & 4 deletions src/js/modules/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { hrefAmpQueryString, hrefQueryString } from "../settingsRoot";

import api from '../api/api.js'
import settings from "../settings";

Expand Down Expand Up @@ -477,7 +475,7 @@ export default (function () {
$this.remove();
}
else{
$this.attr("href", _href + hrefAmpQueryString);
$this.attr("href", _href);
}
});
},
Expand All @@ -488,7 +486,7 @@ export default (function () {
});
},
getLinkToAvailableCourses: function () {
var linkToAvailableCourses = "/search/all_courses" + hrefQueryString;
var linkToAvailableCourses = "/search/all_courses";
//ETH20190409 By making sure the root account loads our design, we do not need a front page.
/*
if (allCoursesFrontpageCourseID > 0) {
Expand Down
123 changes: 0 additions & 123 deletions src/js/rootaccount.js

This file was deleted.

49 changes: 0 additions & 49 deletions src/js/rootaccountfwd-dev.js

This file was deleted.

4 changes: 0 additions & 4 deletions src/js/settingsRoot.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@

var settingsRoot = {

hrefQueryString: "?design=udir",
hrefAmpQueryString: "&design=udir",
feideEnrollRefferers: [
"design=udir",
"enroll_code",
"kslaring.no"
],
Expand Down
Loading

0 comments on commit 8b38338

Please sign in to comment.