diff --git a/src/core/js/views/adaptView.js b/src/core/js/views/adaptView.js index 929ede06d..7ae3074ba 100644 --- a/src/core/js/views/adaptView.js +++ b/src/core/js/views/adaptView.js @@ -12,6 +12,7 @@ define([ this._isRemoved = false; this.preRender(); this.render(); + this.setupOnScreenHandler(); }, preRender: function() {}, @@ -38,6 +39,24 @@ define([ return this; }, + setupOnScreenHandler: function() { + var onscreen = this.model.get('_onScreen'); + + if (!onscreen || !onscreen._isEnabled) return; + + this.$el.on('onscreen.adaptView', _.bind(function (e, m) { + + if (!m.onscreen) return; + + var minVerticalInview = onscreen._percentInviewVertical || 33; + + if (m.percentInviewVertical < minVerticalInview) return; + + this.$el.addClass( onscreen._classes || 'onscreen' ).off('onscreen.adaptView'); + + }, this)); + }, + addChildren: function() { var nthChild = 0; var children = this.model.getChildren(); @@ -93,6 +112,7 @@ define([ }, remove: function() { + this.$el.off('onscreen.adaptView'); this._isRemoved = true; this.model.setOnChildren('_isReady', false); this.model.set('_isReady', false); diff --git a/src/core/js/views/blockView.js b/src/core/js/views/blockView.js index d5524d5ce..e83e60a9f 100644 --- a/src/core/js/views/blockView.js +++ b/src/core/js/views/blockView.js @@ -1,6 +1,6 @@ -define(function(require) { - - var AdaptView = require('coreViews/adaptView'); +define([ + 'core/js/views/adaptView' + ], function(AdaptView) { var BlockView = AdaptView.extend({