javascript - AddThis Wordpress plugin not working with AJAX theme -


i'm using addthis wordpress plugin include share buttons underneath each post in ajax theme, , having trouble getting code right.

i inserted following code in custom button field on settings page:

<div class="addthis_toolbox addthis_default_style" id="toolbox">     <a class="addthis_button_preferred_1"></a>     <a class="addthis_button_preferred_2"></a>     <a class="addthis_button_preferred_3"></a>     <a class="addthis_button_preferred_4"></a>     <a class="addthis_button_compact"></a> </div> 

then in post loop in main page php file have this:

<script>     var tbx = document.getelementbyid("toolbox"),     svcs = {email: 'email', print: 'print', facebook: 'facebook', expanded: 'more'};      (var s in svcs) {         tbx.innerhtml += '<a class="addthis_button_'+s+'">'+svcs[s]+'</a>';     });      function reinitializeaddthis() {         if (window.addthis) {             window.addthis.toolbox("#toolbox");         }     } </script> <iframe style="display: none;" onload="reinitializeaddthis();"></iframe> 

the buttons load sporadically, , disappear after refresh. i'm getting error uncaught referenceerror: reinitializeaddthis not defined confusing... i'd appreciate insight , apologize if unclear. thanks!

i have arrived @ solution, i'll post here in case ever runs same problem.

on addthis settings page, pasted code "custom button" field:

<div class="addthis_toolbox addthis_default_style" id="toolbox">     <a class="addthis_button_preferred_1"></a>     <a class="addthis_button_preferred_2"></a>     <a class="addthis_button_preferred_3"></a>     <a class="addthis_button_preferred_4"></a>     <a class="addthis_button_compact"></a> </div> 

then in post loop within main page php file:

<script type="text/javascript">         $(document).ajaxcomplete(function(){             console.log("all ajax requests completed");              if (window.addthis) {                 window.addthis.toolbox(".addthis_toolbox addthis_default_style");                 console.log("addthis rendered")              };         });         var tbx = document.getelementbyid("toolbox"),             svcs = {email: 'email', print: 'print', facebook: 'facebook', expanded: 'more'};          (var s in svcs) {             tbx.innerhtml += '<a class="addthis_button_'+s+'">'+svcs[s]+'</a>';         };     </script> 

this calls window.addthis.toolbox() function each individual post , creates sharing toolbox after ajax has rendered specified on page.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -