Advertisement
Guest User

Wykop

a guest
May 5th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.01 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.                          <script>
  10.             var currentChildId = "192896";
  11.             var currentLanguageId = 0;
  12.            
  13.             var ENG_LANG_ID = 1;
  14.             var ORT_LANG_ID = 4;
  15.            
  16.             function nl2br(str) {
  17.                 return str.replace(/\\n/g, '<br />');
  18.             }
  19.            
  20.             function initSession() {
  21.                 setAudioEmpty();
  22.                 playAudio();
  23.                 $.ajax({
  24.                     url: '../server/actions/init_session.php',
  25.                     type: "POST",
  26.                     dataType: 'json',
  27.                     data: {child_id:currentChildId}
  28.                 }).done(function(data) {
  29.                     $("#loading").hide();
  30.                     if ( data.is_new ) {
  31.                         startSessionPage("start_session_page", "start_session_button", data.language_id, data.characters);
  32.                     } else {
  33.                         startSessionPage("continue_session_page", "continue_session_button", data.language_id, data.characters);
  34.                     }
  35.                 }).error(alertError);
  36.             }
  37.            
  38.             function startSessionPage(page_id, button_id, language_id, characters) {
  39.                 $("#" + page_id).show();
  40.                 $("#" + button_id).off("click").click(function() {
  41.                     setAudioEmpty();
  42.                     playAudio();
  43.                     startLearningPage(language_id, characters);
  44.                 });
  45.             }
  46.            
  47.             function startLearningPage(language_id, lang_chars) {
  48.                 currentLanguageId = language_id;
  49.                 $("#special_characters").empty();
  50.                
  51.                 $("#special_characters").append($("<div/>").html("&nbsp;"));
  52.  
  53.                 for ( var i = 0; i < lang_chars.length; ++i ){
  54.                     $("#special_characters").append($("<div/>").text(lang_chars[i]).addClass("special_character_button").click(function(i){
  55.                         return function() {
  56.                             $("#answer").val($("#answer").val() + lang_chars[i]);
  57.                             $("#answer").focus();
  58.                         }
  59.                     }(i)));
  60.                 }
  61.                 $("#special_characters").append($("<div/>").html("&nbsp;"));
  62.                 $('#start_session_page').hide();
  63.                 $('#continue_session_page').hide();
  64.                 $('#loading').show();
  65.                 getNextWord();
  66.             }
  67.                    
  68.             function setAudio(word) {
  69.                 var url;
  70.                 var file = word + ".mp3";
  71.                 url = "/mp3/" + currentLanguageId + "/";
  72.                 loadAudio(url + file);
  73.             }
  74.            
  75.             function setAudioEmpty(){
  76.                 loadAudio("/mp3/_empty.mp3");
  77.             }
  78.            
  79.             function loadAudio(url){
  80.                 $('#jquery_audioPlayer').jPlayer("setMedia", { mp3: url });
  81.                 $("#jquery_audioPlayer").jPlayer("load");
  82.             }
  83.            
  84.                
  85.             function playAudio() {
  86.                 $('#jquery_audioPlayer').jPlayer("play");
  87.             }
  88.                
  89.             function learningPageShow(id, speechPart, usageExample, translations, word, has_audio, audio_file_name, is_new_word, is_marketing) {
  90.                 $('.speaker').hide();
  91.                 $('#question_speaker').hide();
  92.                 $('#question_speaker').off('click');
  93.                 $('#answer').off('keyup');
  94.                 $('body').off('keyup');
  95.                 $('#answer').off('enterKey');
  96.                 $('.speaker').off('click');
  97.                 $('#check').off('click');
  98.                 $('#show').off('click');
  99.                 $("#new_word_form .big_button").off("click");
  100.                
  101.                 $('.translations').html(translations);
  102.                 $('.usage_example').html(usageExample);
  103.                 $('.speech_part').html(speechPart);
  104.                
  105.                 $('#loading').hide();
  106.                 $('.back').show();
  107.                 $('#learning_page').show();
  108.                
  109.                 if ( is_new_word || is_marketing ){
  110.                     $("#learning_form").hide();
  111.                     $("#new_word_form").show();
  112.                     $("#know_new").click(function() {
  113.                         if ( is_marketing )
  114.                             possibleWordPageShow(translations);
  115.                         else
  116.                             show_learning_form(id);
  117.                     });
  118.                     $("#dont_know_new").click(function() {
  119.                         if ( is_marketing )
  120.                             possibleWordPageShow(translations);
  121.                         else
  122.                             ask_for_answer(id);
  123.                     });
  124.                     $('body').off('keyup');
  125.                     $("body").keyup(function(e){
  126.                         if (e.keyCode == 13) {
  127.                             $('#know_new').trigger('click');
  128.                         }
  129.                     });
  130.                 } else {
  131.                     show_learning_form(id);
  132.                 }
  133.                
  134.                
  135.  
  136.                 if (has_audio) {
  137.                     setAudio(audio_file_name);
  138.                 }
  139.                 if ( currentLanguageId == ORT_LANG_ID && has_audio ) {
  140.                     playAudio();
  141.                     $("#question_speaker").show();
  142.                     $("#question_speaker").click(function() { playAudio(); });
  143.                 }
  144.             }
  145.            
  146.             function possibleWordPageShow(word) {
  147.                 $('#loading').hide();
  148.                 $("#learning_page").hide();
  149.                 $("#possible_word_page").show();
  150.                 $("#possible_word").text(word);
  151.                 $(".back").show();
  152.                 $("#skip").off("click").click(function(){
  153.                     $("#possible_word_page").hide();
  154.                     $('#loading').show();
  155.                     getNextWord();
  156.                 });
  157.                 $('body').off('keyup').keyup(function(e){
  158.                     if (e.keyCode == 13) {
  159.                         $('#skip').trigger('click');
  160.                     }
  161.                 });
  162.             }
  163.            
  164.             function show_learning_form(id){
  165.                 $("#new_word_form").hide();
  166.                 $("#learning_form").show();
  167.                 $('#answer').keyup(function(e){
  168.                     if(e.keyCode == 13) {
  169.                         $(this).trigger("enterKey");
  170.                     }
  171.                 });
  172.                 $('#answer').bind("enterKey", function(e){
  173.                     checkAnswer(id, $('input[id=answer]').val());
  174.                 });
  175.    
  176.                 $('#check').click(function() {
  177.                     checkAnswer(id, $('input[id=answer]').val());
  178.                 });
  179.                 $('input[id=answer]').val('');
  180.                 $('input[id=answer]').focus();
  181.             }
  182.            
  183.             function ask_for_answer(id){
  184.                 $('#learning_page').hide();
  185.                 $('#loading').show();
  186.                 updateParams(id, '', false);
  187.             }
  188.            
  189.             function checkAnswer(id, answer) {
  190.                 $('#learning_page').hide();
  191.                 $('#loading').show();
  192.                 updateParams(id, answer, true);
  193.             }
  194.            
  195.             function showAnswerPage(id, answer, usageExample, translations, grade, word, answer_show, has_audio, show_grade) {
  196.                 resultCommentMessage(true);
  197.                 if ( show_grade ) {
  198.                     if (grade == 1) { // Correct Answer
  199.                         $('#answer_result').html('<div class="green">Dobrze</div>');
  200.                     } else if (grade == 2) { // Synonym Answer
  201.                         $('#answer_result').html('<div class="blue">Synonim</div>');
  202.                     } else { // Wrong answer
  203.                         $('#answer_result').html('<div class="red">Niepoprawnie</div>');
  204.                     }
  205.                 } else {
  206.                     $('#answer_result').html('<div>&nbsp;</div>');
  207.                 }
  208.                 $('#answer_translations').html(translations);
  209.                 if (grade != 2) {
  210.                     $('#word').html(word);
  211.                 } else {
  212.                     $('#word').html('');
  213.                 }
  214.                
  215.                 $('.usage_example_answer').html(usageExample);
  216.  
  217.                 if (has_audio && grade != 2) {
  218.                     if ( currentLanguageId != ORT_LANG_ID )
  219.                         playAudio();
  220.                     $('.speaker').click(function() {
  221.                         playAudio();
  222.                     });
  223.                     $('.speaker').show();
  224.                 } else {
  225.                     $('.speaker').hide();
  226.                 }
  227.                
  228.                 $('#next_word').html('Następne');
  229.                 $('#answer').off('keyup');
  230.                 $('body').off('keyup');
  231.                 $("body").keyup(function(e){
  232.                     if (e.keyCode == 13) {
  233.                         $('#nextword').trigger('click');
  234.                     }
  235.                 });
  236.                 $('#nextword').off('click');
  237.                 $('#nextword').click(function() {
  238.                     $('#answer_page').hide();
  239.                     $('#loading').show();
  240.                     getNextWord();
  241.                 });
  242.                
  243.                 $('#report_error').off('click');
  244.                 $('#report_error').click(function() {
  245.                     commentPageShow(id, word, answer_show, answer);
  246.                 });
  247.  
  248.                 $('#loading').hide();
  249.                 $('.back').show();
  250.                 $('#answer_page').show();
  251.             }
  252.            
  253.             function resultCommentMessage(show) {
  254.                 if (show) {
  255.                     $('#comment_result_fieldset').hide();
  256.                     $('#answer_result_fieldset').show();
  257.                 } else {
  258.                     $('#answer_result_fieldset').hide();
  259.                     $('#comment_result_fieldset').show();
  260.                 }
  261.             }
  262.            
  263.             function commentPageShow(id, word, answer_show, answer) {
  264.                 $('#answer_page').hide();
  265.                 $('textarea[id=comment_field]').val('');
  266.                 $('#comment_answer').text(answer);
  267.                 $('#comment_word').text(word);
  268.                 if (word != answer_show) {
  269.                     $('#comment_connective').text(' lub ');
  270.                     $('#comment_answer_show').text(answer_show);
  271.                 } else {
  272.                     $('#comment_connective').text('');
  273.                     $('#comment_answer_show').text('');
  274.                 }
  275.                 $('#comment_page').show();
  276.                 $('#comment_button').off('click');
  277.                 $('#comment_button').click(function (){
  278.                     var comment = $('textarea[id=comment_field]').val();
  279.                     $('#comment_page').hide();
  280.                     $('#loading').show();
  281.                     saveComment(id, comment);
  282.                 });
  283.                 $('body').off('keyup');
  284.             }
  285.            
  286.             function finishPageShow(summary) {
  287.                 $('#answer').off('keyup');
  288.                 $('body').off('keyup');
  289.                 $('#return_mainpage').off('click');
  290.                 $("body").keyup(function(e){
  291.                     if (e.keyCode == 13) {
  292.                         $('body').off('keyup');
  293.                         $('.back').trigger('click');
  294.                     }
  295.                 });
  296.                 $('#return_mainpage').click(function (){
  297.                     $('body').off('keyup');
  298.                     $('.back').trigger('click');
  299.                 });
  300.                 $('#session_result').html(nl2br(summary));
  301.                 $('#grade_report_button').click(getGradeReport);
  302.                 $('#loading').hide();
  303.                 $('.back').show();
  304.                 $('#finish_page').show();
  305.             }
  306.            
  307.             function getGradeReport(){
  308.                 $('#finish_page').hide();
  309.                 $('.back').hide();
  310.                 $('#loading').show();
  311.                 $.ajax({
  312.                     url: '../server/actions/grade_report.php',
  313.                     type: "POST",
  314.                     dataType: 'json',
  315.                     data: {child_id:currentChildId,date:new Date().getTime()}
  316.                 }).done(function(data) {
  317.                
  318.                     if ( "prev_mark" in data )
  319.                         $('#prev_mark').text(data.prev_mark);
  320.                     else {
  321.                         $('#prev_mark').hide();
  322.                         $('#prev_mark_label').hide();
  323.                     }
  324.                     $("#work_week_days").text(data.work_week_days);
  325.                     $("#parent_words_extra").text("+" + data.parent_words_extra);
  326.                     $("#teacher_words").text(data.teacher_words);
  327.                     $("#parent_words").text(data.parent_words);
  328.                     $("#current_mark").text(data.current_mark);
  329.                     $("#week_remaining_days").text(data.week_remaining_days);
  330.                    
  331.                     $('#loading').hide();
  332.                     $('.back').show();
  333.                     $('#grade_page').show();
  334.                 }).error(alertError);
  335.             }
  336.            
  337.             function alertError(){
  338.                 alert("Błąd połączenia");
  339.             }
  340.            
  341.             function getNextWord() {
  342.                 $.ajax({
  343.                     url: '../server/actions/generate_next_word.php',
  344.                     type: "POST",
  345.                     dataType: 'json',
  346.                     data: {child_id:currentChildId, date:new Date().getTime()}
  347.                 }).done(function(data) {
  348.                     if (typeof data.id == 'undefined') {
  349.                         finishPageShow(data.summary);
  350.                     } else{
  351.                         learningPageShow(data.id, data.speech_part, data.usage_example, data.translations, data.word, data.has_audio, data.audio_file_name, data.is_new_word, data.type == 'marketing');
  352.                     }
  353.                 }).error(function() {
  354.                     alert("Błąd połączenia");
  355.                 });
  356.             }
  357.  
  358.             function updateParams(id, answer, show_grade) {
  359.                 $.ajax({
  360.                     url: '../server/actions/save_answer.php',
  361.                     type: "POST",
  362.                     dataType: 'json',
  363.                     data: {child_id:currentChildId, word_id: id, answer:answer}
  364.                 }).done(function(data) {
  365.                     showAnswerPage(id, answer, data.usage_example, data.translations, data.grade, data.word,
  366.                         data.answershow, data.has_audio, show_grade);
  367.                 }).error(function() {
  368.                     alert("Błąd połączenia");
  369.                 });
  370.             }
  371.  
  372.             function saveComment(wordId, comment) {
  373.                 $.ajax({
  374.                     url: '../server/actions/save_comment.php',
  375.                     type: "POST",
  376.                     dataType: 'json',
  377.                     data: {child_id:currentChildId, word_id: wordId, comment:comment}
  378.                 }).done(function(data) {
  379.                     resultCommentMessage(false);
  380.                     $('#comment_result').html('<div class="green">Komentarz zapisany</div>');
  381.                     saveCommentEnd();
  382.                    
  383.                 }).error(function() {
  384.                     resultCommentMessage(false);
  385.                     $('#comment_result').html('<div class="red">Komentarz niezapisany</div>');
  386.                     saveCommentEnd();
  387.                 });
  388.             }
  389.            
  390.             function saveCommentEnd() {
  391.                 $('#loading').hide();
  392.                 $('#answer_page').show();
  393.                 $('body').off('keyup');
  394.                 $("body").keyup(function(e){
  395.                     if (e.keyCode == 13) {
  396.                         $('#nextword').trigger('click');
  397.                     }
  398.                 });
  399.             }
  400.            
  401.             function getSessionExpiredHandler(okHandler){
  402.                 return function(data){
  403.                     if ( data.error )
  404.                         window.location.href = "../../teacher2/logout.php?expired=1";
  405.                     else
  406.                         return okHandler(data.ok);
  407.                 }
  408.             }
  409.  
  410.             $(window).load(function(){
  411.                 $('.back').click(function() {
  412.                     if ($('#comment_page').is(':visible')) {
  413.                         $('#comment_page').hide();
  414.                         $('#answer_page').show();
  415.                     } else if($('#grade_page').is(':visible')){
  416.                         $('#grade_page').hide();
  417.                         $('#finish_page').show();
  418.                     } else {
  419.                         window.location.href = "../../ling_dispatcher.php";
  420.                     }
  421.                 });
  422.                 //$('#start_session_button').off('click').click(initSession);
  423.                 //$('#start_session_page').show();
  424.                 setWindowDimensions();
  425.                 //$("#loading").hide();
  426.             });
  427.            
  428.             function setWindowDimensions() {
  429.                 $("#allpage").each(function() {
  430.                     var head = $(this).find("#title");
  431.                     var foot = $(this).find("#footer");
  432.                     var loading = $(this).find("#loading");
  433.                     var learning_page = $(this).find("#learning_page");
  434.                     var answer_page = $(this).find("#answer_page");
  435.                     var finish_page = $(this).find("#finish_page");
  436.                     var comment_page = $(this).find("#comment_page");
  437.                     var answerInput = $(this).find("#answer");
  438.                     var commentInput = $(this).find("#comment_field");
  439.                     var commentButton = $(this).find("#comment");
  440.                     var start_session_page = $(this).find("#start_session_page");
  441.                     var windowHeight = $(window).height() - 20;
  442.                     loading.css("min-height", windowHeight - head.height() - foot.height());
  443.                     learning_page.css("min-height", windowHeight - head.height() - foot.height());
  444.                     answer_page.css("min-height", windowHeight - head.height() - foot.height());
  445.                     finish_page.css("min-height", windowHeight - head.height() - foot.height());
  446.                     comment_page.css("min-height", windowHeight - head.height() - foot.height());
  447.                     start_session_page.css("min-height", windowHeight - head.height() - foot.height());
  448.                     $(this).find("#continue_session_page").css("min-height", 4 * (windowHeight - head.height() - foot.height()) / 5);
  449.                     $(this).find("#continue_session_page").css("margin-top", (windowHeight - head.height() - foot.height() - 4 * (windowHeight - head.height() - foot.height()) / 5));
  450.                     $(this).find("#possible_word_page").css("min-height", windowHeight - head.height() - foot.height());
  451.                     answerInput.css("width", learning_page.width() - 20);
  452.                     commentInput.css("width", comment_page.width() - 20);
  453.                 });
  454.             }
  455.             $(window).bind('resize', function (e) {
  456.                 setWindowDimensions();
  457.             });
  458.        
  459.             $(document).ready(function(){
  460.                 $("#jquery_audioPlayer").jPlayer({
  461.                     swfPath: "../../lib/jQuery.jPlayer.2.4.0",
  462.                     supplied: "mp3",
  463.                     wmode: "window"
  464.                 });
  465.                 initSession();
  466.             });
  467.         </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement