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

47 lines
1.6 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({
attributeBindings: [
"label:title",
"label:aria-label",
"names:data-name",
"values:data-value"
],
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
ariaLabel: Ember.computed.or("computedContent.ariaLabel", "title", "names"),
title: Ember.computed.or("computedContent.title", "names"),
2017-10-20 03:51:08 +08:00
@on("didRender")
_positionFilter() {
if (!this.get("shouldDisplayFilter")) return;
2017-11-10 02:57:53 +08:00
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(selection) {
return Ember.makeArray(selection).map(s => s.name).join(",");
},
@computed("computedContent.selectedComputedContents.[]")
values(selection) {
return Ember.makeArray(selection).map(s => s.value).join(",");
}
2017-10-20 03:51:08 +08:00
});