Source: EventArgs.js

// Licensed Materials - Property of IBM
//
// IBM Watson Analytics
//
// (C) Copyright IBM Corp. 2015
//
// US Government Users Restricted Rights - Use, duplication or
// disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

module.exports = ( function( decl )
{
"use strict";

/**
 * Create new EventArgs. Allows specifying a cancelable parameter as optional argument, which defaults to false.
 * @class module:barejs.EventArgs
 * @param {boolean} [_cancelable] Optional: provide a boolean to set whether this event is cancelable (default: prototype value, which is false for EventArgs).
 * @classdesc Base class for event arguments. Mimics html events cancelable behavior for events that have default behavior that can be canceled.
 * Subclasses can set the cancelable flag on their prototype, or use EventArgs.call( this, true ) to propagate the cancelable flag.
 */
function EventArgs( /*cancelable*/ )
{
    decl.defineProperties( this,
    {
        // Fixate the cancelable property for this object, either to argument 0 or the prototype value
        cancelable: { enumerable: true, value: ( typeof arguments[0] === "boolean" ? arguments[0] : this.cancelable === true ) },
        // Set defaultPrevented to false
        defaultPrevented: { configurable: true, enumerable: true, value: false }
    } );
}

return decl.declareClass( EventArgs,
/** @lends module:barejs.EventArgs# */
{
    /**
     * This value is true if the event got canceled (preventDefault was called, and cancelable is true).
     * @member {boolean}
     * @readonly
     */
    defaultPrevented: { enumerable: true, value: null },

    /**
     * The cancelable flag determines whether this event has behavior that can be canceled.
     * @member {boolean}
     * @readonly
     */
    cancelable: { enumerable: true, writable: true, value: false },

    /**
     * The preventDefault method will flag the EventArgs as defaultPrevented, if cancelable is true.
     * @function
     */
    preventDefault:
    {
        enumerable: true,
        value: function preventDefault()
        {
            if ( ( this.cancelable === true ) && !this.defaultPrevented )
                decl.defineProperty( this, "defaultPrevented", { enumerable: true, value: true } );
        }
    }
} );

// End of define
}( require( "./decl" ) ) );