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

54 lines
1.7 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",
2018-06-15 23:03:24 +08:00
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
forceEscape: Ember.computed.alias("options.forceEscape"),
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.shouldDisplayFilter) return;
2017-11-10 02:57:53 +08:00
const $filter = $(this.element.querySelector(".filter"));
2017-11-10 02:57:53 +08:00
$filter.width(0);
2017-10-20 03:51:08 +08:00
const leftHeaderOffset = $(this.element).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.element).outerWidth(false);
2017-10-20 03:51:08 +08:00
const availableSpace = width - offset;
2017-11-10 02:57:53 +08:00
const $choices = $filter.parent(".choices");
2018-06-15 23:03:24 +08:00
const parentRightPadding = parseInt($choices.css("padding-right"), 10);
2017-11-10 02:57:53 +08:00
$filter.width(availableSpace - parentRightPadding * 4);
2017-10-20 03:51:08 +08:00
},
@computed("computedContent.selection.[]")
names(selection) {
2018-06-15 23:03:24 +08:00
return Ember.makeArray(selection)
.map(s => s.name)
.join(",");
},
@computed("computedContent.selection.[]")
values(selection) {
2018-06-15 23:03:24 +08:00
return Ember.makeArray(selection)
.map(s => s.value)
.join(",");
}
2017-10-20 03:51:08 +08:00
});