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

Object.defineProperty not working with older Safari Versions #50

Open
moehlone opened this issue Apr 1, 2016 · 0 comments
Open

Object.defineProperty not working with older Safari Versions #50

moehlone opened this issue Apr 1, 2016 · 0 comments

Comments

@moehlone
Copy link

moehlone commented Apr 1, 2016

Hi,

I had a problem with Safari on iOS 6.1.3.

The if check

if (!("classList" in document.createElement("_")) || document.createElementNS && !("classList" in document.createElementNS("http://www.w3.org/2000/svg", "g")))

resolves correctly in true and the script comes later to

try { objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);

This is a problem in old Safari Versions, because it is not working on DOM Objects. So there is no error but toggle or add will not work with the additional parameters.

I found a working solution for myself by adding

if ("document" in self) {
var setPropOnDOM = true;

// Detect if we can define properties on DOM Objects
try {
    Object.defineProperty(document.createElement("_"), "classList", {
        "get": function() {}
    });
} catch (e) { //Old Safari versions will break at this point
    setPropOnDOM = false;
}

// Full polyfill for browsers with no classList support
// Including IE < Edge missing SVGElement.classList
if (setPropOnDOM && (!("classList" in document.createElement("_")) || document.createElementNS && !("classList" in document.createElementNS("http://www.w3.org/2000/svg", "g")))) {

Old Safaris will resolve in the catch block and then go on with partial support which is then working like expected. I will finish it next week and come back with a clean and fully response when my unit tests are green in all browsers (including old IE, Safari and so on).

moehlone pushed a commit to moehlone/classList.js that referenced this issue Apr 4, 2016
moehlone pushed a commit to moehlone/classList.js that referenced this issue Apr 4, 2016
moehlone pushed a commit to moehlone/classList.js that referenced this issue Apr 4, 2016
moehlone pushed a commit to moehlone/classList.js that referenced this issue Apr 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant