Forum Discussion

AbnerNoriega-82's avatar
AbnerNoriega-82
Community Member
3 months ago

Is it possible to use JavaScript to edit frame.js?

Hi!

I found this discussion about using some JavaScript code to change menu option from Restricted to Free as needed, but the issue is that it just put a layer over the menu so it is not practical to actually "restrict" the built-in menu to let the learner go back to previous slides from the menu.

In frame.js there is actually the option to change between menu options just updating from "free" to "restricted. 

"menuOptions":{"flow":"free"

I changed it manually and it works. Thing is, I would like to change it via a JavaScript so it will be updated depending on a variable change.

Can this be done? Thank you!

  • I suspect SL processes the options you have identified once, at lesson launch, so changing the value - which is possible through direct manipulation of the browser's document object model (DOM), would not result in rendered/visual functionality

  • In fact i have this worked out quite a while ago.

    ...and came to the conclusion that instead of stopping and restarting the events.. it might be much easier to just block the list items. Thus said and done.. and it works flawless.

    https://360.articulate.com/review/content/c6b7e48a-f204-441d-81ea-4cdd5ed6a524/review

    One big plus of this approach is that you can customize the menu/listitems if you want to.
    https://360.articulate.com/review/content/146cbdd5-f36c-4ce4-a5f6-94effde85c42/review

    As you can see in the second review.
    And here is the working Storyline.

    Kind regards,
    Math

    • AbnerNoriega-82's avatar
      AbnerNoriega-82
      Community Member

      Your solution was the closest one to what we wanted, the issue is that our LD Manager wants us to let the learner go back to visited slides and since yours put an overlay, it wouldn't work that way.

      Thank you so much for it, tho.

      • MathNotermans-9's avatar
        MathNotermans-9
        Community Member

        You could use separate overlays for each menuitem. Then you can target them individually and hide them if a user needs to be able to go back to a visited slide.

  • Noticing just now that you point to my solution and ask if and how to fix it in Articulate's JS files.
    Well you can change the frame JS-files in your Articulate folder at will and then it behaves exactly as you want. Problem however is that on every update the files will be erased and you have to redo it. You could try and override the generated frame.desktop.min.js  from within Storyline, but as all code in Articulate is minified and heavily obsfuscated...well it is a real puzzle to get it working..and as said before...every update will change things...

  • If someone else has this need in the future, my final solution was to create a batch file that automatically updates the menuOption to restricted.

    I know is a very specific need, but maybe it will help someone else later :)

    Since I can't attached files somehow, here is the code:

     

    @echo off

    REM Set the search text and replace text
    set "search_text=\"free\""
    set "replace_text=\"restricted\""

    REM Determine the current directory and specify the file path
    set "main_folder=%cd%"
    set "file=%main_folder%\html5\data\js\frame.js"
    set "temp_file=%file%.tmp"

    REM Check if the file exists
    if not exist "%file%" (
    echo File not found: %file%
    pause
    goto :eof
    )

    echo Processing file: %file%

    REM Use PowerShell to read and modify the file, writing to a temporary file
    powershell -Command ^
    "Get-Content '%file%' | ForEach-Object { $_ -replace '%search_text%', '%replace_text%' } | Set-Content '%temp_file%'"

    if %errorlevel% neq 0 (
    echo Error processing the file with PowerShell.
    pause
    goto :eof
    )

    REM Replace the original file with the modified temporary file
    move /y "%temp_file%" "%file%" >nul

    if %errorlevel% neq 0 (
    echo Error replacing the original file.
    ) else (
    echo Updated file: %file%
    )

    echo Done!
    pause