Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

hackish fixes to make it work with Font Awesome JS. Hardcoded preview… #4

Closed
wants to merge 2 commits into from

Conversation

petervanderwalt
Copy link

… with jquery.html because of time

Refer #3
The CSS fixes under dist/iconpicker-1.5.0.css works 100% (thanks to @Volmarg) from #2

I also used his eachIconEventListener(firstOrSearch) - you can't just merge it, but compare to the original to see what needs to change to support <svg> tags instead of hardcoded <i>

Then the Preview wasnt working, so i opted just in the name of time (got to go soon) to just remove it from my fork and hardcode a replacement, will come back and fix when I get time. I think its as simple as forgetting to update the button's html data-iconpicker-preview="i#IconPreview" to data-iconpicker-preview="svg#IconPreview" oops

@petervanderwalt
Copy link
Author

Yip fixed the preview, data-iconpicker-preview="#IconPreview" did the trick - sorry stupid one in the rush of things)

So merge CSS, compare JS, and make it work (;

@Volmarg
Copy link

Volmarg commented Apr 17, 2020

hax or not - i gonna check this out in free moment as i have small problems with picker now anyway, thanks for mentioning me so that i know that something jus happened

@petervanderwalt
Copy link
Author

hax or not - i gonna check this out in free moment as i have small problems with picker now anyway, thanks for mentioning me so that i know that something jus happened

@Volmarg you saved me day! Finding the root cause (i>svg) and your replacement selector function was saving my ass!

@Volmarg
Copy link

Volmarg commented Apr 18, 2020

So i only made tiny test and with this i can say that I can interract with the icons loaded via fontawesome/all.js

image

However I will need to check this deeper later as in my case due to webpack i had to replace the

$("#macroIconPreview").html("<i class='" + iconClassName + " fa-2x m-2'></i>");

to plain js, but will play a bit with this first as something still crashes for me, anyway Your fix fixes my bug with strange icons shown as [ ], [ ] , [ ] - squares so:

  • Your fix if my fix so gonna fix the bug in fix for my use case anyway - lol

It might be so that it crashes only for me due to some workarounds caused by webpack.

// define icons off

// add listeners each on
var wrapElem = document.querySelector('.ip-icons-content');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add small note why the observer:
// this is required due to case where we use the js based fontawesome as fontawesome changes <i> to <svg>

Copy link

@Volmarg Volmarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that You also added changes to other versions, i bet that the added code is pretty much same. I only use 1.5 so that's why I add comments here.

} else {
inputElm[i].innerHTML = iconClassName;
}
$("#macroIconPreview").html("<i class='" + iconClassName + " fa-2x m-2'></i>");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole code uses rather plain js, and since i cannot use jq in place where i use this plugin then i already wrote working vanilla:

                            let element = document.getElementById('macroIconPreview');
                            if( null !== element ){
                                element.innerHTML = "<i class='" + iconClassName + " fa-2x m-2'></i>";
                            }

// show all button click listener off

// close and remove all on
var removeIpElement = function(delay) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is actually bug. Generally picker works so like yeah it's fine but there was error in console log and i didn't liked it. The pioint is that Your observer (while needed for svg conversion) stacks click events so when You click the fontawesome icon the event here is being called alot of times and js tries to remove non existing element in parent and thus crashes:

            var removeIpElement = function(delay) {
                ipElement.classList.remove('animate');
                setTimeout(function() {
                    let isElementInDom = ( null !== ipElement.parentNode );
                    //prevent handling removal if element is already gof out of daoml
                    if( isElementInDom ){
                        docBody.removeChild(ipElement);
                    }

                }, delay);
            };

@furcan
Copy link
Owner

furcan commented Apr 19, 2020

#3

@furcan furcan closed this Apr 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants