Skip to main content
srih88223272
Participant
June 28, 2016
Question

Javascript coding for captivate

  • June 28, 2016
  • 3 replies
  • 504 views

I have an adobe captivate slide in which there are four buttons. Each button is associated with an array. When button is clicked, the array is displayed. When two buttons are clicked, the arrays get concatenated. I have done everything what I need, but I got stuck with the sorting. The array displayed needs to be sorted in alphabetical order (even if two arrays got concatenated). The array should also get de-duplicated.

I have tried with code below.(JS associated with slide)

var someThings = [ ];
var selected = [ ];
var b_or_v =["bet-vet","bat-vat","reb-rev","bick-vic","ban-van"];
var b_or_p =["back-pack","bet-pet","bit-pit","ban-pan","bin-pin"];
var I_or_e =["bit-bet","pit-pet","sit-set","rib-reb","pick-peck","pin-pen","rip-rep"];
var e_or_a =["bet-bat","set-sat","vet-vat","peck-pack","pet-pat","pen-pan","rep-rap"];
function getUnique( arr )
{
var dupes = [ ];
return arr.filter( function( item )
{
  
return dupes.hasOwnProperty( item ) ? false : ( dupes[ item ] = true );
});
}
function newArray( arr )
{  
var temp = [ ];
if ( selected.indexOf( arr ) != -1 )
{ 
selected
.splice( selected.indexOf( arr ), 1 );
for ( var i = 0; i < selected.length; i++ )
{
temp
= temp.concat( selected[ i ] ).sort();
}
someThings
= temp;
}
else
{
selected
[ selected.length ] = arr+20;
someThings
= someThings.concat( arr ).sort();
} 
}
function newThings( )
{
var str = getUnique( someThings ).toString();
var res = str.replace( /-/g, ", ");
window
.cpAPIInterface.setVariableValue( "things", res );
}

The JS associated with /b/ or /v/ button is

newArray(b_or_v);

The JS associated with /b/ or /p/ button is

newArray(b_or_p);

The JS associated with /I/ or /e/ button is

newArray(I_or_e);

The JS associated with /e/ or /a/ button is

newArray(e_or_a);

The JS associated with submit button :

newThings( );

I got perfect result on jsbin.Im unable to do the same in adobe captivate.

JSBin link( for perfect output):   JS Bin - Collaborative JavaScript Debugging

It is the slideenter image description here

This topic has been closed for replies.

3 replies

srih88223272
Participant
June 29, 2016

If I need to include as external js file, how to do it?

TLCMediaDesign
Inspiring
June 29, 2016

Put the js file here:

C:\Program Files\Adobe\Adobe Captivate 9 x64\HTML\assets\js\

edit the index.htm located here:

C:\Program Files\Adobe\Adobe Captivate 9 x64\HTML\

with this code in the head section:

<script src="assets/js/yourjsfilename.js"></script>

srih88223272
Participant
June 29, 2016

I put my js code in the script window in actions part

TLCMediaDesign
Inspiring
June 29, 2016

If you are executing this in the js window, don't. Put it int the index or an external js file.

srih88223272
Participant
June 29, 2016

I didn't get you. Can you please eleborate?

TLCMediaDesign
Inspiring
June 29, 2016

Where do you have the code?

If you put it in the JS window, Captivate has to escape the code in the CPM.js file.

I always, put my code in an external js file that gets included in the Captivate template files.