links from highlighted text

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Get Involved
Cape Cod 19
Registered User
Posts: 9
Joined: Sun Feb 20, 2011 3:17 pm

links from highlighted text

Post by Cape Cod 19 »

Hello, I apologize if this answer is already posted somewhere here, but I haven't found it.

My question is; is there a way to make links in a post by selecting the text you want to be a link and then clicking on the link button in the bb code box, but only having to insert the url, without having to enter the description? I am using advanced bb code3. When I make a link, the following code appears in the post when i hit the link button-
[url=http://]Description[/url]

Is there a way to make it so you will only have to enter the URL in the window that opens when you hit the link button so that the selection you have highlighted will become a link?

I hope I am being clear?
User avatar
AmigoJack
Registered User
Posts: 5782
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: links from highlighted text

Post by AmigoJack »

Cape Cod 19 wrote:I am using advanced bb code3. When I make a link, the following code appears in the post when i hit the link button-
[url=http://]Description[/url]
This is not the standard phpBB behaviour. Proof: select text here in this editor on this board and then click the URL button.
  • The worst thing about censorship is ███████████
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
Cape Cod 19
Registered User
Posts: 9
Joined: Sun Feb 20, 2011 3:17 pm

Re: links from highlighted text

Post by Cape Cod 19 »

Amigojack- I understand that it's not standard phpbb behavior. Unfortunately this keeps a lot of folks from wanting to use my forum, they are used to the vbulletin which allows just about anything, you can even copy links which don't contain www. or http://..... and still work once posted. It would be very nice if someone could make phpbb work this way.

I just installed advanced bbcode in hopes that the new version would have fixed this, but it doesn't, as a matter of fact, I like the old advanced bbcode box better, much better. I just upgraded my board to 3.08 which I like much better, from my old 3.0, especially the mod installer, makes things much much easier :D
User avatar
AmigoJack
Registered User
Posts: 5782
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: links from highlighted text

Post by AmigoJack »

Oh, you're talking about a URL popup which also assumes the HTTP protocol in case someone omits it? There are a lot of MODs in development.
  • The worst thing about censorship is ███████████
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
Cape Cod 19
Registered User
Posts: 9
Joined: Sun Feb 20, 2011 3:17 pm

Re: links from highlighted text

Post by Cape Cod 19 »

I'm not sure what you said means? I think this picture describes what I am saying
The way the advance bbbox works is horrible. I can't make it work and no one is going to ever use it to make links, oh it's all fine and well that there are magic URL's, but that is only good if you want to put just the link which is not how I or others would like to see it. I am seriously thinking of switching to Vbulletin :roll:

Image
User avatar
Oyabun1
Former Team Member
Posts: 23162
Joined: Sun May 17, 2009 1:05 pm
Location: Australia
Name: Bill

Re: links from highlighted text

Post by Oyabun1 »

Cape Cod 19 wrote:...I am using advanced bb code3. ...
Is there a way to make it so you will only have to enter the URL in the window that opens when you hit the link button so that the selection you have highlighted will become a link?
If you want to modify the behaviour of a feature in a MOD you should ask in the Discussion/Support forum for that MOD.

The standard URL BBCode button does what you're asking, you select the text, click the button, and then insert the link, no need to retype the "description", no MOD required. So, unless the MOD provides some other feature(s) you do require you should consider uninstalling it.
                      Support Request Template
3.0.x: Knowledge Base Styles Support MOD Requests
3.1.x: Knowledge BaseStyles SupportExtension Requests
User avatar
AmigoJack
Registered User
Posts: 5782
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: links from highlighted text

Post by AmigoJack »

Cape Cod 19 wrote:I'm not sure what you said means?
...
I am seriously thinking of switching to Vbulletin
Talk in details: which of my few words didn't make sense to you? Have you followed the link? Did you know that phpBB is for free and vBB is not (and so is the support)?

The following modification works like this: if you click on the B, I, U, IMG or URL button and there is currently no text selected, an input prompt will pop up to make you enter an appropriate value. For the URL BBCode there will be an additional second prompt to optionally enter a link description.

Open /styles/?/template/editor.js and find:

Code: Select all

	//The new position for the cursor after adding the bbcode
	var caret_pos = getCaretPosition(textarea).start;
	var new_pos = caret_pos + bbopen.length;
After, add:

Code: Select all

	/*** 2011-02-26 BEGIN AmigoJack
		Show input prompt if no text is selected, primarily for URLs ***/
	var bbcl= bbopen.replace( /\[|\]/g, '' ).toLowerCase();
	var aType=
	{ 'b': { cap: 'b' }
	, 'i': { cap: 'i' }
	, 'u': { cap: 'u' }
	, 'img': { cap: 'p', pre: 'http://' }
	, 'url': { cap: 'w', pre: 'http://', more: 'Description (optional)' }
	}

	if( aType[bbcl] ) {
		var sPre= aType[bbcl]['pre']? aType[bbcl]['pre']: '';
		var sIns= prompt( help_line[aType[bbcl]['cap']]+ ':', sPre );
		if( sIns== null ) return;

		if( aType[bbcl]['more'] ) {
			var sMore= prompt( aType[bbcl]['more']+ ':' );
			if( sMore!= null ) {
				bbopen= bbopen.replace( /\]$/, '='+ sIns+ ']' );
				sIns= sMore;
			}
		}

		bbopen+= sIns;
	}
	/*** 2011-02-26 END ***/
Tested with OPER11 and FFOX3.5.
  • The worst thing about censorship is ███████████
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
Rafalsky
Registered User
Posts: 9
Joined: Thu Jul 28, 2011 2:38 pm

Re: links from highlighted text

Post by Rafalsky »

@AmigoJack
that's works well but could you provide the code which works slightly differently. As many people write the text first and add links later.

so: I have a text and I highlight the part of the text use URL and box appeared to enter url link.
User avatar
AmigoJack
Registered User
Posts: 5782
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: links from highlighted text

Post by AmigoJack »

Open /styles/?/template/editor.js and find:

Code: Select all

	if ((clientVer >= 4) && is_ie && is_win)
	{
		// Get text selection
		theSelection = document.selection.createRange().text;

		if (theSelection)
		{
After, add:

Code: Select all

			/*** 2011-07-29 BEGIN AmigoJack
				[url] upon selected text should also trigger a prompt for either description or URL ***/
			if( bbopen.replace( /\[|\]/g, '' ).toLowerCase()== 'url' ) {
				var bUrl= theSelection.search( /(^[a-z]+:|www\.)[^ ]+/i )!= -1;
				var sIns= prompt( ( bUrl? 'Description / link title': 'URL' )+ ':', bUrl? '': 'http://' );
				if( sIns!= null ) {
					if( bUrl ) {
						bbopen= '[url=';
						bbclose= ']'+ sIns+ bbclose;
					} else bbopen= '[url='+ sIns+ ']';
				}
			}
			/*** 2011-07-29 END ***/
Find:

Code: Select all

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd);
	var s3 = (txtarea.value).substring(selEnd, selLength);
After, add:

Code: Select all

	/*** 2011-07-29 BEGIN AmigoJack
		[url] upon selected text should also trigger a prompt for either description or URL ***/
	if( open.replace( /\[|\]/g, '' ).toLowerCase()== 'url' ) {
		var bUrl= s2.search( /(^[a-z]+:|www\.)[^ ]+/i )!= -1;
		var sIns= prompt( ( bUrl? 'Description / link title': 'URL' )+ ':', bUrl? '': 'http://' );
		if( sIns!= null ) {
			if( bUrl ) {
				open= '[url=';
				close= ']'+ sIns+ close;
			} else open= '[url='+ sIns+ ']';
		}
	}
	/*** 2011-07-29 END ***/
If you want to support different languages you'd have to edit more. Tested with OPER11.50.
  • The worst thing about censorship is ███████████
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
User avatar
4_seven
I've Been Banned!
Posts: 5155
Joined: Wed Apr 30, 2008 1:41 am

Re: links from highlighted text

Post by 4_seven »

genius work..
Last edited by 4_seven on Tue Feb 28, 2012 12:37 am, edited 1 time in total.
Current Mods | Mod Base | php(BB) programming | No help via PM
Rafalsky
Registered User
Posts: 9
Joined: Thu Jul 28, 2011 2:38 pm

Re: links from highlighted text

Post by Rafalsky »

AmigoJack wrote:Open /styles/?/template/editor.js and find:

Code: Select all

	if ((clientVer >= 4) && is_ie && is_win)
	{
		// Get text selection
		theSelection = document.selection.createRange().text;

		if (theSelection)
		{
After, add:

Code: Select all

			/*** 2011-07-29 BEGIN AmigoJack
				[url] upon selected text should also trigger a prompt for either description or URL ***/
			if( bbopen.replace( /\[|\]/g, '' ).toLowerCase()== 'url' ) {
				var bUrl= theSelection.search( /(^[a-z]+:|www\.)[^ ]+/i )!= -1;
				var sIns= prompt( ( bUrl? 'Description / link title': 'URL' )+ ':', bUrl? '': 'http://' );
				if( sIns!= null ) {
					if( bUrl ) {
						bbopen= '[url=';
						bbclose= ']'+ sIns+ bbclose;
					} else bbopen= '[url='+ sIns+ ']';
				}
			}
			/*** 2011-07-29 END ***/
Find:

Code: Select all

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd);
	var s3 = (txtarea.value).substring(selEnd, selLength);
After, add:

Code: Select all

	/*** 2011-07-29 BEGIN AmigoJack
		[url] upon selected text should also trigger a prompt for either description or URL ***/
	if( open.replace( /\[|\]/g, '' ).toLowerCase()== 'url' ) {
		var bUrl= s2.search( /(^[a-z]+:|www\.)[^ ]+/i )!= -1;
		var sIns= prompt( ( bUrl? 'Description / link title': 'URL' )+ ':', bUrl? '': 'http://' );
		if( sIns!= null ) {
			if( bUrl ) {
				open= '[url=';
				close= ']'+ sIns+ close;
			} else open= '[url='+ sIns+ ']';
		}
	}
	/*** 2011-07-29 END ***/
If you want to support different languages you'd have to edit more. Tested with OPER11.50.

Works perfect,

highlight text -> prompt for url,
highlight url -> prompt for text,

thank you !!!
iamthestreets
Registered User
Posts: 244
Joined: Fri Feb 24, 2012 4:35 pm
Contact:

Re: links from highlighted text

Post by iamthestreets »

when i highlight the text and click URL it does not include the highlighted text as my title of the url link. see below what it does.

I highlighted phpBB.com and clicked url. i still have to enter the description which makes highlighting the text useless. can you help with this please?
for example:

Code: Select all

[url=http://www.phpbb.com/community/viewtopic.php?p=13030489#p13030489]http://www.phpbb.com/community/viewtopic.php?p=13030489#p13030489][/url]phpBB.com
User avatar
4_seven
I've Been Banned!
Posts: 5155
Joined: Wed Apr 30, 2008 1:41 am

Re: links from highlighted text

Post by 4_seven »

check the actuality of your editor.js (should have phpbb 3.0.9 - 3.0.10 state)
also check your edits. i test your example and all works well.
also clear all board-, template-, style- and browser-caches after each edit of template files.
Current Mods | Mod Base | php(BB) programming | No help via PM
iamthestreets
Registered User
Posts: 244
Joined: Fri Feb 24, 2012 4:35 pm
Contact:

Re: links from highlighted text

Post by iamthestreets »

after further testing it does not work in chrome but works in firefox. Do you know why?
User avatar
4_seven
I've Been Banned!
Posts: 5155
Joined: Wed Apr 30, 2008 1:41 am

Re: links from highlighted text

Post by 4_seven »

sorry, its multibrowser-compatible. works for me in all current browsers (just also tested in google chrome (current version)) - check it out here: http://www.4seven.de/forum/media/postin ... e=post&f=9
enter phpbb.com in postbox and hit [URL]
Current Mods | Mod Base | php(BB) programming | No help via PM
Locked

Return to “[3.0.x] MOD Requests”