gpt4 book ai didi

php - Drupal:向 Drupal.settings 添加 js 函数回调

转载 作者:行者123 更新时间:2023-12-01 01:52:59 26 4
gpt4 key购买 nike

我正在使用 [drupal_add_js_()][1] 函数添加 fancybox对我的节点中的某些图像产生影响(我没有使用 Fancybox 模块,因为不符合我的需求)。

简而言之,我需要添加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 ? ' &nbsp; ' + 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
);

编辑我尝试过:

//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 ? ' &nbsp; ' + 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\'; }"

...但它不起作用。

我尝试过

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 ? ' &nbsp; ' + title : '') + '</span>';
}

但又不起作用。

最佳答案

看看 js Drupal.theme 机制。我从 module/block/block.js 中获取的示例

    // A custom message for the blocks page specifically.
Drupal.theme.tableDragChangedWarning = function () {
return '<div class="warning">' + Drupal.theme('tableDragChangedMarker') + ' ' + Drupal.t("The changes to these blocks will not be saved until the <em>Save blocks</em> button is clicked.") + '</div>';
};

它可能很有用。但看起来您确实需要单独的 js 文件来获取您需要的 Drupal.settings 并将它们插入到应用的代码中。

关于php - Drupal:向 Drupal.settings 添加 js 函数回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3855436/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com