hashover icon indicating copy to clipboard operation
hashover copied to clipboard

How to make a PJAX overload on Hashover?

Open LiarOnce opened this issue 8 years ago • 10 comments

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

LiarOnce avatar Mar 24 '17 14:03 LiarOnce

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

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

jacobwb avatar Mar 25 '17 10:03 jacobwb

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');
} 

LiarOnce avatar Mar 25 '17 10:03 LiarOnce

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
	}
});

jacobwb avatar Mar 25 '17 15:03 jacobwb

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');
            } 
        });
    }

LiarOnce avatar Mar 26 '17 04:03 LiarOnce

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'
   }));
}

jacobwb avatar Apr 04 '17 19:04 jacobwb

It doesn't matter, thank you very much.

LiarOnce avatar Apr 05 '17 04:04 LiarOnce

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

LiarOnce avatar Apr 05 '17 13:04 LiarOnce

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.

jacobwb avatar Apr 11 '17 07:04 jacobwb

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

LiarOnce avatar Apr 11 '17 09:04 LiarOnce

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

LiarOnce avatar Apr 11 '17 09:04 LiarOnce