From 96c00f5403b5a41cce92fbd5f7387a50cee4b27e Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 13 Jun 2012 16:46:37 +0200 Subject: [PATCH] fixed ordre mots --- .../interactivities/Ordre mots.wgt/config.xml | 2 +- .../locales/fr/scripts/template2.js | 74 +++++++++++++++---- .../locales/ru/scripts/template2.js | 72 +++++++++++++++--- .../Ordre mots.wgt/scripts/template2.js | 73 ++++++++++++++---- 4 files changed, 181 insertions(+), 40 deletions(-) diff --git a/resources/library/interactivities/Ordre mots.wgt/config.xml b/resources/library/interactivities/Ordre mots.wgt/config.xml index 057fb955..5d2f7da8 100644 --- a/resources/library/interactivities/Ordre mots.wgt/config.xml +++ b/resources/library/interactivities/Ordre mots.wgt/config.xml @@ -4,7 +4,7 @@ xmlns:ub="http://uniboard.mnemis.com/widgets" id="http://www.example.net/widgets/helloworld" version="1.1" - width="750" + width="850" height="320" ub:resizable="true"> diff --git a/resources/library/interactivities/Ordre mots.wgt/locales/fr/scripts/template2.js b/resources/library/interactivities/Ordre mots.wgt/locales/fr/scripts/template2.js index f9c661bb..42d94f88 100644 --- a/resources/library/interactivities/Ordre mots.wgt/locales/fr/scripts/template2.js +++ b/resources/library/interactivities/Ordre mots.wgt/locales/fr/scripts/template2.js @@ -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(''); } -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" )) { diff --git a/resources/library/interactivities/Ordre mots.wgt/locales/ru/scripts/template2.js b/resources/library/interactivities/Ordre mots.wgt/locales/ru/scripts/template2.js index 66e7be65..cae619c4 100644 --- a/resources/library/interactivities/Ordre mots.wgt/locales/ru/scripts/template2.js +++ b/resources/library/interactivities/Ordre mots.wgt/locales/ru/scripts/template2.js @@ -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(''); } -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" )) { @@ -320,4 +368,4 @@ function saveData() { } sankore.setPreference("rightOrdWords", word); } -} \ No newline at end of file +} diff --git a/resources/library/interactivities/Ordre mots.wgt/scripts/template2.js b/resources/library/interactivities/Ordre mots.wgt/scripts/template2.js index 515f2bea..f9d0b656 100644 --- a/resources/library/interactivities/Ordre mots.wgt/scripts/template2.js +++ b/resources/library/interactivities/Ordre mots.wgt/scripts/template2.js @@ -46,13 +46,13 @@ if(window.sankore){ word = sankoreLang.example; } -var doCheckWord = true; - // array of dom elements 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 +92,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 +228,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 +238,7 @@ function checkWord() { w = w.replace( '*', '' ); } + //alert(str + " | " + w) if( str == w ){ $( "#mp_word .letter" ).addClass( "right" ); //message( "Right!" ); @@ -238,6 +280,8 @@ function modeView() if( editMode ){ word = $( "#mp_word input:text" ).attr( "value" ); } + + wgtState = false; // clean the previous word $( "#mp_word" ).empty(); @@ -282,6 +326,7 @@ function modeView() $( "#mp_word" ).css( "margin-left", 0 ); } + checkWord(); } /* @@ -292,13 +337,13 @@ modeEdit function modeEdit() { editMode = true; + wgtState = true; $( "#mp_word").css( "margin-left", 0 ).empty().append(''); } - -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" )) {