Explore the community Forums Lectora Lectora Questions & Answers Retrieve TOC completed pages into variable

Tagged: 

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #347275 Score: 0
    Profile photo of tamer kosker
    tamer kosker
    Member
    beginner
    intermediate
    contributor
    wise owl
    curious george
    @tkosker1029

    Hello All

    Does anyone have a  code sample of a javascript to retrieve completed / incompleted page count into a variable from TOC content without using LMS or scorm?

     

    I will appreciate if you can share any sample doing this.

     

    Regards

    #347284 Score: 0
    Profile photo of tamer kosker
    tamer kosker
    Member
    beginner
    intermediate
    contributor
    wise owl
    curious george
    @tkosker1029

    Just a quick note I need to count the pages which belongs to chapters as completed

    #347438 Score: 1
    Profile photo of Peter Jackson
    Peter Jackson
    Member
    beginner
    intermediate
    advanced
    friend finder
    contributor
    junior moderator
    wise owl
    group mod
    entry
    winner
    14 pts
    @pjackson2462

    G’day Tamer,

    pageStatus = trivPageTracking.GetRangeStatus(pageNumber);

    This will return “complete” or “notstarted”, the pageNumber would start at 1 and end with the number of pages you have in the title.  The number of pages in a give chapter is in the TOC but you need a lot of work to get at it, I suggest that you simple take note of the start and end page numbers of each of the chapters and hard wire these for each title, not the best solution but it will work.

    HTH

    Regards, Peter

    This post has received 1 vote up.
    #347463 Score: 0
    Profile photo of tamer kosker
    tamer kosker
    Member
    beginner
    intermediate
    contributor
    wise owl
    curious george
    @tkosker1029

    Thanks for your suggestion. I just created 10 empty pages and a TOC and run JS as follows :

    cNum=0;
    cNum2=0;
    for (i = 1; i < 11; i++) {
    pageStatus=”incomplete”;
    pageStatus = trivPageTracking.GetRangeStatus(i);
    if (pageStatus===”complete”) {
    cNum=cNum+1;
    }
    }
    Varpagecount.set(cNum);

     

    but this does not return correct number of completed pages. I am new in JS so I might have mistake.

     

    #347470 Score: 0
    Profile photo of Peter Jackson
    Peter Jackson
    Member
    beginner
    intermediate
    advanced
    friend finder
    contributor
    junior moderator
    wise owl
    group mod
    entry
    winner
    14 pts
    @pjackson2462

    G’day Tamer,

    Well done on the JavaScript, I made some changes, try the following:

    var cNum=0;
    var status=”;
    for (i=1; i<11;i++){
    pageStatus = trivPageTracking.GetRangeStatus(i);
    status+= i + ‘ ‘ + pageStatus + ‘ ‘;
    if (pageStatus==’complete’) {
    cNum += cNum;
    }
    }
    alert(cNum + ‘ ‘ + status);

    You had 3 ‘=’ equals in the “if” line.

    If you add a TOC that shows pages visited then the count should be the same as what the TOC displays.  You will need to clear your cache as each time you launch the page visited data is stored in your cache.

    HTH

    #347472 Score: 0
    Profile photo of tamer kosker
    tamer kosker
    Member
    beginner
    intermediate
    contributor
    wise owl
    curious george
    @tkosker1029

    Hi Peter,

    I have tried it but no luck. I have used the code as follows and you can see the result in screenshot I attached. What can be the issue I am missing?

    var cNum=0;
    var status=””;
    for (i=1; i<11;i++){
    pageStatus = trivPageTracking.GetRangeStatus(i);
    status+= i + ” ” + pageStatus + ” “;
    if (pageStatus==”complete”) {
    cNum += cNum;
    }
    }
    alert(cNum + ” ” + status);

    #347503 Score: 0
    Profile photo of Peter Jackson
    Peter Jackson
    Member
    beginner
    intermediate
    advanced
    friend finder
    contributor
    junior moderator
    wise owl
    group mod
    entry
    winner
    14 pts
    @pjackson2462

    I’m really sorry, I have cNum += cNum; it should be cNum += 1;

    That said, I don’t know why your TOC shows that pages completed with the function are not completed in the TOC.  I don’t know how this is possible as it works perfect for me, sorry about that.

    Regards, Peter

    #347524 Score: 0
    Profile photo of tamer kosker
    tamer kosker
    Member
    beginner
    intermediate
    contributor
    wise owl
    curious george
    @tkosker1029

    Hi Peter

    I am also shocked why I am getting these random results. There might be a solution but we two are not enough to solve this I think.

    Thanks for your help.

    Kind Regards

    #347825 Score: 1
    Profile photo of Andrew Gaudet
    Andrew Gaudet
    Moderator
    beginner
    intermediate
    contributor
    verified member
    wise owl
    friend finder
    9 pts
    @agaudet1236

    So i just gave the script a try everything looks good with it.

    However one thing to notice is that this uses a cookie system to track page visitation and display it correctly. If you are in publish preview mode there is the possibility of the status being cached already, which  I ran into when  i visited each page it stored the “complete” status for the page so when i went to “test” it again that value was already complete

    Doing a full publish and storing it on my local webserver and re checking your script there It worked as intended displaying the first page as in progress and each remaining as not started.

    That would explain the random behavior when the script is pretty straight forward. To test it correctly deleting the cookie/clearing your cache between visits is a must to see the correct output.

    This post has received 1 vote up.
    • This reply was modified 7 months, 3 weeks ago by Profile photo of Andrew Gaudet Andrew Gaudet.
    • This reply was modified 7 months, 3 weeks ago by Profile photo of Andrew Gaudet Andrew Gaudet.
    #347892 Score: 0
    Profile photo of Darrel Somoza
    Darrel Somoza
    Member
    contributor
    friend finder
    beginner
    intermediate
    junior moderator
    advanced
    wise owl
    curious george
    159 pts
    @Klaatu

    …disregard

    • This reply was modified 7 months, 3 weeks ago by Profile photo of Darrel Somoza Darrel Somoza.
Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.