Execute custom script after page loaded with Ratchet\\Push.js

杀马特。学长 韩版系。学妹 提交于 2019-12-05 05:00:48
Schmalzy

EDIT: below was how I originally solved this problem, which worked fine, but I came up with a better solution, which I posted as the answer to this question.


I finally figured it out.

On your first page, you need to do the following...

var checkPage = function(){
    //Only run if twitter-widget exists on page
    if(document.getElementById('twitter-widget')) {
        loadTwitterFeed(document,"script","twitter-wjs");
    }
};

window.addEventListener('push', checkPage);

checkPage() will execute for every time a new page is loaded via push.

Just made a change for Ratchet.js to make individual js works for each page more elegant.(https://github.com/mazong1123/ratchet-pro)

By using the new ratchetPro.js, we can do followings:

(function () {
    var rachetPageManager = new window.RATCHET.Class.PageManager();
    rachetPageManager.ready(function () {
       // Put your logic here.
    });
})();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!