覆盖Drupal的JavaScript行为 [英] Overriding Drupal javascript behaviors

查看:118
本文介绍了覆盖Drupal的JavaScript行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在注释表单上覆盖一些核心drupal行为。



如果您以匿名用户的身份发表评论,您的姓名和邮件将存储在一个cookie中,然后JavaScript将使用此代码填写后续注释表单中的相应字段以下:

  Drupal.behaviors.comment = function(context){
var parts = new Array(name ,主页,邮件);
var cookie =''; (i = 0; i <3; i ++){
cookie = Drupal.comment.getCookie('comment_info_'+ parts [i]);

if(cookie!=''){
$(#comment-form input [name =+ parts [i] +]:not(.comment-processed),context)
.val(cookie)
.addClass('comment-processed');
}
}
};

如果我不想填写这些字段,我知道我可以擦掉信息进一步的JavaScript,但我确定有一个更干净的方式来做到这一点。

解决方案

如果你有一个自定义模块,你应该可以覆盖Drupal.behaviors.comment,或者删除它。



  drupal_add_js('delete Drupal.behaviors.comment ','一致'); 

当然,如果你已经有一个js文件被包含在它而不是内联。


I want to override a bit of core drupal behavior on the comment form.

If you make a comment as an anonymous user, your name and mail are stored in a cookie, and then javascript fills out the appropriate fields in subsequent comment forms using this code below:

Drupal.behaviors.comment = function (context) {
  var parts = new Array("name", "homepage", "mail");
  var cookie = '';
  for (i=0;i<3;i++) {
    cookie = Drupal.comment.getCookie('comment_info_' + parts[i]);
    if (cookie != '') {
      $("#comment-form input[name=" + parts[i] + "]:not(.comment-processed)", context)
        .val(cookie)
        .addClass('comment-processed');
    }
  }
};

If I don't want those fields to be filled in, I know I can just wipe out the information with further javascript, but I'm sure there's a 'cleaner' way to do it.

解决方案

If you have a custom module, you should be able to overwrite Drupal.behaviors.comment, or delete it.

something like

drupal_add_js('delete Drupal.behaviors.comment','inline');

Of course if you already have a js file being included put it there rather than inline.

这篇关于覆盖Drupal的JavaScript行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆