mirror of
https://github.com/documize/community.git
synced 2025-07-19 13:19:43 +02:00
event-bus provides scroll and window resize events
This commit is contained in:
parent
003fbacd32
commit
3256292d41
2 changed files with 31 additions and 15 deletions
|
@ -30,24 +30,28 @@ export default Ember.Component.extend(TooltipMixin, NotifierMixin, {
|
||||||
},
|
},
|
||||||
|
|
||||||
didInsertElement() {
|
didInsertElement() {
|
||||||
let s = $(".section-tool");
|
let _this = this;
|
||||||
let pos = s.position();
|
this.eventBus.subscribe('resized', this, 'positionTool');
|
||||||
|
this.eventBus.subscribe('scrolled', this, 'positionTool');
|
||||||
$(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));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
willDestroyElement() {
|
willDestroyElement() {
|
||||||
this.destroyTooltips();
|
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: {
|
actions: {
|
||||||
// Page up - above pages shunt down.
|
// Page up - above pages shunt down.
|
||||||
onPageSequenceChange(pendingChanges) {
|
onPageSequenceChange(pendingChanges) {
|
||||||
|
|
|
@ -1,17 +1,29 @@
|
||||||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
// Copyright 2016 Documize Inc. <legal@documize.com>. 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
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
//
|
//
|
||||||
// You can operate outside the AGPL restrictions by purchasing
|
// You can operate outside the AGPL restrictions by purchasing
|
||||||
// Documize Enterprise Edition and obtaining a commercial license
|
// Documize Enterprise Edition and obtaining a commercial license
|
||||||
// by contacting <sales@documize.com>.
|
// by contacting <sales@documize.com>.
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
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);
|
||||||
},
|
},
|
||||||
|
@ -23,4 +35,4 @@ export default Ember.Service.extend(Ember.Evented, {
|
||||||
unsubscribe: function() {
|
unsubscribe: function() {
|
||||||
return this.off.apply(this, arguments);
|
return this.off.apply(this, arguments);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue