Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render nav icons in IE in white like the other supported browsers #7731

Closed
wants to merge 4 commits into from

Conversation

ppisljar
Copy link
Member

@ppisljar ppisljar commented Jul 13, 2016

fixes #7528

internet explorer doesnt support css3 filter property (which is used to invert images)
i created a directive which uses SVG filters to invert the image in case css3 filter property is not supported.

opts.svgHeight = $elem.height();
opts.svgSource = $elem.attr('src');

opts.svgContent = `<svg xmlns="http://www.w3.org/2000/svg" class="${$elem[0].className}" viewBox="0 0 ${opts.svgWidth} ${opts.svgHeight}" width="${opts.svgWidth}" height="${opts.svgHeight}">`
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is fairly large, how about pulling it out into a template file?

@Bargs
Copy link
Contributor

Bargs commented Jul 26, 2016

Rather than applying the invert filter in two different places (.app-icon css rule and this directive), how about we call this directive filter-invert, give it a % parameter, and have it take care of doing the invert in all browsers? That'll make things easier for anyone who wants to apply an invert in the future.

$(opts.rootElm).addClass(opts.rootFlag);
}

if (!isFilterSupported()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There should also be a check for whether the element is actually an SVG or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

it works with all kind of images

Copy link
Contributor

Choose a reason for hiding this comment

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

Then we should do a check to confirm it's being applied to an img tag

@ppisljar
Copy link
Member Author

makes sense

> svg {
height: 18px;
margin-top: 10px;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The directive should work without needing additional styles applied in an external stylesheet.

@Bargs
Copy link
Contributor

Bargs commented Jul 26, 2016

If this workaround came from a blog or library somewhere, I'd recommend linking to the source either in the code or in your commit message so other devs can read the details in the future if need be.


if (!isFilterSupported()) {
$elem.css('visibility', 'hidden');
$elem.on('load', () => { invert($elem); });
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this really need to wait for onload?

Copy link
Member Author

Choose a reason for hiding this comment

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

i need image width& height

@Bargs Bargs assigned ppisljar and unassigned Bargs Jul 26, 2016

function invert($elem) {
$scope.opts = {
idHash: (Math.random().toString(36) + '00000000000000000').slice(2, 7),
Copy link
Member Author

Choose a reason for hiding this comment

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

do we have a method to generate random string ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not that I know of, but does this really need to be random? As far as I can tell, IDs defined inside the SVGs defs element are scoped to the individual SVG, so this can probably just be hard coded?

@ppisljar ppisljar assigned Bargs and unassigned ppisljar Jul 28, 2016
svgWidth: $elem.width(),
svgHeight: $elem.height(),
svgSource: $elem.attr('src'),
className: $elem[0].className
Copy link
Contributor

Choose a reason for hiding this comment

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

$elem.attr('class') doesn't work?

@Bargs
Copy link
Contributor

Bargs commented Jul 28, 2016

Looks like this branch needs to be rebased on master as well

@ppisljar
Copy link
Member Author

i've tried to make it work with different values but it gives different result than css filter property. i don't really understand how css filter property works ... what should invert(50%) do ?

invert(100%) would do 255-c for each color channel ....

@epixa
Copy link
Contributor

epixa commented Aug 20, 2016

This needs to be rebased or have master merged.

@Bargs
Copy link
Contributor

Bargs commented Aug 23, 2016

@ppisljar it seems like the unsupported browser test isn't done yet, is that right? Just making sure this isn't blocked on me at the moment.

@Bargs
Copy link
Contributor

Bargs commented Aug 26, 2016

Please re-assign me when this is ready for another review

@Bargs Bargs removed their assignment Aug 26, 2016
for browsers that dont support css3 filter property image is inverted with SVG filters
@Bargs
Copy link
Contributor

Bargs commented Sep 8, 2016

Sorry for the delay on getting back to this. LGTM! 🎉 🎉 🎉 🎉 🎉

@Bargs Bargs removed their assignment Sep 8, 2016
@ppisljar ppisljar assigned cjcenizal and thomasneirynck and unassigned cjcenizal Sep 9, 2016
@epixa epixa changed the title fix #7528 - IE shows BLACK nav icons instead of white Render nav icons in IE in white like the other supported browsers Sep 9, 2016
@thomasneirynck
Copy link
Contributor

LGTM,

Perhaps I'm issing something crucial, but I would consider one thing though. This is a LOT of code for a minor cosmetic annoyance. I know it's nice to isolate styling in CSS, but we're adding a whole new compile step for something IMHO is quite minor.

Why not (?)

  • consider just making a white version of the svg icon offline (add fill=white to the svg-icons) (this would leave 3rd party plugin-icons un-inverted. But are they OK to begin with that we are inverting their icon color on-the-fly?)
  • consider rendering the SVG icon raw. Then we only need to change the existing 'global_nav_link.html' file along the lines of.
      //remove this junky IE-incompatile html
      <!--<img-->
      <!--ng-if="icon"-->
      <!--class="global-nav-link__icon-image"-->
      <!--kbn-src="{{ '/' + icon }}"-->
      <!--&gt;-->


      //replace it with this raw SVG
      <div class="global-nav-link__icon-image">
        <svg width="20" height="20" viewBox="0 0 520 520">
          <defs>
            <filter id="matrix-invert">
              <feColorMatrix in="SourceGraphic" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0"/>
            </filter>
          </defs>

             <!--do need to change the rewrite the kbn-src conversion to a kbn-href conversion-->
          <image x="0" y="0" width="520" height="520" preserveAspectRatio="true" filter="url(#matrix-invert)" xlink:href="{{ '/bzg/' + icon }}"/>
        </svg>
      </div>

Both approaches would just be a spot change, iso. creating a whole new programmatic component just to redress this single coloring issue.

But again, maybe I'm missing something obvious.

@cjcenizal
Copy link
Contributor

I think @thomasneirynck is 100% correct here... the problem is the assets are black, but we want them rendered white. So why not just make the assets white? :)

@ppisljar
Copy link
Member Author

i couldn't agree more @thomasneirynck ... if everyone is ok with it i am gonna throw this away and create a new PR where i'll just change the assets to white. It doesnt seem that we use them black at all. i was wondering if dark theme has any effect on how this is rendered, but it doesnt.

@Bargs what do you think ?

@Bargs
Copy link
Contributor

Bargs commented Sep 12, 2016

Sounds fine, we don't use the filter property for this purpose anywhere else anyway.

@ppisljar
Copy link
Member Author

closing in favour of #8221

@ppisljar ppisljar closed this Sep 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IE shows BLACK nav icons instead of white
5 participants