Welcome Guest [Log In] [Register]
This board has been archived and is no longer accepting new questions. If you have a support question for your ZetaBoard, please visit us at the new support board. Registration is free and easy.


Visit the NEW ZetaBoards Support forum!

Username:   Password:
Add Reply
Shorten Long Urls v2.1
Topic Started: Jun 3 2008, 06:57 PM (713 Views)
ProgramFreak
Member Avatar
Member
[ *  * ]
Code:
 

<script type='text/javascript'>
var maxlength = 50;
$(".c_post a").each(function(){
s = $(this).html();
if(s.length > maxlength && !s.match(/\<img[^>]+\>/i)) {
$(this).html(s.substr(0,parseInt(maxlength/2))+'...'+s.substr(s.length-parseInt(maxlength/2),s.length));
}});
</script>


Edit maxlength to the max size it should be.

V2 makes urls nice, keep it at 50, its a decent length:

Posted Image
Edited by ProgramFreak, Jun 17 2008, 01:20 PM.
Offline Profile Quote Post Goto Top
 
Viral
Member Avatar
i'm stanley nao
[ *  *  *  *  * ]
Nice, but wouldn't you do for the substring part

Code: HTML
 
(s.substr(0,maxlength-3)

so it really is a max of 100. You just forgot to count the elipse.
Offline Profile Quote Post Goto Top
 
ProgramFreak
Member Avatar
Member
[ *  * ]
Nope, the ... is added just to look good. If you wanted exactly 100 characters you would do it your way. But thats originally not the actual length. So I'm going to keep it as it is, only thing I'm worried about is matching images. Which I need to do next.

Code:
 
if(s.match(/\<img[^>]+\>/i)) continue;
might work I'm going to do some texting.
Edited by ProgramFreak, Jun 3 2008, 07:12 PM.
Offline Profile Quote Post Goto Top
 
Thunder
Member Avatar
Thunder
[ *  *  * ]
I don't get how this works...
Offline Profile Quote Post Goto Top
 
ProgramFreak
Member Avatar
Member
[ *  * ]
Basically when you have a link thats like:

http://watchinplainsight.info/LONGURL/LONGURL/LONGURL/LONGURL/LONGURL/LONGURL/LONGURL/LONGURL/LONGURL/LONGURL/LONGURL/LONGURL/LONGURL/LONGURL/LONGURL/LONGURL/LONGURL.html

It won't stretch the page
Offline Profile Quote Post Goto Top
 
RyanCE
Member Avatar
The Root Of All
[ * ]
Really good code, long urls do mess up our themes. Thanks for this!
Offline Profile Quote Post Goto Top
 
Marky C
Member
[ * ]
Not quite sure what I should change and where I should put it.

Is just the code I was looking for though
Offline Profile Quote Post Goto Top
 
dark knight
Member Avatar
Member
[ *  *  * ]
bovinejumpsuit
Jun 5 2008, 04:32 AM
Not quite sure what I should change and where I should put it.

Is just the code I was looking for though
You change the 100 part in the second line to how ever many letters you want to show before it shortens it. For example if I wanted to have 80 letters show I'd change the second line from

var maxlength = 100;
to
var maxlength = 80;

Also you go to Board Template and place it in the box that says Below the Board. Hope that helps :)
Offline Profile Quote Post Goto Top
 
Marky C
Member
[ * ]
thanks, excellent code
Offline Profile Quote Post Goto Top
 
ProgramFreak
Member Avatar
Member
[ *  * ]
NP :)
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
Go to Next Page
« Previous Topic · User Created Codes · Next Topic »
Add Reply