<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-167  評論-65  文章-0  trackbacks-0
    環境:ruby 1.8.7 + rails 2.1.0 + jquery + ubuntu 8.10

    效果和xiaonei的  更多新鮮事  一樣:


    前面有篇文章也介紹了一個像 twitter more 的方式分頁的方法,不過那個是用 protorype 做的。。那個做起來簡單一點,因為rails給我們封裝了 insert_html 和 link_to_remote 等方法,這樣更加便捷,但是解決jquery 和 prototype的confilct是一件很讓人頭疼的事,索性今天又實現了一個基于 jquery 的方法,環境是在rails中,需要使用 will_paginate 插件:
    Demo:

    view:

    <script>
    (function($){
        var settings;

        $.bottomlessPagination = function(callerSettings) {
            settings = $.extend({
                ajaxLoaderPath:'/images/loading.gif',
                results:'.results', // results 返回結果外部的class
                objName:'',
                callback:null
            },callerSettings||{});
            settings.imgLoader = new Image();
            settings.imgLoader.src = settings.ajaxLoaderPath;
            settings.href = $(".current").next().attr("href"); //current 是 will_paginate 默認的當前頁 href 的名字

            if ($('div.pagination').size() > 0){ // pagination 是 will_paginate 默認的 class
                $('div.pagination').wrap("<div class='pagination_links'></div>").hide();
                $('.pagination_links').append(
                    "<div class='live_pagination'>" +
                    "<a class='more_links' style='cursor:pointer;'> 查看 " + settings.objName + "...</a>" +
                    "</div>"
                    );
            }
       
            $(".more_links").click(function(){ 
                $(".live_pagination").hide();          
                if ($(".now_loading").size() == 0)              
                    $(".more_links").after("<img class='now_loading' src='"+settings.imgLoader.src+"' />");          
                else
                    $(".now_loading").show();           
                $.get(
                    settings.href,'',function(data){
                        $(settings.results).addrows(data);
                        $(".now_loading").hide();
                        $(".live_pagination").show();
                    }
                    );
                return false;
            });

            $.fn.addrows = function(data) {
                //remove live pagination if there are no more results
                // alert(data.length);
                if (data.length === 1 ){
                   // alert(data.length);
                    $('.live_pagination').remove();
                    $('.pagination_links').append(
                        "<div class='no_pagination'>" +
                        "沒有" + settings.objName +
                        "</div>"
                        );
                    return false;
                }
                //change the href
                ind=settings.href.indexOf("page=");
                page=parseInt(settings.href.charAt(ind+5))+1;
                start=settings.href.slice(0,ind+5);
                stop=settings.href.slice(ind+6);
                settings.href=start.concat(page.toString()).concat(stop);

                //add results to the page
                $(settings.results).append(data);
                if (settings.callback) settings.callback();
            };
        };
    })(jQuery);
    </script>


              <div class="results">
                <%= render :partial => 'activity' , :collection => @all_feed  %>
              </div>
              <%= will_paginate @all_feed  ,
                :class => 'pagination',          
                :previous_label => '&laquo; Previous',
                :next_label     => 'Next &raquo;',
                :renderer => 'WillPaginate::LinkRenderer' %>
              <div>
    <div class="now_loading" style="display:none;">
      <img src="/images/loading.gif"></img>
    </div>
    <script>
      $.bottomlessPagination({objName:'更多更新', callback:function(){
          //highlight current row
          //  $("div.results").effect("highlight", {}, 3000);
        }});
    </script>



    Action:
    def index

        if request.xhr?    
            sleep(1) # make request a little bit slower to see loader :-)   
              render :partial => 'activity' , :collection => @all_feed
    end


    partial:_activity.html.erb
    partial 里輸出數據即可


    主要的注意點就是注意對應class 不要寫錯了,同樣,你也可以把class 換位id做,jquery取id就這樣: $("#ID")

    上面js文件下載:
    http://www.dbank.com/download.action?k=3094283bf64e445f9530ac0554ebc9ce

    ref:
    http://github.com/davidwparker/jquery-bottomless-pagination




    write by feng
    posted on 2009-09-25 16:50 fl1429 閱讀(938) 評論(0)  編輯  收藏 所屬分類: RailsJquery
    已訪問數:
    free counters
    主站蜘蛛池模板: 国产又大又粗又硬又长免费| 日韩欧毛片免费视频| 四虎永久成人免费影院域名| 亚洲香蕉久久一区二区| 热re99久久6国产精品免费| 亚洲精品无码Av人在线观看国产| 精品无码一级毛片免费视频观看| 亚洲乱码国产一区网址| 72pao国产成视频永久免费| 亚洲av无码不卡私人影院| 深夜特黄a级毛片免费播放| 亚洲第一区精品观看| 一级特黄特色的免费大片视频| 亚洲AV无码成H人在线观看| 国产特黄一级一片免费| 亚洲线精品一区二区三区影音先锋| 国产人成网在线播放VA免费| 国产亚洲综合色就色| 最近中文字幕mv免费高清视频8| 亚洲日本在线播放| 成年丰满熟妇午夜免费视频| 噜噜综合亚洲AV中文无码| 亚洲av无码天堂一区二区三区 | 日本高清免费不卡在线| 青青青亚洲精品国产| 国产L精品国产亚洲区久久| 免费日本一区二区| 亚洲精品国产精品国自产网站| 成人毛片免费在线观看| 免费一级毛suv好看的国产网站 | 亚洲天堂一区二区| 毛片免费视频观看| 日韩毛片免费一二三| 亚洲精品高清国产一久久| 成年在线网站免费观看无广告| 色吊丝性永久免费看码| 亚洲精品私拍国产福利在线| 成人免费一级毛片在线播放视频 | 免费观看成人毛片a片2008| 国产亚洲精品2021自在线| 亚洲av午夜福利精品一区人妖|