vForums Support > Programming & Coding :: Code Requests & Support :: > Text Delimitor

Text Delimitor - Posted By anthonydreamsforever (anthonydreamsforever) on 22nd Jan 10 at 8:32pm
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.

Re: Text Delimitor - Posted By Michael (wrighty) on 23rd Jan 10 at 4:58pm
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!


Re: Text Delimitor - Posted By anthonydreamsforever (anthonydreamsforever) on 23rd Jan 10 at 5:41pm
Edit: Works now XD

Thanks bunches Michael

Re: Text Delimitor - Posted By Michael (wrighty) on 23rd Jan 10 at 5:46pm
Global footer. {Smile}

Re: Text Delimitor - Posted By anthonydreamsforever (anthonydreamsforever) on 23rd Jan 10 at 5:49pm
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

Re: Text Delimitor - Posted By Michael (wrighty) on 23rd Jan 10 at 6:13pm
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. {Smile} So menu should be unaffected.

Re: Text Delimitor - Posted By Michael (wrighty) on 23rd Jan 10 at 6:55pm
{Smile}

Glad it's working. {Cheesy}