[483] | 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 | // FIXME: need to adjust the _line somehow, it stops scrolling |
---|
| 9 | |
---|
| 10 | var Scrollpane = declare("dojox.layout.ScrollPane",[ContentPane, Templated],{ |
---|
| 11 | // summary: |
---|
| 12 | // A pane that "scrolls" its content based on the mouse poisition inside |
---|
| 13 | // description: |
---|
| 14 | // A sizable container that takes it's content's natural size and creates |
---|
| 15 | // a scroll effect based on the relative mouse position. It is an interesting |
---|
| 16 | // way to display lists of data, or blocks of content, within a confined |
---|
| 17 | // space. |
---|
| 18 | // |
---|
| 19 | // Horizontal scrolling is supported. Combination scrolling is not. |
---|
| 20 | // example: |
---|
| 21 | // | <div dojoType="dojox.layout.ScrollPane" style="width:150px height:300px;"> |
---|
| 22 | // | <!-- any height content --> |
---|
| 23 | // | </div> |
---|
| 24 | |
---|
| 25 | // _line: dojo/_base/fx._Line |
---|
| 26 | // storage for our top and bottom most scrollpoints |
---|
| 27 | _line: null, |
---|
| 28 | |
---|
| 29 | // _lo: |
---|
| 30 | // the height of the visible pane |
---|
| 31 | _lo: null, |
---|
| 32 | |
---|
| 33 | _offset: 15, |
---|
| 34 | |
---|
| 35 | // orientation: String |
---|
| 36 | // either "horizontal" or "vertical" for scroll orientation. |
---|
| 37 | orientation: "vertical", |
---|
| 38 | |
---|
| 39 | // autoHide: Boolean |
---|
| 40 | // whether the scroll helper should hide when mouseleave |
---|
| 41 | autoHide: true, |
---|
| 42 | templateString: template, |
---|
| 43 | |
---|
| 44 | resize: function(/*Integer?*/ size){ |
---|
| 45 | // summary: |
---|
| 46 | // calculates required sizes. Call this if you add/remove |
---|
| 47 | // content manually, or reload the content. |
---|
| 48 | |
---|
| 49 | // if size is passed, it means we need to take care of sizing ourself (this is for IE<8) |
---|
| 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 | //make sure we reset scroll position, otherwise the content may be hidden |
---|
| 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 | // share a relative position w the scroll offset via a line |
---|
| 77 | var u = this._lo[(vert ? "h" : "w")], |
---|
| 78 | r = Math.min(1, u / val), // ratio |
---|
| 79 | s = u * r, // size |
---|
| 80 | c = Math.floor(u - (u * r)); // center |
---|
| 81 | |
---|
| 82 | this._helpLine = new baseFx._Line(0, c); |
---|
| 83 | |
---|
| 84 | // size the helper |
---|
| 85 | html.style(this.helper, dir, Math.floor(s) + "px"); |
---|
| 86 | |
---|
| 87 | }, |
---|
| 88 | |
---|
| 89 | postCreate: function(){ |
---|
| 90 | this.inherited(arguments); |
---|
| 91 | // for the helper |
---|
| 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 | // orientation helper |
---|
| 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(/* Float */n){ |
---|
| 118 | // summary: |
---|
| 119 | // set the pane's scroll offset, and position the virtual scroll helper |
---|
| 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(/* Event */e){ |
---|
| 126 | // summary: |
---|
| 127 | // calculate the relative offset of the cursor over the node, and call _set |
---|
| 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 | }); |
---|