{"size": 2088, "ext": "js", "max_stars_repo_path": "src/js/selection.js", "max_stars_repo_name": "BrunoRB/flow-chart.js", "max_stars_repo_stars_event_min_datetime": "2015-01-21T17:38:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-15T03:00:07.000Z", "max_issues_repo_path": "src/js/selection.js", "max_issues_repo_name": "vicky002/Flowchart-Evaluator", "max_issues_repo_issues_event_min_datetime": "2015-01-19T23:38:50.000Z", "max_issues_repo_issues_event_max_datetime": "2015-01-19T23:57:13.000Z", "max_forks_repo_path": "src/js/selection.js", "max_forks_repo_name": "vicky002/Flowchart-Evaluator", "max_forks_repo_forks_event_min_datetime": "2015-02-07T11:36:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-02T09:25:06.000Z"}
{"max_stars_count": 75, "max_issues_count": 3, "max_forks_count": 20, "avg_line_length": 22.2127659574, "max_line_length": 69, "alphanum_fraction": 0.6891762452}
/**
 * Selection Submodule
 */
var flow = (function(flow, doc, jsPlumb) {
	'use strict';

	flow.Selection = {};

	var Selection = flow.Selection,
		_selectedElement = null;

	Selection.addSelectedShape = function(shape) {
		this.unselectElements();

		_selectedElement = {
			type: 'shape',
			id: shape.id
		};

		flow.UI.markShapeAsSelected(shape);
	};

	Selection.addSelectedConnection = function(sourceId, targetId) {
		this.unselectElements();

		_selectedElement = {
			type: 'connection',
			from: sourceId,
			to: targetId
		};
	};

	Selection.deleteSelectedItems = function() {
		if (_selectedElement) {
			if (_selectedElement.type === 'shape') {
				var shape = doc.getElementById(_selectedElement.id);
				flow.Util.trigger(flow.Const.SHAPE_EVENT.ALTERATED, shape);
				jsPlumb.detachAllConnections(shape);
				flow.Util.remove(shape);
			}
			else {
				var shapeSource = doc.getElementById(_selectedElement.from),
					conn = jsPlumb.getConnections({
						source: _selectedElement.from,
						target: _selectedElement.to
					})[0];

				flow.Util.trigger(flow.Const.SHAPE_EVENT.ALTERATED, shapeSource);

				jsPlumb.detach(conn);
			}

			_selectedElement = null;
		}
	};

	Selection.getSelectedItem = function() {
		return _selectedElement;
	};

	Selection.unselectShapes = function() {
		if (_selectedElement && _selectedElement.type === 'shape') {
			flow.UI.unmarkShapeAsSelected(
				doc.getElementById(_selectedElement.id)
			);
			_selectedElement = null;
		}
	};

	Selection.unselectConnections = function() {
		if (_selectedElement && _selectedElement.type === 'connection') {
			var conn = jsPlumb.getConnections({
				source: _selectedElement.from,
				target: _selectedElement.to
			})[0];

			conn.setPaintStyle(jsPlumb.Defaults.PaintStyle);
			_selectedElement = null;
		}
	};

	Selection.unselectElements = function() {
		this.unselectShapes();
		this.unselectConnections();
		_selectedElement = null;
		flow.UI.unmarkAllShapes();
	};

	Selection.cleanSelection = function() {
		_selectedElement = null;
	};

	return flow;
})(flow || {}, document, jsPlumb);