0

I have a fixed-size div with generated text inside it.

Is there some simple way to cut the text before div's end and add "..." at the end using DOJO or plain Javascript? Is there a way to do it regardless of what size of font i use?

The only way that comes to my mind is to calculate how many characters with actual font fits into my div and than cut the text to be that long, but this looks pretty lame :-) any suggestions?

thirtydot
  • 224,678
  • 48
  • 389
  • 349
Gatekeeper
  • 1,586
  • 3
  • 21
  • 33
  • 2
    http://stackoverflow.com/questions/4927257/text-overflowellipsis-in-firefox-4/ - doesn't contain a Dojo based solution though. – thirtydot Mar 29 '11 at 15:00
  • Whow, taht looks great in IE, but unfortunetly, i need a cross-browser solution that works in Firefox, IE, Chrome and Safari :-/ But thanks anyway.. – Gatekeeper Mar 29 '11 at 15:04
  • `text-overflow:ellipsis` works fine on WebKit-based browsers. – Stephen Chung Mar 30 '11 at 04:39

1 Answers1

1

May be it helps dojo.html.ellipsis

Andrei
  • 4,237
  • 3
  • 25
  • 31
  • yeah, thats exactly what i was looking for. unfortunetly, there is other problem... i need to apply this in project running on Websphere Commerce, which supports only Dojo 1.3 and this function comes in version 1.4. AAAArgh! Stupid IBM – Gatekeeper Mar 29 '11 at 15:27
  • 1
    copy the file. it's open source, and it may work on Dojo 1.3. – peller Mar 29 '11 at 23:49
  • 1
    Use `text-overflow:ellipsis` for IE and WebKit, use this for FireFox (check dojo.isFF). – Stephen Chung Mar 30 '11 at 04:39
  • And is there a way to use text-overflow:ellipsis on a multi-line text so it displays ellipsis on the last line? All examples i found on text-overflow:ellipsis was using white-space:nowrap, this is no use for me :-( – Gatekeeper Mar 30 '11 at 07:15
  • There is a jquery plugin for truncating text (https://github.com/jsillitoe/jquery-condense-plugin/). You can see implementation of plugin and do something similar... – Andrei Mar 30 '11 at 08:30