mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-14 18:52:05 +03:00
b5a8ac3a7d
jQuery instance isn't iterable, so we cant destructuring it. closes https://github.com/TryGhost/Ghost/issues/6171
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
import Ember from 'ember';
|
|
|
|
const {Component, computed} = Ember;
|
|
const {reads} = computed;
|
|
|
|
function K() {
|
|
return this;
|
|
}
|
|
|
|
export default Component.extend({
|
|
content: null,
|
|
prompt: null,
|
|
optionValuePath: 'id',
|
|
optionLabelPath: 'title',
|
|
selection: null,
|
|
action: K, // action to fire on change
|
|
|
|
// shadow the passed-in `selection` to avoid
|
|
// leaking changes to it via a 2-way binding
|
|
_selection: reads('selection'),
|
|
|
|
actions: {
|
|
change() {
|
|
// jscs:disable requireArrayDestructuring
|
|
let selectEl = this.$('select')[0];
|
|
// jscs:enable requireArrayDestructuring
|
|
let {selectedIndex} = selectEl;
|
|
|
|
// decrement index by 1 if we have a prompt
|
|
let hasPrompt = !!this.get('prompt');
|
|
let contentIndex = hasPrompt ? selectedIndex - 1 : selectedIndex;
|
|
|
|
let selection = this.get('content').objectAt(contentIndex);
|
|
|
|
// set the local, shadowed selection to avoid leaking
|
|
// changes to `selection` out via 2-way binding
|
|
this.set('_selection', selection);
|
|
|
|
this.sendAction('action', selection);
|
|
}
|
|
}
|
|
});
|