Java script does not recognize object

Asked

Viewed 93 times

2

I’m having a problem where my Javascript code when I started IE11 my object core is not recognized, however in any other browser works normally, which might be causing this loading error.

Core code

var core = core || {}

core.home = (function ($) {

    function mover_link_dropdown(elements) {
        $('#dropdown-links-ul').parent().removeClass('none');

        $.each(elements, function (i, v) {
            $('#dropdown-links-ul').append($(v).prop('outerHTML'));
        })
    }

    function getLinks(url) {
        $.ajax({
            url: url,
            success: function (resp) {
                $.each(resp, function (ind, val) {

                    $('#novo-link').parent().after(`<li class="custom-li">
                                    <a href="${val.Url}" target="_blank" class="custom-link m-l-5">
                                        <span>${val.Titulo}</span>
                                    </a>
                                    <span class="label custom-icon-del" id=${val.Id}><i data-toggle="modal" data-target="#modal-confirmar-excluir-link" class="fa fa-times fa-1x"></i></span>
                                    </li>`);
                })
            }
        })
    }

    function move_elements_on_resize() {
        $(window).resize(function () {
            var width_window = window.innerWidth;
            var elements = $('.navbar-custom-menu>.navbar-nav > li > a.custom-link:not(#novo-link)');

            if (width_window >= 992 && width_window < 1200) {
                if (elements.length > 5) {
                    var move = elements.parent().slice(0, 5);
                    console.log(move);
                    mover_link_dropdown(move);
                    move.remove();
                }
            }
            else if (width_window >= 768 && width_window < 991) {
                if (elements.length > 4) {
                    var move = elements.parent().slice(0, 4);
                    mover_link_dropdown(move);
                    move.remove();
                }
            }
            else if (width_window < 768) {
                if (elements.length > 3) {
                    var move = elements.parent().slice(0, 3);
                    mover_link_dropdown(move);
                    move.remove();
                }
            }
        })
    }

    function getEvents() {
        $eventos = $('#agenda-home > .box-body');
        $eventos.html("");

        $.get("/Home/EventosJson", null, function (data) {
            $.each(data, function (i, v) {
                var bg_color = moment(v.DataHora).date() < moment().date() && moment(v.DataHora).month() < moment().month() ? 'bg-red' : 'bg-blue';

                if (bg_color == 'bg-red') {
                    $eventos.prepend(`<div class="event-style ${bg_color}">${moment(v.DataHora).format('HH:mm')} ${v.Titulo}</div>`);
                } else {
                    $eventos.append(`<div class="event-style ${bg_color}">${moment(v.DataHora).format('HH:mm')} ${v.Titulo}</div>`);
                }
            })
        })
    }

    function getPipe(idPipe) {
        var agencia = sessionStorage.getItem('agencia');
        var conta = sessionStorage.getItem('conta');
        $.get('/Home/ObterPipe', { agencia, conta, idPipe }, function (data) {
            core.modal.modalAtualizarpipe(data);
        });
    }

    function getTed(id) {
        $.get('/Home/ObterTed', { id }, function (resp) {
            core.modal.modalAtualizarTED(resp);
        });
    }

    function init() {

        var pathUrlArr = window.location.pathname.split('/').slice(1);
        var currPage = pathUrlArr[pathUrlArr.length - 1];
        var headerPage = currPage ? currPage.charAt(0).toUpperCase() + currPage.slice(1) : "Home";

        var ch = $('section.content-header');
        var arr_li = $('section.content-header > ol');
        ch.prepend(`<h1>${headerPage}</h1>`); // Adiciona o nome do cabeçalho da pagina

        headerPage != "Home" && headerPage != "IndexRT" ? arr_li.append(`<li class="active">${headerPage}</li>`) : null;
        moment.locale('pt-br'); //pt-br
        $('#box-home').hide(0);
        $('[data-toggle="tooltip"]').tooltip();

    }

    function mostrarDadosPesquisaHome(data) {
        $cadu = $('#cadu').empty();
        $niver = $('#niver').empty();
        $nome = $('#nome-cli').empty();
        $api = $('#api').empty();
        $venc = $('#vencimento').empty();
        $pipe = $('#pipe').empty();
        $ted = $('#ted').empty();

        //$niver.text(moment(data.Aniversatio).format('DD/MM'));
        //$nome.text(data.NomeCliente);
        //$cadu.text(`${moment(data.Cadu.Data).format('DD/MM/YYYY')} - ${data.Cadu.Status}`);
        data.API.Data != null ? $api.html(`<small>${data.API.Data} <br>${data.API.Status}</small>`) : $api.text("");

        $.each(data.Vencimentos, (i, v) => {
            var valor = v.SALDO_ATUAL.toLocaleString('pr-BR', { currency: 'BRL', style: 'currency' });
            $venc.append(`<li>
                            <small> ${v.Nome_produto_sistema_origem} - ${valor} </small> &nbsp;
                            <a href="#" data-search=""><i class="fa fa-pencil" style="color:red"></i></a><br /></li>`);

        });

        $.each(data.Pipelines, (i, v) => {
            var valor = v.Valor.toLocaleString('pr-BR', { currency: 'BRL', style: 'currency' });
            $pipe.append(`<li>
                            <small> ${v.Origem} - ${valor} | Previsto para ${moment(v.DataPrevista).format('DD/MM/YYYY')}</small> &nbsp;
                            <a href="#" id="${v.Id}" onclick="core.home.getPipe(this.id)"><i class="fa fa-pencil"  style="color:red"></i></a><br /></li>`);
        });

        $.each(data.TEDs, (i, v) => {
            var valor = v.Valor.toLocaleString('pr-BR', { currency: 'BRL', style: 'currency' });
            $ted.append(`<li>
                            <small>${valor} - ${moment(v.DataPrevista).format('DD/MM/YYYY')}</small> &nbsp;
                            <a href="#" id="${v.Id}" onclick="core.home.getTed(this.id)"><i class="fa fa-pencil" style="color:red"></i></a><br /></li>`);
        });
    }

    function search_by_agencia_conta_cpfcpnj(requestUrl, agencia, conta, cpfCnpj, nome) {
        $.ajax({
            url: requestUrl,
            type: 'GET',
            data: { agencia, conta, cpfCnpj, nome },
            success: function (data) {

                if (data.Agencia == null && data.Conta == null && data.Id == 0) {
                    core.notify.showNotify("Nehum registro encontrado.", 'info', 'top-center')
                    return false;
                }

                $('#box-home').fadeIn('slow');

                mostrarDadosPesquisaHome(data);
                //core.modal.modalCockpit(data.Agencia, data.Conta, data.CPFCNPJ);
                //core.modal.modalSinv(data.Agencia, data.Conta, data.CPFCNPJ);

                sessionStorage.setItem('cliente', JSON.stringify(data));
                sessionStorage.setItem('agencia', data.Agencia);
                sessionStorage.setItem('conta', data.Conta);
                sessionStorage.setItem('nome-cliente', data.NomeCliente);
            },
            error: function (e, b, c, d) {
                console.error(e);
                console.error(b);
                console.error(c);
                console.error(d);
            }
        });
    }

    function newLink(url) {
        var width_window = window.innerWidth;

        if (width_window >= 992 && width_window < 1200) {
            cria_links(url, 5);
        }
        else if (width_window >= 768 && width_window < 991) {
            cria_links(url, 4);
        }
        else if (width_window < 768) {
            cria_links(url, 3);
        }
        else {
            cria_links(url);
        }
    }

    function removeLink() {
        $(document).on('click', '.custom-icon-del', function () {
            var elemento = $(this);

            $('#confirmar').click(() => {
                $('#modal-confirmar-excluir-link').modal('hide')

                elemento.closest('li').remove();

                //TODO: Remover do banco

                if ($('#dropdown-links-ul li').length == 0) {
                    $('#dropdown-links-ul').parent().addClass('none');
                }


            })
        })
    }

    return {
        init,
        newLink,
        removeLink,
        search_by_agencia_conta_cpfcpnj,
        getEvents,
        getPipe,
        getLinks
    }

})($)

I have other modules also in the same format in other files. When I run the application in Chrome or opera, the core object is normally loaded already in ie11 I get the following error SCRIPT5009: 'core' não está definido. How do i load this object?

Thank you.

  • I was looking here and I saw that it is giving error in the code where it has ES6, I believe that it does not recognize this code yet and so it does not load the full code and the error in the page.

  • Recognize it recognizes in var core = core || {}. The problem, as @Robsonsilva mentioned, is that IE11 does not support template literals.

  • @Sam there is some way to fix this without me having to change the whole code?

  • Instead of using template, use string and normal concatenation.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.