discourse/app/assets/javascripts/select-kit/components/multi-select/multi-select-header.js.es6

33 lines
1.3 KiB
Plaintext
Raw Normal View History

2017-10-20 03:51:08 +08:00
import { on } from "ember-addons/ember-computed-decorators";
import computed from "ember-addons/ember-computed-decorators";
import SelectKitHeaderComponent from "select-kit/components/select-kit/select-kit-header";
2017-10-20 03:51:08 +08:00
export default SelectKitHeaderComponent.extend({
2017-10-20 03:51:08 +08:00
attributeBindings: ["names:data-name"],
classNames: "multi-select-header",
layoutName: "select-kit/templates/components/multi-select/multi-select-header",
2017-11-10 02:57:53 +08:00
selectedNameComponent: Ember.computed.alias("options.selectedNameComponent"),
2017-10-20 03:51:08 +08:00
@on("didRender")
_positionFilter() {
2017-11-10 02:57:53 +08:00
if (this.get("shouldDisplayFilter") === false) { return; }
const $filter = this.$(".filter");
$filter.width(0);
2017-10-20 03:51:08 +08:00
const leftHeaderOffset = this.$().offset().left;
2017-11-10 02:57:53 +08:00
const leftFilterOffset = $filter.offset().left;
2017-10-20 03:51:08 +08:00
const offset = leftFilterOffset - leftHeaderOffset;
const width = this.$().outerWidth(false);
const availableSpace = width - offset;
2017-11-10 02:57:53 +08:00
const $choices = $filter.parent(".choices");
const parentRightPadding = parseInt($choices.css("padding-right") , 10);
$filter.width(availableSpace - parentRightPadding * 4);
2017-10-20 03:51:08 +08:00
},
@computed("computedContent.selectedComputedContents.[]")
names(selectedComputedContents) {
return Ember.makeArray(selectedComputedContents).map(sc => sc.name).join(",");
}
2017-10-20 03:51:08 +08:00
});