var presentation = ["One Grain of Rice by Demi<\/phrase>","Long ago<\/word>","India<\/word>","raja<\/word>","wise and fair<\/word>","his province<\/word>","rice farmers<\/word>","decreed<\/word>","give nearly all of their rice<\/word>","store the rice<\/word>","no one will go hungry<\/word>","Long ago<\/strong> in India<\/strong>, there lived a raja<\/strong> who believed he was wise and fair<\/strong>, as a raja<\/strong> should be. The people in his province<\/strong> were rice farmers<\/strong>. The raja<\/strong> decreed<\/strong> that everyone must give nearly all of their rice<\/strong> to him. \"I will store the rice<\/strong> safely,\" the raja<\/strong> promised the people, \"so that in time of famine, everyone will have rice to eat, and no one will go hungry<\/strong>.\" Each year, the raja<\/strong>'s rice collectors gathered nearly all of the people's rice and carried it away to the royal storehouses.<\/phrase>","many years<\/word>","rice grew<\/word>","one year<\/word>","famine and hunger<\/word>","no rice to give<\/word>","no rice to eat<\/word>","raja's ministers implored him<\/word>","give the rice to the people<\/word>","raja must not go hungry<\/word>","For many years<\/strong>, the rice grew<\/strong> well. The people gave nearly all of their rice to the raja<\/strong>, and the storehouses were always full. But the people were left with only enough rice to get by. Then one year<\/strong> the rice grew<\/strong> badly and there was famine and hunger<\/strong>. The people had no rice to give<\/strong> to the raja<\/strong>, and they had no rice to eat<\/strong>. The raja's ministers implored him<\/strong>, \"Your highness, let us open the royal storehouses and give the rice to the people<\/strong>, as you promised.\" \"No!\" cried the raja<\/strong>. How do I know how long the famine will last? I must have the rice for myself. Promis or no promise, a raja must not go hungry<\/strong>!\"<\/phrase>","Time went on<\/word>","more hungry<\/word>","raja ordered a feast for himself<\/word>","elephant<\/word>","full baskets of rice<\/word>","village girl<\/word>","Rani<\/word>","rice was falling<\/word>","catching the falling rice<\/word>","clever<\/word>","Time went on<\/strong>, and the people grew more and more hungry<\/strong>. But the raja<\/strong> would not give out the rice. One day, the raja ordered a feast for himself<\/strong> and his court--as, it seemed to him, a raja<\/strong> should now and then, even when there is famine. A servant led an elephant<\/strong> from a royal storehouse to the palace, carrying two full baskets of rice<\/strong>. A village girl<\/strong> named Rani<\/strong> saw that a trickle of rice was falling<\/strong> from one of the baskets. Quickly she jumped up and walked along beside the elephant<\/strong>, catching the falling rice<\/strong> in her skirt. She was clever<\/strong>, and she began to make a plan.<\/phrase>","I am not a thief<\/word>","Rani's good deed<\/word>","reward you<\/word>","you shall have it<\/word>","give me one grain of rice<\/word>","At the palace, a guard cried, \"Halt, theif! Where are you going with that rice?\".\n\"I am not a thief<\/strong>,\" Rani<\/strong> replied. \"This rice fell from one of the baskets, and I am returning it now to the raja<\/strong>.\" When the raja<\/strong> heard about Rani's good deed<\/strong>, he asked his ministers to bring her before him. \"I wish to reward you<\/strong> for returning what belongs to me,\" the raja<\/strong> said to Rani<\/strong>. \"Ask me for anything, and you shall have it<\/strong>.\"\n\"Your highness,\" said Rani<\/strong>, \"I do not deserve any reward at all. But if you wish, you may give me one grain of rice<\/strong>.\"<\/phrase>","reward you more plentifully<\/word>","reward me in this way<\/word>","single grain of rice<\/word>","each day<\/word>","thirty days<\/word>","double the rice you gave me<\/word>","two grains of rice<\/word>","next day<\/word>","modest reward<\/word>","\"Only one grain of rice?\" exclaimed the raja<\/strong>. \"Surely you will allow me to reward you more plentifully<\/strong>, as a raja<\/strong> should\".\n\"Very well,\" said Rani<\/strong>. \"If it pleased Your Highness, you may reward me in this way<\/strong>. Today, you will give me a single grain of rice<\/strong>. Then, each day<\/strong> for thirty days<\/strong> you will give me double the rice you gave me<\/strong> the day before. Thus, tomorrow you will give me two grains of rice<\/strong>, the next day<\/strong> four grains of rice, and so on for thirty day.\" \"This seems to be a modest reward<\/strong>,\" said the raja<\/strong>. \"But you shall have it<\/strong>.\" And Rani<\/strong> was presented with a single grain of rice<\/strong>.<\/phrase>","ninth day<\/word>","two hundred fifty-six grains of rice<\/word>","small handful<\/word>","enough rice for two bags<\/word>","The next day<\/strong>, Rani<\/strong> was presented with two grains of rice<\/strong>.\nAnd the following day, Rani<\/strong> was presented with four grains of rice.\nOn the ninth day<\/strong>, Rani<\/strong> was presented with two hundred fifty-six grains of rice<\/strong>. She had received in all five hundred and eleven grains of rice, enough for only a small handful<\/strong>.\n\"This girl is honest, but not very clever<\/strong>,\" thought the raja<\/strong>. \"She would have gained more rice by keeping what fell into her skirt!\"\nOn the twelfth day, Rani<\/strong> received two thousand and forty-eight grains of rice, about four handfuls.\nOn the thirteenth day, she received four thousand and ninety-six grains of rice, enough to fill a bowl.\nOn the sixteenth day, Rani<\/strong> was presented with a bag containing thirty-two thousand, seven hundred and sixty-eight grains of rice. All together she had enough rice for two bags<\/strong>.\n\"This doubling up adds up to more rice than I expected\" thought the raja<\/strong>. \"But surely her reward won't amount to much more.\"<\/phrase>","twentieth day<\/word>","twenty-seventh day<\/word>","sixty-four baskets of rice<\/word>","On the twentieth day<\/strong>, Rani<\/strong> was presented with sixteen more bags filled with rice.\nOn the twenty-first day, she received one million, forty-eight thousand, five hundred and seventy-six grains of rice, enough to fill a basket.\nOn the twenty-fourth day, Rani<\/strong> was presented with eight million, three hundred and eighty-eight thousand, six hundred and eight grains of rice--enough to fill eight baskets, which were carried to her by eight royal deer.\nOn the twenty-seventh day<\/strong>, thirty-two brahma bulls were needed to deliver sixty-four baskets of rice<\/strong>. The raja<\/strong> was deeply troubled. \"One grain of rice has grown very great indeed,\" he thought. \"But I shall fulfill the reward to the end, as a raja<\/strong> should.\"<\/phrase>","final day<\/word>","Five hundred and thirty-six million, eight hundred and seventy thousand, nine hundred and twelve grains of rice<\/word>","On the twenty-ninth day<\/strong>, Rani<\/strong> was presented with the contents of two royal storehouses.\nOn the thirtieth and final day<\/strong>, two hundred and fifty-six elephants crossed the province, carrying the contents of the last four royal storehouses--Five hundred and thirty-six million, eight hundred and seventy thousand, nine hundred and twelve grains of rice<\/strong>.<\/phrase>","raja had no more rice to give<\/word>","what will you do with this rice<\/word>","All together, Rani<\/strong> had received more than one billion grains of rice. The raja had no more rice to give<\/strong>. \"And what will you do with this rice<\/strong>,\" said the raja<\/strong> with a sigh, \"now that I have none?\"\n\"I shall give it to all the hungry people,\" said Rani<\/strong>, \"and I shall leave a basket of rice for you, too, if you promise from now on to take only as much rice as you need.\"\n\"I promise,\" said the raja<\/strong>. And for the rest of his days, the raja<\/strong> was truly wise and fair<\/strong>, as a raja<\/strong> should be.<\/phrase>"]; var currentPosition = 0; var totalPositions = 0; var timePerWord = 1500; var timePerPhraseWord = 120 var readAheadPlayerTimer; var autoPlay = true; var setMinimized = false; var wordSpeedOptions = {'Slower':2000,'Moderate':1200,'Fast':800}; var phraseSpeedOptions = {'Slower':280,'Moderate':200,'Fast':80}; var defaultWordSpeedOption = 'Moderate'; var defaultPhraseSpeedOption = 'Moderate'; var logToLTI = false; $(window).load(function(){ totalPositions = presentation.length; if (totalPositions > 0){ $('body').prepend('
'); $('body').prepend('
'); $('#read_ahead_player').prepend('
'); initializeReadAheadControls(); initializeReadAheadSlider(); initializeReadAheadSpeedOptions(); currentReadAheadControls(); resumeReadAheadPlayback(); } }); $(document).keyup(function(e){ switch(e.which) { case 37: pauseReadAheadPresentation(); priorReadAheadPresentationItem(); break; case 39: pauseReadAheadPresentation(); nextReadAheadPresentationItem(); break; default: break; } }); function initializeReadAheadControls(){ var s = ''; s += ''; s += ''; s += ''; s += '
'; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += '
'; $('#read_ahead_player').append(s); } function initializeReadAheadSlider(){ var s = ''; s += '
'; s += '
'; s += '
'; $('#read_ahead_controls').prepend(s); updateReadAheadSliderPosition(); } function initializeReadAheadSpeedOptions(){ var s = '
'; s += '
'; s += ' Word Speed
'; s += '
'; optionCount = 0; for (index in wordSpeedOptions) { optionCount++; } optionWidth = 100 / optionCount; for (index in wordSpeedOptions) { var option = wordSpeedOptions[index]; if (index == defaultWordSpeedOption) { s += ''; updateReadAheadWordSpeed(option); } else { s += ''; } } s += '
'; s += '
'; s += '
'; s += ' Phrase Speed
'; s += '
'; optionCount = 0; for (index in phraseSpeedOptions) { optionCount++; } optionWidth = 100 / optionCount; for (index in phraseSpeedOptions) { var option = phraseSpeedOptions[index]; if (index == defaultWordSpeedOption) { s += ''; updateReadAheadPhraseSpeed(option); } else { s += ''; } } s += '
'; s += '
'; s += '
'; $('#read_ahead_controls').append(s); } function updateReadAheadWordSpeed(microseconds,sender) { microseconds = microseconds != undefined && microseconds > 0 ? microseconds : 0; if (microseconds > 0) { timePerWord = microseconds; } if (sender!=undefined) { $('#slider_control_word_speed').find('a').removeClass('current_speed'); $(sender).addClass('current_speed'); } logReadAheadPlayerAction('updateReadAheadWordSpeed','Presentation',microseconds); } function updateReadAheadPhraseSpeed(microseconds,sender) { microseconds = microseconds != undefined && microseconds > 0 ? microseconds : 0; if (microseconds > 0 ) { timePerPhraseWord = microseconds; } if (sender!=undefined) { $('#slider_control_phrase_speed').find('a').removeClass('current_speed'); $(sender).addClass('current_speed'); } logReadAheadPlayerAction('updateReadAheadPhraseSpeed','Presentation',microseconds); } function updateReadAheadSliderPosition(){ var currentSliderBarWidth = 100 - (100 / totalPositions * (currentPosition + 1)); $('#readAheadSliderBar').css('width',currentSliderBarWidth+'%'); } function currentReadAheadControls(){ $('#read_ahead_player_pause_play').show(); if (currentPosition < totalPositions - 1) { $('#read_ahead_player_next_word').removeClass('disabled'); } else { $('#read_ahead_player_next_word').addClass('disabled'); } if (currentPosition > 0) { $('#read_ahead_player_previous_word').removeClass('disabled'); } else { $('#read_ahead_player_previous_word').addClass('disabled'); } } function restartReadAheadPresentation(){ currentPosition = 0; logReadAheadPlayerAction('restartReadAheadPresentation','Presentation',''); resumeReadAheadPlayback(); } function resumeReadAheadPlayback(){ $('.fa-repeat').removeClass('fa-repeat').addClass('fa-play'); $('#read_ahead_player_pause_play').each(function(){ $(this).find('.fa-play').removeClass('fa-play').addClass('fa-pause'); $(this).off('click'); $(this).attr('onclick','pauseReadAheadPresentation()'); }); logReadAheadPlayerAction('resumeReadAheadPlayback','Presentation',''); playReadAheadPresentation(); } function pauseReadAheadPresentation(){ $('#read_ahead_player_pause_play').each(function(){ $(this).find('.fa-pause').removeClass('fa-pause').addClass('fa-play'); $(this).off('click'); $(this).attr('onclick','resumeReadAheadPlayback()'); }); logReadAheadPlayerAction('pauseReadAheadPresentation','Presentation',''); read_ahead_pause(); } function endReadAheadPresentation(){ $('.fa-play').removeClass('fa-play').addClass('fa-repeat'); $('.fa-pause').removeClass('fa-pause').addClass('fa-repeat'); $('#read_ahead_player_pause_play').each(function(){ $(this).off('click'); $(this).attr('onclick','restartReadAheadPresentation()'); }); logReadAheadPlayerAction('endReadAheadPresentation','Presentation',''); logLTIEndPresentation(); } function playReadAheadPresentation(){ autoPlay=true; currentPosition--; logReadAheadPlayerAction('playReadAheadPresentation','Presentation',''); nextReadAheadPresentationItem(); } function startReadAheadStepper(timeDisplayWord){ clearInterval(readAheadPlayerTimer); readAheadPlayerTimer = setTimeout(function() { read_ahead_step(); },timeDisplayWord); } function stopReadAheadStepper(){ clearInterval(readAheadPlayerTimer); } function read_ahead_step(){ if (autoPlay) { nextReadAheadPresentationItem(); } } function read_ahead_pause(){ autoPlay=false; stopReadAheadStepper(); } function showReadAheadPresentationItem(index){ currentPosition = index; currentPresentationItem = presentation[currentPosition] != undefined ? presentation[currentPosition].trim() : ""; if (currentPresentationItem != "") { currentItemWordCount = presentation[currentPosition].replace("\n","").split(" ").length; if (currentPresentationItem.startsWith("")){ startReadAheadStepper(currentItemWordCount*timePerWord); $('#read_ahead_player_field').html('
'+currentPresentationItem+'
'); logReadAheadPlayerAction('showReadAheadPresentationItem','Word',currentPresentationItem); } else { startReadAheadStepper(currentItemWordCount*timePerPhraseWord); $('#read_ahead_player_field').html('
'+currentPresentationItem.replace("\n","
")+'
'); logReadAheadPlayerAction('showReadAheadPresentationItem','Phrase',''); } } else { if (currentPosition < totalPositions) { nextReadAheadPresentationItem(); } else { endReadAheadPresentation(); read_ahead_minimize(); } } currentReadAheadControls(); updateReadAheadSliderPosition(); saveReadAheadPosition(); } function priorReadAheadPresentationItem(){ stopReadAheadStepper(); logReadAheadPlayerAction('priorReadAheadPresentationItem','Controls',''); showReadAheadPresentationItem(currentPosition-1); } function nextReadAheadPresentationItem(){ stopReadAheadStepper(); logReadAheadPlayerAction('nextReadAheadPresentationItem','Controls',''); showReadAheadPresentationItem(currentPosition+1); } function read_ahead_playAgain(){ currentWordIndex = 0; logReadAheadPlayerAction('read_ahead_playAgain','Controls',''); playReadAheadPresentation(); } function read_ahead_minimize(){ setMinimized = true; logReadAheadPlayerAction('read_ahead_minimize','Controls',''); read_ahead_switch_min_max(); } function read_ahead_maximize(){ setMinimized = false; logReadAheadPlayerAction('read_ahead_maximize','Controls',''); read_ahead_switch_min_max(); } function read_ahead_switch_min_max(forceSwitch){ forceSwitch = forceSwitch != undefined ? forceSwitch : false; if (forceSwitch) { setMinimized = !setMinimized; } if (setMinimized) { $('#read_ahead_player_back').fadeOut(); $('#read_ahead_player').addClass('minimize'); $('.player-icons .fa-stack').removeClass('fa-lg').addClass('fa-sm'); $('.player-icons .fa-minus').removeClass('fa-minus').addClass('fa-expand'); logReadAheadPlayerAction('read_ahead_switch_min_max','Min',''); //$('#read_ahead_player_max_min').each(function(){ // $(this).off('click'); // $(this).attr('onclick','read_ahead_maximize()'); //}); } else { $('#read_ahead_player_back').fadeIn(); $('#read_ahead_player').removeClass('minimize'); $('.player-icons .fa-stack').removeClass('fa-sm').addClass('fa-lg'); $('.player-icons .fa-expand').removeClass('fa-expand').addClass('fa-minus'); logReadAheadPlayerAction('read_ahead_switch_min_max','Max',''); //$('#read_ahead_player_max_min').each(function(){ // $(this).off('click'); // $(this).attr('onclick','read_ahead_minimize()'); //}); } } function saveReadAheadPosition(){ $.ajax({ type:'POST', url:'/ajax/save_user_presentation_position.php', data: { 'id':100, 'position': currentPosition } }) .done(function(results){ }) .fail(function( jqXHR, textStatus ) { alert( "Request failed: " + textStatus ); }); } function logLTIEndPresentation(action) { if (!logToLTI) { return; } $.ajax({ type:'POST', url:'/lti/presentationEnded.php', data: { 'documentId':100, 'userId':0, } }) } function logReadAheadPlayerAction(action,area,details){ var d = new Date(); var t = d.getTime(); action = action != undefined ? action.trim() : 'UNKNOWN'; area = area != undefined ? area.trim() : ''; details = details != undefined ? details : ''; // If we are about to show a new word, increase the number of keywords // reinforced so we can log that for the Dashboard page. if (area == 'Word') { window.keywordCount++; } $.ajax({ type:'POST', url:'/logging/logPlayerAction.php', data: { 'documentId':100, 'userId':0, 'playerAction':action, 'playerArea':area, 'details':details, 'timestamp': t } }) .done(function(results){ }) .fail(function( jqXHR, textStatus ) { alert( "Request failed: " + textStatus ); }); }