djplaner / word-to-canvas-module

A userscript that will create a Canvas Module (including all module items) from a Word document (using special styles)
https://djplaner.github.io/word-to-canvas-module/
MIT License
0 stars 0 forks source link

Add an file link style #26

Open djplaner opened 2 years ago

djplaner commented 2 years ago

Have a canvas file link style in word that allows linking to files within pages.

anchor text is the display name, the link is either file name or link.

Required change

Original

<span class="canvasFileLink">Lifelong Learning and Alice Srpings.docx</span>

Where the innerText is the name of the file.

preview_in_overlay

<span class="instructure_file_holder link_holder instructure_file_link_holder">
<a class="inline_disabled preview_in_overlay" href="FILE_URL?wrap=1" target="_blank"
    data-canvas-previewable="true" data-api-endpoint="FILE_URL" data-api-returntype="File">
</span>

preview inline

<span class="instructure_file_holder link_holder instructure_file_link_holder">
<a class="file_preview_link" href="FILE_URL?wrap=1" target="_blank"
    data-canvas-previewable="true" data-api-endpoint="FILE_URL" data-api-returntype="File"
    aria-expanded="false" aria-controls="preview_1"
>
</span>
djplaner commented 2 years ago

Implementation

djplaner commented 2 years ago

Code

c2m_CompletedView calls

  1. model.createModule
  2. checkEmptyModuleCreated (event handler) which calls findOrCreateModuleItems
  3. checkItemFoundCreated (eventHandler) which calls addModuleItem to add first found item
  4. checkModuleItemAdded (eventHandler) which calls
    1. addModuleItem when not finished to add the next item
    2. renderCreationResults when finished

findOrCreateModuleItems

Currently loops through each item and then calls findOrCreteItem

May need to create a new item type OR perhaps call a different method findExistingFile