0

I am trying to include the timeline API, and install the timline files on my webserver. The timeline-api.js gives an example of an HTML page that contain the following code.

<script>
var Timeline_ajax_url="http://YOUR_SERVER/apis/timeline/ajax/simile-ajax-api.js";
var Timeline_urlPrefix='http://YOUR_SERVER/apis/timeline/';       
</script>
<script src="http://YOUR_SERVER/javascripts/timeline/timeline-api.js"    
type="text/javascript">
</script>

It also contain the following comment.

   /*
    * Eg the two next lines pass the same parameters:
    * Timeline_parameters='bundle=true';                    // pass parameter via js variable
    * <script src="http://....timeline-api.js?bundle=true"  // pass parameter via url 
    */

I am trying to do the same thing in Drupal using the following code.

$timeline_lib_path = $base_path . libraries_get_path('simile_timeline');
// Set some global js variables that the library is going to need for proper inclusion and functionality.
$timeline_inline_js = "
var Timeline_ajax_url = '$timeline_lib_path/timeline_ajax/simile-ajax-api.js',
Timeline_urlPrefix = '$timeline_lib_path/timeline_js/',
Timeline_parameters = 'bundle=true';
";
drupal_add_js('similetimeline',$timeline_inline_js);
drupal_add_js('similetimeline','$timeline_lib_path/timeline_js/timeline-api.js');

I have an uncaught reference error: Timeline is not defined.

5
  • Where did you put this code ? Is the js file correctly added to your page ? It seems unlikely as the second drupal_add_js statement should use double quotes and not simple ones to work.
    – Countzero
    May 26 '12 at 15:11
  • Its in the page call back function. Have tried the double quotes but to no affect :(
    – mu_sa
    May 26 '12 at 15:23
  • Do you see a line in your rendered html page showing the file ? BTW, your statement var statement should also use double quotes, as it contains PHP variables.
    – Countzero
    May 26 '12 at 15:25
  • Yes. the .JS is rendered and where i create the Timeline object in the .JS file it throws an exception there.
    – mu_sa
    May 26 '12 at 15:47
  • can you elobarte a bit more on where to use the double quotes for the var statement.
    – mu_sa
    May 26 '12 at 15:58
0

You have the smallest of errors in your code; in the very last line you're trying to interpolate a variable into a string using single quotes. You need to use double quotes instead:

drupal_add_js('similetimeline',"$timeline_lib_path/timeline_js/timeline-api.js");

Have a peek at the PHP Strings Documentation for more information.

I've just noticed another problem actually; you don't seem to be using drupal_add_js() properly. The first argument should be the name of a file or an inline string, in which case you should specify that it's inline:

drupal_add_js($timeline_inline_js, 'inline');
drupal_add_js("$timeline_lib_path/timeline_js/timeline-api.js");
3
  • Tried both of your advice..Still not working.. :(
    – mu_sa
    May 26 '12 at 16:39
  • I've updated the answer it might help
    – Clive
    May 26 '12 at 16:51
  • It helped. Thanks ! . I am onto next encounterd problem :)
    – mu_sa
    May 26 '12 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.