NUKnightLab / NUKnightLab/TimelineJS3
Local installation and `script_path` option leads to an error
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 3.2k
- Forks
- 645
- PR merge metrics
- No merged PRs in 30d
Description
I think I found a bug related to a local installation when you try to set a custom language (but it looks to be a more global issue related to script_path option, it might be linked to #718).
Steps to reproduce:
- get the
zipfile from https://timeline.knightlab.com/docs/instantiate-a-timeline.html#local_files and unzip it in a local folder - copy-past that minimal example to reproduce the issue:
<link title="timeline-styles" rel="stylesheet" href="/timeline3/css/timeline.css">
<script src="/timeline3/js/timeline.js"></script>
<div id='timeline-embed' style="width: 100%; height: 100vh"></div>
<script id="timeline-data" type="application/json">
{
"title": {
"text": {
"headline": "A bug report",
"text": "About script_path and local files."
}
},
"events": [
{
"start_date": {
"day": "25",
"month": "05",
"year": "2022"
},
"text": {
"headline": "Creation",
"text": "With a minimal scenario."
}
}
]
}
</script>
<script type="text/javascript">
const timeline_json = JSON.parse(
document.getElementById('timeline-data').textContent
)
const options = {
// This is the value that raises an error.
script_path: "/timeline3/js/",
// To make sure it gets used.
language: "fr"
}
window.timeline = new TL.Timeline('timeline-embed', timeline_json, options)
</script>
- check the console of your browser (Firefox 100.0.1 in my case but tested with Chromium too), there is an error
Uncaught TypeError: URL constructor: /timeline3/js/ is not a valid URL.even if you serve that folder.
If I switch the script_path option to a full local URL (let's say http://127.0.0.1:8000/timeline3/js/ it does solve the problem but it's not really portable 😄).
That line looks to be responsible of the issue: https://github.com/NUKnightLab/TimelineJS3/blob/master/src/js/timeline/Timeline.js#L219 and there is probably something to fix on that line too: https://github.com/NUKnightLab/TimelineJS3/blob/master/src/js/timeline/Timeline.js#L232
Please let me know if I missed something, I'm new to the project. I'm willing to contribute with a PR if there is some guidance from a more experimented person 🤗
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the local installation example and inspect src/js/timeline/Timeline.js at the reported lines 219 and 232. Reproduce the error with a relative script_path and language set to fr, then verify that the local timeline loads without the URL constructor error while retaining support for a full local URL.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100