Drupal 5.1 で timeline module を利用する

Inside ASCADE は Drupla 5.1 で構築されておりますが、Drupal 4.X 向けにリリースされている timeline moduleを Drupal 5.1 に適応した際のメモ(というか差分)です。

ちなみに、timeline は MIT の SIMILE(Semantic Interoperability of Metadata and Information in unLike Environments) Project の 1プロダクトで、timeline module は それを drupal のコンテンツ表示に利用したモジュールです。

timeline  at SIMILE

timeline module  at drupal.org

ファイル一覧
timeline/
timeline/tests/
timeline/tests/feed.test
timeline/CHANGELOG.txt
timeline/INSTALL.txt
timeline/README.txt
timeline/timeline.css
timeline/timeline.info
timeline/timeline.install
timeline/timeline.js
timeline/timeline.module
timeline/timeline.theme.inc
timeline/timeline.views.inc
timeline/LICENSE.txt
tar ztf timeline-4.7.x-1.0.tar.gz
Drupal 5.1 向け修正対象ファイル一覧
Drupal 5.1 向け修正内容

1. timeline.install

まずは timeline.install ファイルです。Drupal 5.x 系から module_exist は module_existsに変更になりました。

   if (!module_exist('views'))
before : timeline.install
   if (!module_exists('views'))
after : timeline.install

2. timeline.js

続いて timeline.js ファイルです。Timeline.create 関数に渡す第一パラメータを document.getElementById(id) に変更します。

   var widget = Timeline.create($(id),
                                bandInfos,
                                orientation);
before : timeline.js
   var widget = Timeline.create(document.getElementById(id),
                                bandInfos,
                                orientation);
after : timeline.js

3. timeline.theme.inc

次に timeline.theme.inc ファイルです。theme_add_style 関数は Drupal 5.X では drupal_add_css ですのでこれを変更します。

   theme_add_style(drupal_get_path('module', 'timeline') . '/timeline.css');
before : timeline.theme.inc
   drupal_add_css(drupal_get_path('module', 'timeline') . '/timeline.css');
after : timeline.theme.inc

timeline widget を生成する箇所のスクリプトを修正します。参考にしたのはこちらのページ。というわけでここは after のみ掲載します。

   $output = "

   <div id=\"$timeline->id\" class=\"timeline\" style=\"$style\">
   </div>

   <script type=\"text/javascript\">

     var createWidgetFunction = function() {
       return createTimelineWidget(\"$timeline->id\",
                                   Timeline.$timeline->orientation,
                                   \"$timeline->start_date\",
                                   '+9',
                                   \"$url\",
                                   \"json\");
     }
     setTimeout(createWidgetFunction, 1);

   </script>

   ";
after : timeline.theme.inc

以上で、Drupal 4.X 用 timeline モジュールが Drupal 5.1 で動作するようになります。

patch file

patch file を作成しましたので、ファイルをダウンロードし、以下のように適用してください。download

patch < timeline-4.7.x-1.0.patch 
Inside ASCADE 表示向けに調整する

Drupal 5.1 への対応とは別に、Inside ASCADE でのユーザビリティ向上のため調整した箇所を例示します。

Inside ASCADE 対応の対象ファイル一覧
Inside ASCADE 対応内容

1. timeline.js

Inside ASCADE のコンテンツ更新頻度は週1本程度ですので、timeline 導入によりコンテンツの時系列による見栄え、操作性を考慮し、intervalUnit 及び intervalPixels を表示具合を確認しながら設定しました。

  var bandInfos = [
    Timeline.createBandInfo({
      width:          '75%',
      intervalUnit:   Timeline.DateTime.DAY,
      intervalPixels: 200,
      eventSource:    eventSource,
      date:           initialDate,
      timeZone:       timeZone,
      theme:          theme
    }),
    Timeline.createBandInfo({
      width:          '25%',
      intervalUnit:   Timeline.DateTime.MONTH,
      intervalPixels: 200,
      eventSource:    eventSource,
      date:           initialDate,
      timeZone:       timeZone,
      theme:          theme,
      showEventText:  false,
      trackHeight:    0.5,
      trackGap:       0.2
    })
  ];
before : timeline.js
  var bandInfos = [
    Timeline.createBandInfo({
      width:          '75%',
      intervalUnit:   Timeline.DateTime.MONTH,
      intervalPixels: 220,
      eventSource:    eventSource,
      date:           initialDate,
      timeZone:       timeZone,
      theme:          theme
    }),
    Timeline.createBandInfo({
      width:          '25%',
      intervalUnit:   Timeline.DateTime.YEAR,
      intervalPixels: 500,
      eventSource:    eventSource,
      date:           initialDate,
      timeZone:       timeZone,
      theme:          theme,
      showEventText:  false,
      trackHeight:    0.5,
      trackGap:       0.2
    })
  ];
after : timeline.js

2. timeline.theme.inc

表示時に現在時刻が中心になるよう timeline オブジェクトに start_date を追加し、現在時刻を設定します。上記のcreateTimelineWidget へ渡す基準時刻も initial_date から start_date に変更になっています。

if (empty($timeline->initial_date)) {
    $timeline->initial_date =
    date('D M d Y G:i:s') . ' GMT' . date('O');
}
before : timeline.theme.inc
if (empty($timeline->start_date)) {
    $timeline->start_date =
    date('D M d Y G:i:s') . ' GMT' . date('O');
}
after : timeline.theme.inc

3. timeline.module

表示する高さもデフォルトだと少し高すぎるので調整しました。

define('TIMELINE_HEIGHT',
       variable_get('timeline_default_height', '400px'));
before : timeline.module
define('TIMELINE_HEIGHT',
       variable_get('timeline_default_height', '250px'));
after : timeline.module