Colorbox 和 Drupal 视图 Ajax 寻呼机
我正在一个 Drupal 网站上工作,其中 Colorbox 用于图像,但它是手动添加的,而不是通过模块。
当 Colorbox 用于通过视图生成的照片库并且通过 AJAX 处理分页时,就会出现此问题。第一页工作正常,但任何其他页面都不会触发 Colorbox 弹出窗口。
在我看来,Colorbox 不知道新元素,因为在加载页面时它们不存在于 DOM 中。带着这个想法,我尝试将 Colorbox $.colorbox.init() 方法绑定到分页事件,但总是返回错误:
“Undefined: $.colorbox.init()”
这是我添加到 Drupal 的 Views 模块中进行测试的内容这是在分页事件(ajax_views.js line:132)的成功状态下:
success: function(response) {
$.event.trigger('pagedContent');
这是我捕获的内容:
$(document).bind('pagedContent', function() {
$.colorbox.init(); });
我也尝试再次运行常规初始化,但没有结果。
$(document).bind('pagedContent', function() {
$('myselector').colorbox(); });
我确信我应该采取稍微不同的方式来遵循 drupal 最佳实践,但这似乎应该有效,而我想知道为什么它不起作用。我是否偏离了轨道,方法是否错误?
I am working on a Drupal site where Colorbox is being used for images, but it's been added manually, not via a module.
The problem occurs when Colorbox is being used for a photo-gallery generated with Views and paging is handled with AJAX. The first page works fine, but any additional pages do not fire the Colorbox pop-up.
It seems to me that Colorbox is not aware of the new elements, because they were not present in the DOM when the page was loaded. With that thought I attempted to bind the Colorbox $.colorbox.init() method to the paging event, but always returns the error:
"Undefined: $.colorbox.init()"
Here is what I added to Drupal's Views module to test this, upon Success status from the paging event (ajax_views.js line:132):
success: function(response) {
$.event.trigger('pagedContent');
Here is what I'm catching it with:
$(document).bind('pagedContent', function() {
$.colorbox.init(); });
I also tried just running the regular initialization again instead, with no results.
$(document).bind('pagedContent', function() {
$('myselector').colorbox(); });
I'm sure I should approach this a little differently to follow drupal best practices, but this seems like it should work and I'm wondering why it does not. Am I way off track here, is the approach wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用 Drupal Behaviours 或 JQuery live 函数,才能将事件附加到异步显示的元素。
You must use Drupal Behaviors, or JQuery live function, in order to attach events to elements that appear asynchronously.