Index: trunk/extensions/Storyboard/jquery/jquery.ajaxscroll.js |
— | — | @@ -36,11 +36,13 @@ |
37 | 37 | var ele = this; |
38 | 38 | var $me = jQuery( this ); |
39 | 39 | var $sp; |
40 | | - var fnEnd; |
41 | 40 | var offset = 0; |
42 | 41 | var lsp = -1; |
43 | 42 | |
44 | | - _css(); |
| 43 | + $me.css( { |
| 44 | + "overflow-x": "hidden", |
| 45 | + "overflow-y": "auto" |
| 46 | + } ); |
45 | 47 | |
46 | 48 | opt.boxTemplate = ( opt.boxTemplate || "<span class='" + opt.boxClass + "'> </span>" ); |
47 | 49 | opt.batchTemplate = ( opt.batchTemplate || "<span></span>" ); |
— | — | @@ -50,40 +52,27 @@ |
51 | 53 | offset = batch( $sp, offset, opt ); |
52 | 54 | $me.scrollTop(0).scrollLeft(0); |
53 | 55 | |
54 | | - _ab(); |
| 56 | + var os = $me.find( '.batch:first' ).next().offset().top; |
| 57 | + var b = ( $me.height() / os + 1 ) * os; |
55 | 58 | |
56 | | - fnEnd = vEnd; |
| 59 | + if ( "auto" == opt.uBound ) { |
| 60 | + opt.uBound = b; |
| 61 | + } |
57 | 62 | |
| 63 | + if ( "auto" == opt.lBound ) { |
| 64 | + opt.lBound = -b; |
| 65 | + } |
| 66 | + |
| 67 | + if ( "auto" == opt.eBound ) { |
| 68 | + opt.eBound = b * 2; |
| 69 | + } |
| 70 | + |
58 | 71 | setTimeout( monEnd, opt.endDelay ); |
59 | 72 | |
60 | 73 | if( typeof opt.updateBatch == 'function' ){ |
61 | 74 | setTimeout( handleScrolling, opt.scrollDelay ); |
62 | 75 | } |
63 | 76 | |
64 | | - function _css(){ |
65 | | - $me.css( { |
66 | | - "overflow-x": "hidden", |
67 | | - "overflow-y": "auto" |
68 | | - } ); |
69 | | - } |
70 | | - |
71 | | - function _ab(){ |
72 | | - var os = $me.find( '.batch:first' ).next().offset().top; |
73 | | - var b = ( $me.height() / os + 1 ) * os; |
74 | | - |
75 | | - if ( "auto" == opt.uBound ) { |
76 | | - opt.uBound = b; |
77 | | - } |
78 | | - |
79 | | - if ( "auto" == opt.lBound ) { |
80 | | - opt.lBound = -b; |
81 | | - } |
82 | | - |
83 | | - if ( "auto" == opt.eBound ) { |
84 | | - opt.eBound = b * 2; |
85 | | - } |
86 | | - } |
87 | | - |
88 | 77 | function batch( $s, offset, opt ) { |
89 | 78 | var $b; |
90 | 79 | var i; |
— | — | @@ -111,12 +100,12 @@ |
112 | 101 | return offset; |
113 | 102 | }; |
114 | 103 | |
115 | | - function vScroll() { |
116 | | - // If a batcnh is currently being loaded, we can't start another one yet. |
117 | | - if ( opt.busy ) { |
118 | | - return; |
119 | | - } |
120 | | - |
| 104 | + /** |
| 105 | + * This function emulates a scroll event handler by firing itself every so many ms. |
| 106 | + * It checks if the user has scrolled down far enough, and calls the update batch |
| 107 | + * function if this is the case. |
| 108 | + */ |
| 109 | + function handleScrolling() { |
121 | 110 | var so = $me.scrollTop(); |
122 | 111 | |
123 | 112 | if( lsp != so) { |
— | — | @@ -129,13 +118,20 @@ |
130 | 119 | |
131 | 120 | if ( opt.lBound > p || p > opt.uBound ) { |
132 | 121 | return; |
133 | | - } |
| 122 | + } |
134 | 123 | |
135 | | - opt.busy = true; |
136 | 124 | opt.updateBatch( $b.removeClass( opt.emptyBatchClass ), opt ); |
137 | 125 | }); |
138 | 126 | } |
| 127 | + |
| 128 | + setTimeout( handleScrolling, opt.scrollDelay ); |
139 | 129 | }; |
| 130 | + |
| 131 | + function monEnd() { |
| 132 | + if ( offset < opt.maxOffset ) { |
| 133 | + setTimeout( monEnd, vEnd() ); |
| 134 | + } |
| 135 | + } |
140 | 136 | |
141 | 137 | function vEnd() { |
142 | 138 | if ( ele.scrollTop > 0 && ele.scrollHeight - ele.scrollTop < opt.eBound ) { |
— | — | @@ -146,21 +142,6 @@ |
147 | 143 | return opt.endDelay; |
148 | 144 | }; |
149 | 145 | |
150 | | - /** |
151 | | - * This function emulates a scroll event handler by firing itself every so many ms, and |
152 | | - * then calling a function checking if the user has scrolled, and if any batches should be loaded. |
153 | | - */ |
154 | | - function handleScrolling() { |
155 | | - vScroll(); |
156 | | - setTimeout( handleScrolling, opt.scrollDelay ); |
157 | | - }; |
158 | | - |
159 | | - function monEnd() { |
160 | | - if ( offset < opt.maxOffset ) { |
161 | | - setTimeout( monEnd, fnEnd() ); |
162 | | - } |
163 | | - } |
164 | | - |
165 | 146 | }); |
166 | 147 | }; |
167 | 148 | })(jQuery); |