jacobwb / hashover

Free and Open Source PHP Comment System

Home Page:http://tildehash.com/?page=hashover

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to make a PJAX overload on Hashover?

LiarOnce opened this issue · comments

Hashover fails to load under PJAX and needs to be refreshed before it will be displayed.

Fails to load, or fails to re-load/refresh?

Are you returning the HashOver script tag in the AJAX HTML response?

It Fails to load.
No,because I don't know what to do.
This is the overloaded function of my original comment plugin.:

if (typeof DUOSHUO !== 'undefined'){
    DUOSHUO.EmbedThread('.ds-thread');
} 

I think I need to know a little more about your code.

Do you have something like this in your code somewhere?

pjax.connect ({
	'container': 'content',

	'success': function(event){
		// Code here
	},

	'ready': function(){
		// Code here
	}
});

Yes, there is a section of code in my WordPress theme:

$(document).pjax('a[target!=_top]', '#page', {
            fragment: '#page',
            timeout: 8000,
        }).on('pjax:send', function() {
            $('#loading').fadeIn(300);
            Siren.MNH();
        }).on('pjax:complete', function() { 
            Siren.AH();
            Siren.PE();
            Siren.CE();
            $("#loading").fadeOut(500);
            if(Poi.codelamp == 'open'){ self.Prism.highlightAll(event) }; // 解决Prism.js代码高亮
            if($('.ds-thread').length > 0) {  // 解决多说问题
               if (typeof DUOSHUO !== 'undefined'){
                  DUOSHUO.EmbedThread('.ds-thread'); 
               }else{ 
                  $.getScript("//static.duoshuo.com/embed.js"); 
              }
            }       
        }).on('submit', '.search-form,.s-search', function (event) {
            event.preventDefault();
            $.pjax.submit(event, '#page', {
                fragment:'#page', 
                timeout:8000,
            });
            if($('.js-search.is-visible').length > 0){
                $('.js-toggle-search').toggleClass('is-active');
                $('.js-search').toggleClass('is-visible');
            } 
        });
    }

Sorry for the delay.

Assuming the HashOver div element gets added to the page when navigating, you should be able to simply add the hashover.js script to the page again.

I would try replacing this code...

if($('.ds-thread').length > 0) {  // 解决多说问题
   if (typeof DUOSHUO !== 'undefined'){
      DUOSHUO.EmbedThread('.ds-thread'); 
   }else{ 
      $.getScript("//static.duoshuo.com/embed.js"); 
  }
}

With something like this...

if ($('#hashover').length > 0) {
   $('#hashover').after ($('<script></script>', {
      id: 'hashover-loader',
      type: 'text/javascript',
      src: '/hashover/hashover.js'
   }));
}

It doesn't matter, thank you very much.

The code looks no problem, but the code causes some errors that cause the HashOver to fail to load successfully under PJAX.
(I have closed a name called Autoptimize plugin, which is a plugin under WordPress.)
Strangely enough, I did not locate the error associated with the code in the browser's developer tool, and only the JQuery error and an XMLHttpRequest warning were output.
errors

Maybe try this code instead?

if ($('#hashover').length > 0) {
   $.getScript("/hashover/hashover.js");
}

I don't know why the code would cause this kind of problem. Though, I can't be sure what is causing the issue without direct access to the website where this code is being used.

I think it would be better if it could be packaged into a function like Duoshuo(Code:DUOSHUO.EmbedThread('.ds-thread'); ).

Failed to load, but there is a strange parameter here when loading.
If the load is successful, it should be ?ver=next, not ?_=1491903816809.
snipaste_20170411_175436.png