
JavaScriptMVC 函式庫
|
235
return Math.max(0, newCount );
},
setOffset : function( newOffset ){
return Math.max( 0 , Math.min(newOffset, this.count ) )
},
next : function(){
this.attr('offset', this.offset+this.limit);
},
prev : function(){
this.attr('offset', this.offset - this.limit )
},
canNext : function(){
return this.offset > this.count - this.limit
},
canPrev : function(){
return this.offset > 0
}
})
這麼一來,就能讓 jQuery 網頁小工具的程式碼,變得簡潔得多:
$.fn.nextPrev = function(paginate){
this.delegate('.next','click', function(){
paginate.next();
})
this.delegate('.prev','click', function(){
paginate.prev();
});
var self = this;
paginate.bind('updated.attr', ...