migliori / universal-icon-picker

Vanilla JS Icon Picker for any Icon Library
https://universal-icon-picker.miglisoft.com
MIT License
78 stars 9 forks source link

Issue with opening picker after snippet redraw #10

Closed juniwalk closed 1 year ago

juniwalk commented 1 year ago

I am using your picker with Nette Framework (php) and Naja.js (js) which uses "snippets" as blocks of html to be updated after ajax request.

After update of the snippet with picker in it, it would not reopen, I had to add to add onBeforeOpen listener to remove uip-close class.

$('input.icon-picker').each(function() {
    let preview = $(this).parents('.input-group').find('.icon-preview i');
    let target = $(this).attr('id');

    let iconPicker = new UniversalIconPicker('#'+target, {
        iconLibraries: ['font-awesome.min.json'],

        onBeforeOpen: function() {
            $('#uip-modal-'+target).removeClass('uip-close');
        },

        onSelect: function(info) {
            $(preview).attr('class', info.iconClass).addClass('fa-fw');
            $('#'+target).val(info.iconClass);
        }
    });

    $(preview).attr('class', $(this).val()).addClass('fa-fw');
});

Edit: This code gets called on load and after snippet update so picker should be reinitialized.

migliori commented 1 year ago

The iconpicker allows you to set your onBeforeOpen conditions, so this is not a problem.

juniwalk commented 1 year ago

The fact that I have to do in onBeforeOpen what should be done in open method by the iconpicker is not a problem?

migliori commented 1 year ago

Indeed I don't know exactly the way you load your page, snippet and ajax data. Adding $('#uip-modal-'+target).removeClass('uip-close'); somewhere in the plugin CORE code might solve the issue, but I can't reproduce the case easily.

juniwalk commented 1 year ago

Well there is this code in open method that I think handles this:

                } else {
                    //Icon library open if dom element exist
                    this.universalDomEle.classList.remove('uip-close');
                    this.universalDomEle.classList.add('uip-open');
                }

Which means the issue must be there? My javascript knowledge is very limited, I might try to fix it however I don't know if I won't break something else.

migliori commented 1 year ago

Yes, that's the question. I don't want to break anything, so I'd need to be able to reproduce your issue.

If you can provide me a simple test file, without using any framework or external tool then I'll work on it.