/* For license terms, see /license.txt */
/**
* Whenever the cardgame.js file is included into the loaded JavaScript,
* search for the user picture in the left menu and add a div
* "enjoy-cardgame" to it to show a little drawing cards icon to enable
* this plugin
*/
$(document).ready(function ($) {
if (!document.getElementById('havedeckcardgame')) {
$('.sidebar .panel-body .img-circle').parent().parent().after('
')
} else {
$('.sidebar .panel-body .img-circle').parent().parent().after('')
}
})
/**
* This function inserts the element 'home-card' for the card game
* before the .page-content element on the page (the right side of the
* "my courses" page) only if the element with id 'home-card' does not exist
* yet.
*/
function installCardView () {
if (!document.getElementById('home-card')) {
var mess1 = $('#cardgamemessage').html()
var h = ''
h += ''
var panClass = 'pimg0' + $('#pancardgame').html()
// Setup the 3x5 table of images
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
'
h += '
' + mess1 + '
'
h += '
'
h += '
'
h += ''
$('.page-content').before(h)
} else {
$('#home-card').fadeToggle()
}
}
/**
* Animate the scissors
*/
function animationOpenCardView () {
$('#scissors').addClass('scissorsrightinitfinal')
setTimeout(function () {
$('#scissors').fadeOut()
$('.linescissors').fadeOut()
$('#messagePackDeck').css('display', 'none')
$('#messagePackDeck').removeClass('messagePackDeck')
}, 2600)
setTimeout(function () {
$('.cardgame-pack').addClass('cardgame-open')
$('.card-one').addClass('card-one-2')
}, 3000)
}
function cardOpenCardView () {
$('.card-one').removeClass('card-one-2')
setTimeout(function () {
$('.puzzlecardone').fadeIn()
randomOpenCardView()
}, 700)
}
function randomOpenCardView () {
var part = Math.floor(Math.random() * (15 - 1 + 1)) + 1
$('.puzzlecardone').css('display', 'block')
$('#scissors').fadeOut()
$('.linescissors').fadeOut()
$('#messagePackDeck').css('display', 'none')
$('#messagePackDeck').removeClass('messagePackDeck')
var memocardgame = $('#memocardgame').html()
var parts = memocardgame
var arrayOfStrings = parts.split(';')
var findDouble = false
for (var i = 0; i < arrayOfStrings.length; i++) {
var idpart = arrayOfStrings[i]
idpart = idpart.replace('!!', '')
idpart = idpart.replace('!', '')
idpart = idpart.replace('!', '')
idpart = idpart.replace(';', '')
$('#puzzlepart' + idpart).css('opacity', 0)
if (part == idpart) {
findDouble = true
}
}
if (findDouble) {
part = Math.floor(Math.random() * (15 - 1 + 1)) + 1
}
if (memocardgame.indexOf('!' + part + ';') != -1) {
part = Math.floor(Math.random() * (15 - 1 + 1)) + 1
}
if (memocardgame.indexOf('!' + part + ';') != -1) {
part = Math.floor(Math.random() * (15 - 1 + 1)) + 1
}
if (memocardgame.indexOf('!' + part + ';') != -1) {
var mess2 = $('#cardgameloose').html()
$('#messagePackDeck').html(mess2)
$('#messagePackDeck').css('display', 'block')
$('#messagePackDeck').css('backgroundColor', 'red')
$('#messagePackDeck').addClass('messagePackDeckBottom')
var lk = $('#linkcardgame').html()
$.ajax({ url: lk + '?loose=1' }).done(function () { })
} else {
var lk = $('#linkcardgame').html()
$.ajax({ url: lk + '?part=' + part }).done(function () { })
setTimeout(function () {
$('#puzzlepart' + part).addClass('puzzlepartstar')
}, 600)
setTimeout(function () {
$('#puzzlepart' + part).css('opacity', 0)
}, 1200)
setTimeout(function () {
var mess2 = $('#cardgameengage').html()
$('#messagePackDeck').html(mess2)
$('#messagePackDeck').css('display', 'block')
$('#messagePackDeck').addClass('messagePackDeckBottom')
$('#viewDeckBottom').css('display', 'block')
}, 1500)
}
$('#plugin-cardgame-icon').removeClass('enjoy-cardgame-active')
$('#plugin-cardgame-icon').addClass('enjoy-cardgame')
}
/**
* This function adds the cardgame area block (in invisible state), then
* changes the visibility of blocks inside the puzzle area to show them
*/
function onlyOpenCardView () {
installCardView();
var memocardgame = $('#memocardgame').html()
$('.puzzlecardone').css('display', 'block')
$('#scissors').css('display', 'none')
$('.linescissors').css('display', 'none')
$('#messagePackDeck').css('display', 'none')
$('#messagePackDeck').removeClass('messagePackDeck')
var lk = $('#linkcardgame').html()
var parts = memocardgame
// alert(parts);
var arrayOfStrings = parts.split(';')
for (var i = 0; i < arrayOfStrings.length; i++) {
var idpart = arrayOfStrings[i]
idpart = idpart.replace('!!', '')
idpart = idpart.replace('!', '')
idpart = idpart.replace('!', '')
idpart = idpart.replace(';', '')
$('#puzzlepart' + idpart).css('opacity', 0)
}
var mess2 = $('#cardgameengage').html()
$('#messagePackDeck').html(mess2)
$('#messagePackDeck').css('display', 'block')
$('#messagePackDeck').addClass('messagePackDeckBottom')
$('#viewDeckBottom').css('display', 'block')
}
function minimizePuzzle () {
$('.puzzlecardone').addClass('puzzleMin')
setTimeout(function () {
$('.puzzleMinOther').css('display', 'block')
var panNumber = parseInt($('#pancardgame').html())
if (panNumber > 1) {
$('#puzzleMinOther1').addClass('pimg01')
}
if (panNumber > 2) {
$('#puzzleMinOther2').addClass('pimg02')
}
if (panNumber > 3) {
$('#puzzleMinOther3').addClass('pimg03')
}
if (panNumber > 4) {
$('#puzzleMinOther4').addClass('pimg04')
}
}, 1000)
}