Arjunsos / simile-widgets

Automatically exported from code.google.com/p/simile-widgets
0 stars 0 forks source link

TIMEPLOT: ?local doesn't work #74

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When specifying the "?local" option, Timeplot assumes two things.
1) The scripts are in the same location as the HTML calling them.
2) The scripts exist in the root of the location the HTML came from.

For example, install the Simile suite into a directory called simile on a
webserver named sam. The script tag would look like this:
<script src="http://sam/simile/timeplot/api/1.0/timeplot-api.js?local"
type="text/javascript"/>

Now I load an HTML file from my local drive, file:///C:/temp/tp.htm

Timeplot will fail because at lines 142 and 153 of timeplot-api.js the
local urls are hard coded to "/". This means the browser is trying to
retrieve simile-ajax-api.js from the root of where the HTML came from (i.e.
file:///C:/simile-ajax-api.js)

To solve this problem, I created a script variable named "simileroot" and
store the url to where Simile is installed. Here's how to call it.

<script>
var simileroot = "http://sam/simile";
</script>
<script src="http://sam/simile/timeplot/api/1.0/timeplot-api.js?local"
type="text/javascript"/>

I modified line 142 of timeplot-api.js to read:
var timelineURL = (local) ? simileroot +
"/timeline/api-2.0/timeline-api.js?bundle=false" :
"http://static.simile.mit.edu/timeline/api-2.0/timeline-api.js";

I modified line 153 of timeplot-api.js to read:
simileroot + "/ajax/api-2.0/simile-ajax-api.js?bundle=false" :

I also had to modify line 107 of timeplot-api.js to read:
var timeplotURLPrefix = Timeplot.urlPrefix;
The conditional test was no longer needed.

This took longer to debug than normal because Firefox ASSumes that the
encoding of the Javascript files are the same as the HTML file calling
them. Powershell has a rather annoying habit of writing UNICODE when you
redirect the output of a script to a file. So, when my script produced a
UTF16 HTML file, Firefox was failing to load the timeplot-api.js file
saying "Invalid character line 1". grr arg

Keep up the fantastic work!

[Reported by Sam Blackburn on simile.mit.edu]

You know, additionally, the way that timeplot appears to be looking for
?local also won't work:

    var local = false;

    // obtain local mode from the document URL
    if (document.location.search.length > 0) {
        var params = document.location.search.substr(1).split("&");
        for (var i = 0; i < params.length; i++) {
            if (params[i] == "local") {
                local = true;
            }
        }
    }

The above code will pull from the parent document's location.search, not
the url with which the javascript was called.

Users who want to use timeplot locally will probably have to simply set the
flag to true in their own local copy.

[Comment by Paul Huff on simile.mit.edu]

Original issue reported on code.google.com by stefano.mazzocchi@gmail.com on 25 Mar 2009 at 5:41

GoogleCodeExporter commented 8 years ago

Original comment by stefano.mazzocchi@gmail.com on 25 Mar 2009 at 6:42