API Docs for: 0.0.1
Show:

File: src/link/Mouse.js

/**
 * @author Vsevolod Strukchinsky @floatdrop
 */

/**
Mouse class handles clicks.

@example
	var mouse = new LINK.Mouse();
	mouse.on.click(shootCallback);
	mouse.on.move(lookCallback);

@class Mouse
@constructor
**/
LINK.Mouse = function (objectToListen) {

	var self = this;

	objectToListen = objectToListen || document;

	/**
	 * The current position of the mouse
	 *
	 * @property position
	 * @type Point
	 * @readOnly
	 */
	this.position = new PIXI.Point(0, 0);
	objectToListen.addEventListener('mousemove', this.onMouseMove.bind(this), false);

	this.callbacks = {};

	this.on = {};

	Object.keys(this.Events).forEach(function (eventName) {
		self.on[eventName] = function (callback) {
			self.callbacks[eventName] = callback;
		};

		var event = LINK.Mouse.Events[eventName];
		if (event === 'mousemove' || event === 'mousewheel') return;
		objectToListen.addEventListener(event, this.onMouse.bind(this), false);

	});

};

LINK.Mouse.constructor = LINK.Mouse;
LINK.Mouse.prototype = Object.create(Object.prototype);

LINK.Mouse.prototype.onMouse = function (e) {
	this.updateCoords(e);
	var button = e.button || 0;
	if (this.callbacks[button]) {
		this.callbacks[button](button);
	}

	return true;
};

LINK.Mouse.prototype.onMouseMove = function (e) {
	this.updateCoords(e);
	return true;
};

LINK.Mouse.prototype.updateCoords = function (e) {
	this.position.x = e.pageX;
	this.position.y = e.pageY;
};

LINK.Mouse.Events = {
	wheel: 'mousewheel',
	move: 'mousemove',
	down: 'mousedown',
	up: 'mouseup',
	click: 'click',
	dbclick: 'dblclick',
	rclick: 'contextmenu',
	contextmenu: 'contextmenu'
};