Source: Dialog.js

/*
 *  2016 Maciej Wiecierzewski
 */

Dialog.currentDialog = null;
Dialog.stage = null;
Dialog.actions = [];


/**
 * @constructor
 * @classdesc Manages displaying interface elements
 */
function Dialog()
{
    this.container = new createjs.Container();
}

/**
 * Adds interface action.
 * @param {string} actionName
 * @param {function} callback
 */
Dialog.addAction = function(actionName, callback)
{
    this.actions[actionName] = callback;
}

/*
 * Adds 'click' event listener
 * @param {type} object EaselJS object
 * @param {type} action
 * @returns {undefined}
 */
Dialog.onClick = function(object, action)
{
    object.addEventListener('click', function(event) { Dialog.actions[action](event.target.id); } );
}

/**
 * Changes the current dialog to itself therefore making itself visible and appearing on the screen
 */
Dialog.prototype.show = function()
{
    if(Dialog.currentDialog !== null)
    {
        Dialog.stage.removeChild(Dialog.currentDialog.container);
    }
    
    Dialog.stage.addChild(this.container);
    Dialog.currentDialog = this;
    this.resize();
}

/**
 * Resizes the dialog
 * @virtual
 */
Dialog.prototype.resize = function()
{
}