如何构建 Drupal 7 和 Drupal 7页面加载叠加上的 Colorbox?
我正在尝试使用 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 环境中实现了此功能,但在重新创建时遇到了困难。
我使用这些资源让我走到这一步...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对 Drupal 没有任何熟悉,但可能只是您需要将 open 属性添加到您的 colorbox 选项中:
我不确定您的情况,但您可能不需要将 colorbox 附加到元素(您是否计划将其设置为可点击以便您可以第二次打开它?)。如果没有,直接调用colorbox即可。将其替换
为:
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:
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:
With this:
感谢@Jack 的帮助,让我到达那里(有点......)这就是我所做的。首先,作为练习,我抛弃了 drupal 的东西(b/ci 知道我可以作弊并将我的脚本放入其中,而无需 drupal 特定的东西。然后我这样做了:
这本质上就是我想要的。我确信有一个更优雅和 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:
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...