SVG not appearing in IE11

I have the following polyfill for IE11/Edge in place


/**
 * Generate an unique identifier
 * @return {String}
 */
function getUniqueID() {
  return 'clip-path-' + Math.random().toString(36).substring(7);
}

/**
 * Checks if css property clip-path supports 'polygon()' attribute
 * @return {Boolean} Return TRUE if browser has support
 */
var hasSupportToPolygon = (function () {

  var testEl    = document.createElement('div');
  var propValue = 'polygon(0 0, 0 0, 0 0, 0 0)';

  testEl.style.clipPath = propValue;

  return testEl.style.clipPath === propValue;

})();

/**
 * Use SVG polygon
 */
function SVGPolyfill(element, pathPoints, edge) {

  var units = 'px';
  var svgUnits = 'userSpaceOnUse';
  if(pathPoints.indexOf('%') !== -1){
    units = '%';
    svgUnits = 'objectBoundingBox';
  }
  pathPoints = pathPoints.replace(/px|em|%/g, '');

  // Remove units from path
  if(units !== 'px'){
    var finishedPathPoints = '';
    var arrayPathPoints = pathPoints.split(', ');
    for (var i = 0; i < arrayPathPoints.length; i++)
    {
      var item = arrayPathPoints[i];
      var arrayPathPoint = item.split(' ');
      var lN = Number(arrayPathPoint[0]), rN = Number(arrayPathPoint[1]);
      if(lN !== 0){
        lN = (lN/100);
      }
      if(rN !== 0){
        rN = (rN/100);
      }
      finishedPathPoints += lN+' '+rN;
      if(i < (arrayPathPoints.length - 1)){
        finishedPathPoints += ', ';
      }
    }
    pathPoints = finishedPathPoints;
  }



  var elClipPathId = element.getAttribute('data-clip-path-id');
  if(elClipPathId) {
    var actualClipPath = document.getElementById(elClipPathId);
    actualClipPath.setAttribute('clipPathUnits', svgUnits);
    var actualPolygon = document.querySelector('#' + elClipPathId + ' > polygon');
    actualPolygon.setAttribute('points', pathPoints);
  } else {
    var clipPathID = getUniqueID();

    var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
    svg.setAttribute('width', '0');
    svg.setAttribute('height', '0');
    svg.setAttribute('data-clip-path-id', clipPathID);
    svg.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', 'http://www.w3.org/1999/xlink');

    if(edge){
      if(element.getAttribute('class')){
        svg.setAttribute('class', element.getAttribute('class'));
      }
      element.setAttribute('class', '');
      element.style.width = "100%";
      element.style.height = "100%";
      svg.style.width = "100%";
      svg.style.height = "100%";

      var defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs');

      var clipPath = document.createElementNS('http://www.w3.org/2000/svg', 'clipPath');
      clipPath.setAttribute('id', clipPathID);
      clipPath.setAttribute('clipPathUnits', svgUnits);

      var polygon = document.createElementNS('http://www.w3.org/2000/svg', 'polygon');
      polygon.setAttribute('points', pathPoints);

      var foreignObject = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
      foreignObject.setAttribute('clip-path', 'url(#'+clipPathID+')');
      foreignObject.setAttribute('width', '100%');
      foreignObject.setAttribute('height', '100%');

      foreignObject.appendChild(element.cloneNode(true));
      svg.appendChild(foreignObject);

      clipPath.appendChild(polygon);
      defs.appendChild(clipPath);
      svg.appendChild(defs);

      element.parentNode.replaceChild(svg, element);
    }else{
      var clipPath = document.createElementNS('http://www.w3.org/2000/svg', 'clipPath');
      clipPath.setAttribute('id', clipPathID);

      clipPath.setAttribute('clipPathUnits', svgUnits);

      var polygon = document.createElementNS('http://www.w3.org/2000/svg', 'polygon');
      polygon.setAttribute('points', pathPoints);

      clipPath.appendChild(polygon);
      svg.appendChild(clipPath);
      document.body.appendChild(svg);
      element.setAttribute('data-clip-path-id', clipPathID);

      setTimeout(function () {
        element.style.clipPath = 'url(#' + clipPathID + ')';
      }, 0);
    }
  }
}

/**
 * Apply clip path
 */
function applyClipPath(element, pathPoints, _supportPolygon) {

  _supportPolygon = typeof _supportPolygon !== 'undefined' ? _supportPolygon : hasSupportToPolygon;

  // Chrome / Safari
  if(typeof(element.style.webkitClipPath) !== 'undefined'){

    element.style.webkitClipPath = 'polygon(' + pathPoints + ')';

    // Unprefixed support
  } else if(_supportPolygon){

    element.style.clipPath = 'polygon(' + pathPoints + ')';

    // SVG
  } else {
    SVGPolyfill(element, pathPoints, true);//get ie11 to run as well
    //Edge
    // if(window.navigator.userAgent.indexOf("Edge") > -1){

    //   SVGPolyfill(element, pathPoints, true);
    //   console.log("edge");
    //   //Other
    // }else{
    //   SVGPolyfill(element, pathPoints);
    //   console.log("ie11 gets this");
    // }
  }
}

/**
 * Main function
 */
function ClipPath(selector, pathPoints, supportPolygon) {

  if(!selector) {
    console.error('Missing selector');
    return false;
  }

  var nodeList = document.querySelectorAll(selector || '');

  Array.prototype.forEach.call(nodeList, function(element) {

    var elementPathPoints = element.getAttribute('data-clip') || pathPoints;

    if(elementPathPoints) {
      applyClipPath(element, elementPathPoints, supportPolygon);
    } else {
      console.error('Missing clip-path parameters. Please check ClipPath() arguments or data-clip attribute.', element);
    }

  });

}

ClipPath.applyClipPath = applyClipPath;

if(typeof jQuery !== 'undefined') {
  (function($, _ClipPath){
    $.fn.ClipPath = function(pathStr) {

      // pathStr can be an object due backward compatibility
      // but pathStr must be a string
      if(pathStr === Object(pathStr) && pathStr.path) {
        pathStr = pathStr.path;
      }

      return this.each(function() {
        _ClipPath.applyClipPath(this, $(this).attr('data-clip') || pathStr);
      });

    };
  })(jQuery, ClipPath);
}

exports.ClipPath = ClipPath;

Near the end of the file, there’s some commented out code. Note that.

The issue is that I have a treatment I made with clip path, knowing edge/ie11 would require work. So I managed to get this in chrome/ff, etc.

However, in edge/ie11, I was seeing the following (completely expected)

So I use a polyfill (code pasted above). I noticed that in edge/IE11, it wasn’t working the same, and that’s wehre the commenetd out code comes into play. If I used the actual polyfill how it was written, then IE11 does not work at all, so I’m modifying it, or at least that’s the goal of this thread. In edge, with the polyfill, I get the correct result

https://fnlst.com/jasG9X

…but in IE11, I get a completely blank screen. The SVGs are there, but it’s completely blank. I have no clue what’s going on and I’m about to rip all the hair I’ve accumulated during this quarantine, out of my head.

I’m just praying someone can figure out what’s going on. Not sure if this is an HTML/CSS bug, or javascript, so I’m just assuming JS is the answer here.

I want to avoid posting the page link, but I will if someone needs it.

Here is the regular HTML:

<section class="fsElement fsContent diamond-image" id="fsEl_2208" data-use-new="true" data-image-sizes="[{&quot;url&quot;:&quot;https://resources.finalsite.net/images/f_auto,q_auto,t_image_size_1/v1587058280/ncchristianorg/hrdjtzv3ew007qr5hbye/BuildingShot.jpg&quot;,&quot;width&quot;:256},{&quot;url&quot;:&quot;https://resources.finalsite.net/images/f_auto,q_auto,t_image_size_2/v1587058280/ncchristianorg/hrdjtzv3ew007qr5hbye/BuildingShot.jpg&quot;,&quot;width&quot;:512},{&quot;url&quot;:&quot;https://resources.finalsite.net/images/f_auto,q_auto,t_image_size_3/v1587058280/ncchristianorg/hrdjtzv3ew007qr5hbye/BuildingShot.jpg&quot;,&quot;width&quot;:800},{&quot;url&quot;:&quot;https://resources.finalsite.net/images/f_auto,q_auto,t_image_size_4/v1587058280/ncchristianorg/hrdjtzv3ew007qr5hbye/BuildingShot.jpg&quot;,&quot;width&quot;:1200},{&quot;url&quot;:&quot;https://resources.finalsite.net/images/f_auto,q_auto,t_image_size_5/v1587058280/ncchristianorg/hrdjtzv3ew007qr5hbye/BuildingShot.jpg&quot;,&quot;width&quot;:1600},{&quot;url&quot;:&quot;https://resources.finalsite.net/images/f_auto,q_auto/v1587058280/ncchristianorg/hrdjtzv3ew007qr5hbye/BuildingShot.jpg&quot;,&quot;width&quot;:2016}]" data-aspect-ratio="0.75" alt="" style="background-image: url(&quot;https://resources.finalsite.net/images/f_auto,q_auto,t_image_size_3/v1587058280/ncchristianorg/hrdjtzv3ew007qr5hbye/BuildingShot.jpg&quot;); clip-path: polygon(50% 0%, 100% 41.667%, 100% 57.667%, 50% 100%, 0px 57.667%, 0px 41.667%);">

				<header>
			<h2 class="fsElementTitle">Emily</h2>
			<div class="fsElementHeaderContent">
				<button>Open Testimonial</button>
			</div>
	</header>
	<div class="fsElementContent">
			<p>NCCS Faculty</p>


	</div>
	<footer>
		<div class="fsElementFooterContent">
			<div><br>
&nbsp;</div>

		</div>
	</footer>


	</section>

Here is an example of the code Edge gets with the polyfill

<svg xmlns="http://www.w3.org/2000/svg" class="fsElement fsContent diamond-image" style="width: 100%; height: 100%;" width="0" height="0" xmlns:xlink="http://www.w3.org/1999/xlink" data-clip-path-id="clip-path-2lfwt8"><foreignObject clip-path="url(#clip-path-2lfwt8)" width="100%" height="100%"><section id="fsEl_2211" style='width: 100%; height: 100%; background-image: url("https://resources.finalsite.net/images/f_auto,q_auto,t_image_size_4/v1586456325/ncchristianorg/fxfdn7ajgvxqubc2c6dn/2018-11NCCSweb110of150.jpg");' data-use-new="true" data-image-sizes='[{"url":"https://resources.finalsite.net/images/f_auto,q_auto,t_image_size_1/v1586456325/ncchristianorg/fxfdn7ajgvxqubc2c6dn/2018-11NCCSweb110of150.jpg","width":256},{"url":"https://resources.finalsite.net/images/f_auto,q_auto,t_image_size_2/v1586456325/ncchristianorg/fxfdn7ajgvxqubc2c6dn/2018-11NCCSweb110of150.jpg","width":512},{"url":"https://resources.finalsite.net/images/f_auto,q_auto,t_image_size_3/v1586456325/ncchristianorg/fxfdn7ajgvxqubc2c6dn/2018-11NCCSweb110of150.jpg","width":800},{"url":"https://resources.finalsite.net/images/f_auto,q_auto,t_image_size_4/v1586456325/ncchristianorg/fxfdn7ajgvxqubc2c6dn/2018-11NCCSweb110of150.jpg","width":1200},{"url":"https://resources.finalsite.net/images/f_auto,q_auto/v1586456325/ncchristianorg/fxfdn7ajgvxqubc2c6dn/2018-11NCCSweb110of150.jpg","width":1440}]' data-aspect-ratio="0.4930555555555556" alt="">

				<header>
			<h2 class="fsElementTitle">Synclair</h2>
			<div class="fsElementHeaderContent">
				<button>Open Testimonial</button>
			</div>
	</header>
	<div class="fsElementContent">
			<p>Student, class of ‘20</p>


	</div>
	<footer>
		<div class="fsElementFooterContent">
			<div><br>
&nbsp;</div>

		</div>
	</footer>


	</section></foreignObject><defs><clipPath id="clip-path-2lfwt8" clipPathUnits="objectBoundingBox"><polygon points="0.5,0 1,0.41667 1,0.57667 0.5,1 0,0.57667 0,0.41667" /></clipPath></defs></svg>

And here’s what IE11 generates:

<svg xmlns="http://www.w3.org/2000/svg" class="fsElement fsContent diamond-image" style="width: 100%; height: 100%;" width="0" height="0" data-clip-path-id="clip-path-6nfjxhl"><foreignObject clip-path="url(&quot;#clip-path-6nfjxhl&quot;)" width="100%" height="100%"><section id="fsEl_2208" style='width: 100%; height: 100%; background-image: url("https://resources.finalsite.net/images/f_auto,q_auto,t_image_size_2/v1587058280/ncchristianorg/hrdjtzv3ew007qr5hbye/BuildingShot.jpg");' data-use-new="true" data-image-sizes='[{"url":"https://resources.finalsite.net/images/f_auto,q_auto,t_image_size_1/v1587058280/ncchristianorg/hrdjtzv3ew007qr5hbye/BuildingShot.jpg","width":256},{"url":"https://resources.finalsite.net/images/f_auto,q_auto,t_image_size_2/v1587058280/ncchristianorg/hrdjtzv3ew007qr5hbye/BuildingShot.jpg","width":512},{"url":"https://resources.finalsite.net/images/f_auto,q_auto,t_image_size_3/v1587058280/ncchristianorg/hrdjtzv3ew007qr5hbye/BuildingShot.jpg","width":800},{"url":"https://resources.finalsite.net/images/f_auto,q_auto,t_image_size_4/v1587058280/ncchristianorg/hrdjtzv3ew007qr5hbye/BuildingShot.jpg","width":1200},{"url":"https://resources.finalsite.net/images/f_auto,q_auto,t_image_size_5/v1587058280/ncchristianorg/hrdjtzv3ew007qr5hbye/BuildingShot.jpg","width":1600},{"url":"https://resources.finalsite.net/images/f_auto,q_auto/v1587058280/ncchristianorg/hrdjtzv3ew007qr5hbye/BuildingShot.jpg","width":2016}]' data-aspect-ratio="0.75" alt="">

				<header>
			<h2 class="fsElementTitle">Emily</h2>
			<div class="fsElementHeaderContent">
				<button>Open Testimonial</button>
			</div>
	</header>
	<div class="fsElementContent">
			<p>NCCS Faculty</p>


	</div>
	<footer>
		<div class="fsElementFooterContent">
			<div><br>
&nbsp;</div>

		</div>
	</footer>


	</section></foreignObject><defs><clipPath id="clip-path-6nfjxhl" clipPathUnits="objectBoundingBox"><polygon points="0.5,0 1,0.41667 1,0.57667 0.5,1 0,0.57667 0,0.41667" /></clipPath></defs></svg>

Update - I know why they are disappearing in IE11; foreignobject isn’t supported in IE11. So I put the polyfill back to what it’s supposed to be (using the if/else).

But now I get no <svg> in IE11! It’s like the polyfill isn’t set up for IE11.

Just so frustrated I could cry :expressionless: . Custom CSS shapes are just the worst.

The worst.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.