-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #326 from matematikk-mooc/KURSP-902-uob-tabs
KURSP-902: uob-tabs and mark-as-done button
- Loading branch information
Showing
10 changed files
with
330 additions
and
2,710 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import '../../vue/design/re-styles/buttons.scss'; | ||
|
||
export default (function () { | ||
return { | ||
replaceMarkAsDone: function () { | ||
|
||
const originalMarkAsDoneButton = document.querySelector('#mark-as-done-checkbox'); | ||
|
||
if (!originalMarkAsDoneButton) { | ||
return; | ||
} | ||
|
||
const notCompletedContent = `<span class="mark-done-labels"><img src="${SERVER}vector_images/markasdone.svg"/><p>Merk som ferdig</p></span>`; | ||
const completedContent = `<span class="mark-done-labels"><img src="${SERVER}vector_images/markasdonecompleted.svg"/><p>Ferdig</p></span>`; | ||
|
||
const attributes = Array.from(originalMarkAsDoneButton.attributes).reduce((acc, attr) => { | ||
if (attr.name !== 'class') { | ||
acc[attr.name] = attr.value; | ||
} | ||
return acc; | ||
}, {}); | ||
|
||
let newMarkAsDoneButton = document.createElement('button'); | ||
newMarkAsDoneButton.classList.add('custom-button'); | ||
newMarkAsDoneButton.classList.add('custom-mark-as-done-checkbox'); | ||
|
||
for (const [attr, value] of Object.entries(attributes)) { | ||
newMarkAsDoneButton.setAttribute(attr, value); | ||
if(attr === 'data-is-checked' && value === 'true') { | ||
newMarkAsDoneButton.classList.add('custom-mark-as-done-completed'); | ||
newMarkAsDoneButton.setAttribute('completed', 'true') | ||
newMarkAsDoneButton.innerHTML = completedContent | ||
} | ||
else if(attr === 'data-is-checked' && value === 'false') { | ||
newMarkAsDoneButton.innerHTML = notCompletedContent | ||
} | ||
} | ||
|
||
newMarkAsDoneButton.onclick = ((event) => { | ||
console.log(event) | ||
if(newMarkAsDoneButton.getAttribute('completed') === 'true') { | ||
newMarkAsDoneButton.setAttribute('completed', 'false'); | ||
newMarkAsDoneButton.classList.remove('custom-mark-as-done-completed'); | ||
newMarkAsDoneButton.innerHTML = notCompletedContent | ||
} | ||
else{ | ||
newMarkAsDoneButton.setAttribute('completed', 'true'); | ||
newMarkAsDoneButton.classList.add('custom-mark-as-done-completed'); | ||
newMarkAsDoneButton.innerHTML = completedContent | ||
|
||
} | ||
}) | ||
originalMarkAsDoneButton.parentNode.replaceChild(newMarkAsDoneButton, originalMarkAsDoneButton); | ||
|
||
}, | ||
|
||
|
||
} | ||
|
||
})(); | ||
|
||
//Rediger | ||
// let editButton = document.getElementsByClassName("btn edit-wiki")[0]; | ||
//Publisert | ||
// let publishButton = document.getElementsByClassName("btn btn-published")[0]; | ||
//Avpublisert | ||
// let unpublishButton = document.getElementsByClassName("btn btn-unpublished")[0]; | ||
//Studentvisning | ||
// const studentViewButton = document.getElementById('easy_student_view'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import '../../vue/design/re-styles/tabs.scss'; | ||
export default (function () { | ||
|
||
var strSetNum = 0; | ||
function transformTabs(){ | ||
onElementRendered('#content .user_content.enhanced,#content .show-content.enhanced', | ||
function($content) { | ||
// Store references to the active tab and pane | ||
var activeTab = null; | ||
var activePane = null; | ||
|
||
var tables = document.getElementsByTagName('table'); | ||
|
||
for (var i = 0; i < 10; i++) { | ||
var table = null; | ||
for (var j = 0; j < tables.length; j++) { | ||
let cell = tables[j].querySelectorAll('tbody > tr > td')[0]; | ||
let celltext = cell.textContent.trim(); | ||
if (celltext.includes("[uob-tabs]")) { | ||
table = tables[j]; | ||
} | ||
} | ||
|
||
if (!table) { | ||
break; | ||
} | ||
|
||
var customSegments = document.createElement('div'); | ||
customSegments.className = 'custom-segments'; | ||
customSegments.setAttribute('id', 'custom-segments' + i); | ||
var ul = document.createElement('ul'); | ||
var div = document.createElement('div'); | ||
div.className = 'custom-segments__tabHeaders'; | ||
ul.className = 'custom-segments__segments'; | ||
div.appendChild(ul); | ||
customSegments.appendChild(div); | ||
strSetNum++; | ||
|
||
var tds = table.querySelectorAll('td'); | ||
for (var k = 1; k < tds.length; k++) { | ||
var strAnchor = 'set' + strSetNum + 'tab' + Math.floor(k / 2); | ||
|
||
if (k % 2 === 0) { | ||
var li = document.createElement('li'); | ||
li.className = 'custom-segments__segment'; | ||
var a = document.createElement('a'); | ||
a.href = '#' + strAnchor; | ||
a.innerHTML = tds[k].textContent; | ||
|
||
// Add a click event listener to the tab | ||
li.addEventListener('click', function (event) { | ||
event.preventDefault(); | ||
|
||
var iframes = document.getElementsByTagName('iframe'); | ||
var ready = { | ||
context: 'h5p', | ||
action: 'ready' | ||
}; | ||
var resize = { | ||
context: 'h5p', | ||
action: 'resize' | ||
}; | ||
|
||
for (var i = 0; i < iframes.length; i++) { | ||
if (iframes[i].src.indexOf('h5p') !== -1) { | ||
iframes[i].contentWindow.postMessage(ready, '*'); | ||
iframes[i].contentWindow.postMessage(resize, '*'); | ||
}; | ||
} | ||
|
||
// Deactivate the previously active tab and pane | ||
if (activeTab) { | ||
activeTab.classList.remove('active'); | ||
} | ||
if (activePane) { | ||
activePane.classList.remove('active'); | ||
} | ||
|
||
|
||
// Activate the current tab and pane | ||
activeTab = this; | ||
activePane = document.getElementById(this.firstChild.getAttribute('href').substring(1)); | ||
activeTab.classList.add('active'); | ||
activePane.classList.add('active'); | ||
}); | ||
|
||
li.appendChild(a); | ||
ul.appendChild(li); | ||
} | ||
|
||
if (k % 2 === 1) { | ||
var pane = document.createElement('div'); | ||
pane.className = 'custom-segments__pane'; | ||
pane.setAttribute('id', strAnchor); | ||
let child = tds[k].innerHTML; | ||
pane.innerHTML = child; | ||
customSegments.appendChild(pane); | ||
|
||
// Initially, activate the first tab and pane | ||
if (Math.floor(k / 2) == 1) { | ||
pane.classList.add('active'); | ||
li.classList.add('active'); | ||
activeTab = li | ||
activePane = pane; | ||
|
||
} | ||
} | ||
} | ||
|
||
table.parentNode.insertBefore(customSegments, table); | ||
table.remove(); | ||
|
||
|
||
}}); | ||
} | ||
function onElementRendered(selector, cb, _attempts) { | ||
var el = $(selector); | ||
_attempts = ++_attempts || 1; | ||
if (el.length) return cb(el); | ||
if (_attempts >= 60) return; | ||
|
||
setTimeout(function() { | ||
onElementRendered(selector, cb, _attempts); | ||
}, 200); | ||
} | ||
|
||
function onPage(regex, fn) { | ||
if (location.pathname.match(regex)) fn(); | ||
} | ||
return { | ||
init: function() { | ||
// Add UoB enhancements to rich content displayed in courses. | ||
onPage(/\/(courses|groups)\/\d+/, function() { | ||
transformTabs(); | ||
}); | ||
} | ||
}; | ||
|
||
|
||
})(); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.