Drupal 7 主菜单、JQuery 和 JQuery 的问题升级主题中的超级鱼

发布于 2024-10-11 11:01:36 字数 1239 浏览 8 评论 0原文

我正在将 Drupal 6 主题更新为 Drupal 7。在 Drupal 6 版本中,我有一个不错的小菜单功能,它将 JQuery 注入主菜单中,使其作为下拉菜单工作(+一个用于获取菜单树的预处理功能)这效果很好。

在我的主题的 Drupal 7 版本中,我像在 Drupal 6 中那样调用信息文件中的 JavaScript,并查看渲染页面的源代码,它没有注入菜单本身。我将下面的脚本以及标准的 superfish.js 称为(在 Drupal 6 中再次运行良好)。

   Drupal.behaviors.skyBehavior = function(context) {
  /**
   * Superfish Menus
   * http://users.tpg.com.au/j_birch/plugins/superfish/
   * @see js/superfish.js
   */
  jQuery('#navigation ul').superfish({
    animation: { opacity: 'show', height:'show' },
    easing: 'swing',
    speed: 250,
    autoArrows:  false,
    dropShadows: false /* Needed for IE */
  });
};

我相信完成所有繁重工作的行是: jQuery('#navigation ul').superfish({ (请注意,菜单周围的 div id 是“#navigation”,然后

    标记在此之后开始。)

我在 Drupal 7 版本中运行预处理函数也是为了获取我的菜单主菜单的树,我可以看到在 Firebug 中查看的整个树,但我可以看到 Jquery 注入的代码丢失了。

在我的 Drupal 6 主题中,我会看到:

但在我的主题的 Drupal 7 版本中,我在 Firebug 中看到的只是:

我对 JavaScript 不太了解,所以我希望这可以给某人敲响警钟,让他们知道如何找到解决方案。谢谢。

I am updating a Drupal 6 theme to Drupal 7. In the Drupal 6 version, I had a nice little menu function which injected JQuery into the Primary menu to make it work as a drop down (+ a preprocess function to get the menu tree) and this worked great.

In the Drupal 7 version of my theme, I call the JavaScripts in my info file as I did in Drupal 6 and looking at the source of my rendered page, it's not injecting into the menu itself. I call the script below as well as the standard superfish.js (which again worked fine in Drupal 6.)

   Drupal.behaviors.skyBehavior = function(context) {
  /**
   * Superfish Menus
   * http://users.tpg.com.au/j_birch/plugins/superfish/
   * @see js/superfish.js
   */
  jQuery('#navigation ul').superfish({
    animation: { opacity: 'show', height:'show' },
    easing: 'swing',
    speed: 250,
    autoArrows:  false,
    dropShadows: false /* Needed for IE */
  });
};

I belive the line that does all the heavy lifting is: jQuery('#navigation ul').superfish({
(Note that my surrounding div id for the menu is "#navigation" and then <ul> tag starts after that.)

I am running a preprocess function in my Drupal 7 version also to get my menu tree for the Main Menu and I can see the entire tree viewed in Firebug but I can see that the Jquery injected code is missing.

In my Drupal 6 theme I would see:

<ul class="menu sf-js-enabled" style="visibility: hidden; display: none;">... -- and of course mousing over changes "display: none" to "visible".

But in the Drupal 7 version of my theme, all I see in Firebug is:
<ul class="menu">...

I don't know a lot about JavaScript so I am hoping this might ring a bell with someone as to how to find a fix. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

烟花易冷人易散 2024-10-18 11:01:36

您可以查看在 Drupal 7 中管理 js 来入门。建议是创建一个闭包,尽管我不知道这会如何影响您的代码。

如果它没有帮助,您可以通过在代码中执行 alert('message') 或类似的操作来测试行为/js 文件是否正在运行。

You can take a look at Managing js in Drupal 7 to get you started. The advice is to create a closure, though I don't see how that should effect your code.

If it doesn't help you can test if the behavior / js file is being run by doing an alert('message') or something similar in the code.

看海 2024-10-18 11:01:36

以下是基于 @googletorp 发送给我的页面链接的代码:

(function ($) {

  Drupal.behaviors.MyTheme = {
    attach: function(context, settings) {
      $('#navigation ul', context).superfish(function () {

      });
    }
  };

})(jQuery);

下拉菜单现在可以在 Drupal 7 中使用,但我仍然需要弄清楚如何添加缓动、速度和动画的代码...

Here is the code based on the page link that @googletorp sent me:

(function ($) {

  Drupal.behaviors.MyTheme = {
    attach: function(context, settings) {
      $('#navigation ul', context).superfish(function () {

      });
    }
  };

})(jQuery);

The drop down menus are now working in Drupal 7 but I still need to figure out how to add the code for easing, speed and animation...

丶情人眼里出诗心の 2024-10-18 11:01:36

刚刚意识到我从未发布过工作代码。这是有效的 Drupal 7 代码:

(function ($) {

Drupal.behaviors.MyTheme = {

attach: function(context, settings) {
$('#navigation ul', context).superfish({

animation: { opacity: 'show', height:'show' },
speed: 250,
autoArrows: false,
dropShadows: false /* Needed for IE */

});
}};

})(jQuery);

Just realized that I never posted working code. Here is Drupal 7 code that works:

(function ($) {

Drupal.behaviors.MyTheme = {

attach: function(context, settings) {
$('#navigation ul', context).superfish({

animation: { opacity: 'show', height:'show' },
speed: 250,
autoArrows: false,
dropShadows: false /* Needed for IE */

});
}};

})(jQuery);
醉酒的小男人 2024-10-18 11:01:36

天哪,

花了 2 天的时间用 jquery 循环插件解决了类似的问题。解决方案在这里:

http://drupal.org/node/1043478#comment-4168166

看来是 php 代码的问题。您必须确保<'>就像<\'>

Holy Cow,

worked 2 days to solve a similar problem with jquery cycle plugin. The solution is here:

http://drupal.org/node/1043478#comment-4168166

Seams to be a problem with php code. You have to secure the <'> like <\'>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文