123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- /* 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('<div id="plugin-cardgame-icon" class="enjoy-cardgame" onClick="onlyOpenCardView();" ></div>')
- } else {
- $('.sidebar .panel-body .img-circle').parent().parent().after('<div id="plugin-cardgame-icon" class="enjoy-cardgame-active" onClick="installCardView()" ></div>')
- }
- })
- /**
- * This function inserts the <article> 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 = '<article id="home-card" style="border:solid 1px gray;" >'
- h += '<div class="cardgame-pack" >'
- var panClass = 'pimg0' + $('#pancardgame').html()
- // Setup the 3x5 table of images
- h += '<div class="puzzlecardone ' + panClass + '" >'
- h += '<div id="puzzlepart1" class="puzzlepart1" ></div>'
- h += '<div id="puzzlepart2" class="puzzlepart1" ></div>'
- h += '<div id="puzzlepart3" class="puzzlepart1" ></div>'
- h += '<div id="puzzlepart4" class="puzzlepart1" ></div>'
- h += '<div id="puzzlepart5" class="puzzlepart1" ></div>'
- h += '<div id="puzzlepart6" class="puzzlepart1" ></div>'
- h += '<div id="puzzlepart7" class="puzzlepart1" ></div>'
- h += '<div id="puzzlepart8" class="puzzlepart1" ></div>'
- h += '<div id="puzzlepart9" class="puzzlepart1" ></div>'
- h += '<div id="puzzlepart10" class="puzzlepart1" ></div>'
- h += '<div id="puzzlepart11" class="puzzlepart1" ></div>'
- h += '<div id="puzzlepart12" class="puzzlepart1" ></div>'
- h += '<div id="puzzlepart13" class="puzzlepart1" ></div>'
- h += '<div id="puzzlepart14" class="puzzlepart1" ></div>'
- h += '<div id="puzzlepart15" class="puzzlepart1" ></div>'
- h += '</div>'
- h += '<div id="puzzleMinOther1" class="puzzleMinOther" ></div>'
- h += '<div id="puzzleMinOther2" class="puzzleMinOther" ></div>'
- h += '<div id="puzzleMinOther3" class="puzzleMinOther" ></div>'
- h += '<div id="puzzleMinOther4" class="puzzleMinOther" ></div>'
- h += '<div class="card-one" onclick="cardOpenCardView();" ></div>'
- h += '<div class="linescissors" ></div>'
- h += '<div id="viewDeckBottom" class="viewDeckBottom" onClick="minimizePuzzle()" ></div>'
- h += '<div id="messagePackDeck" class="messagePackDeck" >' + mess1 + '</div>'
- h += '<div id="scissors" class="scissorsrightinit" onclick="animationOpenCardView();" ></div>'
- h += '</div>'
- h += '</article>'
- $('.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)
- }
|