update ember-cloaking to support bottom fixed element

This commit is contained in:
Régis Hanol 2014-06-06 18:59:07 +02:00
parent e0b72997db
commit 8262279380
2 changed files with 27 additions and 10 deletions

View file

@ -86,7 +86,8 @@
loadingHTML=controller.loadingHTML loadingHTML=controller.loadingHTML
preservesContext="true" preservesContext="true"
uncloakDefault="true" uncloakDefault="true"
offsetFixed="header"}} offsetFixed="header"
offsetFixedBottom="#reply-control"}}
{{/unless}} {{/unless}}
{{#if postStream.loadingBelow}} {{#if postStream.loadingBelow}}

View file

@ -10,7 +10,8 @@
Ember.CloakedCollectionView = Ember.CollectionView.extend({ Ember.CloakedCollectionView = Ember.CollectionView.extend({
topVisible: null, topVisible: null,
bottomVisible: null, bottomVisible: null,
offsetFixedElement: null, offsetFixedTopElement: null,
offsetFixedBottomElement: null,
init: function() { init: function() {
var cloakView = this.get('cloakView'), var cloakView = this.get('cloakView'),
@ -119,21 +120,27 @@
topView = this.findTopView(childViews, viewportTop, 0, childViews.length-1), topView = this.findTopView(childViews, viewportTop, 0, childViews.length-1),
bodyHeight = this.get('wrapperHeight') ? this.$().height() : $('body').height(), bodyHeight = this.get('wrapperHeight') ? this.$().height() : $('body').height(),
bottomView = topView, bottomView = topView,
offsetFixedElement = this.get('offsetFixedElement'); offsetFixedTopElement = this.get('offsetFixedTopElement'),
offsetFixedBottomElement = this.get('offsetFixedBottomElement');
if (windowBottom > bodyHeight) { windowBottom = bodyHeight; } if (windowBottom > bodyHeight) { windowBottom = bodyHeight; }
if (viewportBottom > bodyHeight) { viewportBottom = bodyHeight; } if (viewportBottom > bodyHeight) { viewportBottom = bodyHeight; }
if (offsetFixedElement) { if (offsetFixedTopElement) {
windowTop += (offsetFixedElement.outerHeight(true) || 0); windowTop += (offsetFixedTopElement.outerHeight(true) || 0);
} }
if (offsetFixedBottomElement) {
windowBottom -= (offsetFixedBottomElement.outerHeight(true) || 0);
}
// Find the bottom view and what's onscreen // Find the bottom view and what's onscreen
while (bottomView < childViews.length) { while (bottomView < childViews.length) {
var view = childViews[bottomView], var view = childViews[bottomView],
$view = view.$(), $view = view.$(),
// in case of not full-window scrolling // in case of not full-window scrolling
scrollOffset = this.get('wrapperTop') >> 0, scrollOffset = this.get('wrapperTop') || 0,
viewTop = $view.position().top + scrollOffset, viewTop = $view.offset().top + scrollOffset,
viewBottom = viewTop + $view.height(); viewBottom = viewTop + $view.height();
if (viewTop > viewportBottom) { break; } if (viewTop > viewportBottom) { break; }
@ -183,14 +190,23 @@
}, },
_startEvents: function() { _startEvents: function() {
if (this.get('offsetFixed')) {
Em.warn("Cloaked-collection's `offsetFixed` is deprecated. Use `offsetFixedTop` instead.");
}
var self = this, var self = this,
offsetFixed = this.get('offsetFixed'), offsetFixedTop = this.get('offsetFixedTop') || this.get('offsetFixed'),
offsetFixedBottom = this.get('offsetFixedBottom'),
onScrollMethod = function() { onScrollMethod = function() {
Ember.run.debounce(self, 'scrollTriggered', 10); Ember.run.debounce(self, 'scrollTriggered', 10);
}; };
if (offsetFixed) { if (offsetFixedTop) {
this.set('offsetFixedElement', $(offsetFixed)); this.set('offsetFixedTopElement', $(offsetFixedTop));
}
if (offsetFixedBottom) {
this.set('offsetFixedBottomElement', $(offsetFixedBottom));
} }
$(document).bind('touchmove.ember-cloak', onScrollMethod); $(document).bind('touchmove.ember-cloak', onScrollMethod);