kswedberg / jquery-expander

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

nested tags interrupt the sumTagLess counter #58

Closed jbeach closed 11 years ago

jbeach commented 11 years ago

I recently implemented this plugin (version 1.4.5) , as follows:

// slicePoint: 235
<div class="expandable">
  <p>
    Can your students apply Gibbs Free Energy equation? Gain insight into your</p>
  <ul>
    <li>
      <u><em><strong>students' prior knowledge and</strong></em></u></li>
    <li>
      <u><em><strong>misunderstandings of Building Block A to help you select</strong></em></u></li>
    <li>
      <u><em><strong>activities that build their ability to make predictions about changes in free energy availability at the molecular and cellular level.</strong></em></u></li>
  </ul>
</div>

With this example, I discovered that the first nested opening tag without a space in front of it (<em>) is treated as a text character in the while (summTagless < o.slicePoint) loop and the rest of the summary text counting is then thrown off. This really showed up in differences between FFX and IE8 because of additional markup attributes in IE8 which were being treated as text.

It seemed to fix the problem when I updated the rTagPlus regex to account for nested tags:

OLD: rTagPlus = /^<[^>]+>.?/
NEW: rTagPlus = /^(<[^>]+>)+.?/

After my local fix, both FFX and IE started slicing the summary at the desired 235 text characters.

Thanks for writing such a great plug in!

kswedberg commented 11 years ago

thank you so much for the report and for proposing a solution! I will try to incorporate it into the plugin as soon as I get a chance.