From 7127b6f8b7e40babc36c8392a2680e13bf702bd8 Mon Sep 17 00:00:00 2001 From: Silvio Date: Tue, 25 Jun 2013 16:12:57 -0300 Subject: Allow different data sources --- timelinejs.module | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/timelinejs.module b/timelinejs.module index fbb2caf..f8ea9f6 100644 --- a/timelinejs.module +++ b/timelinejs.module @@ -186,20 +186,39 @@ function timelinejs_widget($nid = NULL, $width = '960px', $height = '500px') { /** * Menu callback. */ -function timelinejs($nid, $width = '960px', $height = '500px') { +function timelinejs($nid = NULL, $width = '960px', $height = '500px') { global $language; global $theme; global $base_url; + if ($nid == NULL) { + drupal_not_found(); + } + + $node = node_load($nid); $theme_path = drupal_get_path('theme', $theme); $library_path = libraries_get_path('timelinejs'); - $css = (file_exists($theme_path .'/timeline.css')) ? '/'. $theme_path .'/timeline.css' : '/'. $library_path .'/compiled/css/timeline.css'; + // Determine stylesheet + if (file_exists($theme_path .'/timeline.css')) { + $css = '/'. $theme_path .'/timeline.css'; + } + else { + $css = '/'. $library_path .'/compiled/css/timeline.css'; + } + + // Determine data source + if (isset($node->field_source['und'][0]['value'])) { + $source = $node->field_source['und'][0]['value']; + } + else { + $source = $base_url .'/timelinejs/json/'. (int) $nid; + } return theme('timelinejs', array( 'width' => $width, 'height' => $height, - 'source' => $base_url .'/timelinejs/json/'. (int) $nid, + 'source' => $source, 'css' => $css, 'lang' => '/'. $library_path .'/compiled/js/locale/'. $language->language .'.js', 'library_path' => $library_path, -- cgit v1.2.3