0
Answered
Is there a way to load script files located in a different directories
Just wondering if you support loading JavaScript files that are not located in the same folder as the html file?
I have the following folder structure…
Textastic/Library
Textastic/Filters
Textastic/CanvasPlay
the html file in CanvasPlay includes the following script files..
../Library/script.js
../Filters/script.js
script.js
script.js loads, but not the other files.
am I missing something, or does your viewer not support this?
Customer support service by UserEcho
Using relative paths should work. Can you please show me the relevant part of your .html file?
Please note that file paths on iOS are case-sensitive. So "Filters" is not the same folder as "filters".
Just to be sure, I tried it out:
In Local Files, I created the folders "Library" and "CanvasPlay".
Then I added the file "script.js" in the "Library" folder with these contents:
I added the file "index.html" in the "CanvasPlay" folder:
When I preview the "CanvasPlay/index.html" file, it does show the JavaScript alert from "Library/script.js".
Sweet, I’ll double check my code
Folder and file names are all good but still doesn’twork… I am storing all my folders/files on iCloud Drive. I’ll duplicate the file structure on my iPad, and see if that makes a difference. Not sure if the path needs to somehow reference iCloud Drive.
The first screenshot is of the html file that is in a folder where all its referenced files are located. I copied that html file to another folder (second screen shot) which is at the same level the original html file is in. Then I changed the references to the src files using indirect addressing. When I try to run new html file I get LineChart not found. That’s the first line in the embedded script, and LineChart is defined in ChartClass/script.js
I moved the folders using relative file addresses to the local files , and it worked. The same folders on iCloud don't work.
It seems like it's something to do with iCloud.
I just moved the folders from "Local Files" to the "iCloud" location on my iPad and it still works for me.
Not sure what's going on.
Can you please double-check the name of the "ChartClass" folder? Maybe there is a space somewhere (e.g. "ChartClass<space>") or something?
Does it recognize the "../ChartClass/style.css" file?
If you want, you can make a .zip file with the ChartClass and ChartUse folder in Textastic and send it to support@textasticapp.com so I can try to reproduce the issue here.
I sent support a very simplified version that exhibits the issue on my end.
I unzipped your two .zip files into Textastic's "iCloud" location.
Both "relative.html" and "relativeTest.html" work for me.
Here are screenshots from my iPad:
What I just noticed: in my screenshot, the back button is labelled "iCloud" while in your screenshot, the back button is labelled "Textastic".
Have you maybe added two folders in iCloud Drive using "Add External Folder…" and are trying to reference from one external folder to the other?
This won't work. It needs to be the same external folder. So you need to add the parent folder that contains the two subfolders that contain your files.
So, if you have a folder in iCloud Drive called "Projects" which in turn contains "ChartClass" and "ChartUse", add the "Projects" folder as an external folder to Textastic and it should work.
I have a folder in iCloud labeled Textastic. That’s where the relative and RelativeTest folders are located.
it’s is interesting to note that when I press the iCloud tab under Local Files in your app the result is empty. Maybe I don’t understand what’s meant by add external folder in the app.
Click the "iCloud" location that is shown in this screenshot and create a file or folder in it using the "+" button. Then you should get a new folder called "Textastic" in the Files app that has Textastic's app icon on it.
I do have an external folder setup as Textastic in the app (see the screenshot I sent earlier), and if I navigate to relativeTest from there, it works fine! It doesn’t work if I navigate to to it from the relativeTest folder (also in the previous screenshot). I guess I’m confused about the function/use of “external folders”
I'll try to explain:
Each app can have a folder in iCloud Drive that it can access without the user needing to add it manually.
This folder only appears in the Files app when there is at least a single file in it.
So, please go to "iCloud" in Textastic and add a file or folder.
Then, a folder called "Textastic" should appear in the Files app at iCloud Drive/Textastic with Textastic's app icon on it.
This is the recommended approach.
Alternatively, you can give Textastic access to any folder in iCloud Drive by using the "Add External Folder…" command. This also works for folders in "On my iPad" or with folders in the Git client "Working Copy" among other things.
Please also have a look at this topic in the manual: https://www.textasticapp.com/v10/manual/managing_files/local_files_icloud.html
It tries to explain the Local Files and iCloud locations as well as external folders.
My issue (not an issue with your design, but the problem I was having) is the following. I thought I was creating shortcuts to app folders with the ‘Add External Folder” menu item. It’s when I navigate to one of my apps by clicking on that apps “External Folder” (see “relativeTest External: iCloud Drive” in the photo I sent) that the relative addressing doesn’t work. I suppose I shouldn’t be creating external folders as shortcuts to apps, as that breaks something.
I see. Yeah, please only add the parent folder as an external folder.
Textastic doesn't know the relationship between external folders.
If you use the "Add External Folder…" command, the system presents the Files app user interface in a secure way (using XPC).
When the user selects a folder, Textastic gets a so-called "security scoped URL" from the system. Opening this URL extends the app's sandbox so it can now access that folder.
Textastic has very limited information about folders opened in this way. For example, it does not know that folder "ChartUse" and "ChartClass" share the same parent folder.
That's why relative URLs only work within the same location (Local Files, iCloud, or an external folder).
sounds good, thanks.
BTW, I love the app. Keep up the good work, it gives this old retired EE a platform to help keep the grey matter working.