kswedberg / jquery-expander

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

slicePoint option not working #30

Closed S0VIET closed 12 years ago

S0VIET commented 12 years ago

Hi, When I try to set the option slicePoice to something other than the default, it doesn't work and cuts off at the default 100chars, here's my JS:

    <script type="text/javascript">
            $(document).ready(function() {
            $('dl.expander dd:eq(0)').expander();
            $('dl.expander dd:gt(0)').expander({
            preserveWords: true,
            slicePoint: 200,
            collapseTimer: 0,
            userCollapse: true,
            beforeExpand: function() {
              $(this).parent().parent().append('<div class="success">before expand.</div>');
            },
            afterExpand: function() {
              $(this).parent().parent().append('<div class="success">after expand.</div>');
            },
            onCollapse: function(byUser) {
              var by = byUser ? 'user' : 'timer';
              $(this).parent().parent().append('<div class="success">on collapse (' + by + ').</div>');
            }
          });
        });
    </script>

Thanks.

kswedberg commented 12 years ago

I can't reproduce the problem you're seeing ( http://plugins.learningjquery.com/expander/test/?single%20block%3A%20slicePoint%20200%2C%20without%20preserving%20word%20boundaries )

would you mind putting together a reduced test case that shows the problem so I can take a look at what's going on? something on http://jsfiddle.net or http://jsbin.com would be ideal.

thanks!

S0VIET commented 12 years ago

jsfiddle wasn't working too well so I copied the source and made it work on this:

http://205.185.127.183/~soviet/test.html

As you can see, the first entry cuts off at 100 chars, and the second cuts off at the desired 200 chars.

kswedberg commented 12 years ago

That's right. It's working exactly as you are instructing it to work. The first entry cuts off at 100 characters because you have called .expander() without any options and 100 characters is the default: $('dl.expander dd:eq(0)').expander();

The second one cuts off at 200 characters because you are calling .expander() with a bunch of options (including slicePoint: 200) for every <dd> element greater than index 0 (all but the first, or ... :gt(0)):

$('dl.expander dd:gt(0)').expander({
        preserveWords: true,
        slicePoint: 200,
       // etc. 
  });

If you want all of them to act the same way, just remove the first call — the one without the options — and change the selector of the second to include all of the <dd> elements:

$('dl.expander dd').expander({ // your options go here });

S0VIET commented 12 years ago

Thank you, that solved my problem. I'm not very good with Javascript as I haven't had the need to work with it's code excessively.

kswedberg commented 12 years ago

No problem. Glad you were able to get it working.