@ -21,7 +21,7 @@ var sankoreLang = {
answer : "Ceci est une réponse possible" ,
q : "Q" ,
add _new _question : " Ajouter une nouvelle question ..." ,
options : "O ptions" ,
options : "Les o ptions" ,
close : "Fermer" ,
delete _question : "Supprimer la question" ,
delete _answer : "Supprimer la proposition" ,
@ -40,28 +40,8 @@ var sankoreLang = {
slate : "ardoise" ,
pad : "tablette" ,
none : "aucun" ,
help : "Aide" ,
help _content : "<p><h2>Choisir</h2></p>" +
"<p><h3>Question à choix multiples (QCM).</h3></p>" +
"<p>Une question est posée avec plusieurs choix de réponses possibles. Le but est de choisir la bonne réponse.</p>" +
"<p>Le bouton “Recharger” réinitialise les exercices.</p>" +
"<p>Le bouton “Modifier” vous permet :</p>" +
"<ul><li>de choisir le thème de l’interactivité : tablette, ardoise ou aucun (par défaut aucun),</li>" +
"<li>de modifier un exercice ou d’en créer de nouveaux dans la même activité.</li></ul>" +
"<p>En mode édition, pour créer un nouvel exercice, cliquez sur “Ajouter une nouvelle question …”, puis.</p>" +
"<ul><li>insérez la question en cliquant sur le champ de texte “Saisir la question ici ...”,</li>" +
"<li>cliquez sur ”Options” pour choisir l’affichage des propositions (une seule bonne réponse, plusieurs bonnes réponses, liste déroulante). Cliquez sur “Fermer”,</li>" +
"<li>cliquez sur ”Ajouter une proposition” et saisissez la proposition dans le champ de texte,</li>" +
"<li>définissez la ou les propositions correctes en cliquant sur la case à cocher à gauche des bonnes réponses.</li>" +
"<li>Pour supprimer une proposition, cliquez sur la croix située à droite de celle-ci.</li></ul>" +
"<p>Pour supprimer un exercice, cliquez sur la croix à droite du numéro de ”Options”.</p>" +
"<p>Le bouton “Afficher” vous permet d’utiliser l’activité.</p>"
help : "aide" ,
help _content : "Ceci est un exemple de contenu de l'aide ..."
} ;
var questionArray ;
@ -101,23 +81,26 @@ function init(){
//import saved data
if ( window . sankore ) {
if ( sankore . preference ( "qstArrayData" , "" ) && sankore . preference ( "qstArrayData" , "" ) != "[]" ) {
questionArray = jQuery . parseJSON ( sankore . preference ( "qstArrayData" , "" ) ) ;
for ( var i in questionArray ) {
addQstBlock ( questionArray [ i ] . id , questionArray [ i ] . text , questionArray [ i ] . type , "style='display: none;'" ) ;
for ( var j in questionArray [ i ] . answers )
addAnsBlock ( questionArray [ i ] . answers [ j ] . id , questionArray [ i ] . id , questionArray [ i ] . answers [ j ] . text , true , questionArray [ i ] . rightAns , questionArray [ i ] . type ) ;
}
displayData ( true ) ;
}
else {
displayData ( false ) ;
begin = false ;
if ( sankore . preference ( "qstArrayData" , "" ) && sankore . preference ( "qstArrayData" , "" ) != "[]" )
questionArray = jQuery . parseJSON ( sankore . preference ( "qstArrayData" , "" ) ) ;
else
questionArray = jQuery . parseJSON ( '[{"text":"' + sankoreLang . example _question + '","type":"1","id":538,"rightAns":"2","answers":[{"id":953,"text":"' + sankoreLang . answer + ' 1.","value":1,"state":"","was":false},{"id":526,"text":"' + sankoreLang . answer + ' 2.","value":2,"state":"","was":false},{"id":473,"text":"' + sankoreLang . answer + ' 3.","value":3,"state":"","was":false}]}]' ) ;
for ( i in questionArray ) {
addQstBlock ( questionArray [ i ] . id , questionArray [ i ] . text , questionArray [ i ] . type , "style='display: none;'" ) ;
for ( j in questionArray [ i ] . answers )
addAnsBlock ( questionArray [ i ] . answers [ j ] . id , questionArray [ i ] . id , questionArray [ i ] . answers [ j ] . text , true , questionArray [ i ] . rightAns , questionArray [ i ] . type ) ;
}
displayData ( ) ;
}
else {
displayData ( false ) ;
begin = false ;
questionArray = jQuery . parseJSON ( '[{"text":"' + sankoreLang . example _question + '","type":"1","id":538,"rightAns":"2","answers":[{"id":953,"text":"' + sankoreLang . answer + ' 1.","value":1,"state":"","was":false},{"id":526,"text":"' + sankoreLang . answer + ' 2.","value":2,"state":"","was":false},{"id":473,"text":"' + sankoreLang . answer + ' 3.","value":3,"state":"","was":false}]}]' ) ;
for ( i in questionArray ) {
addQstBlock ( questionArray [ i ] . id , questionArray [ i ] . text , questionArray [ i ] . type , "style='display: none;'" ) ;
for ( j in questionArray [ i ] . answers )
addAnsBlock ( questionArray [ i ] . answers [ j ] . id , questionArray [ i ] . id , questionArray [ i ] . answers [ j ] . text , true , questionArray [ i ] . rightAns , questionArray [ i ] . type ) ;
}
displayData ( ) ;
}
//saving widget data into sankore object for a correct import
@ -452,10 +435,10 @@ function init(){
//toggle button click trigger
//toggleButton.trigger("click");
//show data in display mode
function displayData ( flag ) {
function displayData ( ) {
$ ( "#addQstDiv" ) . hide ( ) ;
$ ( ".qstDiv" ) . hide ( ) ;
addToPage ( questionArray , flag ) ;
addToPage ( questionArray ) ;
}
//set widget in edit mode
@ -473,92 +456,72 @@ function init(){
}
// show questions and answers in display mode
function addToPage ( array , flag ) {
if ( flag ) {
var counter = 1 ;
for ( var i in array ) {
function addToPage ( array ) {
var counter = 1 ;
for ( var i in array ) {
var qstDiv = $ ( "<div class='qstDivDisplay' id='" + array [ i ] . id + "qstDivDisplay'>" ) ;
var spanOptConn = $ ( "<div class='spanOptConn'>" ) . appendTo ( qstDiv ) ;
var qstNumber = $ ( "<span class='qstNumber'>" + sankoreLang . question + " " + counter + "</span>" ) . appendTo ( spanOptConn ) ;
var qstContent = $ ( "<div class='qstContentDisplay'>" + array [ i ] . text + "</div>" ) . appendTo ( qstDiv ) ;
var ansDiv = $ ( "<div class='ansDiv' id='" + array [ i ] . id + "ansDiv'>" ) . appendTo ( qstDiv ) ;
var qstDiv = $ ( "<div class='qstDivDisplay' id='" + array [ i ] . id + "qstDivDisplay'>" ) ;
var spanOptConn = $ ( "<div class='spanOptConn'>" ) . appendTo ( qstDiv ) ;
var qstNumber = $ ( "<span class='qstNumber'>" + sankoreLang . question + " " + counter + "</span>" ) . appendTo ( spanOptConn ) ;
var qstContent = $ ( "<div class='qstContentDisplay'>" + array [ i ] . text + "</div>" ) . appendTo ( qstDiv ) ;
var ansDiv = $ ( "<div class='ansDiv' id='" + array [ i ] . id + "ansDiv'>" ) . appendTo ( qstDiv ) ;
var ansCount = 1 ;
var type = array [ i ] . type ;
var selInput = $ ( "<select>" ) ;
if ( type == 3 ) {
var newAnswer = $ ( "<div class='newAnswer'>" ) ;
newAnswer . appendTo ( ansDiv ) ;
var selectSpan = $ ( "<span id='answerText'>" ) . appendTo ( newAnswer ) ;
selInput . appendTo ( selectSpan ) ;
$ ( "<option value='0'>" + sankoreLang . select _text + "</option>" ) . appendTo ( selInput ) ;
}
for ( var j in array [ i ] . answers ) {
switch ( type ) {
case "1" :
var local _state = "" ;
var local _color = "" ;
if ( begin ) {
local _state = array [ i ] . answers [ j ] . state ;
local _color = ( array [ i ] . answers [ j ] . value == array [ i ] . rightAns ) ? ( ( array [ i ] . answers [ j ] . was ) ? "style='background-color: #6c0;'" : "" ) : ( ( array [ i ] . answers [ j ] . was ) ? "style='background-color: red;'" : "" ) ;
}
newAnswer = $ ( "<div class='newAnswer'>" ) ;
var ansInput = $ ( "<input type='radio' name='" + counter + "' value='" + array [ i ] . answers [ j ] . value + "' " + local _state + " style='float: left; margin-right: 10px;'/>" ) . appendTo ( newAnswer ) ;
var ansSpan = $ ( "<span class='ansSpanDisplay'>" + ansCount + ".</span>" ) . appendTo ( newAnswer ) ;
var ansContent = $ ( "<div class='ansContentDisplay' " + local _color + "><span id='answerText'>" + array [ i ] . answers [ j ] . text + "</span></div>" ) . appendTo ( newAnswer ) ;
newAnswer . appendTo ( ansDiv ) ;
break ;
case "2" :
local _state = "" ;
local _color = "" ;
if ( begin ) {
local _state = ( array [ i ] . answers [ j ] . state ) ? "checked" : "" ;
local _color = ( array [ i ] . rightAns . replace ( /,/g , "" ) . indexOf ( array [ i ] . answers [ j ] . value + " " , 0 ) != - 1 ) ? ( ( array [ i ] . answers [ j ] . was ) ? "style='background-color: #6c0;'" : "" ) : ( ( array [ i ] . answers [ j ] . was ) ? "style='background-color: red;'" : "" ) ;
}
newAnswer = $ ( "<div class='newAnswer'>" ) ;
ansInput = $ ( "<input type='checkbox' value='" + array [ i ] . answers [ j ] . value + "' " + local _state + " style='float: left; margin-right: 10px;'/>" ) . appendTo ( newAnswer ) ;
ansSpan = $ ( "<span class='ansSpanDisplay'>" + ansCount + ".</span>" ) . appendTo ( newAnswer ) ;
ansContent = $ ( "<div class='ansContentDisplay' " + local _color + "><span id='answerText'>" + array [ i ] . answers [ j ] . text + "</span></div>" ) . appendTo ( newAnswer ) ;
newAnswer . appendTo ( ansDiv ) ;
break ;
case "3" :
local _state = "" ;
local _color = "" ;
if ( begin ) {
local _state = ( array [ i ] . answers [ j ] . state ) ? "selected" : "" ;
local _color = ( array [ i ] . answers [ j ] . value == array [ i ] . rightAns ) ? ( ( array [ i ] . answers [ j ] . was ) ? "#6c0" : "" ) : ( ( array [ i ] . answers [ j ] . was ) ? "red" : "" ) ;
}
ansInput = $ ( "<option value='" + array [ i ] . answers [ j ] . value + "' " + local _state + ">" + array [ i ] . answers [ j ] . text + "</option>" ) . appendTo ( selInput ) ;
if ( local _state && local _color )
selInput . css ( "background-color" , local _color ) ;
break ;
}
ansCount ++ ;
}
qstDiv . appendTo ( "#data" ) ;
counter ++ ;
var ansCount = 1 ;
var type = array [ i ] . type ;
var selInput = $ ( "<select>" ) ;
if ( type == 3 ) {
var newAnswer = $ ( "<div class='newAnswer'>" ) ;
newAnswer . appendTo ( ansDiv ) ;
var selectSpan = $ ( "<span id='answerText'>" ) . appendTo ( newAnswer ) ;
selInput . appendTo ( selectSpan ) ;
$ ( "<option value='0'>" + sankoreLang . select _text + "</option>" ) . appendTo ( selInput ) ;
}
begin = false ;
} else {
counter = 1 ;
qstDiv = $ ( "<div class='qstDivDisplay'>" ) ;
spanOptConn = $ ( "<div class='spanOptConn'>" ) . appendTo ( qstDiv ) ;
qstNumber = $ ( "<span class='qstNumber'>" + sankoreLang . question + " " + counter + "</span>" ) . appendTo ( spanOptConn ) ;
qstContent = $ ( "<div class='qstContentDisplay'>" + sankoreLang . example _question + "</div>" ) . appendTo ( qstDiv ) ;
ansDiv = $ ( "<div class='ansDiv'>" ) . appendTo ( qstDiv ) ;
ansCount = 1 ;
for ( j = 0 ; j < 3 ; j ++ ) {
newAnswer = $ ( "<div class='newAnswer'>" ) ;
ansInput = $ ( "<input type='radio' name='1' style='float: left; margin-right: 10px;'/>" ) . appendTo ( newAnswer ) ;
ansSpan = $ ( "<span class='ansSpanDisplay'>" + ansCount + ".</span>" ) . appendTo ( newAnswer ) ;
ansContent = $ ( "<div class='ansContentDisplay'>" + sankoreLang . answer + " " + ansCount + ".</div>" ) . appendTo ( newAnswer ) ;
newAnswer . appendTo ( ansDiv ) ;
for ( var j in array [ i ] . answers ) {
switch ( type ) {
case "1" :
var local _state = "" ;
var local _color = "" ;
if ( begin ) {
local _state = array [ i ] . answers [ j ] . state ;
local _color = ( array [ i ] . answers [ j ] . value == array [ i ] . rightAns ) ? ( ( array [ i ] . answers [ j ] . was ) ? "style='background-color: #6c0;'" : "" ) : ( ( array [ i ] . answers [ j ] . was ) ? "style='background-color: red;'" : "" ) ;
}
newAnswer = $ ( "<div class='newAnswer'>" ) ;
var ansInput = $ ( "<input type='radio' name='" + counter + "' value='" + array [ i ] . answers [ j ] . value + "' " + local _state + " style='float: left; margin-right: 10px;'/>" ) . appendTo ( newAnswer ) ;
var ansSpan = $ ( "<span class='ansSpanDisplay'>" + ansCount + ".</span>" ) . appendTo ( newAnswer ) ;
var ansContent = $ ( "<div class='ansContentDisplay' " + local _color + "><span id='answerText'>" + array [ i ] . answers [ j ] . text + "</span></div>" ) . appendTo ( newAnswer ) ;
newAnswer . appendTo ( ansDiv ) ;
break ;
case "2" :
local _state = "" ;
local _color = "" ;
if ( begin ) {
local _state = ( array [ i ] . answers [ j ] . state ) ? "checked" : "" ;
local _color = ( array [ i ] . rightAns . replace ( /,/g , "" ) . indexOf ( array [ i ] . answers [ j ] . value + " " , 0 ) != - 1 ) ? ( ( array [ i ] . answers [ j ] . was ) ? "style='background-color: #6c0;'" : "" ) : ( ( array [ i ] . answers [ j ] . was ) ? "style='background-color: red;'" : "" ) ;
}
newAnswer = $ ( "<div class='newAnswer'>" ) ;
ansInput = $ ( "<input type='checkbox' value='" + array [ i ] . answers [ j ] . value + "' " + local _state + " style='float: left; margin-right: 10px;'/>" ) . appendTo ( newAnswer ) ;
ansSpan = $ ( "<span class='ansSpanDisplay'>" + ansCount + ".</span>" ) . appendTo ( newAnswer ) ;
ansContent = $ ( "<div class='ansContentDisplay' " + local _color + "><span id='answerText'>" + array [ i ] . answers [ j ] . text + "</span></div>" ) . appendTo ( newAnswer ) ;
newAnswer . appendTo ( ansDiv ) ;
break ;
case "3" :
local _state = "" ;
local _color = "" ;
if ( begin ) {
local _state = ( array [ i ] . answers [ j ] . state ) ? "selected" : "" ;
local _color = ( array [ i ] . answers [ j ] . value == array [ i ] . rightAns ) ? ( ( array [ i ] . answers [ j ] . was ) ? "#6c0" : "" ) : ( ( array [ i ] . answers [ j ] . was ) ? "red" : "" ) ;
}
ansInput = $ ( "<option value='" + array [ i ] . answers [ j ] . value + "' " + local _state + ">" + array [ i ] . answers [ j ] . text + "</option>" ) . appendTo ( selInput ) ;
if ( local _state && local _color )
selInput . css ( "background-color" , local _color ) ;
break ;
}
ansCount ++ ;
}
qstDiv . appendTo ( "#data" ) ;
counter ++ ;
}
begin = false ;
}
}