The page takes to mount a JS that assembles a class = 'marquee'

0

Good morning dear friends,

I have a question here in my code that is taking my sleep, if anyone can help.

Stopping at the next ...

On the screen of the system you need to be passing a message (s) (marquee type HTML) as a link for when the user clicks it to go to the page that is in the link.

These messages are registered by a specific user so I get these messages via query and transform into links (via PHP) and use a javascript to pass the messages on the screen and when there is more than one it passes one at a time. p>

The code is running and does the want, however it takes a while to mount the link (run the javascript), it runs the first time the message goes out like this ( Globe Test ) after a while, it assembles the right link that would be like the (Test Globe)

If someone can help, I appreciate it.

I'm using the Yii2 Framework. BD SQL SErver 2012.

I have the following code.

the php that brings up the DB search already separating the messages (which comes by a register) separating by, and ''. And it transforms the message into links to access the messages directly from that link by turning the page.

public static function getNoticias() {
    $models = self::find()
            ->select('ds_alerta, nm_link, nm_imagem')
            ->where('st_ativo = 1')
            ->asArray()
            ->all();

    $rec = [];
    foreach ($models as $model) {
        $imagem = '';
        $conteudo = '';

        if (empty($model['nm_link'])) {
            $conteudo = $model['ds_alerta'];
        } else {
            $conteudo = '<a href="' . $model['nm_link'] . '">' . $model['ds_alerta'] . '</a>';
        }

        if (!empty($model['nm_imagem'])) {
            $imagem = '<img src="' . $model['nm_imagem'] . '">';
        }

        $rec[] = $imagem . $conteudo;
    }

    return "'" . implode("','", $rec) . "'";
}

The Js code to run the messages one at a time. (it runs each message according to the angle it is in the php search.)

var alertMessages;

$ (function () {

$('.link-menu').click(function () {
    $(this).find("span").toggleClass("glyphicon-chevron-down").toggleClass("glyphicon-chevron-right");
});

Util.urlCaminho = $('#pathCaminho').val();

$(function () {
    $(".menu-lateral-body").mCustomScrollbar({
        axis: "y",
        theme: "minimal-dark"
    });
});

$(document).ready(function () {

    $('body').on('click', 'a.manual-download', function (event) {
        event.preventDefault();

        Util.ModalAlertExclusaoJson({
            mensagem: "Clique aqui para obter o manual de utilização?",
            url: $(this).attr('href')
        });
    });

    var indice = 0;
    var tamanho = alertaMensagens.length;

    $(".marquee-text").text(alertaMensagens[indice]);

    var marquee = $('div.marquee');
    marquee.each(function () {
        var mar = $(this), indent = mar.width();
        mar.marquee = function () {
            indent--;
            mar.css('text-indent', indent);
            if (indent < -1 * mar.children('div.marquee-text').width()) {
                if ((indice + 1) > tamanho) {
                    indice = 0;
                } else {
                    indice++;
                }
                indent = mar.width();

                $(".marquee-text").html(alertaMensagens[indice]);
            }
        };
        mar.data('interval', setInterval(mar.marquee, 10 / 6000000));
    });
});

})

and my div marquee gets

alertMessages = []; to display the messages on the screen.

    
asked by anonymous 26.04.2018 / 15:58

1 answer

0

If you have too many messages it will take a while, so in SqlServer there is OFFSET FETCH or row_number() , to limit it, imagine if the sites did not have paging, it would take hours to download the page to view / / p>

I do not think Yii or limit() generate the query for both Sql Server and Mysql, then your code should look like this:

$models = self::find()
        ->select('ds_alerta, nm_link, nm_imagem')
        ->where('st_ativo = 1')
        ->limit(10)
        ->asArray()
        ->all();

% wont% will limit it to 10 results, this is just an example , you can change it by 10 as many times as necessary, as long as it is not too large.

You can also choose to randomly display so that different items will always be displayed, as is demonstrated in this SOen response and just adapt to the use of ->limit(10) as shown in this response :

$models = self::find()
        ->select('ds_alerta, nm_link, nm_imagem')
        ->where('st_ativo = 1')
        ->orderBy(new Expression('NEWID()'))
        ->limit(10)
        ->asArray()
        ->all();
    
26.04.2018 / 16:10