在ajax调用后重新加载Visual Composer网格 [英] reload visual composer grid after ajax call

查看:58
本文介绍了在ajax调用后重新加载Visual Composer网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在以wordpress主题实现barba.js.除VisualComposer网格外,我设法使大多数javascript函数在页面更改后都能正常工作.

I am currently implementing barba.js in a wordpress theme. I have managed to make most of the javascript functions to work properly after page change except the VisualComposer grid.

阅读线程,我已经成功使Visual Composer基本除了通过 window.vc_js();

Reading this thread I have managed to make Visual composer basic functions work except the grid via window.vc_js();

如果我添加 window.resize(); ,我会得到 window.resize不是函数错误.

If I add window.resize(); I get a window.resize is not a function error.

在很多页面中, window.vc_js()我也遇到相同的错误- window.vc_js不是函数

In quite a few pages I also get the same error with window.vc_js() - window.vc_js is not a function

如何初始化vc_grid?当Visual composer实际上处于活动状态时,为什么会出现这些错误?

How can I initalize the vc_grid? Why do I get these error when Visual composer is actually active?

任何帮助表示赞赏

推荐答案

tl; dr

在此处输入您的自定义javascript代码:

tl;dr

put your custom javascript code in here:

$(window).bind( 'grid:items:added', function(){ 
  // add some logic here
});

如果您需要在加载 之后做出一些逻辑,请按以下步骤进行操作(我正在从某个网站粘贴我的代码):

if you need to make some logic after Visual Composer grid has been loaded then do it like this (I'm pasting my code from some site):

// catch VISUAL COMPOSER AFTER GRID ITEMS ARE LOADED .. hook and update date strings,, ONCE!
$(window).bind( 'grid:items:added', function(){
    if ( ! $( 'body' ).attr('masonicaDone' ) == "1" ){
        $('.enddate, .startdate').each( function(ix, el){
            var tmm = sDate( TIME( $(el).text().trim() ), lang ) + ' ∙ ' + sTime( TIME( $(el).text().trim() ), lang  );
            $(el).text( tmm );
        });
        $( 'body' ).attr('masonicaDone', 1);
    }
});

最主要的是将 bind 绑定到'grid:items:added'事件,该事件在ajax数据传输完毕后运行,在我的示例中,我m将日期格式化为本地格式(而不是本机php日期格式,WP)

the main thing is to bind to 'grid:items:added' event, that runs after ajax data has come down the wire,, in my example I'm formating date to local format (and not to native php date format, WP)

此外,拥有一个非常重要的标志是添加某种标志(我对主体有attr'ing),然后再做一次(我将格式化日期字符串两次并且有错误),但是只有第一次(在ajax之后).请注意,单击过滤器按钮(大多数时候是投资组合类别)时会触发此事件,谁可能也知道一些转换.

Also, very important to have is to add somekind of flag (I'm attr'ing on body) to not do it more then once (I'd endup with formating the datestring twice and have errors) but only first time (on after ajax). Note that this same event is fired on clicking on filter buttons (portfolio categories most of the time) and who knows maybe some transitions also..

这篇关于在ajax调用后重新加载Visual Composer网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆