We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Shorten Long URLs in Posts
Topic Started: Apr 18 2013, 07:23 AM (1,773 Views)
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
Code Name: Shorten Long URLs in Posts

What the code does: Will turn this:

http://www.thelongestdomainnameintheworldandthensomeandthensomemoreandmore.com/

To this:

http://www.thelongestdomainnameintheworldandthenso...

How to use the code: Install as instructed, no editing is required.

How to install the code:

Admin CP Posted Image Themes Posted Image Board Template Posted Image Below the Board
Code:
 
<script type="text/javascript">
//<![CDATA[
$('a[rel="nofollow"]').each(function () {
if ($(this).text().length > 50) {
var text = $(this).text();
var subs = text.substring(0, 50);
$(this).text(subs + '...');
}
});
//]]>
</script>
Extra notes: Very simple, just created for the convenience factor.
Edited by Cory, Apr 25 2013, 05:27 PM.
Offline Profile Quote Post Goto Top
 
pacisangelo
Member Avatar
Member
[ *  * ]
Nice code. thanks
Offline Profile Quote Post Goto Top
 
DaPizzaMan
Member Avatar
#TeamSupport

I should note that the topic buttons also have a rel that equals "nofollow" so this doesn't work too well unless you define it to the `td.c_post` area, or (what I did to the code to help someone) make it only for links that don't have any children element.
Offline Profile Quote Post Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
Code has been updated.
Offline Profile Quote Post Goto Top
 
Ferby
Member Avatar
Developer
[ *  *  *  *  * ]
Cory
Apr 25 2013, 05:32 PM
Code has been updated.
Are you sure? I don't see any difference. Also a variable to change the length limit would be helpful to most people. I'd change it to 15, personally.
Offline Profile Quote Post Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
The if statement should suffice.

I don't think a variable is necessary when the code is that small.
Offline Profile Quote Post Goto Top
 
Ido
Member
[ * ]
Can this code work in the shoutbox as well?
Offline Profile Quote Post Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
Code:
 
$('a[rel="nofollow"]').each(function () {
Change that to this:
Code:
 
$('a[rel="nofollow"], #shoutbox a').each(function () {
Offline Profile Quote Post Goto Top
 
polocolo
Member Avatar
Member
[ *  *  * ]
Thank you!

EDIT: I amended the code as follows but full URL link still shows in the shoutbox area.

<script type="text/javascript">
//<![CDATA[
$('a[rel="nofollow"], #shoutbox a').each(function () {
if ($(this).text().length > 30) {
var text = $(this).text();
var subs = text.substring(0, 30);
$(this).text(subs + '...');
}
});
//]]>
</script>
Edited by polocolo, Sep 17 2016, 06:14 PM.
Offline Profile Quote Post Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
Is it only doing that when you submit a shout, or for every shout posted?
Offline Profile Quote Post Goto Top
 
polocolo
Member Avatar
Member
[ *  *  * ]
After I applied the code those url links already posted in the past didn't change (still with the full links). So I tested by making a few links but still no change.
Offline Profile Quote Post Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
Try this instead:
Code:
 
<script type="text/javascript">
//<![CDATA[
function shortenURL() {
$('a[rel="nofollow"], #shoutbox a').each(function() {
if ($(this).text().length > 30) {
var text = $(this).text();
var subs = text.substring(0, 30);
$(this).text(subs + '...');
}
});
}

shortenURL();

$(document).ajaxSuccess(function() {
shortenURL();
});
//]]>
</script>
Offline Profile Quote Post Goto Top
 
Skyon Archer
Member Avatar
Member
[ *  *  *  * ]
You could also add a shortened URL bbcode button to your forum as mentioned in this topic.
Offline Profile Quote Post Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
I'd personally prefer, if I added either version to my forum, this version because it is done automatically and doesn't rely on a third-party service.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · ZetaBoards Codes & Modifications · Next Topic »
Add Reply