如何构建 Drupal 7 和 Drupal 7页面加载叠加上的 Colorbox?

发布于 2024-12-12 20:34:04 字数 1378 浏览 0 评论 0原文

我正在尝试使用 Drupal 7 & 构建页面加载叠加层。 Colorbox 和我被难住了。我的 JS / JQuery 技能非常薄弱,并且已经遇到了障碍。我在视图中创建了一个块并将其推送到我的主页。 我在 tpl.php 文件中手动添加了 .colorbox 类,这允许添加其余的 colorbox 特定类。 这是我的块的代码:

<section id="block-views-hp-overlay-hp-overlay-block" class="block block-views colorbox init-colorbox-processed-processed cboxElement" style="display:none;"> 

这是我的 Drupalized jQuery 文件:

/* overlay */
(function ($) {

Drupal.behaviors.initColorboxHP = {
  attach: function (context, settings) {
    if (!$.isFunction($.colorbox)) {
      return;
    }
    $('#block-views-hp-overlay-hp-overlay-block', context)
      .filter('.colorbox')
      .once('init-colorbox-processed')
      .colorbox({inline:true,href:"#block-views-hp-overlay-hp-overlay-block",innerWidth:"600px", innerHeight:"600px"});
  }
};

{
  $(document).bind('cbox_complete', function () {
    Drupal.attachBehaviors('#cboxLoadedContent');
  });
}

})(jQuery);

我期望发生的是通过内联样式定义隐藏块,它确实如此。然后我的 colorbox/jquery 会拾取它并在一个漂亮的叠加层中显示它。似乎没有调用事件处理程序,但我不确定如何继续,所以任何指导将不胜感激。我看到其他一些人已经在非 Drupal 环境中实现了此功能,但在重新创建时遇到了困难。

我使用这些资源让我走到这一步...

http://drupal.org/node/863858

http://jacklmoore.com/colorbox/faq/#faq-cookie

I am attempting to build an on-page-load overlay using Drupal 7 & Colorbox and am stumped. I my JS / JQuery skills are pretty slim and I've hit a barrier. I've created a Block in views and pushing it to my home page.
I added the .colorbox class manually in my tpl.php file, which is allowing the rest of the colorbox specific classes to be added.
here is the code for my block:

<section id="block-views-hp-overlay-hp-overlay-block" class="block block-views colorbox init-colorbox-processed-processed cboxElement" style="display:none;"> 

here is my Drupalized jQuery file:

/* overlay */
(function ($) {

Drupal.behaviors.initColorboxHP = {
  attach: function (context, settings) {
    if (!$.isFunction($.colorbox)) {
      return;
    }
    $('#block-views-hp-overlay-hp-overlay-block', context)
      .filter('.colorbox')
      .once('init-colorbox-processed')
      .colorbox({inline:true,href:"#block-views-hp-overlay-hp-overlay-block",innerWidth:"600px", innerHeight:"600px"});
  }
};

{
  $(document).bind('cbox_complete', function () {
    Drupal.attachBehaviors('#cboxLoadedContent');
  });
}

})(jQuery);

What I expected to happen was the block to be hidden via an inline style definition, which it is. Then my colorbox/jquery would pick it up show it in a nice overlay. Seems like an event handler is not being invoked, but I am not sure how to proceed, so any guidance will be much appreciated. I see some other folks have gotten this working in non-Drupal contexts, but am having difficulty recreating.

I used these resources to get me this far...

http://drupal.org/node/863858

http://jacklmoore.com/colorbox/faq/#faq-cookie

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

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

发布评论

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

评论(2

杯别 2024-12-19 20:34:04

我对 Drupal 没有任何熟悉,但可能只是您需要将 open 属性添加到您的 colorbox 选项中:

{inline:true,href:"#block-views-hp-overlay-hp-overlay-block",innerWidth:"600px", innerHeight:"600px", open:true}

我不确定您的情况,但您可能不需要将 colorbox 附加到元素(您是否计划将其设置为可点击以便您可以第二次打开它?)。如果没有,直接调用colorbox即可。将其替换

$('#block-views-hp-overlay-hp-overlay-block', context)
  .filter('.colorbox')
  .once('init-colorbox-processed')
  .colorbox({inline:true,href:"#block-views-hp-overlay-hp-overlay-block",innerWidth:"600px", innerHeight:"600px"});

为:

    $.colorbox({inline:true,href:"#block-views-hp-overlay-hp-overlay-block",innerWidth:"600px", innerHeight:"600px"});

I don't have any familiarity with Drupal, but it may just be that you need to add the open property to your colorbox options:

{inline:true,href:"#block-views-hp-overlay-hp-overlay-block",innerWidth:"600px", innerHeight:"600px", open:true}

I'm not sure about your situation, but you probably don't need to attach colorbox to an element (are you planning on it being clickable so that you can open it a 2nd time?). If not, just call colorbox directly. Replace this:

$('#block-views-hp-overlay-hp-overlay-block', context)
  .filter('.colorbox')
  .once('init-colorbox-processed')
  .colorbox({inline:true,href:"#block-views-hp-overlay-hp-overlay-block",innerWidth:"600px", innerHeight:"600px"});

With this:

    $.colorbox({inline:true,href:"#block-views-hp-overlay-hp-overlay-block",innerWidth:"600px", innerHeight:"600px"});
如此安好 2024-12-19 20:34:04

感谢@Jack 的帮助,让我到达那里(有点......)这就是我所做的。首先,作为练习,我抛弃了 drupal 的东西(b/ci 知道我可以作弊并将我的脚本放入其中,而无需 drupal 特定的东西。然后我这样做了:

jQuery(document).ready(function($) {
$('#block-views-hp-overlay-hp-overlay-block').show();
$.fn.colorbox({inline:true,href:"#block-views-hp-overlay-hp-overlay-block",innerWidth:"600px", innerHeight:"600px",open:true});

 $(document).bind('cbox_closed', function(){
            $('#block-views-hp-overlay-hp-overlay-block').hide();
    });

});

这本质上就是我想要的。我确信有一个更优雅和 Drupal 正确的方法,所以当我弄清楚时我会发布它......

Thanks for the help @Jack, that got me there (sort of...) here is what i did. First, as an exercise, i dumped the drupal stuff (b/c i knew i could cheat and get my script in there w/out the drupal specific stuff. Then I did this:

jQuery(document).ready(function($) {
$('#block-views-hp-overlay-hp-overlay-block').show();
$.fn.colorbox({inline:true,href:"#block-views-hp-overlay-hp-overlay-block",innerWidth:"600px", innerHeight:"600px",open:true});

 $(document).bind('cbox_closed', function(){
            $('#block-views-hp-overlay-hp-overlay-block').hide();
    });

});

Which is essentially what i am going for. I am sure there is a more elegant and Drupal proper way, so i'll post that when I figure it out...

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