From 3256292d4195491a57b94e5ec50dfa9cd51882fd Mon Sep 17 00:00:00 2001 From: Harvey Kandola Date: Wed, 5 Oct 2016 16:21:52 -0700 Subject: [PATCH] event-bus provides scroll and window resize events --- .../components/document/document-sidebar.js | 28 +++++++++++-------- app/app/services/event-bus.js | 18 ++++++++++-- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/app/app/components/document/document-sidebar.js b/app/app/components/document/document-sidebar.js index 3deaee27..f1fdc1f0 100644 --- a/app/app/components/document/document-sidebar.js +++ b/app/app/components/document/document-sidebar.js @@ -30,24 +30,28 @@ export default Ember.Component.extend(TooltipMixin, NotifierMixin, { }, didInsertElement() { - let s = $(".section-tool"); - let pos = s.position(); - - $(window).scroll(_.throttle(function() { - let windowpos = $(window).scrollTop(); - if (windowpos - 200 >= pos.top) { - s.addClass("stuck-tool"); - s.css('left', parseInt($(".zone-sidebar").css('width')) - 18 + 'px'); - } else { - s.removeClass("stuck-tool"); - } - }, 50)); + let _this = this; + this.eventBus.subscribe('resized', this, 'positionTool'); + this.eventBus.subscribe('scrolled', this, 'positionTool'); }, willDestroyElement() { this.destroyTooltips(); }, + positionTool() { + let s = $(".section-tool"); + let pos = s.position(); + let windowpos = $(window).scrollTop(); + + if (windowpos - 200 >= pos.top) { + s.addClass("stuck-tool"); + s.css('left', parseInt($(".zone-sidebar").css('width')) - 18 + 'px'); + } else { + s.removeClass("stuck-tool"); + } + }, + actions: { // Page up - above pages shunt down. onPageSequenceChange(pendingChanges) { diff --git a/app/app/services/event-bus.js b/app/app/services/event-bus.js index 58301200..a62d82ae 100644 --- a/app/app/services/event-bus.js +++ b/app/app/services/event-bus.js @@ -1,17 +1,29 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com import Ember from 'ember'; 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() { return this.trigger.apply(this, arguments); }, @@ -23,4 +35,4 @@ export default Ember.Service.extend(Ember.Evented, { unsubscribe: function() { return this.off.apply(this, arguments); } -}); \ No newline at end of file +});