Comments (3)
When I call just
update
, it doesn't init recently added folds
When you say "init recently added folds", what are you referring to exactly?
from accordion.
@Alhadis, sorry, I explained it a bit unclear.
I didn't create any folds, I just dynamically change accordion items, by adding and deleting HTML items from it. And to make those items work, I had to init this accordion again.
I'm just wondering, is it possible to destroy the previous accordion object, because I saw that it was still kept in accordions
array.
from accordion.
Short answer: no it's not possible because it shouldn't be needed. Accordions can be disabled and reenabled programmatically after construction, which is (almost) the same as destroying and recreating it.
What you're experiencing is a limitation caused by a pretty stupid oversight on my behalf... one I'm surprised I never noticed earlier — there's no way of dynamically adding or removing accordion folds.
I'll need to fix this. In the meantime, you can use this ugly and illogical workaround:
Click to show
// Usage:
let el = document.createElement("li");
el.innerHTML = "<h3>Foo</h3><div>Bar</div>";
addFold(el, document.querySelector(".accordion"));
function addFold(element, accordion){
if(!(accordion instanceof Accordion))
accordion = Accordion.getAccordion(accordion);
const prev = accordion.folds[accordion.folds.length - 1];
const fold = new prev.constructor(accordion, element);
accordion.folds.push(fold);
prev.nextFold = fold;
fold.previousFold = prev;
if(element.parentElement !== accordion.el)
accordion.el.appendChild(element);
accordion.update();
return fold;
}
function removeFold(fold){
if(fold instanceof HTMLElement)
fold = Accordion.getFold(fold);
const {parentElement} = fold.el;
parentElement && parentElement.removeChild(fold.el);
const {folds} = fold.accordion;
const index = folds.indexOf(fold);
if(~index){
const prev = folds[index - 1];
const next = folds[index + 1];
folds.splice(index, 1);
prev.nextFold = next;
if(next)
next.previousFold = prev;
}
fold.accordion.update();
}
As for destroying an Accordion
instance... well, as mentioned before, it shouldn't be necessary, but now that I think about it, it would benefit applications needing to perform a clean teardown of their state. That's unrelated to this issue, however.
from accordion.
Related Issues (19)
- Rewrite code in ECMAScript 6 HOT 2
- Update height if contents change HOT 6
- Enter and spacebar to open/close accordion item HOT 22
- README - bundled demos link broken HOT 1
- Where is demo? HOT 5
- Loaded event? HOT 23
- Deep linking HOT 6
- Anyway to access the click event? HOT 2
- Responsive heightOffset HOT 3
- Height not updating when closing an accordion nested in another
- Feature: Only open one accordion at a time, collapse others? HOT 3
- Incorrect heights set for nested accordions with pre-opened folds
- Borders aren't considered when calculating fold heights HOT 1
- To-do list
- Option to allow only one fold to be open at a time HOT 3
- Strange type rendering issue with Chrome 55 / Mac 10.10.5 HOT 14
- Doesn't work on IE HOT 11
- Great Plugin HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from accordion.