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/select-kit/addon/components/select-kit/select-kit-body.js
Michael Brown d9a02d1336
Revert "Revert "Merge branch 'master' of https://github.com/discourse/discourse""
This reverts commit 20780a1eee.

* SECURITY: re-adds accidentally reverted commit:
  03d26cd6: ensure embed_url contains valid http(s) uri
* when the merge commit e62a85cf was reverted, git chose the 2660c2e2 parent to land on
  instead of the 03d26cd6 parent (which contains security fixes)
2020-05-23 00:56:13 -04:00

60 lines
1.3 KiB
JavaScript

import Component from "@ember/component";
import { computed } from "@ember/object";
import { bind } from "@ember/runloop";
export default Component.extend({
layoutName: "select-kit/templates/components/select-kit/select-kit-body",
classNames: ["select-kit-body"],
attributeBindings: ["selectKitId:data-select-kit-id"],
selectKitId: computed("selectKit.uniqueID", function() {
return `${this.selectKit.uniqueID}-body`;
}),
rootEventType: "click",
init() {
this._super(...arguments);
this.handleRootMouseDownHandler = bind(this, this.handleRootMouseDown);
},
didInsertElement() {
this._super(...arguments);
document.addEventListener(
this.rootEventType,
this.handleRootMouseDownHandler,
true
);
},
willDestroyElement() {
this._super(...arguments);
document.removeEventListener(
this.rootEventType,
this.handleRootMouseDownHandler,
true
);
},
handleRootMouseDown(event) {
if (!this.selectKit.isExpanded) {
return;
}
const headerElement = document.querySelector(
`[data-select-kit-id=${this.selectKit.uniqueID}-header]`
);
if (headerElement && headerElement.contains(event.target)) {
return;
}
if (this.element.contains(event.target)) {
return;
}
this.selectKit.close(event);
}
});