2016-07-07 14:30:45 -07:00
|
|
|
define(['EventEmitter'], function (EventEmitter) {
|
|
|
|
function Selection() {
|
|
|
|
EventEmitter.call(this);
|
|
|
|
this.selectedValues = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
Selection.prototype = Object.create(EventEmitter.prototype);
|
|
|
|
|
|
|
|
Selection.prototype.select = function (value) {
|
|
|
|
this.selectedValues.push(value);
|
2016-08-19 19:07:53 -07:00
|
|
|
this.emit('change', this.selectedValues);
|
2016-07-07 14:30:45 -07:00
|
|
|
return this.deselect.bind(this, value);
|
|
|
|
};
|
|
|
|
|
|
|
|
Selection.prototype.deselect = function (value) {
|
|
|
|
this.selectedValues = this.selectedValues.filter(function (v) {
|
|
|
|
return v !== value;
|
|
|
|
});
|
2016-08-19 19:07:53 -07:00
|
|
|
this.emit('change', this.selectedValues);
|
2016-07-07 14:30:45 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
Selection.prototype.selected = function () {
|
|
|
|
return this.selectedValues;
|
|
|
|
};
|
|
|
|
|
|
|
|
Selection.prototype.clear = function () {
|
|
|
|
this.selectedValues = [];
|
2016-08-19 19:07:53 -07:00
|
|
|
this.emit('change', this.selectedValues);
|
2016-07-07 14:30:45 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
return Selection;
|
|
|
|
});
|