| 1 |
define(["dojo/_base/kernel","dojo/_base/declare","dojo/_base/html","dojo/_base/fx", |
| 2 |
"dijit/_Templated","dijit/layout/ContentPane","dojo/dom-class", |
| 3 |
"dojo/text!./resources/ScrollPane.html"], |
| 4 |
function(kernel,declare,html,baseFx,Templated,ContentPane,domClass,template){ |
| 5 |
|
| 6 |
kernel.experimental("dojox.layout.ScrollPane"); |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
var Scrollpane = declare("dojox.layout.ScrollPane",[ContentPane, Templated],{ |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
_line: null, |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
_lo: null, |
| 32 |
|
| 33 |
_offset: 15, |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
orientation: "vertical", |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
autoHide: true, |
| 42 |
templateString: template, |
| 43 |
|
| 44 |
resize: function( size){ |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
if(size){ |
| 51 |
if(size.h){ |
| 52 |
html.style(this.domNode,'height',size.h+'px'); |
| 53 |
} |
| 54 |
if(size.w){ |
| 55 |
html.style(this.domNode,'width',size.w+'px'); |
| 56 |
} |
| 57 |
} |
| 58 |
var dir = this._dir, |
| 59 |
vert = this._vertical, |
| 60 |
val = this.containerNode[(vert ? "scrollHeight" : "scrollWidth")]; |
| 61 |
|
| 62 |
html.style(this.wrapper, this._dir, this.domNode.style[this._dir]); |
| 63 |
this._lo = html.coords(this.wrapper, true); |
| 64 |
|
| 65 |
this._size = Math.max(0, val - this._lo[(vert ? "h" : "w")]); |
| 66 |
if(!this._size){ |
| 67 |
this.helper.style.display="none"; |
| 68 |
|
| 69 |
this.wrapper[this._scroll]=0; |
| 70 |
return; |
| 71 |
}else{ |
| 72 |
this.helper.style.display=""; |
| 73 |
} |
| 74 |
this._line = new baseFx._Line(0 - this._offset, this._size + (this._offset * 2)); |
| 75 |
|
| 76 |
|
| 77 |
var u = this._lo[(vert ? "h" : "w")], |
| 78 |
r = Math.min(1, u / val), |
| 79 |
s = u * r, |
| 80 |
c = Math.floor(u - (u * r)); |
| 81 |
|
| 82 |
this._helpLine = new baseFx._Line(0, c); |
| 83 |
|
| 84 |
|
| 85 |
html.style(this.helper, dir, Math.floor(s) + "px"); |
| 86 |
|
| 87 |
}, |
| 88 |
|
| 89 |
postCreate: function(){ |
| 90 |
this.inherited(arguments); |
| 91 |
|
| 92 |
if(this.autoHide){ |
| 93 |
this._showAnim = baseFx._fade({ node:this.helper, end:0.5, duration:350 }); |
| 94 |
this._hideAnim = baseFx.fadeOut({ node:this.helper, duration: 750 }); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
this._vertical = (this.orientation == "vertical"); |
| 99 |
if(!this._vertical){ |
| 100 |
domClass.add(this.containerNode,"dijitInline"); |
| 101 |
this._dir = "width"; |
| 102 |
this._edge = "left"; |
| 103 |
this._scroll = "scrollLeft"; |
| 104 |
}else{ |
| 105 |
this._dir = "height"; |
| 106 |
this._edge = "top"; |
| 107 |
this._scroll = "scrollTop"; |
| 108 |
} |
| 109 |
|
| 110 |
if(this._hideAnim){ |
| 111 |
this._hideAnim.play(); |
| 112 |
} |
| 113 |
html.style(this.wrapper,"overflow","hidden"); |
| 114 |
|
| 115 |
}, |
| 116 |
|
| 117 |
_set: function(n){ |
| 118 |
|
| 119 |
|
| 120 |
if(!this._size || n === 'focused'){ return; } |
| 121 |
this.wrapper[this._scroll] = Math.floor(this._line.getValue(n)); |
| 122 |
html.style(this.helper, this._edge, Math.floor(this._helpLine.getValue(n)) + "px"); |
| 123 |
}, |
| 124 |
|
| 125 |
_calc: function(e){ |
| 126 |
|
| 127 |
|
| 128 |
if(!this._lo){ this.resize(); } |
| 129 |
this._set(this._vertical ? |
| 130 |
((e.pageY - this._lo.y) / this._lo.h) : |
| 131 |
((e.pageX - this._lo.x) / this._lo.w) |
| 132 |
); |
| 133 |
}, |
| 134 |
|
| 135 |
_enter: function(e){ |
| 136 |
if(this._hideAnim){ |
| 137 |
if(this._hideAnim.status() == "playing"){ |
| 138 |
this._hideAnim.stop(); |
| 139 |
} |
| 140 |
this._showAnim.play(); |
| 141 |
} |
| 142 |
}, |
| 143 |
|
| 144 |
_leave: function(e){ |
| 145 |
if(this._hideAnim){ |
| 146 |
this._hideAnim.play(); |
| 147 |
} |
| 148 |
} |
| 149 |
}); |
| 150 |
return Scrollpane; |
| 151 |
}); |