File "std-flashcards.min.js"

Path: /StudyIB/js/flashcards/std-flashcardsminjs
File size: 9.46 KB
MIME-type: text/plain
Charset: utf-8

 
Open Back
var nFlashcards=0,flashCards=[],click=0,id1=null,id2=null,hash1=null,hash2=null,subjectId=null,levels=null,mode=null,topics=null,limit=null,cardsReported=[],isAbleToSetAnAnswer=!1,correct=0,incorrect=0,event,nTimeToShow=0,count=1,numberOfFlashcards=0,data={},isEditor=!1,startTime=0,start=0,end=0,diff=0,timerID=0,fcMinW=670,fcMinH=390,fcControlsW=280;function showFlashcards(){$("#fc-viewer").hasClass("flipped")&&$("#fc-viewer").toggleClass("flipped");var data={ticket:$("#ticket").val(),"subject-id":subjectId,"level-ids":levels,"mode-game":mode,"topic-ids":topics,limit:limit};$.post("/pages/subjects/flashcards/flashcards.php?action=show-flashcards",data,(function(response){"1"==response.success?void 0===response.data||0==response.data?alert("No cards to load"):"Game"==mode?(loadGame(response.data,data),getScores(null)):(cardsData=response.data,nFlashcards=response.n_flashcards,currentPosition=0,(error=loadCard(currentPosition))?alert(error):saveStats(cardsData[currentPosition].card_id)):alert(response.msg)}),"json")}function loadGame(dataFromDB){for(var index=0;index<dataFromDB.length;index++){var fc,contentFront=['<div class="col-lg-4 col-md-6 col-sm-6">','<div class="panel panel-fcgame panel-default panel-default-fcgame flashcard shadow-bottom" data-hash="'+(fc=dataFromDB[index]).content_front.hashCode()+'" data-id="'+index+'">','<div class="panel-body text-center">','<div class="fc-text">'+fc.content_front+"</div>","</div>","</div>","</div>"],contentBack=['<div class="col-lg-4 col-md-6 col-sm-6">','<div class="panel panel-fcgame panel-default panel-default-fcgame flashcard reverse-flashcard shadow-bottom" data-hash="'+fc.content_back.hashCode()+'" data-id="'+index+'">','<div class="panel-body text-center">','<div class="fc-text">'+fc.content_back+"</div>","</div>","</div>","</div>"];flashCards.push(contentFront.join("")),flashCards.push(contentBack.join(""))}var fc;numberOfFlashcards=flashCards.length,nTimeToShow=parseInt(numberOfFlashcards)/12,shuffle(fc=flashCards.slice(0,12)),$("#fcgame-body .row-fluid .fc-content").empty(),$("#fcgame-body .row-fluid .fc-content").html(fc.join("")),$("#fcgame-viewer").modal("show")}function paintFlashcards(arrFlashcards,start,end){var delayInMilliseconds=600;++count<=nTimeToShow&&setTimeout((function(){var fc=arrFlashcards.slice(start,end),resizeElement;shuffle(fc),$("#fcgame-body .row-fluid .fc-content").empty(),$("#fcgame-body .row-fluid .fc-content").html(fc.join("")),resizeText($("#fc-content").find(".panel-body"))}),600)}function showResults(){setTimeout((function(){var finalTime=$("#chronometer").text()+$("#chronometer-msec").text();finalTime=finalTime.split(":");var minuts=parseInt(finalTime[0]),seconds=parseInt(finalTime[1]),mseconds=parseInt(finalTime[2]),dismiss=['<button type="button" class="close pull-right dismiss-modal-fcgame" data-dismiss="modal" aria-label="Close">','<span aria-hidden="true"><i class="fa fa-remove" style="color: black;"></i></span>',"</button>"],showResults=['<div style="padding-bottom: 15px;">','You have finished the set in <span class="time">'+minuts+"' "+seconds+"''</span> ",'with <span class="errors">'+incorrect+" errors.</span>","</div>"],showFc=flashCards.join("").replace(/<div class="col-lg-4 col-md-6 col-sm-6">/g,'<div class="col-lg-6 col-md-6 col-sm-6">'),resizeElement;$("#end-game-dismiss").html(dismiss.join("")),$("#end-game-results").html(showResults.join("")),$("#end-game-fc").html(showFc),$("#end-game").find(".flashcard").css("cursor","initial"),$("#end-game").fadeIn(),$("#end-game-results").addClass("magictime vanishIn"),resizeText($("#end-game").find(".panel-body")),flashCards=[]}),1e3)}function shuffle(array){var j,x,i;for(i=array.length-1;i>0;i--)j=Math.floor(Math.random()*(i+1)),x=array[i],array[i]=array[j],array[j]=x;return array}function chrono(){end=new Date,diff=end-start;var msec=(diff=new Date(diff)).getMilliseconds(),sec=diff.getSeconds(),min=diff.getMinutes(),hr=diff.getHours()-1;min<10&&(min="0"+min),sec<10&&(sec="0"+sec),msec<10?msec="00"+msec:msec<100&&(msec="0"+msec),document.getElementById("chronometer").innerHTML=min+":"+sec+":",document.getElementById("chronometer-msec").innerHTML=msec,timerID=setTimeout("chrono()",10)}function chronoStop(){clearTimeout(timerID)}function chronoStart(){start=new Date,chrono()}function chronoReset(){document.getElementById("chronometer").innerHTML="00:00:",document.getElementById("chronometer-msec").innerHTML="000",start=new Date}function resizeText(element){element.each((function(){for(var children=$(this).children();children.height()>$(this).height();)children.css("font-size",parseInt(children.css("font-size"))-1+"px")}))}function saveScores(dataResults){pageId="undefined"!=typeof pageId?pageId:null;var userId=$("#user-id").val(),dataToSave={ticket:$("#ticket").val(),"user-id":void 0===userId?0:userId,"subject-id":subjectId,"score-time":dataResults["score-time"],"score-errors":dataResults["score-errors"],topics:topics,levels:levels,nflashcards:limit,"page-id":pageId};$.post("/pages/subjects/flashcards/flashcards.php?action=save-scores",dataToSave,(function(response){"0"==response.success&&alert(response.msg),"2"==response.success&&console.log("Preview mode has been finished")}),"json")}function getScores(dataResults){var scoreTime=null!=dataResults?dataResults["score-time"]:dataResults,data={ticket:$("#ticket").val(),"subject-id":subjectId,"score-time":scoreTime,topics:topics,levels:levels,nflashcards:limit};$.post("/pages/subjects/flashcards/flashcards.php?action=get-scores",data,(function(response){if("0"==response.success&&alert(response.msg),null!=response.record){var bestRecord=response.record.split(":"),minuts=parseInt(bestRecord[0]),seconds=parseInt(bestRecord[1]),mseconds=parseInt(bestRecord[2]);$("#best-time").css("visibility","visible"),$("#best-record").text(minuts+"m "+seconds+"s "+mseconds+"ms")}else $("#best-time").css("visibility","hidden");null!=scoreTime&&response.score_percent>50&&setTimeout((function(){var scorePercent=100==response.score_percent?'<span style="color: green;"><strong>Congrats, you have reached the best punctuation of the game!</strong></span>':'You are better than <span style="color: dodgerblue;">'+response.score_percent+"%</span> of the users that played this game.";$("#end-game").find("#show-percent").html(scorePercent),$("#show-percent").addClass("magictime tinDownIn"),$("#show-percent").show()}),2e3)}),"json")}function saveStats(cardId){var data={ticket:$("#ticket").val(),"subject-id":subjectId,"card-id":cardId,notes:$(".card-notes").val()};$.post("/pages/subjects/flashcards/flashcards.php?action=save-stats",data,(function(response){"0"==response.success&&alert(response.msg)}),"json")}$(document).ready((function(){var fcViewer=$("#fc-viewer");setViewerSize(fcViewer),$(".show-flashcards").click((function(){subjectId=$(this).data("subject-id"),levels=$(this).data("levels"),mode=$(this).data("mode"),topics=$(this).data("topics"),limit=$(this).data("n-flashcards"),showFlashcards()})),$(".issue-description").on("keyup",(function(e){e.preventDefault(),$(this).closest(".report-problem").find(".send-report").toggleClass("disabled",!$(this).val().trim().length)})),$(".show-fc-info").on("click",(function(e){e.preventDefault(),fcViewer.find(".fc-info").fadeToggle("slow")})),flipCard(fcViewer),moveNextPreviousCard(fcViewer),shuffleCards(fcViewer),"undefined"!=typeof isMobileDevice&&isMobileDevice()&&swipeNextPreviousCard(new Hammer(document.querySelector(".fc-viewer-inner"))),markCardAsFavorite(fcViewer),markCardAsRight(fcViewer),markCardAsWrong(fcViewer),reportCardIssue(fcViewer),closeReportCardIssue(fcViewer),resetCardData(fcViewer),clearCardModal(fcViewer),sendCardReport(),saveCardNotes(),$("#fcgame-viewer").on("shown.bs.modal",(function(){resizeText($(".panel-body")),$("#end-game").hide()})),$("#fcgame-viewer").on("hidden.bs.modal",(function(){click=0,correct=0,incorrect=0,id1=null,id2=null,hash1=null,hash2=null,flashCards=[],chronoStop(),chronoReset(),$("#start-game").show(),$("#end-game").hide()})),$("#play-game").click((function(){chronoStart(),$("#start-game").fadeOut("slow")})),$("#cancel-game").click((function(){$("#fcgame-viewer").modal("hide")})),$("#fc-content").delegate(".flashcard","click",(function(){if(!$(this).hasClass("hide-correct")){var delayInMilliseconds=1e3,el;if(1===++click&&(id1=$(this).data("id"),hash1=$(this).data("hash")),2===click&&(id2=$(this).data("id"),hash2=$(this).data("hash")),click<=2)if($(this).addClass("yellow-flashcard"),2==click&&id1===id2&&hash1!==hash2){if((el=$(".yellow-flashcard")).addClass("green-flashcard"),el.removeClass("yellow-flashcard"),$(".hide-correct").off("click","**"),setTimeout((function(){$(".green-flashcard").addClass("hide-correct"),click=0,id1=null,id2=null,hash1=null,hash2=null}),100),6==++correct){var start=12*parseInt(count),end=parseInt(start)+12;if(end<=numberOfFlashcards)paintFlashcards(flashCards,start,end);else{count=1,$("#show-percent").removeClass("magictime tinDownIn"),$("#show-percent").hide(),chronoStop(),showResults();var dataResults=[];dataResults["score-errors"]=incorrect,dataResults["score-time"]=$("#chronometer").text()+$("#chronometer-msec").text(),setTimeout((function(){getScores(dataResults),saveScores(dataResults)}),500)}correct=0}}else if(2==click){var el;incorrect++,(el=$(".yellow-flashcard")).addClass("red-flashcard"),el.removeClass("yellow-flashcard"),setTimeout((function(){$(".flashcard").removeClass("red-flashcard"),click=0,id1=null,id2=null,hash1=null,hash2=null}),1e3)}}}))})),String.prototype.hashCode=function(){var hash=0,i,chr;if(0===this.length)return hash;for(i=0;i<this.length;i++)hash=(hash<<5)-hash+(chr=this.charCodeAt(i)),hash|=0;return hash};