Advertisement
Guest User

Untitled

a guest
Feb 10th, 2018
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.14 KB | None | 0 0
  1. function init()
  2. {
  3. if(type == 'test' || type == 'test-finale'){
  4. openNr(2);
  5. }else{
  6. window.oncontextmenu = function(){return false;}
  7. openNr(1);
  8. }
  9. }
  10.  
  11. function openNr(nr,mode)
  12. {
  13. if(type == 'test' || type == 'test-finale'){
  14. document.getElementById('n-slide').innerHTML = 'Test';
  15. }else{
  16. if(nr == '1'){
  17. document.getElementById('n-slide').innerHTML = 'Video';
  18. }else{
  19. document.getElementById('n-slide').innerHTML = 'Test';
  20. }
  21. }
  22.  
  23. document.getElementById('ico-freccia-ind').style.opacity = '0';
  24. document.getElementById('ico-freccia-av').style.opacity = '0';
  25. document.getElementById('ico-freccia-ind').setAttribute('onclick','');
  26. document.getElementById('ico-freccia-av').setAttribute('onclick','');
  27.  
  28. document.getElementById('ico-unit-load').style.display = 'block';
  29. document.getElementById('ico-unit-attesa').style.display = 'none';
  30. document.getElementById('ico-unit-incorso').style.display = 'none';
  31. document.getElementById('ico-unit-completato').style.display = 'none';
  32.  
  33. if(type == 'test' || type == 'test-finale'){
  34. //
  35. }else{
  36. if(nr > 1){
  37. document.getElementById('ico-freccia-ind').style.opacity = '1';
  38. document.getElementById('ico-freccia-ind').setAttribute('onclick','openNr('+(nr-1)+',\'no-block\')');
  39. }
  40. }
  41.  
  42. if(nr <= lesson_location)
  43. {
  44. document.getElementById('ico-unit-load').style.display = 'none';
  45. document.getElementById('ico-unit-attesa').style.display = 'none';
  46. document.getElementById('ico-unit-incorso').style.display = 'none';
  47. document.getElementById('ico-unit-completato').style.display = 'block';
  48.  
  49. document.getElementById('ico-freccia-av').style.opacity = '1';
  50. if(nr == nSlide){
  51. //document.getElementById('ico-freccia-av').setAttribute("onclick","doQuit()");
  52. document.getElementById('ico-freccia-av').setAttribute("onclick","window.open('"+pag_principale+"','_top')");
  53. }else{
  54. document.getElementById('ico-freccia-av').setAttribute('onclick','openNr('+(nr+1)+'),\'no-block\')');
  55. }
  56. }
  57. else
  58. {
  59. document.getElementById('ico-unit-load').style.display = 'none';
  60. document.getElementById('ico-unit-attesa').style.display = 'none';
  61. document.getElementById('ico-unit-incorso').style.display = 'block';
  62. document.getElementById('ico-unit-completato').style.display = 'none';
  63. }
  64.  
  65.  
  66. nRisp = 0;
  67.  
  68. var audio_tic = document.getElementById('tic');
  69. var audio_frusta = document.getElementById('frusta');
  70. var audio_beep = document.getElementById('beep3');
  71. var audio_no = document.getElementById('no');
  72. var audio_waw = document.getElementById('waw');
  73. var audio_ding = document.getElementById('ding');
  74.  
  75. for(var i=1; i<=nSlide; i++)
  76. {
  77. if(document.getElementById('unit-'+i))
  78. {
  79. document.getElementById('u-'+i).style.display = 'none';
  80.  
  81. if(nr == i)
  82. {
  83. if(i==1)
  84. {
  85. //1. Video
  86. var video3 = document.getElementById('unit-'+nr+'-video');
  87.  
  88. if(mode == 'no-block'){
  89. video3.currentTime = 0;
  90. }
  91.  
  92. video3.play();
  93. startVideoCrono(nr,mode);
  94. video3.onended = function() {
  95. if(timeTot >= video3.currentTime){
  96. save(nr);
  97. }else{
  98. video3.currentTime = timeTot;
  99. video3.play();
  100. }
  101. };
  102. /*video3.onseeking = function() {
  103. if(video3.currentTime > timeTot){
  104. video3.currentTime = timeTot;
  105. }
  106. };*/
  107. /*$('#unit-'+nr+'-video').bind("ended", function() {
  108. save(nr);
  109. });*/
  110. }
  111. else if(i==2)
  112. {
  113. //2. Verifica finale
  114. for(j=1; j<=nTest; j++){
  115. if(j==1){
  116. document.getElementById('unit-'+i+'-test-'+j).style.display = 'block';
  117. }else{
  118. document.getElementById('unit-'+i+'-test-'+j).style.display = 'none';
  119. }
  120. document.getElementById('unit-'+i+'-test-'+j+'-A').setAttribute("class","risposta");
  121. document.getElementById('unit-'+i+'-test-'+j+'-B').setAttribute("class","risposta");
  122. document.getElementById('unit-'+i+'-test-'+j+'-C').setAttribute("class","risposta");
  123. document.getElementById('unit-'+i+'-test-'+j+'-A').setAttribute("onclick","setTest("+i+","+j+",'A');");
  124. document.getElementById('unit-'+i+'-test-'+j+'-B').setAttribute("onclick","setTest("+i+","+j+",'B');");
  125. document.getElementById('unit-'+i+'-test-'+j+'-C').setAttribute("onclick","setTest("+i+","+j+",'C');");
  126.  
  127. document.getElementById('unit-'+i+'-test-'+j+'-OK').style.display = 'none';
  128. }
  129. document.getElementById('unit-'+i+'-test-avanti').style.display = 'none';
  130. document.getElementById('unit-'+i+'-test-'+(nTest+1)).style.display = 'none';
  131. }
  132. else if(i==3)
  133. {
  134. //1. Attestato digitale
  135. //save(nr);
  136. //document.getElementById('ifr-attestato').src = 'attestato.html';
  137. }
  138. document.getElementById('u-'+i).style.display = 'block';
  139. document.getElementById('unit-'+i).style.display = 'block';
  140. }
  141. else
  142. {
  143. if(i==1)
  144. {
  145. //1. Approfondimento contenutistico (video da 3 minuti)
  146. var video3 = document.getElementById('unit-'+i+'-video');
  147. //video3.currentTime = 0;
  148. video3.pause();
  149. }
  150. else if(i==2)
  151. {
  152. //2. Verifica finale
  153. }
  154. else if(i==3)
  155. {
  156. //3. Attestato digitale
  157. }
  158.  
  159. document.getElementById('unit-'+i).style.display = 'none';
  160. }
  161. }
  162. }
  163. }
  164.  
  165. function setTest(id, nr, risposta)
  166. {
  167. var audio_tic = document.getElementById('tic');
  168. var audio_frusta = document.getElementById('frusta');
  169. var audio_beep = document.getElementById('beep3');
  170. var audio_no = document.getElementById('no');
  171. var audio_waw = document.getElementById('waw');
  172. var audio_ding = document.getElementById('ding');
  173.  
  174. rispEsatta = document.getElementById('unit-'+id+'-test-'+nr+'-OK').innerHTML;
  175.  
  176. document.getElementById('unit-'+id+'-test-'+nr+'-A').setAttribute("onClick","return false;");
  177. document.getElementById('unit-'+id+'-test-'+nr+'-B').setAttribute("onClick","return false;");
  178. document.getElementById('unit-'+id+'-test-'+nr+'-C').setAttribute("onClick","return false;");
  179.  
  180. document.getElementById('unit-'+id+'-test-'+nr+'-A').setAttribute("class","risposta risposta-disabled");
  181. document.getElementById('unit-'+id+'-test-'+nr+'-B').setAttribute("class","risposta risposta-disabled");
  182. document.getElementById('unit-'+id+'-test-'+nr+'-C').setAttribute("class","risposta risposta-disabled");
  183.  
  184. if(risposta == rispEsatta)
  185. {
  186. //audio_waw.play();
  187. audio_tic.play();
  188.  
  189. //document.getElementById('unit-'+id+'-test-'+nr+'-'+risposta).setAttribute("class","risposta risposta-esatta");
  190. document.getElementById('unit-'+id+'-test-'+nr+'-'+risposta).setAttribute("class","risposta risposta-disabled-clicked");
  191.  
  192. nRisp++;
  193. risp = nRisp;
  194. }
  195. else
  196. {
  197. //audio_no.play();
  198. audio_tic.play();
  199.  
  200. /*if(rispEsatta == 'A'){
  201. document.getElementById('unit-'+id+'-test-'+nr+'-A').setAttribute("class","risposta risposta-esatta");
  202. }else if(rispEsatta == 'B'){
  203. document.getElementById('unit-'+id+'-test-'+nr+'-B').setAttribute("class","risposta risposta-esatta");
  204. }else if(rispEsatta == 'C'){
  205. document.getElementById('unit-'+id+'-test-'+nr+'-C').setAttribute("class","risposta risposta-esatta");
  206. }
  207. document.getElementById('unit-'+id+'-test-'+nr+'-'+risposta).setAttribute("class","risposta risposta-no");*/
  208. document.getElementById('unit-'+id+'-test-'+nr+'-'+risposta).setAttribute("class","risposta risposta-disabled-clicked");
  209.  
  210. risp = nRisp;
  211. }
  212.  
  213. document.getElementById('unit-'+id+'-test-avanti').style.display = 'block';
  214. document.getElementById('unit-'+id+'-test-avanti').setAttribute('onClick','nextDomanda('+id+','+nr+','+risp+','+nTest+');');
  215. }
  216.  
  217. function nextDomanda(id, nr, risp, nTest)
  218. {
  219. var audio_tic = document.getElementById('tic');
  220. var audio_frusta = document.getElementById('frusta');
  221. var audio_beep = document.getElementById('beep3');
  222. var audio_no = document.getElementById('no');
  223. var audio_waw = document.getElementById('waw');
  224. var audio_ding = document.getElementById('ding');
  225.  
  226. audio_tic.play();
  227. //alert(id+'-'+nr+'-'+risp+'-'+nTest);
  228. document.getElementById('unit-'+id+'-test-'+nr).style.display = 'none';
  229. document.getElementById('unit-'+id+'-test-'+(nr+1)).style.display = 'block';
  230. document.getElementById('unit-'+id+'-test-'+(nr+1)).style.opacity = 0;
  231. document.getElementById('unit-'+id+'-test-avanti').style.display = 'none';
  232. document.getElementById('unit-'+id+'-test-avanti').setAttribute('onClick','return false;');
  233. $('#unit-'+id+'-test-'+(nr+1)).animate(
  234. {
  235. opacity: 1
  236. },
  237. {
  238. duration: 500
  239. }
  240. );
  241. if(nr == nTest){
  242. if(risp == 1){
  243. txt='domanda';
  244. }else{
  245. txt='domande';
  246. }
  247. document.getElementById('unit-'+id+'-risultato').innerHTML = '<strong>'+risp+' '+txt+' su '+nTest+'</strong>';
  248. save(id);
  249. }
  250. }
  251.  
  252. function openMenu(nr)
  253. {
  254. var audio_tic = document.getElementById('tic');
  255. var audio_frusta = document.getElementById('frusta');
  256. var audio_beep = document.getElementById('beep3');
  257. var audio_no = document.getElementById('no');
  258. var audio_waw = document.getElementById('waw');
  259. var audio_ding = document.getElementById('ding');
  260.  
  261. nRisp = 0;
  262.  
  263. for(var i=1; i<=nSlide; i++)
  264. {
  265. if(document.getElementById('unit-'+i))
  266. {
  267. if(i==1){
  268. //1. Video
  269. var video3 = document.getElementById('unit-'+i+'-video');
  270. //video3.currentTime = 0;
  271. video3.pause();
  272. }
  273. else if(i==2){
  274. //2. Verifica finale
  275. }
  276. else if(i==3){
  277. //3. Attestato digitale
  278. }
  279.  
  280. document.getElementById('u-'+i).style.display = 'block';
  281. document.getElementById('unit-'+i).style.display = 'none';
  282. }
  283. }
  284. }
  285.  
  286. function save(nr)
  287. {
  288. var audio_tic = document.getElementById('tic');
  289. var audio_frusta = document.getElementById('frusta');
  290. var audio_beep = document.getElementById('beep3');
  291. var audio_no = document.getElementById('no');
  292. var audio_waw = document.getElementById('waw');
  293. var audio_ding = document.getElementById('ding');
  294.  
  295. var id_user = id_user_log; // risorsa esterna
  296. var id_unit = id_unit_log; // risorsa esterna
  297. var content = 1;
  298.  
  299. if(nr == 1){
  300. //1. Video
  301. audio_ding.play();
  302. document.getElementById('unit-popup').style.display = 'block';
  303.  
  304. if(nSlide == 1){
  305. document.getElementById('unit-popup-txt').innerHTML = 'LEZIONE TERMINATA <div class="ico-freccia" style="margin-top:-10px;width:120px;float:right;" onclick="document.getElementById(\'unit-popup\').style.display=\'none\'; document.getElementById(\'unit-'+nr+'-video\').currentTime=0; document.getElementById(\'unit-'+nr+'-video\').play();"> < REPLAY </div>';
  306. document.getElementById('unit-popup-btn').innerHTML = 'VAI ALLA PROSSIMA LEZIONE >';
  307. //document.getElementById('unit-popup-btn').setAttribute("onclick","doQuit()");
  308. document.getElementById('unit-popup-btn').setAttribute("onclick","window.open('"+pag_principale+"','_top')");
  309. }else if(nSlide == 2){
  310. document.getElementById('unit-popup-txt').innerHTML = 'VIDEO TERMINATO <div class="ico-freccia" style="margin-top:-10px;width:120px;float:right;" onclick="document.getElementById(\'unit-popup\').style.display=\'none\'; document.getElementById(\'unit-'+nr+'-video\').currentTime=0; document.getElementById(\'unit-'+nr+'-video\').play();"> < REPLAY </div>';
  311. document.getElementById('unit-popup-btn').innerHTML = 'VAI AL TEST >';
  312. document.getElementById('unit-popup-btn').setAttribute("onclick","document.getElementById('unit-popup').style.display='none'; openNr("+(nr+1)+");");
  313. }
  314. }
  315. else if(nr == 2)
  316. {
  317. //2. Verifica finale
  318. audio_ding.play();
  319. document.getElementById('unit-popup').style.display = 'block';
  320. if(nRisp == 1){
  321. txt='a';
  322. }else{
  323. txt='e';
  324. }
  325. if(nRisp < nTest){
  326. document.getElementById('unit-popup-txt').innerHTML = '<br>Spiacente. Hai risposto correttamente solo a<br><span style="font-size:24px;font-weight:bold;">'+nRisp+' domand'+txt+' su '+nTest+'</span>.';
  327. if(type == 'test-finale'){
  328. document.getElementById('unit-popup-txt').innerHTML += '<br>Per ottenere l\'<span style="font-size:20px;font-weight:bold;">ATTESTATO DIGITALE<span style="font-size:20px;font-weight:bold;"><br><span style="font-size:20px;font-weight:bold;">DEVI RISPONDERE ESATTAMENTE A TUTTE LE DOMANDE</span>';
  329. }else{
  330. document.getElementById('unit-popup-txt').innerHTML += '<br>Per Passare alla lezione successiva<br><span style="font-size:20px;font-weight:bold;">DEVI RISPONDERE ESATTAMENTE A TUTTE LE DOMANDE</span>';
  331. }
  332. if(type == 'test' || type == 'test-finale'){
  333. document.getElementById('unit-popup-btn').innerHTML = 'RICOMINCIA IL TEST >';
  334. document.getElementById('unit-popup-btn').setAttribute("onclick","document.getElementById('unit-popup').style.display='none'; openNr("+(nr)+");");
  335. }else{
  336. document.getElementById('unit-popup-btn').innerHTML = '< TORNA AL VIDEO';
  337. document.getElementById('unit-popup-btn').setAttribute("onclick","document.getElementById('unit-popup').style.display='none'; openNr("+(nr-1)+",'no-block');");
  338. }
  339. }else{
  340. document.getElementById('unit-popup-txt').innerHTML = '<br>BRAVO!<BR/>Hai risposto correttamente a<br><span style="font-size:24px;font-weight:bold;">'+nRisp+' domand'+txt+' su '+nTest+'</span>';
  341. if(type == 'test-finale'){
  342. document.getElementById('unit-popup-txt').innerHTML += '<br>CORSO TERMINATO.';
  343. document.getElementById('unit-popup-btn').innerHTML = 'SCARICA il tuo ATTESTATO DI PARTECIPAZIONE >';
  344. //document.getElementById('unit-popup-btn').setAttribute("onclick","doQuit()");
  345. document.getElementById('unit-popup-btn').setAttribute("onclick","window.open('"+pag_principale+"?action=attestato','_top')");
  346. }else{
  347. if(type == 'test'){
  348. document.getElementById('unit-popup-txt').innerHTML += '<br>TEST TERMINATO.';
  349. }else{
  350. document.getElementById('unit-popup-txt').innerHTML += '<br>LEZIONE TERMINATA.';
  351. }
  352. document.getElementById('unit-popup-btn').innerHTML = 'VAI ALLA PROSSIMA LEZIONE >';
  353. //document.getElementById('unit-popup-btn').setAttribute("onclick","doQuit()");
  354. document.getElementById('unit-popup-btn').setAttribute("onclick","window.open('"+pag_principale+"','_top')");
  355. }
  356.  
  357. }
  358. content = nRisp/*+'/'+nTest*/;
  359. }
  360. else if(nr == 3)
  361. {
  362. //3. Attestato digitale
  363. }
  364.  
  365. //------------------------------------------------------
  366. if(nSlide == 1)//lezione video
  367. {
  368. lesson_location = nr;
  369. doLMSSetValue( "cmi.core.lesson_location", nr );
  370.  
  371. doLMSSetValue( "cmi.core.lesson_status", "completed" );
  372. }
  373. else if(nSlide == 2) //lezione video + test
  374. {
  375. if(nr == 2)
  376. {
  377. if(nRisp == nTest)
  378. {
  379. lesson_location = nr;
  380. doLMSSetValue( "cmi.core.lesson_location", nr );
  381.  
  382. doLMSSetValue( "cmi.core.lesson_status", "completed" );
  383. doLMSSetValue( "cmi.core.score", content );
  384. }
  385. else
  386. {
  387. doLMSSetValue( "cmi.core.score", content );
  388. }
  389. }
  390. else
  391. {
  392. lesson_location = nr;
  393. doLMSSetValue( "cmi.core.lesson_location", nr );
  394. }
  395. }
  396. if(nr<nSlide){
  397. activateUnit(parseInt(nr)+1);
  398. }
  399. //------------------------------------------------------
  400.  
  401. }
  402.  
  403. //--------------------------
  404. function startVideoCrono(nr,mode)
  405. {
  406. var video = document.getElementById('unit-'+nr+'-video');
  407.  
  408. // video.readyState
  409. //0 = HAVE_NOTHING - no information whether or not the audio/video is ready
  410. //1 = HAVE_METADATA - metadata for the audio/video is ready
  411. //2 = HAVE_CURRENT_DATA - data for the current playback position is available, but not enough data to play next frame/millisecond
  412. //3 = HAVE_FUTURE_DATA - data for the current and at least the next frame is available
  413. //4 = HAVE_ENOUGH_DATA - enough data available to start playing
  414.  
  415. if(mode == 'no-block')
  416. {
  417. if(video.readyState == 0){ // Internet Explorer
  418. video.onloadedmetadata = function() {
  419. video.currentTime = 0;
  420. };
  421. }else{ // Tutti gli altri browser
  422. video.currentTime = 0;
  423. }
  424. }
  425. else
  426. {
  427. if(doLMSGetValue( "cmi.core.total_time")){
  428. time_init = doLMSGetValue( "cmi.core.total_time");
  429. }
  430. var timeSplit = time_init.split(':');
  431. var timeH = parseInt(timeSplit[0]);
  432. var timeM = parseInt(timeSplit[1]);
  433. var timeS = parseInt(timeSplit[2]);
  434. timeTot = (timeH*3600)+(timeM*60)+timeS;
  435.  
  436. if(video.readyState == 0){ // Internet Explorer
  437. video.onloadedmetadata = function() {
  438. video.currentTime = timeTot;
  439. };
  440. }else{ // Tutti gli altri browser
  441. video.currentTime = timeTot;
  442. }
  443. }
  444.  
  445. setInterval("videoCrono('"+nr+"')", 1000);
  446. }
  447. function videoCrono(nr)
  448. {
  449. var video = document.getElementById('unit-'+nr+'-video');
  450.  
  451. if(video.currentTime >= timeTot){
  452. timeTot++;
  453. }
  454.  
  455. var hh = parseInt((timeTot - 1) / 3600);
  456. var hh_t = hh; if(hh < 9){hh_t = '0'+hh;}
  457. var hh_res = (timeTot - 1) % 3600;
  458. var mm = parseInt(hh_res / 60);
  459. var mm_t = mm; if(mm < 9){mm_t = '0'+mm;}
  460. var ss = (timeTot - 1) % 60;
  461. var ss_t = ss; if(ss < 9){ss_t = '0'+ss;}
  462. var timeTxt = hh_t+':'+mm_t+':'+ss_t;
  463.  
  464. //document.getElementById('timer').innerHTML = (timeTot - 1)+' -> '+timeTxt;
  465. //------------------------------------------------
  466. if(timeTot == 1 || timeTot % 15 == 0 || timeTot == (Math.ceil(video.duration)-1)){
  467. doLMSSetValue( "cmi.core.total_time", timeTxt);
  468. }
  469. //------------------------------------------------
  470.  
  471. if(video.currentTime > (timeTot+1)){
  472. video.currentTime = timeTot;
  473. }
  474. }
  475. //---------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement