Skip to content

Commit 85524d1

Browse files
committed
2.2.0
1 parent e9958d0 commit 85524d1

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

dist/details-element-polyfill.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Details Element Polyfill 2.1.1
2+
Details Element Polyfill 2.2.0
33
Copyright © 2018 Javan Makhmali
44
*/
55
(function() {
@@ -62,32 +62,45 @@ Copyright © 2018 Javan Makhmali
6262
value: function value(name, _value) {
6363
var _this = this;
6464
var call = function call() {
65-
setAttribute.call(_this, name, _value);
65+
return setAttribute.call(_this, name, _value);
6666
};
67-
return this.tagName == "DETAILS" ? triggerToggleIfToggled(this, call) : call();
67+
if (name == "open" && this.tagName == "DETAILS") {
68+
var wasOpen = this.hasAttribute("open");
69+
var result = call();
70+
if (!wasOpen) {
71+
var summary = this.querySelector("summary");
72+
if (summary) summary.setAttribute("aria-expanded", true);
73+
triggerToggle(this);
74+
}
75+
return result;
76+
}
77+
return call();
6878
}
6979
},
7080
removeAttribute: {
7181
value: function value(name) {
7282
var _this2 = this;
7383
var call = function call() {
74-
removeAttribute.call(_this2, name);
84+
return removeAttribute.call(_this2, name);
7585
};
76-
return this.tagName == "DETAILS" ? triggerToggleIfToggled(this, call) : call();
86+
if (name == "open" && this.tagName == "DETAILS") {
87+
var wasOpen = this.hasAttribute("open");
88+
var result = call();
89+
if (wasOpen) {
90+
var summary = this.querySelector("summary");
91+
if (summary) summary.setAttribute("aria-expanded", false);
92+
triggerToggle(this);
93+
}
94+
return result;
95+
}
96+
return call();
7797
}
7898
}
7999
});
80100
}
81101
function polyfillToggle() {
82102
onTogglingTrigger(function(element) {
83-
var summary = element.querySelector("summary");
84-
if (element.hasAttribute("open")) {
85-
element.removeAttribute("open");
86-
element.setAttribute("aria-expanded", false);
87-
} else {
88-
element.setAttribute("open", "");
89-
element.setAttribute("aria-expanded", true);
90-
}
103+
element.hasAttribute("open") ? element.removeAttribute("open") : element.setAttribute("open", "");
91104
});
92105
}
93106
function polyfillToggleEvent() {
@@ -171,15 +184,6 @@ Copyright © 2018 Javan Makhmali
171184
event.initEvent("toggle", true, false);
172185
element.dispatchEvent(event);
173186
}
174-
function triggerToggleIfToggled(element, callback) {
175-
var wasOpen = element.getAttribute("open");
176-
var result = callback();
177-
var isOpen = element.getAttribute("open");
178-
if (wasOpen != isOpen) {
179-
triggerToggle(element);
180-
}
181-
return result;
182-
}
183187
function findElementsWithTagName(root, tagName) {
184188
return (root.tagName == tagName ? [ root ] : []).concat(typeof root.getElementsByTagName == "function" ? slice.call(root.getElementsByTagName(tagName)) : []);
185189
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "details-element-polyfill",
3-
"version": "2.1.1",
3+
"version": "2.2.0",
44
"description": "HTML <details> element polyfill",
55
"main": "dist/details-element-polyfill.js",
66
"files": [

0 commit comments

Comments
 (0)