<tfoot id='aoUM7'></tfoot>
    <bdo id='aoUM7'></bdo><ul id='aoUM7'></ul>
  • <i id='aoUM7'><tr id='aoUM7'><dt id='aoUM7'><q id='aoUM7'><span id='aoUM7'><b id='aoUM7'><form id='aoUM7'><ins id='aoUM7'></ins><ul id='aoUM7'></ul><sub id='aoUM7'></sub></form><legend id='aoUM7'></legend><bdo id='aoUM7'><pre id='aoUM7'><center id='aoUM7'></center></pre></bdo></b><th id='aoUM7'></th></span></q></dt></tr></i><div id='aoUM7'><tfoot id='aoUM7'></tfoot><dl id='aoUM7'><fieldset id='aoUM7'></fieldset></dl></div>
  • <legend id='aoUM7'><style id='aoUM7'><dir id='aoUM7'><q id='aoUM7'></q></dir></style></legend>

      1. <small id='aoUM7'></small><noframes id='aoUM7'>

      2. 从 Drupal 7 中的模块 .js 文件调用全局 JS 函数

        Call global JS function from module .js file in Drupal 7(从 Drupal 7 中的模块 .js 文件调用全局 JS 函数)
        1. <legend id='TmcdO'><style id='TmcdO'><dir id='TmcdO'><q id='TmcdO'></q></dir></style></legend>
              <bdo id='TmcdO'></bdo><ul id='TmcdO'></ul>
            • <small id='TmcdO'></small><noframes id='TmcdO'>

                <tbody id='TmcdO'></tbody>

            • <i id='TmcdO'><tr id='TmcdO'><dt id='TmcdO'><q id='TmcdO'><span id='TmcdO'><b id='TmcdO'><form id='TmcdO'><ins id='TmcdO'></ins><ul id='TmcdO'></ul><sub id='TmcdO'></sub></form><legend id='TmcdO'></legend><bdo id='TmcdO'><pre id='TmcdO'><center id='TmcdO'></center></pre></bdo></b><th id='TmcdO'></th></span></q></dt></tr></i><div id='TmcdO'><tfoot id='TmcdO'></tfoot><dl id='TmcdO'><fieldset id='TmcdO'></fieldset></dl></div>
              • <tfoot id='TmcdO'></tfoot>

                  本文介绍了从 Drupal 7 中的模块 .js 文件调用全局 JS 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  With the great help of Sk8erPeter I managed to execute Javascript code on node creation and node update of a certain content type in Drupal 7.

                  My problem now is that I can not call the function FB.api from withing this modules js files. Does it have something to do with Javascript namespaces? Running the FB.api() function from console works fine...

                  Thanks in advance for any help.

                  Nils

                  解决方案

                  Based on your comments... I'm just watching your testModule.behaviors.js, and it doesn't even look similar to the function that I wrote to you here in the other topic.

                  Your current code is only like this:

                  FB.api(
                      '/me/shareatear:share',
                      'post',
                      { tear: document.URL },
                      function(response) {
                         if (!response || response.error) {
                            alert('Error occured');
                         } else {
                            alert('done. ' + response.id);
                         }
                      });
                  

                  Where is Drupal.behaviors, and its attach function I showed you earlier? Where are all the other stuffs? :)
                  It's not even surprising that the current code outputs an error, because I think this JavaScript file is included before even defining the FB object, and this way you call this code directly in the header.

                  I think your testModule.behaviors.js file should look like this (based on the previous code we were talking about):

                  (function ($) {
                      Drupal.behaviors.testModule = {
                          doitnow: function () {
                              alert("A new "tear" content has just been added!");
                  
                              // change this code to the appropriate one
                              FB.api('/me/shareatear:share', 'post', {
                                  tear: document.URL
                              }, function (response) {
                                  if (!response || response.error) {
                                      alert('Error occured');
                                  } else {
                                      alert('done. ' + response.id);
                                  }
                              });
                  
                          },
                  
                          attach: function (context, settings) {
                              try {
                                  if (settings.testModule.tear_just_added) {
                                      this.doitnow();
                                  }
                              } catch (ex) {}
                          }
                      };
                  })(jQuery);
                  

                  So REPLACE your CURRENT content (where you are only calling FB.api without any Drupal-specific behaviors "wrappers"), and change its content to this one.


                  EDIT:

                  OK, try to set the weight of this module higher ONCE with the following db_query(), so its hooks get invoked later than the other modules' hooks. After putting these lines in your code, save the file, delete the Drupal cache, and after that, comment out the appropriate line! It's not needed to run all the time, in every page loads!

                  /**
                   * Implements hook_init()
                   * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_init/7
                   */
                  function testModule_init() {
                      // after putting this in your file, save it, delete cache, then COMMENT OUT THE FOLLOWING LINE!!! It should only RUN ONCE (it's enough).
                      db_query("UPDATE {system} SET weight = 111 WHERE type = 'module' AND name = 'testModule'");
                  }
                  

                  这篇关于从 Drupal 7 中的模块 .js 文件调用全局 JS 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                  <i id='hT01l'><tr id='hT01l'><dt id='hT01l'><q id='hT01l'><span id='hT01l'><b id='hT01l'><form id='hT01l'><ins id='hT01l'></ins><ul id='hT01l'></ul><sub id='hT01l'></sub></form><legend id='hT01l'></legend><bdo id='hT01l'><pre id='hT01l'><center id='hT01l'></center></pre></bdo></b><th id='hT01l'></th></span></q></dt></tr></i><div id='hT01l'><tfoot id='hT01l'></tfoot><dl id='hT01l'><fieldset id='hT01l'></fieldset></dl></div>

                    <legend id='hT01l'><style id='hT01l'><dir id='hT01l'><q id='hT01l'></q></dir></style></legend>

                    <small id='hT01l'></small><noframes id='hT01l'>

                          <tbody id='hT01l'></tbody>
                      1. <tfoot id='hT01l'></tfoot>
                          • <bdo id='hT01l'></bdo><ul id='hT01l'></ul>