• i believe in what i do •
sirimalla_savechild_1098

SCORM 1.2 CMI Suspend Data

| 0 Comments | 0 TrackBacks
cmi.suspend_data: Provides space to store and retrieve data between learner sessions
Here is the code to add and retrieve Suspend Data for SCORM courses. 
Call the following functions on your course content to Set and Get the Suspend Data. 
Example: 
  • To Set call - addToSuspendData('userLocation', 'Hyderabad');
  • To Get Call - getElementFromSuspendData('userLocation');
Actual Code:
// Set Suspend Data
 function addToSuspendData(tagName, tagValue){
 	var tString = get("cmi.suspend_data");
	if( tString == null ){
		tString = "";
	}
	tString = addElement( tString, tagName, tagValue );
	set("cmi.suspend_data", tString);
 
 }
 
// Get Suspend Data
function getElementFromSuspendData(elementName){
 	var tString = get("cmi.suspend_data");
	if( tString == null ){
		tString = "";
	}
	return getElementValue(tString,elementName);
}
 
//private functions for get and set.
function getElementValue(completeString, tagName){
	var tStartIndex = completeString.indexOf( "<" +tagName+ ">" ) ;
	var tString = "";	
	if( tStartIndex != -1 ){
		tStartIndex = tStartIndex + tagName.length + 2;
	var tEndIndex = completeString.indexOf("");
	if( tEndIndex == -1 ){
		tEndIndex = completeString.length;
	}
	tString = completeString.substring( tStartIndex, tEndIndex );
	}
	return tString;	
}

function getElementString(tagName, tagValue){
	return "<" + tagName + ">" + tagValue + "";
}


function addElement(completeString, tagName, tagValue){
	var tStartIndex = completeString.indexOf( "<" +tagName+ ">" );
	if( tStartIndex == -1 ){
		completeString += getElementString(tagName,tagValue);
	}
	else{
		tStartIndex +=  tagName.length + 2;
		tEndIndex = completeString.indexOf("");
		completeString = completeString.substring(0,tStartIndex) +  tagValue + completeString.substring(tEndIndex,completeString.length);
	}
	return completeString;
}

No TrackBacks

TrackBack URL: http://sirimalla.com/mt5/mt-tb.cgi/91

Leave a comment