anthonydreamsforever Guest | Text Delimitor (22nd Jan 10 at 8:32pm UTC) | | I didn't seem to find this anywhere, but I'm looking for a text limit code that will add "..." when text is too long.
Also, I'd like to apply to this to any HTTP link wherever it is on the page if that's possible. But I'll be happy with a simple limitor. | |
|
Michael Moderator
    
![[Avatar]](http://av.wservices.co.uk/av.png) Recoding the future Posts: 4,043 Status: Offline Gender: Male Location: UK Joined:
Additional Groups: Coding Team
  
pmvForum | Re: Text Delimitor (23rd Jan 10 at 4:58pm UTC) | | You'd want to use the function: string.substr(a, b); If you set a to 0, and b to the length that you want it to be, then the string will be truncated to that length.
This could be used much like:
<script type = 'text/javascript'>
var length = 30;
function cut(x, y) { return(x.substr(0, y) + "..."); }
for(i = 0, a = get('a', 'tag'); i < a.length; i++) if(a[i].innerHTML.length > length) a[i].innerHTML = cut(a[i].innerHTML, length); </script>
The cut function will truncate the string and add the dots for you, to a length specified through the variable length. I haven't tested this, but it should work, any problems, let me know!
| |
|
anthonydreamsforever Guest | Re: Text Delimitor (23rd Jan 10 at 5:41pm UTC) | | Edit: Works now XD
Thanks bunches Michael | |
|
Michael Moderator
    
![[Avatar]](http://av.wservices.co.uk/av.png) Recoding the future Posts: 4,043 Status: Offline Gender: Male Location: UK Joined:
Additional Groups: Coding Team
  
pmvForum | Re: Text Delimitor (23rd Jan 10 at 5:46pm UTC) | | Global footer. | |
|
anthonydreamsforever Guest | Re: Text Delimitor (23rd Jan 10 at 5:49pm UTC) | | Ok it works almost too good
My menu buttons are gone.
Ok... So when I said all links it did just that XD and it really works, however I see a few instances where we should probably tell it not to shorten...
http://tfc.forums.us | |
|
Michael Moderator
    
![[Avatar]](http://av.wservices.co.uk/av.png) Recoding the future Posts: 4,043 Status: Offline Gender: Male Location: UK Joined:
Additional Groups: Coding Team
  
pmvForum | Re: Text Delimitor (23rd Jan 10 at 6:13pm UTC) | | Change if(a[i].innerHTML.length > length) to if(a[i].innerHTML.length > length && !a[i].href.match(/forums\.us/))
That'll make it change all links except links to your forum. So menu should be unaffected.
| |
|
Michael Moderator
    
![[Avatar]](http://av.wservices.co.uk/av.png) Recoding the future Posts: 4,043 Status: Offline Gender: Male Location: UK Joined:
Additional Groups: Coding Team
  
pmvForum | Re: Text Delimitor (23rd Jan 10 at 6:55pm UTC) | |
Glad it's working.
| |
|