|
|
|
@ -32,8 +32,8 @@ var sankoreLang = { |
|
|
|
|
example: "Il*était*une*fois*...", |
|
|
|
|
wgt_name: "Ordonner des mots", |
|
|
|
|
reload: "Recharger", |
|
|
|
|
slate: "Ardoise", |
|
|
|
|
pad: "Tablette" |
|
|
|
|
slate: "Bois", |
|
|
|
|
pad: "Pad" |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var word = ""; |
|
|
|
@ -53,6 +53,8 @@ var letters = []; |
|
|
|
|
|
|
|
|
|
var editMode = false; // just a flag
|
|
|
|
|
|
|
|
|
|
var wgtState = false; // just another flag
|
|
|
|
|
|
|
|
|
|
// if use the "edit" button or rely on the api instead
|
|
|
|
|
var isSankore = false; |
|
|
|
|
// whether to do window.resize or not (window = widget area)
|
|
|
|
@ -92,20 +94,64 @@ $(document).ready(function(){ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
$("#wgt_name").text(sankoreLang.wgt_name); |
|
|
|
|
|
|
|
|
|
$("#wgt_reload").text(sankoreLang.reload).click(function(){ |
|
|
|
|
window.location.reload(); |
|
|
|
|
if(wgtState) |
|
|
|
|
$("#wgt_display").trigger("click"); |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
$( "#mp_word" ).empty(); |
|
|
|
|
|
|
|
|
|
// create new set of letters
|
|
|
|
|
var letters; |
|
|
|
|
if(window.sankore && curWord && !editMode) |
|
|
|
|
letters = createWordLetters( curWord ); |
|
|
|
|
else |
|
|
|
|
letters = shuffle( createWordLetters( word ) ); |
|
|
|
|
|
|
|
|
|
for( i in letters ){ |
|
|
|
|
$("#mp_word").append( letters[i] ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// in sankore api there would be a function to check
|
|
|
|
|
// the answer, so no update parameter would be needed
|
|
|
|
|
if( !isSankore ){ |
|
|
|
|
$( "#mp_word" ).sortable( { |
|
|
|
|
update: checkWord |
|
|
|
|
} ); |
|
|
|
|
} else $( "#mp_word" ).sortable(); |
|
|
|
|
|
|
|
|
|
// adjustWidth
|
|
|
|
|
var totalLettersWidth = 0; |
|
|
|
|
for( i in letters ){ |
|
|
|
|
var currentWidth = $( letters[i] ).outerWidth( true ); |
|
|
|
|
totalLettersWidth += currentWidth; |
|
|
|
|
} |
|
|
|
|
totalLettersWidth += 1; |
|
|
|
|
|
|
|
|
|
var width = Math.max( |
|
|
|
|
totalLettersWidth, |
|
|
|
|
min_view_width |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// shift the words to the right to center them
|
|
|
|
|
if( width > totalLettersWidth ){ |
|
|
|
|
$( "#mp_word" ).css( "margin-left", Math.round( (width - totalLettersWidth)/2 ) ); |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
$( "#mp_word" ).css( "margin-left", 0 ); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
$(".style_select option[value='1']").text(sankoreLang.slate); |
|
|
|
|
$(".style_select option[value='2']").text(sankoreLang.pad); |
|
|
|
|
|
|
|
|
|
$(".style_select").change(function (event){ |
|
|
|
|
changeStyle($(this).find("option:selected").val()); |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
$("#mp_word input:text").live("change", function(){ |
|
|
|
|
saveData(); |
|
|
|
|
}); |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
@ -184,10 +230,7 @@ scans the letters and checks |
|
|
|
|
if they are in the right order |
|
|
|
|
*/ |
|
|
|
|
function checkWord() |
|
|
|
|
{ |
|
|
|
|
if( !doCheckWord ) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
var str = ""; |
|
|
|
|
$( "#mp_word .letter" ).each( function(){ |
|
|
|
|
str += $(this).text(); |
|
|
|
@ -197,6 +240,7 @@ function checkWord() |
|
|
|
|
{ |
|
|
|
|
w = w.replace( '*', '' ); |
|
|
|
|
} |
|
|
|
|
//alert(str + " | " + w)
|
|
|
|
|
if( str == w ){ |
|
|
|
|
$( "#mp_word .letter" ).addClass( "right" ); |
|
|
|
|
//message( "Right!" );
|
|
|
|
@ -238,6 +282,8 @@ function modeView() |
|
|
|
|
if( editMode ){ |
|
|
|
|
word = $( "#mp_word input:text" ).attr( "value" ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
wgtState = false; |
|
|
|
|
|
|
|
|
|
// clean the previous word
|
|
|
|
|
$( "#mp_word" ).empty(); |
|
|
|
@ -282,6 +328,7 @@ function modeView() |
|
|
|
|
$( "#mp_word" ).css( "margin-left", 0 ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
checkWord(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
@ -292,12 +339,13 @@ modeEdit |
|
|
|
|
function modeEdit() |
|
|
|
|
{ |
|
|
|
|
editMode = true; |
|
|
|
|
wgtState = true; |
|
|
|
|
$( "#mp_word").css( "margin-left", 0 ).empty().append('<input value="'+word+'">'); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function saveData() { |
|
|
|
|
if (window.widget) { |
|
|
|
|
if (window.widget) { |
|
|
|
|
window.widget.onleave = function(){ |
|
|
|
|
sankore.setPreference("ord_words_style", $(".style_select").find("option:selected").val()); |
|
|
|
|
if($( "#mp_word input:text" ).attr( "value" )) |
|
|
|
|
{ |
|
|
|
|