_.Module.define({path:"common/component/ScrollPanel",sub:{dom:null,$content:null,$scrollBar:null,$scrollButton:null,_hasScroll:false,_scrollStep:50,_scrollTop:0,_maxHeight:0,initial:function(a){this._buildUI(a);this._bindEvents(a);$(a.container).append(this.dom);this.setHeight(a.height||100);if(a.content){this.setContent(a.content)}if(a.scrollBarShow){this.bind("onScrollBarShow",a.scrollBarShow)}if(a.scrollBarHide){this.bind("onScrollBarHide",a.scrollBarHide)}},_buildUI:function(b){var a=this,c={left:0,top:0};this.dom=$('<div class="tbui_scroll_panel"></div>');this.dom.html(['<div class="tbui_panel_content j_panel_content clearfix"><ul></ul></div>','<div class="tbui_scroll_bar j_scroll_bar">','<div class="tbui_scroll_button j_scroll_button">&nbsp;</div>',"</div>"].join(""));this.$content=this.dom.find(".j_panel_content:first");this.$scrollBar=this.dom.find(".j_scroll_bar:first");this.$scrollButton=this.dom.find(".j_scroll_button:first");if(b.padding){this.$content.css("padding",b.padding)}},_bindEvents:function(b){var a=this,c=a.$content.get(0);this.$scrollButton.on("drag",function(d,e){if(!e){return}var f=e.position;c.scrollTop=(f.top+2)/a.$content.height()*c.scrollHeight});this.$content.mousewheel(function(d,e){d.preventDefault();d.stopPropagation();if(!a._hasScroll){return}a.scrollTopTo(a._scrollTop-e*a._scrollStep)})},scrollTopTo:function(c){var a=this,b=a.$content.get(0);var c=Math.max(Math.min(c,b.scrollHeight-a.$content.height()),0);if(c==a._scrollTop){return}a._scrollTop=c;a.$content.stop();a.$content.scrollTop(a._scrollTop);a._resizeScroll()},setHeight:function(a){this._maxHeight=a;this._resizeHeight();this._resizeScroll();this.$scrollButton.draggable({containment:"parent"})},setContent:function(a){this.$content.html(a);this.$content.get(0).scrollTop=this._scrollTop=0;this._resizeHeight();this._resizeScroll()},appendContent:function(a){this.$content.append(a);this._resizeHeight();this.scrollTopTo(20000)},clearContent:function(){this.setContent("")},_resizeHeight:function(){this.$content.css("height","");var b=this.$content.get(0),c=b.scrollHeight,a=Math.min(c,this._maxHeight);this.$content.css("height",a)},_resizeScroll:function(){var c=this.$content.get(0),d=c.scrollHeight,b=c.scrollTop,a=this.$content.innerHeight();if(d<=a){this.$scrollBar.hide();this.dom.addClass("tbui_no_scroll_bar");this.trigger("onScrollBarHide");this._hasScroll=false}else{this.$scrollBar.show();this.$scrollBar.height(a);this.$scrollButton.height(a/d*a);this.$scrollButton.css("top",b/d*a);this.trigger("onScrollBarShow");this._hasScroll=true}}}});