silegis-mg/editor-articulacao

View on GitHub
src/eventos/EventoInterno.js

Summary

Maintainability
A
0 mins
Test Coverage
/* Copyright 2017 Assembleia Legislativa de Minas Gerais
 * 
 * This file is part of Editor-Articulacao.
 *
 * Editor-Articulacao is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, version 3.
 *
 * Editor-Articulacao is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Editor-Articulacao.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Representa um evento interno, a ser disparado pelo EditorArticulacaoController.dispatchEvent.
 * Como o IE 11 possui problemas para herdar classes de CustomEvent, foi criada esta classe
 * intermediária para gerar o CustomEvent.
 */
class EventoInterno {
    constructor(nome, dados) {
        this.nome = nome;
        this.dados = dados;
    }

    getCustomEvent() {
        return new CustomEvent(this.nome, this.dados);
    }
}

// Polyfill de https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill
(function () {
    if (typeof window.CustomEvent === "function") return false;

    function CustomEvent(event, params) {
        params = params || { bubbles: false, cancelable: false, detail: undefined };
        var evt = document.createEvent('CustomEvent');
        evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
        return evt;
    }

    CustomEvent.prototype = window.Event.prototype;

    window.CustomEvent = CustomEvent;
})();

export default EventoInterno;