185 |
* selection and actual browser scrolling if necessary. |
* selection and actual browser scrolling if necessary. |
186 |
* |
* |
187 |
* @param int direction -1 means scroll up, +1 means scroll down |
* @param int direction -1 means scroll up, +1 means scroll down |
188 |
|
* @param boolean scrollWrap wrap when scrolling (default: true) |
189 |
* @return boolean False |
* @return boolean False |
190 |
*/ |
*/ |
191 |
Refeed.App.doScroll = function(direction) |
Refeed.App.doScroll = function(direction, scrollWrap) |
192 |
{ |
{ |
193 |
if(this.listedThings.length == 0) { |
if(this.listedThings.length == 0) { |
194 |
return false; |
return false; |
195 |
} |
} |
196 |
|
|
197 |
var newThing = null; |
var newThing = null; |
198 |
var winBox = this.getWindowBox(); |
var winBox = this.getWindowBox(); |
199 |
var docBox = this.getDocumentBox(); |
var docBox = this.getDocumentBox(); |
201 |
var scrolledToBottom = winBox.bottom() >= docBox.bottom(); |
var scrolledToBottom = winBox.bottom() >= docBox.bottom(); |
202 |
var scrolledToTop = winBox.top() <= 0; |
var scrolledToTop = winBox.top() <= 0; |
203 |
|
|
204 |
|
if (scrollWrap == null) scrollWrap = true; |
205 |
|
|
206 |
if(!scrolledToBottom && !scrolledToTop && (this.selectedThing == null || !winBox.isOverlapping(this.selectedThing.getNodeBox()))) { |
if(!scrolledToBottom && !scrolledToTop && (this.selectedThing == null || !winBox.isOverlapping(this.selectedThing.getNodeBox()))) { |
207 |
// we're scrolled someplace in the middle, and there's nothing |
// we're scrolled someplace in the middle, and there's nothing |
208 |
// selected in view, so find something appropriate within the |
// selected in view, so find something appropriate within the |
219 |
// just pick the next thing |
// just pick the next thing |
220 |
newThing = this.listedThings[newPos]; |
newThing = this.listedThings[newPos]; |
221 |
|
|
222 |
} else { |
} else if (scrollWrap) { |
223 |
// looks like we're set to scroll off the edge of the document |
// looks like we're set to scroll off the edge of the document |
224 |
if(this.selectedThing == null) { |
if(this.selectedThing == null) { |
225 |
// ...and nothing is selected, |
// ...and nothing is selected, |
245 |
window.scrollTo(0, docBox.bottom()); |
window.scrollTo(0, docBox.bottom()); |
246 |
} |
} |
247 |
} |
} |
248 |
} |
} else { |
249 |
|
// no scrollWrap |
250 |
|
return false; |
251 |
|
} |
252 |
} |
} |
253 |
|
|
254 |
this.selectThing(newThing); |
this.selectThing(newThing); |