/* For licensing terms, see /license.txt */
/**
* When the document is ready, do some preparation for the dictionary H5P content type elements
*/
$(document).ready(function () {
var u = window.top.location.href
if (u.indexOf('action=edit') == -1) {
$('#dictionary').css('display', 'none')
var btn = ''
btn += 'Create Page '
//$("#dictionary").parent().prepend(btn);
}
$('#dictionary_title').parent().parent().css('display', 'none')
$('#dictionary_node_type').parent().parent().css('display', 'none')
$('#dictionary_submit').parent().parent().css('display', 'none')
$('#dictionary_descript').parent().parent().css('display', 'none')
$('#dictionary_terms_a').parent().parent().css('display', 'none')
$('#dictionary_terms_b').parent().parent().css('display', 'none')
$('#dictionary_terms_c').parent().parent().css('display', 'none')
$('#dictionary_terms_d').parent().parent().css('display', 'none')
$('#dictionary_terms_e').parent().parent().css('display', 'none')
$('#dictionary_terms_f').parent().parent().css('display', 'none')
$('#dictionary_opt_1').parent().parent().css('display', 'none')
$('#dictionary_opt_2').parent().parent().css('display', 'none')
$('#dictionary_opt_3').parent().parent().css('display', 'none')
$('#dictionary_submit').parent().prepend('' + $('#h5p_cancel').html() + ' ')
$('#dictionary_submit').click(function (e) {
var pagetype = $('#dictionary_node_type').val()
if (pagetype == 'dialogcard') {
if (controlsFieldsdialogcard() == false) {
e.preventDefault()
}
}
var title = $('#dictionary_title').val()
if (title == '') {
$('#dictionary_title').css('background', 'pink')
e.preventDefault()
} else {
if (u.indexOf('action=edit') == -1) {
if (pagetype == '') {
e.preventDefault()
}
}
}
})
})
/**
* Add an H5P option to the breadcrumb bar
*/
$(document).ready(function () {
var menuBc = '
').dialog({
modal: true, width: '80%', title: 'Select your file', zIndex: 99999,
create: function (event, ui) {
$(this).elfinder({
resizable: false,
url: '../../main/inc/lib/elfinder/connectorAction.php',
commandsOptions: {
getfile: {
oncomplete: 'destroy'
}
}, getFileCallback: function (file) {
$('#' + targetInputImg).val(file.url)
var imgBlok = targetInputImg.replace('imagecard', 'imageBlockPreview')
var imgPath = $('#' + targetInputImg).val()
$('.' + imgBlok).css('background-image', 'url(' + imgPath + ')')
jQuery('a.ui-dialog-titlebar-close[role="button"]').click()
jQuery('button.ui-dialog-titlebar-close[role="button"]').click()
}
}).elfinder('instance')
}
})
}
/**
* Get an element by Id
* @param n
* @returns {string|*}
*/
function getbyelem (n) {
if (document.getElementById(n)) {
var tagName = document.getElementById(n).tagName
if (tagName == 'SELECT') {
var get_id = document.getElementById(n)
var resultselect = get_id.options[get_id.selectedIndex].value
//console.log(resultselect);
return resultselect
}
if (tagName == 'INPUT') {
return document.getElementById(n).value
}
if (tagName == 'TEXTAREA') {
var ct = document.getElementById(n).value
ct = ct.replace('\n', '
')
return ct
}
} else {
return '-'
}
}
/**
* Check the given radio button
* @param r
*/
function checkRadio (r) {
$('#rad' + r).prop('checked', true)
$('#dictionary_node_type').val(r)
}
/**
* Show the interface for the words match H5P element type
*/
function interfacewordsmatch () {
$('.dataTables_wrapper').css('display', 'none')
$('#dictionary_node_type').parent().parent().css('display', 'none')
$('#nodeselection').parent().parent().css('display', 'none')
$('#dictionary_title').parent().parent().css('display', '')
$('#dictionary_title').parent().append('
' + $('#h5p_title_help').html() + ' ')
$('#dictionary_submit').parent().parent().css('display', '')
$('#dictionary_descript').parent().parent().css('display', '')
$('#dictionary_descript').parent().append('
' + $('#h5p_descr_help').html() + ' ')
$('#dictionary_descript').val($('#h5p_wordsmatch_tutor').html())
$('#dictionary').css('display', '')
$('#addElement').css('display', 'none')
$('#nodeselection').css('display', 'none')
$('#dictionary_terms_a').parent().parent().css('display', '')
$('#dictionary_terms_a').val($('#h5p_wordsmatch_load').html())
$('#dictionary_terms_a').parent().append('
' + $('#h5p_wordsmatch_help').html() + ' ')
interfaceNameLabel('terms_a', $('#h5p_wordsmatch_term_a').html())
}
/**
* Show the interface for the Name Label H5P element type
*/
function interfaceNameLabel (idjq, name) {
$('label').each(function (index) {
var forSrcAttr = $(this).attr('for')
if (typeof forSrcAttr === 'undefined') {
forSrcAttr = ''
}
if (forSrcAttr.indexOf('_' + idjq) != -1) {
$(this).html(name)
}
})
}
/**
* Show the interface for the Memory H5P element type
*/
function interfacememory () {
interfacedialogcard()
}
/**
* Show the interface for the Dialog Card H5P element type
*/
function interfacedialogcard () {
$('.dataTables_wrapper').css('display', 'none')
$('#dictionary_node_type').parent().parent().css('display', 'none')
$('#nodeselection').parent().parent().css('display', 'none')
$('#dictionary_title').parent().parent().css('display', '')
$('#dictionary_title').parent().append('
' + $('#h5p_title_help').html() + ' ')
$('#dictionary_submit').parent().parent().css('display', '')
$('#dictionary_descript').parent().parent().css('display', '')
$('#dictionary_descript').parent().append('
' + $('#h5p_dialogcard_help').html() + ' ')
$('#dictionary_descript').val($('#h5p_dialogcard_tutor').html())
$('#dictionary').css('display', '')
$('#addElement').css('display', 'none')
$('#nodeselection').css('display', 'none')
$('#dictionary_terms_a').parent().parent().css('display', '')
var dterma = $('#dictionary_terms_a').val()
$('#dictionary_terms_a').parent().append(interfaceCard('a', dterma))
interfaceNameLabel('terms_a', $('#h5p_dialogcard_term_a').html())
$('#dictionary_terms_b').parent().parent().css('display', '')
var dtermb = $('#dictionary_terms_b').val()
$('#dictionary_terms_b').parent().append(interfaceCard('b', dtermb))
interfaceNameLabel('terms_b', '')
$('#dictionary_terms_c').parent().parent().css('display', '')
var dtermc = $('#dictionary_terms_c').val()
$('#dictionary_terms_c').parent().append(interfaceCard('c', dtermc))
interfaceNameLabel('terms_c', '')
$('#dictionary_terms_d').parent().parent().css('display', '')
var dtermd = $('#dictionary_terms_d').val()
$('#dictionary_terms_d').parent().append(interfaceCard('d', dtermd))
interfaceNameLabel('terms_d', '')
$('#dictionary_terms_e').parent().parent().css('display', '')
var dterme = $('#dictionary_terms_e').val()
$('#dictionary_terms_e').parent().append(interfaceCard('e', dterme))
interfaceNameLabel('terms_e', '')
$('#dictionary_terms_f').parent().parent().css('display', '')
var dtermf = $('#dictionary_terms_f').val()
$('#dictionary_terms_f').parent().append(interfaceCard('f', dtermf))
interfaceNameLabel('terms_f', '')
plusDialogCard()
setTimeout(function () {
interfaceEvents(dterma, 'a')
interfaceEvents(dtermb, 'b')
interfaceEvents(dtermc, 'c')
interfaceEvents(dtermd, 'd')
interfaceEvents(dterme, 'e')
interfaceEvents(dtermf, 'f')
displayInterfaceCardAll()
}, 200)
setTimeout(function () {
compileInterfaceCardAll()
}, 500)
}
/**
* Add a dialog card
*/
function plusDialogCard () {
var h = '
'
$('#dictionary_terms_f').parent().append(h)
}
/**
* Add a dialog card process
*/
function plusDialogCardProcess () {
if (lastCardBlockId == 'a') {
$('.cardBlockEditb').css('display', 'block')
$('#outrecto' + 'b').val('?')
}
if (lastCardBlockId == 'b') {
$('.cardBlockEditc').css('display', 'block')
$('#outrecto' + 'c').val('?')
}
if (lastCardBlockId == 'c') {
$('.cardBlockEditd').css('display', 'block')
$('#outrecto' + 'd').val('?')
}
if (lastCardBlockId == 'd') {
$('.cardBlockEdite').css('display', 'block')
$('#outrecto' + 'e').val('?')
}
if (lastCardBlockId == 'e') {
$('.cardBlockEditf').css('display', 'block')
$('#outrecto' + 'f').val('?')
}
displayInterfaceCardAll()
}
/**
* Show the interface for the Card H5P element type
*/
function interfaceCard (letterId, collTerms) {
$('#dictionary_terms_' + letterId).css('display', 'none')
$('#dictionary_terms_' + letterId).parent().parent().css('margin-bottom', '0px')
var h = '
'
h += '
'
if (GlobalTypeNode == 'memory') {
h += '
'
} else {
h += '
'
}
h += '
Back : '
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
if (letterId != 'a') {
h += '
'
}
h += '
'
return h
}
/**
* Show the interface for the Events H5P element type
*/
function interfaceEvents (collTerms, let) {
if (collTerms.indexOf('|') == -1 || collTerms == '') {
collTerms = collTerms + '||'
}
var parts = collTerms.split('|')
$('#imagecard' + let).val(parts[2])
$('.imageBlockPreview' + let).css('background-image', 'url(' + parts[2] + ')')
var editor1 = window.pell.init({
element: document.getElementById('recto' + let),
defaultParagraphSeparator: 'p',
onChange: function (html) {
$('#outrecto' + let).val(html)
}
})
editor1.content.innerHTML = parts[0]
$('#outrecto' + let).val(parts[0])
var editor2 = window.pell.init({
element: document.getElementById('verso' + let),
defaultParagraphSeparator: 'p',
onChange: function (html) {
$('#outverso' + let).val(html)
}
})
if (parts[1] == 'undefined') {
parts[1] == ''
}
editor2.content.innerHTML = parts[1]
$('#outverso' + let).val(parts[1])
}
/**
* Prepare the interface for all 6 cards in a Card H5P element type
*/
function compileInterfaceCardAll () {
compileInterfaceCard('a')
compileInterfaceCard('b')
compileInterfaceCard('c')
compileInterfaceCard('d')
compileInterfaceCard('e')
compileInterfaceCard('f')
setTimeout(function () {compileInterfaceCardAll()}, 300)
}
var lastCardBlockId = 'b'
/**
* Display the interface for all 6 cards in a Card H5P element type
*/
function displayInterfaceCardAll () {
displayInterfaceCard('b')
displayInterfaceCard('c')
displayInterfaceCard('d')
displayInterfaceCard('e')
displayInterfaceCard('f')
$('.deleteBlockCard' + lastCardBlockId).css('display', 'block')
}
/**
* Delete the interface of a Card H5P element type
*/
function deleteInterfaceCard (letterId) {
$('.cardBlockEdit' + letterId).css('display', 'none')
$('.deleteBlockCard' + letterId).css('display', 'none')
$('#outrecto' + letterId).val('')
displayInterfaceCardAll()
}
/**
* Show the interface for the words match H5P element type
*/
function displayInterfaceCard (letterId) {
var rectoRef = $('#outrecto' + letterId).val()
if (rectoRef != '') {
$('.cardBlockEdit' + letterId).css('display', 'block')
$('.deleteBlockCard' + letterId).css('display', 'none')
lastCardBlockId = letterId
} else {
$('.cardBlockEdit' + letterId).css('display', 'none')
}
}
/**
* Prepae the interface for the Card H5P element type
*/
function compileInterfaceCard (letterId) {
var rectoRef = $('#outrecto' + letterId).val()
var versoRef = $('#outverso' + letterId).val()
var imagecardRef = $('#imagecard' + letterId).val()
if (imagecardRef == 'img/' || imagecardRef == '' || imagecardRef == 'dialogcard.jpg') {
imagecardRef = 'dialogcard.jpg'
$('#imagecard' + letterId).val('dialogcard.jpg')
$('.imageBlockPreview' + letterId).css('background-image', 'url(resources/img/' + imagecardRef + ')')
}
var fullStr = rectoRef + '|' + versoRef + '|' + imagecardRef
$('#dictionary_terms_' + letterId).val(fullStr)
}
/**
* Mark the cards depending on the answer
*/
function controlsFieldsdialogcard () {
var b = true
var rectoRef = $('#outrectoa').val()
if (rectoRef == '') {
b = false
$('#rectoa').css('background', 'pink')
} else {
$('#rectoa').css('background', 'white')
}
var versoRef = $('#outversoa').val()
if (versoRef == '') {
b = false
$('#versoa').css('background', 'pink')
} else {
$('#versoa').css('background', 'white')
}
return b
}
/**
* Show the interface for the drag-the-words H5P element type
*/
function interfacedragthewords () {
$('.dataTables_wrapper').css('display', 'none')
$('#dictionary_node_type').parent().parent().css('display', 'none')
$('#nodeselection').parent().parent().css('display', 'none')
$('#dictionary_title').parent().parent().css('display', '')
$('#dictionary_title').parent().append('
' + $('#h5p_title_help').html() + ' ')
$('#dictionary_submit').parent().parent().css('display', '')
$('#dictionary_descript').parent().parent().css('display', '')
$('#dictionary_descript').parent().append('
' + $('#h5p_descr_help').html() + ' ')
$('#dictionary_descript').val($('#h5p_dragthewords_tutor').html())
$('#dictionary').css('display', '')
$('#addElement').css('display', 'none')
$('#nodeselection').css('display', 'none')
$('#dictionary_terms_a').parent().parent().css('display', '')
$('#dictionary_terms_a').val($('#h5p_dragthewords_load').html())
$('#dictionary_terms_a').parent().append('
' + $('#h5p_dragthewords_help').html() + ' ')
}
/**
* Show the interface for the mark-the-words H5P element type
*/
function interfacemarkthewords () {
$('.dataTables_wrapper').css('display', 'none')
$('#dictionary_node_type').parent().parent().css('display', 'none')
$('#nodeselection').parent().parent().css('display', 'none')
$('#dictionary_title').parent().parent().css('display', '')
$('#dictionary_title').parent().append('
' + $('#h5p_title_help').html() + ' ')
$('#dictionary_submit').parent().parent().css('display', '')
$('#dictionary_descript').parent().parent().css('display', '')
$('#dictionary_descript').parent().append('
' + $('#h5p_descr_help').html() + ' ')
$('#dictionary_descript').val($('#h5p_markthewords_tutor').html())
$('#dictionary').css('display', '')
$('#addElement').css('display', 'none')
$('#nodeselection').css('display', 'none')
$('#dictionary_terms_a').parent().parent().css('display', '')
$('#dictionary_terms_a').val($('#h5p_markthewords_load').html())
$('#dictionary_terms_a').parent().append('
' + $('#h5p_markthewords_help').html() + ' ')
interfaceNameLabel('terms_a', $('#h5p_markthewords_term_a').html())
}
/**
* Show the interface for the guess-the-answer H5P element type
*/
function interfaceguesstheanswer () {
$('.dataTables_wrapper').css('display', 'none')
$('#dictionary_node_type').parent().parent().css('display', 'none')
$('#nodeselection').parent().parent().css('display', 'none')
$('#dictionary_title').parent().parent().css('display', '')
$('#dictionary_title').parent().append('
' + $('#h5p_title_help').html() + ' ')
$('#dictionary_submit').parent().parent().css('display', '')
$('#dictionary_descript').parent().parent().css('display', '')
$('#dictionary_descript').parent().append('
' + $('#h5p_descr_help').html() + ' ')
$('#dictionary_descript').val($('#h5p_guesstheanswer_tutor').html())
$('#dictionary').css('display', '')
$('#addElement').css('display', 'none')
$('#nodeselection').css('display', 'none')
$('#dictionary_terms_a').parent().parent().css('display', '')
$('#dictionary_terms_a').val($('#h5p_guesstheanswer_load').html())
$('#dictionary_terms_a').parent().append('
' + $('#h5p_guesstheanswer_help').html() + ' ')
$('#dictionary_terms_b').parent().parent().css('display', '')
var im = '
'
$('#dictionary_terms_b').parent().append('
' + im + '
')
$('#dictionary_terms_c').parent().parent().css('display', '')
interfaceNameLabel('terms_a', $('#h5p_guesstheanswer_term_a').html())
interfaceNameLabel('terms_b', $('#h5p_guesstheanswer_term_b').html())
interfaceNameLabel('terms_c', $('#h5p_guesstheanswer_term_c').html())
setTimeout(function () {
overviewguesstheanswer()
}, 500)
}
/**
* Show an overview of the guess-the-answer H5P element type
*/
function overviewguesstheanswer () {
var imagecardRef = $('#dictionary_terms_b').val()
if (imagecardRef == 'img/' || imagecardRef == '' || imagecardRef == 'dialogcard.jpg') {
imagecardRef = 'resources/img/dialogcard.jpg'
}
$('.imageBlockPreviewLarge').css('background-image', 'url(' + imagecardRef + ')')
setTimeout(function () {
overviewguesstheanswer()
}, 500)
}