ShareThis problem

Nmaster88
Nmaster88
@nmaster88
8 years ago
94 posts
I'm using to following code to have the icon of sharethis:

        {literal}
            <script type="text/javascript">{var switchTo5x=true;</script>
            <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
            <script type="text/javascript">stLight.options({ publisher: "123456789-91211-121314-121617-181920212223242526", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>

            <span class='st_sharethis_large' displayText='ShareThis'></span>

        {/literal}
This code works well if i simply go to the page i have it. But if i go to the page through ajax as i'm doing in our site it doesn't work.
In the image in attach i give an example, in the right i have a list of playlists i want to load on the left side, if i click on the button the left side will be populated by the songs of it.
The jquery i use to do that is this:
    $(document).on('click','#addplaylisttolist',function(){
        myPlaylist.pause();
        myPlaylist.remove();
        $("#playlist_selected_songs").empty();
        $.each($(this).find("span"),function(){
                $("#playlist_individual_li").load('listen_playlist_section_content_item_add',{musicId:$(this).attr('data-id-music'),musicTitle:$(this).attr('data-title'),musicArtist:$(this).attr('data-artist'),musicFile:$(this).attr('data-mp3'),musicPoster:$(this).attr('data-poster'),musicTime:$(this).attr('data-time-music')},function(){
                    $("#playlist_selected_songs").append($("#playlist_individual_li").html());
                });
            });
        myPlaylist.play();
    });
With this template:
<li class="list-group-item">
    <div class="pull-right m-l">
        <span class="addtolistbutton">
            {jrCore_module_function function='jrPlaylist_button' playlist_for='jrAudio' item_id=$musicId class='circleplus_icon_playlist' title='Add To Playlist'}
        </span>
        {if jrUser_is_logged_in()}
            <a href="" id="listen_playlist_delete_item" title="delete music"><i class="icon-close"></i></a>
        {/if}
        {literal}
            <script type="text/javascript">$(function() {var switchTo5x=true;});</script>
            <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
            <script type="text/javascript">$(function() {stLight.options({ publisher: "123456789-91211-121314-121617-181920212223242526", doNotHash: false, doNotCopy: false, hashAddressBar: false});});</script>

            <span class='st_sharethis_large' displayText='ShareThis'></span>

        {/literal}
    </div>
    <a href="" class="addplaylistmusic jp-play-me m-r-sm pull-left" data-title="{$musicTitle}" data-artist="{$musicArtist}" data-mp3="{$musicFile}" data-m4a="{$musicFile}" data-poster="{$musicPoster}">
        <i class="icon-control-play text"></i>
        <i class="icon-control-pause text-active"></i>
    </a>
    <div class="clear text-ellipsis">
        <a href="$(this).attr('data-path')"><span>
                {$musicTitle}
                </span></a>
        <span class="text-muted"> --
            {$musicTime}
                </span>
    </div></li>
The code in the template related to the sharethis doesn't work. As anyone tried to do anything like this or as an idea how i can fix this? I think ajax doesn't let this inline scripts work. Thanks for the help!
sharethis_1.jpg
sharethis_1.jpg  •  127KB

sharethis_2.jpg
sharethis_2.jpg  •  161KB


updated by @nmaster88: 08/01/16 04:35:48AM
brian
@brian
8 years ago
10,148 posts
correct - when you load something up via AJAX, the script tags are not going to load in the remove scripts and make that available for you - you need to move the ShareThis JS out to the main page - not the page being loaded via an XHR call. The, in the callback function for the load you need to initialize your ShareThis on the newly loaded contents.

Let me know if that helps


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Nmaster88
Nmaster88
@nmaster88
8 years ago
94 posts
I'm having problems finding how to do it, what do you mean? Thanks
michael
@michael
8 years ago
7,715 posts
after your ajax call, load the sharethis stuff again on the main page. You cant have the share this stuff on the page that's loaded via ajax.

Tags