kswedberg / jquery-expander

Expand and Collapse HTML content
https://kswedberg.github.io/jquery-expander/
Other
459 stars 168 forks source link

Is 'destroy' supposed to re-expand compacted elements? #61

Closed otravers closed 11 years ago

otravers commented 11 years ago

Hi,

First thanks for this plugin, it's pretty nifty and I'm pretty close to getting what I need out of it. I'm working on an outline mode that crunches long articles into shorter versions. This is triggered by the user clicking on a button, an action that the user should then be able to roll back by clicking the same button again. This is shown in simplified fashion in the following jsfiddle example using a link called "[OUTLINE]".

http://jsfiddle.net/2wUJG/

Applying expander('destroy') does remove the expanding links [+], but it does not show the full content (unless the element had manually been expanded beforehand), which was my expectation. In other words my code is intended to re-expand all the elements that had been compacted. Maybe there's something wrong with my selectors?

Thanks for any help.

PS: destroy is not documented at http://plugins.learningjquery.com/expander/index.html#options

I had to Google to find the Github ticket which introduced that ability to the expander method.

kswedberg commented 11 years ago

Hi there, Thanks for the report. There is still, obviously, a lot of work that needs to be done with .expander('destroy'). Part of the problem lies in how I'm slicing and dicing the elements: I'm using regular expressions. Unfortunately, that means things get messed up sometimes, like when there are unordered lists involved (because I wrap everything in a <div>, which is invalid as a parent of <li> elements).

Anyway, I hacked an ugly fix to your particular problem. I put in on jsbin instead of jsfiddle because I needed better access to the console. Here it is: http://jsbin.com/eyohez/2 (you can see the code, too, by going to http://jsbin.com/eyohez/2/edit).

otravers commented 11 years ago

Thanks, I figured there would be a manual way to undo the expanding. If I want to really use this for my purposes though, I'll have to find how to replace somewhat complex Jquery selectors with a javascript loop, as my outline function takes 10 seconds to complete on my average laptop with Chrome! We have very long articles (10,000+ words - they're reports really) that we display on a single page. This translates into thousands of DOM elements so I have to be conservative in how I traverse the page. For now I'll stick with altogether hiding the nonessential parts.

Anyway I'm just rambling outside of the scope of my initial report, thanks for clarifying what I can and cannot do with your plugin and offering a hack.

kswedberg commented 11 years ago

I see! Yes, in your case you're probably much better off with a custom, streamlined solution. I'm going to close this issue for now, but if there is anything I can do to help, let me know.