rviscomi / trunk8

jQuery Truncation Plugin -- THIS PROJECT IS NO LONGER MAINTAINED
MIT License
703 stars 95 forks source link

How to truncate elements based on a class name? #67

Closed udayakiran closed 8 years ago

udayakiran commented 9 years ago

My idea is to add a class name say "text_trunk8" to an element and let all the elements with this class get truncated.

One thing i can do is to call $(".text_trunk8").trunk8() on page load (jquery dom:loaded event). But this does not work for the elements loaded later with Ajax and etc. So, instead going by multiple events, a way to support truncation of all elements with a specific class or attribute , all the times would be nice.

Not sure if there is a jQuery event which can be used. Could not find one. So, discussing this here so that i can get either leads on this. Probably adding this to trunk8 will make it more elegant to use..

Thanks.

screeny05 commented 8 years ago

That's no problem with this plugin but rather one in your code. You've got two possibilities:

  1. call .trunk8() everytime you add an .text_trunk8-element to your page
  2. have a look at this stackoverflow-question which suggests using either a loop to periodically apply trunk8 or using a Mutation Observer.

Consider Browser-support when opting for mutation-observer

udayakiran commented 8 years ago

Yes, Was looking if any solution i am unaware from the plugin's side. But, obviously calling .trunk8() each time i load the element is the way (calling it on dom load, any ajax response and etc.). Another requirement for truncation to work is that the element needs to be visible when trunk8() is applied. So, need to make sure that as well.

Thanks!