2

この tumblr に石積みと一緒に無限スクロールを実装しました: [リンクのリビジョンを確認]

オーディオ プレーヤーは、無限スクロールで読み込まれた投稿には表示されず、代わりに「[オーディオを聞くには Flash 9 が必要です。]」というテキストが表示されます。

Inspire Well tumblr テーマ (別のハイパーリンクを投稿することはできませんが、簡単にググることができます) は、次のコードによってこの問題を解決したようです:

if(InspireWell.infiniteScrolling && InspireWell.indexPage){
  $masonedColumn.infinitescroll({
    navSelector  : 'ul.page_nav',  // selector for the paged navigation 
    nextSelector : 'ul.page_nav li.page_next a',  // selector for the NEXT link (to page 2)
    itemSelector : '.post',     // selector for all items you'll retrieve
    loadingImg : '',
    donetext  : 'No more pages to load.',
    errorCallback: function() { 
      // fade out the error message after 2 seconds
      //$('#infscr-loading').animate({opacity: .8},2000).fadeOut('normal');   
    }
  },
  // call masonry as a callback
  function( newElements ) { 

    $(newElements).css({ visibility: 'hidden' });

    $(newElements).each(function() {
      if($(this).hasClass("audio")){
        var audioID = $(this).attr("id");
        var $audioPost = $(this);
        $audioPost.find(".player span").css({ visibility: 'hidden' });

        var script=document.createElement('script');
        script.type='text/javascript';
        script.src="http://assets.tumblr.com/javascript/tumblelog.js?16";

        $("body").append(script);

        $.ajax({
        url: "http://thetestinggrounds.tumblr.com/api/read/json?id=" + audioID,
          dataType: "jsonp",
          timeout: 5000,
          success: function(data){
            $audioPost.find(".player span").css({ visibility: 'visible' });
            $audioPost.find("span:first").append('<script type="text/javascript">replaceIfFlash(9,"audio_player_' + audioID + '",\'\x3cdiv class=\x22audio_player\x22\x3e' + data.posts[0]['audio-player'] +'\x3c/div\x3e\')</script>');
          }
        });
      }
    });

これをタンブラーに適応させようとしました(正しい要素を見つけているかどうかを確認するためのプレースホルダーテキストを使用):

 $(window).load(function(){
   $('#allposts').masonry({
     singleMode: true,
     itemSelector: '.box' 
   });
   $('#allposts').infinitescroll({
     navSelector : "div.navigation",
     nextSelector : "div.navigation a:first",
     itemSelector : ".box",
     debug : true
   },
     function( newElements ) {
       $(this).masonry({ appendedContent: $( newElements ) });
       $(newElements).each(function(){
         if($(this).hasClass("audio")){
           var audioID = $(this).attr("id");
       var $audioPost = $(this);
       $audioPost.find(".audio span");
           var script=document.createElement('script');
           script.type='text/javascript';
           script.src="http://assets.tumblr.com/javascript/tumblelog.js?16";
           $("body").append(script);
       $.ajax({
         url: "http://fuckyeahempathy.tumblr.com/api/read/json?id=" + audioID,
     dataType: "jsonp",
     timeout: 5000,
     success: function(data){
       $audioPost.find(".audio span");
       $audioPost.find("span:first").append("<p>audio player not working</p>");
         }
       });
         }
       });
     }
   ); 
});

しかし、テキストの兆候はありません。どんな助けでも大歓迎です。

4

2 に答える 2

2

作成中のテンプレートに同じ機能を実装する必要があったときに思いついたソリューションを次に示します。

HTML で、コメントの間に AudioPlayer Tumblr タグを含めます。これは、読み込まれたスクリプトが呼び出されないようにするためです。また、「unloaded」クラスを追加して、この投稿のオーディオ プレーヤーをロードしたかどうかを追跡します。

...
{block:AudioPlayer}
    <div class="audio-player unloaded">
        <!--{AudioPlayerBlack}-->
    </div>
{/block:AudioPlayer}
...

ページが読み込まれた後にコメント付きのコードを見ると、embed タグが Tumblr の JavaScript 関数の 1 つに渡されていることがわかります。コメントしたので、実行されません。代わりに、この文字列を抽出して div の内容を置き換えます。

これを行う JavaScript 関数を作成します。これは通常の JavaScript で実行できますが、時間を節約するために jQuery で実行します。これは、テンプレートで行った方法です。

function loadAudioPosts() {
    // For each div with classes "audio-player" and "unloaded"
    $(".audio-player.unloaded").each(function() {

        // Extract the <embed> element from the commented {AudioPlayer...} tag.
        var new_html = $(this).html().substring(
            $(this).html().indexOf("<e"),    // Start at "<e", for "<embed ..."
            $(this).html().indexOf("d>")+2   // End at "d>", for "...</embed>"
        );

        // Replace the commented HTML with our new HTML
        $(this).html(new_html);

        // Remove the "unloaded" class, to avoid reprocessing
        $(this).removeClass("unloaded");
    });
}

loadAudioPosts()ページの読み込み時に 1 回呼び出してから、無限スクロールで追加の投稿が読み込まれるたびに呼び出します。

于 2012-10-15T14:04:34.033 に答える
1

html

<div class="audio" id="{postID}">{AudioPlayerBlack}</div>

CSS

.audio {
        height:30px;
        overflow-y: hidden;
    }
.audio span {
        display:none;
    }

ジャワ

setTimeout(function() {
                        $wall.masonry({ appendedContent: $(newElements) });
                        /* repair audio players*/
                        $('.audio').each(function(){
                            var audioID = $(this).attr("id");
                            var $audioPost = $(this);
                            $.ajax({
                                url: 'http://yoolk.tumblr.com/api/read/json?id=' + audioID,
                                dataType: 'jsonp',
                                timeout: 50000,
                                success: function(data){
                                    $audioPost.append('\x3cdiv style=\x22background-color:white;height:30px\x22 class=\x22audio_player\x22\x3e' + data.posts[0]['audio-player'] +'\x3c/div\x3e');
                                }
                            });
                        });


                    }, 2000);
于 2011-02-08T01:04:51.470 に答える