webogram scroll
var atBottom = true | |
var scrollTopInitial = -1 | |
$(scrollableWrap).on('scroll', function (e) { | |
if (!element.is(':visible') || | |
$(scrollableWrap).hasClass('im_history_to_bottom') || | |
curAnimation) { | |
return | |
} | |
var st = scrollableWrap.scrollTop | |
atBottom = st >= scrollableWrap.scrollHeight - scrollableWrap.clientHeight | |
if (scrollTopInitial >= 0 && scrollTopInitial != st) { | |
scrollTopInitial = -1 | |
} | |
if (!moreNotified && st <= 300) { | |
moreNotified = true | |
$scope.$emit('history_need_more') | |
} else if (!lessNotified && st >= scrollableWrap.scrollHeight - scrollableWrap.clientHeight - 300) { | |
lessNotified = true | |
$scope.$emit('history_need_less') | |
} | |
}) | |
function updateSizes (heightOnly) { | |
if (!element.is(':visible') && !$(element[0].parentNode.parentNode).is(':visible')) { | |
return | |
} | |
if ($(sendFormWrap).is(':visible')) { | |
if (!sendForm || !sendForm.offsetHeight) { | |
sendForm = $('.im_send_form', element)[0] | |
} | |
$(sendFormWrap).css({ | |
height: $(sendForm).height() | |
}) | |
} | |
if (!headWrap || !headWrap.offsetHeight) { | |
headWrap = $('.tg_page_head')[0] | |
} | |
if (!footer || !footer.offsetHeight) { | |
footer = $('.footer_wrap')[0] | |
} | |
var footerHeight = footer ? footer.offsetHeight : 0 | |
if (footerHeight) { | |
footerHeight++ // Border bottom | |
} | |
var historyH = $($window).height() - bottomPanelWrap.offsetHeight - (headWrap ? headWrap.offsetHeight : 48) - footerHeight | |
$(historyWrap).css({ | |
height: historyH | |
}) | |
updateBottomizer() | |
if (heightOnly === true) return | |
if (atBottom) { | |
onContentLoaded(function () { | |
// console.log('change scroll bottom') | |
scrollableWrap.scrollTop = scrollableWrap.scrollHeight | |
updateScroller() | |
}) | |
} | |
updateScroller(100) | |
} | |
function updateBottomizer () { | |
$(historyMessagesEl).css({marginTop: 0}) | |
var marginTop = scrollableWrap.offsetHeight - | |
historyMessagesEl.offsetHeight - | |
emptyWrapEl.offsetHeight - | |
(Config.Mobile ? 0 : 39) | |
if (historyMessagesEl.offsetHeight > 0 && marginTop > 0) { | |
$(historyMessagesEl).css({marginTop: marginTop}) | |
} | |
$(historyWrap).nanoScroller() | |
} | |
$($window).on('resize', updateSizes) | |
updateSizes() |
$scope.$on('ui_history_prepend', function () { | |
var sh = scrollableWrap.scrollHeight | |
var st = scrollableWrap.scrollTop | |
var pr = parseInt($(scrollableWrap).css('paddingRight')) | |
var ch = scrollableWrap.clientHeight | |
$(scrollableWrap).addClass('im_history_to_bottom') | |
scrollableWrap.scrollHeight // Some strange Chrome bug workaround | |
$(scrollable).css({bottom: -(sh - st - ch), paddingRight: pr}) | |
var upd = function () { | |
$(scrollableWrap).removeClass('im_history_to_bottom') | |
$(scrollable).css({bottom: '', paddingRight: ''}) | |
if (scrollTopInitial >= 0) { | |
changeScroll() | |
} else { | |
// console.log('change scroll prepend') | |
scrollableWrap.scrollTop = st + scrollableWrap.scrollHeight - sh | |
} | |
updateBottomizer() | |
moreNotified = false | |
$timeout(function () { | |
if (scrollableWrap.scrollHeight != sh) { | |
$(scrollableWrap).trigger('scroll') | |
} | |
}) | |
clearTimeout(timer) | |
unreg() | |
} | |
var timer = setTimeout(upd, 0) | |
var unreg = $scope.$on('$viewContentLoaded', upd) | |
}) | |
$scope.$on('ui_history_append', function () { | |
var sh = scrollableWrap.scrollHeight | |
onContentLoaded(function () { | |
atBottom = false | |
updateBottomizer() | |
lessNotified = false | |
if (scrollTopInitial >= 0) { | |
changeScroll() | |
} | |
$timeout(function () { | |
if (scrollableWrap.scrollHeight != sh) { | |
$(scrollableWrap).trigger('scroll') | |
} | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment