From 4b828a3db6cc159fc3cef46672c77d5d533d04f2 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Fri, 18 Apr 2014 19:32:49 -0500 Subject: [PATCH] Improve syntax for update_toc() - use jQuery whenever possible - refs #398 (cherry picked from commit 7642f07e71d4c26cf3af94c43b8ecae00fe9ccd9) --- main/newscorm/scorm_api.php | 86 +++++++++++++------------------------ 1 file changed, 30 insertions(+), 56 deletions(-) diff --git a/main/newscorm/scorm_api.php b/main/newscorm/scorm_api.php index 0628b9ff1f..5187aab1f7 100644 --- a/main/newscorm/scorm_api.php +++ b/main/newscorm/scorm_api.php @@ -2,13 +2,13 @@ /* For licensing terms, see /license.txt */ /** - * API event handler functions for Scorm 1.1 and 1.2 and 1.3 + * API event handler functions for Scorm 1.1 and 1.2 and 1.3 * - * @author Denes Nagy - * @author Yannick Warnier - * @version v 1.0 - * @access public - * @package chamilo.learnpath.scorm + * @author Denes Nagy (original author - 2003-2004) + * @author Yannick Warnier (extended and maintained - 2005-2014) + * @version v 1.1 + * @access public + * @package chamilo.learnpath.scorm */ /** @@ -552,7 +552,7 @@ function LMSGetValue(param) { } else if(param == 'cmi.interactions._children'){ // ---- cmi.interactions._children result = 'id,time,type,correct_responses,weighting,student_response,result,latency'; - } else{ + } else { // ---- anything else // Invalid argument error olms.G_LastError = G_InvalidArgumentError ; @@ -1162,60 +1162,34 @@ function update_toc(update_action, update_id, change_ids) { logit_lms('update_toc("'+update_action+'", '+update_id+')',2); if (update_id != 0) { - switch (update_action) { - case 'unhighlight': - if (update_id%2==0) { - myelem.attr('class',"scorm_item_2"); - } else { - myelem.attr('class',"scorm_item_1"); - } - break; - case 'highlight': + // Switch function is broken + if (update_action == "unhighlight" || update_action == "highlight") { + if (update_action == "unhighlight") { + myelem.removeClass('scorm_item_highlight'); + } else { if (change_ids=='yes') { olms.lms_next_item = update_id; olms.lms_previous_item = update_id; } - myelem.attr('class',"scorm_item_highlight"); - break; - case 'not attempted': - if( myelemimg.attr('src') != '../img/notattempted.gif') { - myelemimg.attr('src','../img/notattempted.gif'); - myelemimg.attr('alt','n'); - } - break; - case 'incomplete': - if( myelemimg.attr('src') != '../img/incomplete.png') { - myelemimg.attr('src','../img/incomplete.png'); - myelemimg.attr('alt','i'); - } - break; - case 'completed': - if( myelemimg.attr('src') != '../img/completed.png') { - myelemimg.attr('src','../img/completed.png'); - myelemimg.attr('alt','c'); - } - break; - case 'failed': - if( myelemimg.attr('src') != '../img/delete.png') { - myelemimg.attr('src','../img/delete.png'); - myelemimg.attr('alt','f'); - } - break; - case 'passed': - if( myelemimg.attr('src') != '../img/completed.png' && myelemimg.attr('alt') != 'passed') { - myelemimg.attr('src','../img/completed.png'); - myelemimg.attr('alt','p'); - } - break; - case 'browsed': - if( myelemimg.attr('src') != '../img/completed.png' && myelemimg.attr('alt') != 'browsed') { - myelemimg.attr('src','../img/completed.png'); - myelemimg.attr('alt','b'); - } - break; - default: + myelem.addClass('scorm_item_highlight'); + } + } else { + myelem.removeClass("scorm_not_attempted scorm_incomplete scorm_completed scorm_failed scorm_passed"); + if (update_action == "not attempted") { + myelem.addClass('scorm_not_attempted'); + } else if (update_action == "incomplete") { + myelem.addClass('scorm_incomplete'); + } else if (update_action == "completed") { + myelem.addClass('scorm_completed'); + } else if (update_action == "failed") { + myelem.addClass('scorm_failed'); + } else if (update_action == "passed") { + myelem.addClass('scorm_passed'); + } else if (update_action == "browsed") { + myelem.addClass('scorm_completed'); + } else { logit_lms('Update action unknown',1); - break; + } } } return true;