即時通訊使用[drupal_add_js_()][1]
函數添加fancybox效果我的節點(即時通訊不使用Fancybox模塊,因爲不適合我的需要)。Drupal:添加一個js函數回調Drupal.settings
總之,我需要添加titleFormat
函數來格式化圖像標題;在我的JavaScript文件,它看起來像:
$("a[rel=myfancy_group]").fancybox({
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'titlePosition': 'over',
'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
return '<span><b>' + title + '</b> | Image ' + (currentIndex + 1) + ' of ' + currentArray.length + (title.length ? ' ' + title : '') + '</span>';
}
});
這是我drupal_add_js
功能的外觀:
drupal_add_js(
array(
'mycustom_fancybox' => array(
'selector' => 'div.field-field-immagini-minigallery a',
'group' => TRUE,
'options' => array(
'transitionIn' => 'elastic',
'transitionOut' => 'elastic',
'titlePosition' => 'inside',
'titleShow' => TRUE,
'width' => 500,
'cyclic' => TRUE,
'titleFormat' => ???
)
)
),
'setting',
'footer',
FALSE,
TRUE,
TRUE
);
編輯我已經tryed:
//add fancybox settings
drupal_add_js(
array(
'mycustom_fancybox' => array(
'selector' => 'div.field-field-immagini-minigallery a',
'group' => TRUE,
'options' => array(
'transitionIn' => 'elastic',
'transitionOut' => 'elastic',
'titlePosition' => 'inside',
'titleShow' => TRUE,
'width' => 500,
'cyclic' => TRUE,
'titleFormat' => "function my_title_format(title, currentArray, currentIndex, currentOpts) { return '<span><b><i>' + title + '</i></b> | Immagine ' + (currentIndex + 1) + ' di ' + currentArray.length + (title.length ? ' ' + title : '') + '</span>'; }"
)
)
),
'setting',
'footer',
FALSE,
TRUE,
TRUE
);
但(因爲我認爲)Drupal渲染它像:
"function (title, currentArray, currentIndex, currentOpts) { return \'\x3cspan\x3e\x3cb\x3e\x3ci\x3e\' + title + \'\x3c/i\x3e\x3c/b\x3e | Immagine \' + (currentIndex + 1) + \' di \' + currentArray.length + (title.length ? \' \x26nbsp; \' + title : \'\') + \'\x3c/span\x3e\'; }"
...並沒有工作。
我tryed
drupal_add_js(
array(
'mycustom_fancybox' => array(
'selector' => 'div.field-field-immagini-minigallery a',
'group' => TRUE,
'options' => array(
'transitionIn' => 'elastic',
'transitionOut' => 'elastic',
'titlePosition' => 'inside',
'titleShow' => TRUE,
'width' => 500,
'cyclic' => TRUE,
'titleFormat' => 'my_title_format'
)
)
),
'setting',
'footer',
FALSE,
TRUE,
TRUE
);
//and, in my js file, added:
function my_title_format(title, currentArray, currentIndex, currentOpts) {
return '<span><b><i>' + title + '</i></b> | Immagine ' + (currentIndex + 1) + ' di ' + currentArray.length + (title.length ? ' ' + title : '') + '</span>';
}
但同樣doestn工作。
問題的總體目標並不清楚。你想添加'titleFormat'並且你無法使它工作? – 2010-10-04 13:08:33
@NoParrots:我想在Drupal.settings中添加titleFormat選項,但是我不知道如何去做,因爲titleFormat不是一個字符串/布爾值,而是一個函數回調函數。 – Strae 2010-10-04 13:15:41
您是否嘗試過在選項數組中傳遞函數回調?它工作嗎?如果不是,那麼將函數定義放在單引號內怎麼辦? – 2010-10-04 13:33:34