1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 21:29:42 +02:00

event-bus provides scroll and window resize events

This commit is contained in:
Harvey Kandola 2016-10-05 16:21:52 -07:00
parent 003fbacd32
commit 3256292d41
2 changed files with 31 additions and 15 deletions

View file

@ -30,22 +30,26 @@ export default Ember.Component.extend(TooltipMixin, NotifierMixin, {
}, },
didInsertElement() { didInsertElement() {
let _this = this;
this.eventBus.subscribe('resized', this, 'positionTool');
this.eventBus.subscribe('scrolled', this, 'positionTool');
},
willDestroyElement() {
this.destroyTooltips();
},
positionTool() {
let s = $(".section-tool"); let s = $(".section-tool");
let pos = s.position(); let pos = s.position();
$(window).scroll(_.throttle(function() {
let windowpos = $(window).scrollTop(); let windowpos = $(window).scrollTop();
if (windowpos - 200 >= pos.top) { if (windowpos - 200 >= pos.top) {
s.addClass("stuck-tool"); s.addClass("stuck-tool");
s.css('left', parseInt($(".zone-sidebar").css('width')) - 18 + 'px'); s.css('left', parseInt($(".zone-sidebar").css('width')) - 18 + 'px');
} else { } else {
s.removeClass("stuck-tool"); s.removeClass("stuck-tool");
} }
}, 50));
},
willDestroyElement() {
this.destroyTooltips();
}, },
actions: { actions: {

View file

@ -12,6 +12,18 @@
import Ember from 'ember'; import Ember from 'ember';
export default Ember.Service.extend(Ember.Evented, { export default Ember.Service.extend(Ember.Evented, {
init() {
let _this = this;
window.addEventListener("scroll", _.debounce(function() {
_this.publish('scrolled', null);
}, 100));
window.addEventListener("resize", _.debounce(function() {
_this.publish('resized', null);
}, 100));
},
publish: function() { publish: function() {
return this.trigger.apply(this, arguments); return this.trigger.apply(this, arguments);
}, },