0

I am using the mmenu plugin found here http://mmenu.frebsite.nl/. It works with a pre-defined list.

I am using for a contact list where users change state regularly. I have tried the below function to update the list dynamically but the mmenu plugin seems to be no longer working with the newly added items.

is there a way to make it update?

function updateChatContacts() {
    $(".contacts-list-chat").empty();

    for (var key in contacts) {
        var state;
        if(contacts[key].state === 'DND')
            state = 'busy';
        else if(contacts[key].state === 'page-me')
            state = 'away';
        else
            state = contacts[key].state;

        var elem = '<li class="img no-arrow">'+
                        '<span>'+
                            '<i class="'+state+'"></i>'+
                            '<img src="assets/img/avatars/avatar2.png" alt="avatar 2"/>'+
                            '<div class="chat-name">'+key+'</div>'+
                            '<div>'+state.charAt(0).toUpperCase() + state.slice(1)+'</div>'+
                        '</span>'+
                        '<ul class="chat-messages">'+
                            '<div class="chat-input">'+
                                '<input type="text" class="form-control send-message" placeholder="Type your message" />'+
                            '</div>'+
                        '</ul>'+
                    '</li>';

        //if (markers[key].selected === true) {
        $(".contacts-list-chat").append(elem);

    }
}
Vince Lowe
  • 3,521
  • 7
  • 36
  • 63
  • Have you tried running the `mmenu` line again after adding the elements? So after adding, execute the `$(".contacts-list-chat").mmenu();` code – sbonkosky Apr 30 '14 at 17:05
  • @sbonkosky yes, i have had no luck with that. – Vince Lowe May 01 '14 at 08:17
  • The plugin prevents creating a menu twice by checking for "mmenu" in the data of the element. Not sure if it'll work, but you could remove that before executing the plugin: $(".contacts-list-chat").data("mmenu", false).mmenu(); – Fred May 01 '14 at 18:49

0 Answers0