如何重写will_paginate方法

WillPaginate::ViewHelpers.pagination_options.merge!(
     :previous_label => '« 上一页',

     :next_label => '下一页 »'
   )
   module WillPaginate

     module ViewHelpers

       alias_method :orig_will_paginate,:will_paginate

       def will_paginate(*args)

         pagination = orig_will_paginate(*args).to_s  return "" if pagination.blank?

        total_page = WillPaginate::ViewHelpers.total_pages_for_collection(*args);

        total = hidden_field_tag "total",total_page

        text = text_field_tag "text",nil,:size =>3,:maxlength=>5,

        :onkeydown => "
             if(event.keyCode ==13){

                var  bl = !isNaN(Number($(this).val())) && ($(this).val()  != 0);

                var p = bl ? ($(this).val() > $('#total').val() ? $('#total').val() : $(this).val()) : 1;

                var h = document.location.href;

                var url = h.indexOf('?')>0 ? h.substring(0,h.indexOf('?')) : h;

                var href = url + '?page=' + p;

                window.location.href = href;
              }"
        return "#{bb}#{pagination}跳转到#{aa}页"
      end
    end
  end


:onkeydown => "
        if(event.keyCode ==13){
            if($(this).val()==''){
               alert('请输入需要跳转的页码!');
            }else{
               //判断输入的值是否为正整数
               var bl = !isNaN(Number($(this).val())) && ($(this).val() > 0);
               //输入的值小于1则取1,大于total则取total
               var p= bl ? (Number($(this).val())>Number($('#total').val()) ? 
                   $('#total').val():$(this).val()): 1;
  
               var h= document.location.href;
               var url = h.indexOf('?')>0 ? (h.indexOf('page=')>0 ? h.replace
               (/page=.*&|page=.*/,'page='+p+'&'):h+'&page='+p) : (h+'?&page='+p);
               window.location.href=url;}}" 

你可能感兴趣的:(NAT)