Skip to content

Commit 8ea3f38

Browse files
committed
adjustScrollTop simplified
1 parent 07465e5 commit 8ea3f38

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

src/ui-scroll.coffee

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -221,20 +221,13 @@ angular.module('ui.scroll', [])
221221
topPadding.height (buffer.first - buffer.minIndex()) * viewport.averageItemHeight
222222
bottomPadding.height (buffer.maxIndex() - buffer.next + 1) * viewport.averageItemHeight
223223

224-
viewport.adjustScrollTop = (options) ->
225-
return if not options or not options.height
226-
# edge case 1, scroll up from the very top position
227-
if options.prepend
228-
paddingHeight = topPadding.height() - options.height
229-
if paddingHeight >= 0
230-
topPadding.height paddingHeight
231-
else
232-
topPadding.height 0
233-
viewport.scrollTop viewport.scrollTop() - paddingHeight
234-
235-
# edge case 2, scroll down from the very bottom position
236-
#if options.clipTop and options.height - bottomPadding.height() > 0
237-
#viewport.scrollTop viewport.scrollTop() + options.height - bottomPadding.height()
224+
viewport.adjustScrollTop = (height) ->
225+
paddingHeight = topPadding.height() - height
226+
if paddingHeight >= 0
227+
topPadding.height paddingHeight
228+
else
229+
topPadding.height 0
230+
viewport.scrollTop viewport.scrollTop() - paddingHeight
238231

239232
viewport
240233

@@ -430,12 +423,12 @@ angular.module('ui.scroll', [])
430423
promises = promises.concat (buffer.remove wrapper)
431424

432425
if toBePrepended.length
433-
adjustPaddingSettings = { height: 0, prepend: true }
426+
adjustedPaddingHeight = 0
434427
for wrapper in toBePrepended
435428
keepFetching = insertWrapperContent(wrapper) || keepFetching
436429
wrapper.op = 'none'
437-
adjustPaddingSettings.height += wrapper.element.height()
438-
viewport.adjustScrollTop(adjustPaddingSettings)
430+
adjustedPaddingHeight += wrapper.element.height()
431+
viewport.adjustScrollTop(adjustedPaddingHeight)
439432

440433
# re-index the buffer
441434
item.scope.$index = buffer.first + i for item,i in buffer

0 commit comments

Comments
 (0)