Home Reference Source

vgui/obj/10-event.js

"use strict";

Object.defineProperty(exports, "__esModule", {
	value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

/**
 * Represents an event that bubbles up
 */
var Event = exports.Event = function () {
	/**
  * Creates a default Event
  */
	function Event() {
		_classCallCheck(this, Event);

		this._target = global.document;
		this._cancelable = false;
		this._defaultPrevented = false;
		this._propagating = true;
	}

	/**
  * The type of the event
  */


	_createClass(Event, [{
		key: "_cancel",


		/**
   * @access private
   * @protected
   * Should be overridden for cancelation effects
   */
		value: function _cancel() {}
		//Virtual


		/**
   * Stops the event from bubbling up.
   */

	}, {
		key: "stopPropagation",
		value: function stopPropagation() {
			this._propagating = false;
		}

		/**
   * Prevents the default action from happening.
   * This does not stop propagation.
   */

	}, {
		key: "preventDefault",
		value: function preventDefault() {
			if (!this.cancelable) return;
			if (this._defaultPrevented) return;
			this._cancel();
		}
	}, {
		key: "type",
		get: function get() {
			return "Event";
		}

		/**
   * The element where the Event originated
   */

	}, {
		key: "target",
		get: function get() {
			return this._target;
		}

		/**
   * Wether this event should bubble up the DOM tree
   */

	}, {
		key: "bubbles",
		get: function get() {
			return this._propagating;
		}

		/**
   * Wether preventDefault can be called to stop the default action
   */

	}, {
		key: "cancelable",
		get: function get() {
			return this._cancelable;
		}
	}]);

	return Event;
}();