Tumblr 音频播放器无法通过无限滚动加载

发布于 2024-10-02 20:06:29 字数 3111 浏览 0 评论 0原文

我在这个 tumblr 上实现了无限滚动和砌体:[检查链接的修订]

通过无限滚动加载的帖子中,而是显示文本“[需要 Flash 9 才能收听音频。]”

音频播放器不会出现在 好吧,tumblr 主题(我无法发布另一个超链接,但你可以轻松地用 google 搜索它)似乎通过以下代码解决了这个问题:

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

我尝试将其改编为我的 tumblr(使用占位符文本来查看是否找到了正确的元素) :

 $(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>");
         }
       });
         }
       });
     }
   ); 
});

但没有文字的迹象。任何帮助将不胜感激。

I implemented infinite scroll along with masonry on this tumblr: [check revision for link]

The audio player does not appear in posts loaded through infinite scroll, instead it displays the text "[Flash 9 is required to listen to audio.]"

The Inspire Well tumblr theme (I can't post another hyperlink but you can easily google it) seems to have solved this problem through this code:

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

I tried to adapt this for my tumblr (with placeholder text to see if it was finding the correct element):

 $(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>");
         }
       });
         }
       });
     }
   ); 
});

But there is no sign of the text. Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

原来是傀儡 2024-10-09 20:06:29

这是当我需要在我创建的模板中实现相同功能时想到的一个解决方案。

在 HTML 中,在注释之间包含 AudioPlayer Tumblr 标签。这是为了防止调用加载的脚本。还要添加一个“unloaded”类来跟踪我们是否已加载本文的音频播放器。

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

如果您在页面加载后查看注释代码,您会注意到嵌入标签被传递到 Tumblr JavaScript 函数之一。既然我们评论了它,它就不会执行。相反,我们需要提取该字符串并用它替换 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() 一次,然后每次无限时调用 loadAudioPosts()滚动加载其他帖子。

Here is a solution I came up with when I needed to implement the same functionality in the template I was creating.

In your HTML, include your AudioPlayer Tumblr tag between comments. This is to prevent loaded scripts from being called. Also add a class "unloaded" to keep track whether or not we've loaded the audio player for this post or not.

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

If you look at the commented code after the page is loaded, you will notice an embed tag being passed to one of the Tumblr javascript functions. Since we commented it, it will not execute. Instead we will want to extract this string and replace the div contents with it.

Create a javascript function which will do this. This can be done with regular javascript, but to save time I will do it with jQuery since this is how I did it for my template:

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

Call loadAudioPosts() once on page load, then every time your infinite scrolling loads additional posts.

枯寂 2024-10-09 20:06:29

html

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

css

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

java

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

html

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

css

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

java

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文