代码之家  ›  专栏  ›  技术社区  ›  Strae

Drupal:向Drupal.设置

  •  3
  • Strae  · 技术社区  · 15 年前

    我正在使用 [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
    );
    

    但是(正如我所想的)德鲁帕尔把它渲染成:

    "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>';
    }
    

    2 回复  |  直到 15 年前
        1
  •  0
  •   Igor Rodinov    15 年前

    看看jsDrupal主题机械化。 我从模块/模块获取的示例/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>';
      };
    

        2
  •  0
  •   Sid Kshatriya    15 年前

    再想一想。。。为什么需要发送函数回调 定义 ? drupal_add_js的目的是传递参数。函数回调永远不会改变,对吧?你可以在你的自定义javascript文件中定义它。。。