Skip to content

Commit

Permalink
Merge pull request #597 from matematikk-mooc/stage
Browse files Browse the repository at this point in the history
DIT-474: Release 2024 49-51
  • Loading branch information
ajxudir authored Dec 17, 2024
2 parents 5761c05 + c8e79f5 commit 989f10e
Show file tree
Hide file tree
Showing 21 changed files with 696 additions and 347 deletions.
27 changes: 27 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Provide a short description about the changes.

---

Added

- List new features, functionality

Changed

- List changes to existing functionality

Removed

- List features or functionality removed

Fixed

- List features or functionality that has been fixed

---

## Checklist

- [ ] Add a short description of the changes. (will be used for public changelog)
- [ ] Fill out Added, Changed, Removed, Fixed and remove any unused lists (will be used for public changelog)
- [ ] Make sure both security and lint tests have passed since continue-on-error is enabled.
11 changes: 3 additions & 8 deletions src/js/3party/vimeo.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,8 @@ export default (function() {
var buttonImg = button.getElementsByTagName('img')[0];
buttonImg.src = buttonImg.src.includes('expand_more') ? expandLess : expandMore;
var transcriptSelect = document.getElementById(transcript.getTranscriptSelectId());
transcriptSelect.style.display = transcriptSelect.style.display === 'none' ? 'block' : 'none';
$(transcriptSelect).fadeToggle(250);
transcriptSelect.style.marginTop = '1rem';

var body = document.getElementById(transcriptContentId);
var iframe = document.getElementById(iframeId);
var bodyDisplayStyle = getComputedStyle(body).display;
Expand All @@ -346,19 +345,15 @@ export default (function() {
} else {
slideDownAndAdjustIframe(400, body, iframe);
}


event.preventDefault();
});

function slideUpAndAdjustIframe(duration, element, iframe) {
element.style.display = 'none';
element.classList.remove('uob-box');
$(element).slideToggle(250);
}

function slideDownAndAdjustIframe(duration, element, iframe) {
element.style.display = 'block';
element.classList.add('uob-box');
$(element).slideToggle(250);
}

return { transcriptArea: p, transcriptContentArea: e };
Expand Down
168 changes: 135 additions & 33 deletions src/js/account-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,34 @@ import { createApp } from 'vue';
import utilRoot from './utilRoot';

var udirDesignLoaded;

var themeCookieName = 'use_localhost_theme';

jQuery.extend({
getCookie: function (name) {
var value = '; ' + document.cookie;
var parts = value.split('; ' + name + '=');
if (parts.length === 2) return parts.pop().split(';').shift();
return null;
},

setCookie: function (name, value, days) {
var expires = '';
if (days) {
var date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
expires = '; expires=' + date.toUTCString();
}
document.cookie = name + '=' + value + expires + '; path=/';
},

deleteCookie: function (name) {
document.cookie =
name + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
},

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

// Handle Script loading
Expand All @@ -20,8 +42,8 @@ jQuery.extend({
if (
!done &&
(!this.readyState ||
this.readyState == "loaded" ||
this.readyState == "complete")
this.readyState == 'loaded' ||
this.readyState == 'complete')
) {
done = true;
if (callback) callback();
Expand All @@ -40,24 +62,103 @@ jQuery.extend({
});

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

var redirected = false;
var themeSettings = {
url: SERVER,
js: DESIGNJS,
css: DESIGNCSS,
};

var useLocalhostTheme = $.getCookie(themeCookieName) === 'true';
if (useLocalhostTheme) {
themeSettings.url = 'http://localhost:9000/';
themeSettings.css = 'kompetanseportalen-localhost.css';
themeSettings.js = 'kompetanseportalen-localhost.js';
console.log('Using localhost theme:', themeSettings);
} else {
console.log('Using default theme:', themeSettings);
}

var isBrandConfigPage =
window.location.pathname === '/accounts/1/brand_configs';
if (isBrandConfigPage) {
try {
if (isBrandConfigPage) {
var intervalTime = 1000;
var checkInterval;

function runWhenTemaVisible() {
var isThemeHeadingVisible = $("h1:contains('Tema')").is(':visible');

if (isThemeHeadingVisible) {
var content = $('#content');
if (content.length) {
var buttonWrapper = $(
'<div id="theme-toggle-wrapper" style="margin-bottom: 20px;display: flex;justify-content: flex-end;"></div>',
);

function getButtonLabel() {
var cookieValue = $.getCookie(themeCookieName);
return cookieValue === 'true'
? 'Switch to default theme'
: 'Switch to localhost theme';
}

var themeSwitchButton = $('<button>', {
class: 'Button Button--primary',
type: 'button',
text: getButtonLabel(),
click: function () {
var currentCookie = $.getCookie(themeCookieName);
if (currentCookie === 'true') {
$.deleteCookie(themeCookieName);
} else {
$.setCookie(themeCookieName, 'true', 15);
}

window.location.reload();
$(this).text(getButtonLabel());
},
});

buttonWrapper.append(themeSwitchButton);
content.prepend(buttonWrapper);
}

clearInterval(checkInterval);
} else {
console.log(
'<h1>Tema</h1> is still not visible. Checking again...',
);
}
}

checkInterval = setInterval(runWhenTemaVisible, intervalTime);
}
} catch (error) {
console.error('Error in brand config page', error);
}
}

// Redirect if necessary
if (document.location.pathname == "/search/all_courses" && document.location.search.includes('?enroll_code')) {
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")) {
} 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 */
} 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")) {
if (!document.location.search.includes('normalLogin=1')) {
if (document.getElementById('wrapper')) {
document.getElementById('wrapper').remove();
}
Expand All @@ -68,52 +169,53 @@ jQuery(document).ready(function ($) {
if (parent) {
parent.appendChild(login);
}
customLogin.mount("#login-component");
customLogin.mount('#login-component');
} else {
$(".ic-Login").show();
$("#f1_container").show(); // Small screens
$('.ic-Login').show();
$('#f1_container').show(); // Small screens
}
}
}
} else if (document.location.pathname == "/courses") {
} 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 == "/") {
} else if (document.location.pathname == '/') {
setTimeout(function () {
if (!$(".ic-DashboardCard__header_hero").length) {
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"/>
<img src="${themeSettings.url}bitmaps/nyinnlogging.png" width="70%" alt="Ny innloggingsskjerm"/>
</div>
`;
document.getElementById('dashboard-activity').insertAdjacentHTML('beforebegin', html);
document
.getElementById('dashboard-activity')
.insertAdjacentHTML('beforebegin', html);
}
}, 1000)
}, 1000);
}

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

var filename = SERVER + DESIGNCSS;
var filename = `${themeSettings.url}${themeSettings.css}`;

var fileref = document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
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)
$.getScript(`${themeSettings.url}${themeSettings.js}`);
};
document.getElementsByTagName('head')[0].appendChild(fileref);
} else {
console.log("Udir design already loaded.");
console.log('Udir design already loaded.');
}
}

});
Loading

0 comments on commit 989f10e

Please sign in to comment.