File size: 1,666 Bytes
af6912c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var highlight = require('../interactive/highlight');
var unhighlight = require('../interactive/unhighlight');

function Selectables(paper, selectTypes, tuneNumber) {
	this.elements = [];
	this.paper = paper;
	this.tuneNumber = tuneNumber;
	this.selectTypes = selectTypes;
}

Selectables.prototype.getElements = function () {
	return this.elements;
};

Selectables.prototype.add = function (absEl, svgEl, isNoteOrTabNumber, staffPos) {
	if (!this.canSelect(absEl))
		return;
	var params;
	if (this.selectTypes === undefined)
		params = { selectable: false, "data-index": this.elements.length }; // This is the old behavior.
	else
		params = { selectable: true, tabindex: 0, "data-index": this.elements.length };
	this.paper.setAttributeOnElement(svgEl, params);
	var sel = { absEl: absEl, svgEl: svgEl, isDraggable: isNoteOrTabNumber };
	if (staffPos !== undefined)
		sel.staffPos = staffPos;
	this.elements.push(sel);

};

Selectables.prototype.canSelect = function (absEl) {
	if (this.selectTypes === false)
		return false;
	if (!absEl || !absEl.abcelem)
		return false;
	if (this.selectTypes === true)
		return true;
	if (this.selectTypes === undefined) {
		// by default, only notes and tab numbers can be clicked.
		if (absEl.abcelem.el_type === 'note' || absEl.abcelem.el_type === 'tabNumber') {
			return true;
		}
		return false;
	}
	return this.selectTypes.indexOf(absEl.abcelem.el_type) >= 0;
};

Selectables.prototype.wrapSvgEl = function (abcelem, el) {
	var absEl = {
		tuneNumber: this.tuneNumber,
		abcelem: abcelem,
		elemset: [el],
		highlight: highlight,
		unhighlight: unhighlight
	};
	this.add(absEl, el, false);
};

module.exports = Selectables;