vForums Support Banner



 

Welcome Guest! Please Login or Register
vForums Support :: Programming & Coding :: Code Requests & Support :: Text Delimitor - View Topic
Topic Rating: *****
Printable View
anthonydreamsforever
Guest
Text Delimitor (22nd Jan 10 at 3:32pm EST)
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]
Recoding the future

Posts: 3,974
Status: Offline
Gender: Male
Location: UK
Joined:  

Additional Groups:
Coding Team
***


Reputation: 55%  


pmtwitter vForum
Re: Text Delimitor (23rd Jan 10 at 11:58am EST)
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 12:41pm EST)
Edit: Works now XD

Thanks bunches Michael
Michael
Moderator
*****

[Avatar]
Recoding the future

Posts: 3,974
Status: Offline
Gender: Male
Location: UK
Joined:  

Additional Groups:
Coding Team
***


Reputation: 55%  


pmtwitter vForum
Re: Text Delimitor (23rd Jan 10 at 12:46pm EST)
Global footer. {Smile}

anthonydreamsforever
Guest
Re: Text Delimitor (23rd Jan 10 at 12:49pm EST)
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]
Recoding the future

Posts: 3,974
Status: Offline
Gender: Male
Location: UK
Joined:  

Additional Groups:
Coding Team
***


Reputation: 55%  


pmtwitter vForum
Re: Text Delimitor (23rd Jan 10 at 1:13pm EST)
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.

Michael
Moderator
*****

[Avatar]
Recoding the future

Posts: 3,974
Status: Offline
Gender: Male
Location: UK
Joined:  

Additional Groups:
Coding Team
***


Reputation: 55%  


pmtwitter vForum
Re: Text Delimitor (23rd Jan 10 at 1:55pm EST)
{Smile}

Glad it's working. {Cheesy}

 Printable View

All times are GMT+0 :: The current time is 5:28am
Page generated in 0.3006 seconds
with 43 Database Queries and 0 cache files
This Forum is Powered By vForums (v2.3)
Create a Forum for Free | Find Forums