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

Add feature that allows HTML content in trigger #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions assets/css/aria.accordion.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@
width: 0;
}

/**
* Ensure the entire button area is clickable
*/
.accordion__trigger:before {
content : "";
position: absolute;
top : -4px;
left : 0;
width : 100%;
height : 100%;
}

.accordion__trigger:hover:after,
.accordion__trigger:focus:after,
.accordion__trigger[aria-expanded="true"]:after {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/aria.accordion.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
var targetID;
var targetState;
var newButton;
var buttonText;
var headingNodes;
var i;

for ( i = 0; i < headings.length; i++ ) {
Expand All @@ -208,7 +208,7 @@

// setup new heading buttons
newButton = doc.createElement('button');
buttonText = heading.textContent;
headingNodes = heading.cloneNode(true); // clone the heading contents
// clear out the heading's content
heading.innerHTML = '';
// provide the heading with a class for styling
Expand Down Expand Up @@ -243,7 +243,9 @@

// Add the Button & previous heading text
heading.appendChild(newButton);
newButton.appendChild(doc.createTextNode(buttonText));
while( headingNodes.childNodes.length > 0 ) { // loop thru the heading content
newButton.appendChild(headingNodes.childNodes[0]); // adding the nodes to the button
}
}
}; // ARIAaccordion.createButton

Expand Down Expand Up @@ -272,6 +274,9 @@
var getID;
var i;
var thisTrigger = e.target;
if (e.target.nodeName != 'BUTTON') {
thisTrigger = e.target.parentElement;
}

// check to see if a trigger is disabled
if ( thisTrigger.getAttribute('aria-disabled') !== 'true' ) {
Expand Down