willDestroyElement: function() { this._super(); this._unregisterScrollableParents(); $(window).off('resize', functionProxy(this.updatePosition, this)); $(window).off('mousedown', functionProxy(this._didMouseDownWindow, this)); $(document).off('scroll', functionProxy(this.updatePosition, this)); },
_registerScrollableParents: function() { Em.assert('_scrollableParents should be empty when initializing this component', !this.get('_scrollableParents.length')); var el = this._targetEl, parents = this.get('_scrollableParents') || Em.A(); while (el.length) { //If document, we've reached the top (Firefox doesn't like using .css on document) if (el[0] === document) { break; } //Define properties that denote "scrollable". This is not foolproof, as "initial" and "inherit" could //potentially still result in a scrollable element var sp = Em.A(['scroll', 'auto']); //Check if overflows are scrollable if (sp.contains(el.css('overflow')) || sp.contains(el.css('overflow-x')) || sp.contains(el.css('overflow-y'))) { parents.push(el); el.on('scroll', functionProxy(this.updatePosition, this)); } //Next el = el.parent(); } this.set('_scrollableParents', parents); },
didInsertElement: function() { this._super(); this._updateZIndex(); this._registerScrollableParents(); //Bind events $(window).on('resize', functionProxy(this.updatePosition, this)); $(window).on('mousedown', functionProxy(this._didMouseDownWindow, this)); $(document).on('scroll', functionProxy(this.updatePosition, this)); //Set _bodyExtraHeight (any extra height outside of the scrollable area) var bodyEl = this.$('.popover-body'); if (bodyEl.length) { this.set('_bodyExtraHeight', this.$().outerHeight() - bodyEl.outerHeight()); } //Update position this.updatePosition(); },
addOrRemoveDropTargetEvents: function(method) { var dropTarget = this.getDropTarget(), body = $(this.container.lookup('application:main').get('rootElement')); body[method]('dragenter', functionProxy(this.onBodyDragEnter, this)); body[method]('dragleave', functionProxy(this.onBodyDragLeave, this)); body[method]('dragover', functionProxy(this.onBodyDragOver, this)); body[method]('drop', functionProxy(this.onBodyDrop, this)); dropTarget[method]('dragover', functionProxy(this.onDragOver, this)); dropTarget[method]('dragleave', functionProxy(this.onDragLeave, this)); dropTarget[method]('drop', functionProxy(this.onDrop, this)); },
scrollableParents.forEach(function(parent) { parent.off('scroll', functionProxy(self.updatePosition, self)); });
show: function(targetView, targetEl) { this.set('targetView', targetView); targetView.one('willDestroyElement', functionProxy(this.destroy, this)); this._targetEl = targetEl ? $(targetEl) : targetView.$(); this.appendTo(this.container.lookup('application:main').get('rootElement')); },