This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/mixins/docking.js.es6
2019-10-30 15:13:48 -05:00

44 lines
1.0 KiB
JavaScript

import Mixin from "@ember/object/mixin";
import { debounce } from "@ember/runloop";
const helper = {
offset() {
const mainOffset = $("#main").offset();
const offsetTop = mainOffset ? mainOffset.top : 0;
return (window.pageYOffset || $("html").scrollTop()) - offsetTop;
}
};
export default Mixin.create({
queueDockCheck: null,
init() {
this._super(...arguments);
this.queueDockCheck = () => {
debounce(this, this.safeDockCheck, 5);
};
},
safeDockCheck() {
if (this.isDestroyed || this.isDestroying) {
return;
}
this.dockCheck(helper);
},
didInsertElement() {
this._super(...arguments);
$(window).bind("scroll.discourse-dock", this.queueDockCheck);
$(document).bind("touchmove.discourse-dock", this.queueDockCheck);
this.dockCheck(helper);
},
willDestroyElement() {
this._super(...arguments);
$(window).unbind("scroll.discourse-dock", this.queueDockCheck);
$(document).unbind("touchmove.discourse-dock", this.queueDockCheck);
}
});