Skip to main content
Inspiring
March 9, 2018
Answered

CP9 - Hide a Group using JavaScript - Is there a better solution?

  • March 9, 2018
  • 2 replies
  • 4273 views

CP9 - HTML5 only

Hello,

I need to hide Groups using Javascript stored in an external library.

It appears that Javascript cannot hide a Group using the Group name.

The only way to do it is to hide each individual item in the group.

Although this is tedious and requires the names of the items in the Group to be numbered, it is the only way I know of doing this.

If anyone can suggest a better way I would really appreciate it, as I have about 100 groups that I need to do this with.

Thank you

Peter

This is my code:

function myHideGroup(GroupName){

// Hide all items in a Group.

// Items in the Group must be named with the Group name followed by a number.

// Example item names, 'doctor01' 'doctor02' etc.

// Name of the group to be hidden.

   var tmpGroupName = GroupName;

// Define vars to use.

   var tmpItemName  = "";

   var tmpItemNumber = "";

// Loop through all the items in the group.

   var myLoop;

   for (myLoop = 1; myLoop <= 50; myLoop++) {

     //Convert item number to a string so it can be used in the item name.

       var tmpItemNumber = myLoop.toString();

     //Pad the item number with zeros to match my names in captivate.

       while (tmpItemNumber.length < 2) {tmpItemNumber = '0' + tmpItemNumber;}

     //Concat the GroupName and ItemNumber to create the name of item to be hidden, such as 'doctor01'.

       var tmpItemName = tmpGroupName.concat(tmpItemNumber);

     //Hide the item

       cp.hide(tmpItemName);

       }

End of message.

    This topic has been closed for replies.
    Correct answer TLCMediaDesign

    You are correct that there are no groups when the file is published. Captivate just executes script to hide all of the individual objects the same as what your script is doing.

    I use a script that resets the slide to all objects original visibility state and then shows the objects with the specific naming convention.

    Your script could be modified slightly to get all of the items on a slide and check if the GroupName is in the name of the element.

    Since jQuery is available you can just do this:

    hideGroup('doctor');

    function hideGroup( which )

    {

    $("*[id*="+ which +"]:visible").each(function()

    {

      cp.hide( $(this).attr( "id" ));

    });

    }

    This will hide all objects with "doctor" in the name.

    2 replies

    Inspiring
    March 12, 2018

    Thank you all,

    I spent a few hours hard coding!

    Would still love to hear from anyone with a solution.

    Cheers.

    Peter

    TLCMediaDesign
    TLCMediaDesignCorrect answer
    Inspiring
    March 12, 2018

    You are correct that there are no groups when the file is published. Captivate just executes script to hide all of the individual objects the same as what your script is doing.

    I use a script that resets the slide to all objects original visibility state and then shows the objects with the specific naming convention.

    Your script could be modified slightly to get all of the items on a slide and check if the GroupName is in the name of the element.

    Since jQuery is available you can just do this:

    hideGroup('doctor');

    function hideGroup( which )

    {

    $("*[id*="+ which +"]:visible").each(function()

    {

      cp.hide( $(this).attr( "id" ));

    });

    }

    This will hide all objects with "doctor" in the name.

    Inspiring
    March 13, 2018

    TLC.

    Big thank you!

    That code is just so useful.

    I have added it into my library of external Javascript and I'm sure I can use it in other projects.

    Much appreciated.

    Peter

    Lilybiri
    Legend
    March 9, 2018

    Sorry, corrected a typo in the subject because Java is a totally different language than JavaScript.

    I suppose you mean an external JS-file? External Library in Captivate has another menaing to me: library from a previous project opened in the present project (File, Import menu) that allows you to reuse assets, including Shared Actions.

    Grouping happens on the stage. Is there any reason why you cannot simpy choose 'Hide Group' command, either with a simple, an advanced or a shared action. All will be converted to JS on runtime. Beware: you may have a reason for preferring JS, but that is not clear from the description.

    Can you check the version number: it should be 9.0.2.437.

    Inspiring
    March 9, 2018

    Lilybiri,

    Thank you for the correction.

    I need to use Javascript as there are lots of other actions taking place that are already in the java library.

    The solution I would like to use is to be able to somehow get a list of the item names of the items in the group, and then hide each of them.

    Thank you

    Peter

    Lilybiri
    Legend
    March 9, 2018

    IWhy no combination? I mean combining a simple command with JS? Like just hiding a group in combination with calling a function?