var sankoreLang = { display: "Display", edit: "Edit", short_desc: "Listen to the sound and make the correct word.", add: "Add new block", enter: "Enter your instruction here ...", example: "example", wgt_name: "Order the letters", reload: "Reload", slate: "Wood", pad: "Pad", none: "None", help: "Help", help_content: "This is an example of help content ..." }; //main function function start(){ $("#wgt_display").text(sankoreLang.display); $("#wgt_edit").text(sankoreLang.edit); $("#wgt_name").text(sankoreLang.wgt_name); $("#wgt_reload").text(sankoreLang.reload); $("#wgt_help").text(sankoreLang.help); $("#help").html(sankoreLang.help_content); $(".style_select option[value='1']").text(sankoreLang.slate); $(".style_select option[value='2']").text(sankoreLang.pad); $(".style_select option[value='3']").text(sankoreLang.none); if(window.sankore){ if(sankore.preference("associer_sound","")){ var data = jQuery.parseJSON(sankore.preference("associer_sound","")); importData(data); } else showExample(); if(sankore.preference("ord_let_style","")){ changeStyle(sankore.preference("ord_let_style","")); $(".style_select").val(sankore.preference("ord_let_style","")); } else changeStyle("3") } else showExample(); //events if (window.widget) { window.widget.onleave = function(){ exportData(); sankore.setPreference("ord_let_style", $(".style_select").find("option:selected").val()); } } $("#wgt_help").click(function(){ var tmp = $(this); if($(this).hasClass("open")){ $("#help").slideUp("100", function(){ tmp.removeClass("open"); $("#data").show(); }); } else { $("#data").hide(); $("#help").slideDown("100", function(){ tmp.addClass("open"); }); } }); $("#wgt_reload").click(function(){ if($("#wgt_display").hasClass("selected")){ $("#wgt_edit").trigger("click"); $("#wgt_display").trigger("click"); } else { $("#wgt_display").trigger("click"); } }); $("#wgt_reload, #wgt_display, #wgt_edit").mouseover(function(){ exportData(); }); $(".style_select").change(function (event){ changeStyle($(this).find("option:selected").val()); }) $("#wgt_display, #wgt_edit").click(function(event){ if(this.id == "wgt_display"){ if(!$(this).hasClass("selected")){ if(window.sankore) sankore.enableDropOnWidget(false); $(this).addClass("selected"); $("#wgt_edit").removeClass("selected"); $(".style_select").css("display","none"); $(".add_block").remove(); $(".cont").each(function(){ var container = $(this); var tmp_array = []; var imgs_container = container.find(".imgs_cont"); container.find(".text_cont .audio_desc").removeAttr("contenteditable"); container.find(".audio_block").removeAttr("ondragenter") .removeAttr("ondragleave") .removeAttr("ondragover") .removeAttr("ondrop") container.find(".close_cont").remove(); var answer = imgs_container.find(".audio_answer").text(); imgs_container.find(".audio_answer").remove(); imgs_container.find("input").val(answer); for(var j in answer){ var tmp_letter = $("
" + answer[j] + "
"); tmp_array.push(tmp_letter); } tmp_array = shuffle(tmp_array); for(var i = 0; i").appendTo(container); container.find(".imgs_cont").removeClass("imgs_answers_red") .removeClass("imgs_answers_green") .addClass("imgs_answers_gray") .sortable("destroy"); container.find(".text_cont .audio_desc").attr("contenteditable","true"); container.find(".audio_block").attr("ondragenter", "return false;") .attr("ondragleave", "$(this).removeClass('audio_gray'); return false;") .attr("ondragover", "$(this).addClass('audio_gray'); return false;") .attr("ondrop", "$(this).removeClass('audio_gray'); return onDropAudio(this,event);"); container.find(".img_block").remove(); $("
" + container.find(".imgs_cont input").val() + "
").appendTo(container.find(".imgs_cont")); }); $("
" + sankoreLang.add + "
").appendTo("#data"); $(this).css("display", "none"); $("#wgt_display").css("display", "block"); } } $("audio").each(function(){ this.pause(); $(this).parent().find(":first-child").removeClass("stop").addClass("play"); }); }); //add new block $(".add_block").live("click", function(){ addContainer(); }); //adding new img $(".add_img").live("click", function(){ addImgBlock($(this)); }); //deleting a block $(".close_cont").live("click",function(){ $(this).parent().remove(); refreshBlockNumbers(); }); //deleting the img block $(".close_img").live("click", function(){ var i = 0; var tmp_obj = $(this).parent().parent(); $(this).parent().remove(); }); //correct image $(".true_img").live("click",function(){ $(this).parent().parent().find(".img_block").each(function(){ $(this).find("input").val(0); var tmp_div = $(this).find(".false_img"); if(tmp_div) tmp_div.removeClass("false_img").addClass("true_img"); }) $(this).parent().find("input").val(1); $(this).removeClass("true_img").addClass("false_img"); }); //wrong image $(".false_img").live("click",function(){ $(this).parent().find("input").val(0); $(this).removeClass("false_img").addClass("true_img"); }); //play/pause event $(".play, .stop").live("click", function(){ var tmp_audio = $(this); var audio = tmp_audio.parent().find("audio").get(0); if($(this).hasClass("play")){ if(tmp_audio.parent().find("source").attr("src")){ tmp_audio.removeClass("play").addClass("stop"); var id = setInterval(function(){ if(audio.currentTime == audio.duration){ clearInterval(id); tmp_audio.removeClass("stop").addClass("play"); } }, 10); tmp_audio.parent().find("input").val(id); audio.play(); } } else { $(this).removeClass("stop").addClass("play"); clearInterval( tmp_audio.parent().find("input").val()) audio.pause(); } }); $(".replay").live("click", function(){ var tmp_audio = $(this).prev(); var audio = $(this).parent().find("audio").get(0); if(tmp_audio.parent().find("source").attr("src")){ $(this).prev().removeClass("play").addClass("stop"); clearInterval($(this).parent().find("input").val()); var id = setInterval(function(){ if(audio.currentTime == audio.duration){ clearInterval(id); tmp_audio.removeClass("stop").addClass("play"); } }, 10); tmp_audio.parent().find("input").val(id); audio.currentTime = 0; audio.play(); } }); } //export function exportData(){ var array_to_export = []; if($("#wgt_edit").hasClass("selected")){ $(".cont").each(function(){ var cont_obj = new Object(); cont_obj.text = $(this).find(".audio_desc").text(); cont_obj.audio = $(this).find("source").attr("src"); cont_obj.answer = $(this).find(".audio_answer").text(); cont_obj.cur_answer = ""; array_to_export.push(cont_obj); }); } else { $(".cont").each(function(){ var cont_obj = new Object(); cont_obj.text = $(this).find(".audio_desc").text(); cont_obj.audio = $(this).find("source").attr("src"); cont_obj.answer = $(this).find(".imgs_cont input").val(); cont_obj.cur_answer = getAnswer($(this).find(".imgs_cont")); array_to_export.push(cont_obj); }); } if(window.sankore) sankore.setPreference("associer_sound", JSON.stringify(array_to_export)); if($("#wgt_display").hasClass("selected")){ if(window.sankore) sankore.setPreference("associer_sound_state", "display"); } else{ if(window.sankore) sankore.setPreference("associer_sound_state", "edit"); } } //import function importData(data){ var tmp = 0; for(var i in data){ var tmp_array = []; var container = $("
").appendTo("#data"); var sub_container = $("
").appendTo(container); var imgs_container = $("
").appendTo(container); $("
"+ (++tmp) +"
").appendTo(sub_container); var text = $("
").appendTo(sub_container); var audio_block = $("
").appendTo(text); $("
").appendTo(audio_block); $("
").appendTo(audio_block); var source = $("").attr("src", data[i].audio); var audio = $("