cms.js icon indicating copy to clipboard operation
cms.js copied to clipboard

IE11 support / Object.assign()

Open raygit83 opened this issue 6 years ago • 1 comments

Any chance to see an IE11 patch which apparently doesn't support Object.assign() ?

Thanks.

raygit83 avatar May 08 '19 15:05 raygit83

Here are the changes required to facilitate IE11 support:

  1. Add a polyfill for Object.assign(), e.g. right before this.init() on the bottom of CMS.js:

"function"!=typeof Object.assign&&(Object.assign=function(n,t){"use strict";if(null==n)throw new TypeError("Cannot convert undefined or null to object");for(var r=Object(n),e=1;e<arguments.length;e++){var o=arguments[e];if(null!=o)for(var c in o)Object.prototype.hasOwnProperty.call(o,c)&&(r[c]=o[c])}return r});

The ES5 polyfills pulled in via the example pages' html do not include a Object.assign() implementation btw.

  1. Use a different means to trigger a hashchange event in this.init():

Replace

window.dispatchEvent(new HashChangeEvent('hashchange'));

by the following snippet

try {
  window.dispatchEvent(new HashChangeEvent('hashchange'));
}
catch(e) {
  window.location.hash = window.location.hash;
}

In IE new HashChangeEvent results in "Undefined property: HashChangeEvent." and window.location.hash = window.location.hash; won't trigger a hashchange event in e.g. Chrome, so keeping the old code in a try block seems to be a good idea.

raygit83 avatar May 09 '19 09:05 raygit83