What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » General » Forum & Website » Url link button

Url link button
Author: Message:
John Anderton
Elite Member
*****

Avatar

Posts: 3908
Reputation: 80
37 / Male / Flag
Joined: Nov 2004
Status: Away
O.P. Url link button
The button on the toolbar whilst making a thread has the url button .... it works perfectly if we click it, enter/donot enter a url.

But if we have already typed the text, we select it and then click the button then it doesnt wrap the selected text in the link.

Test Examples Below

Normal Urls:
Google

Without any text:
http://www.google.com

The Problem (Different Texts Entered):
WwW.Google.ComGoogleundefined

In the last example, I first typed the text "Google", then selected it and then did the normal procedure of adding the link ... only i entered "WwW.Google.Com" for the text which it should show

The Problem (Same Text Entered; May Be Confusing :P):
GoogleGoogleundefined

The same problem as above.

Can this be fixed cause it should work right ? Cause it works on wysiwyg (A) and for the bold, italic and underline tags too

No parsing the above test samples, incase someone needs it .... its quicker than quoting me :P (more lazy too :P)

[i]Normal Urls:[/i]
[url=http://www.google.com]Google[/url]

[i]Without any text:[/i]
[url]http://www.google.com[/url]

[i]The Problem (Different Texts Entered):[/i]
[url=http://www.google.com]WwW.Google.Com[/url]Googleundefined

In the last example, I first typed the text "Google", then selected it and then did the normal procedure of adding the link ... only i entered "WwW.Google.Com" for the text which it should show

[i]The Problem (Same Text Entered; May Be Confusing :P):[/i]
[url=http://www.google.com]Google[/url]Googleundefined

The same problem as above.


Note: Dont even think about posting here to test this out .... it just leads to spam and ignorance of the problem.
[

KarunAB.com
]

[img]http://gamercards.exophase.com/459422.png[
/img]
11-15-2005 10:20 AM
Profile E-Mail PM Web Find Quote Report
ShawnZ
Veteran Member
*****

Avatar

Posts: 3146
Reputation: 43
32 / Male / Flag
Joined: Jan 2003
RE: Url link button
Err, what's wrong?
Spoiler:
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
11-15-2005 01:38 PM
Profile PM Web Find Quote Report
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
35 / Male / Flag
Joined: Mar 2004
RE: Url link button
quote:
Originally posted by ShawnZ
Err, what's wrong?
type "this is a link to blah.com"  then select that , it should ask you just to put a url then make that a description and the whole thing a link
eg
user highlighs his description then clicks the url button , it then pops up asking for a url he then enters it.
which creates
[url=popupstuff]what was selected[/url]
or if a url was selected it should auto just make that a url eg
user selects "http://thedt.net" and clicks url button , it should wrap that with [url] tags.


thats what he wants :P

This post was edited on 11-15-2005 at 02:08 PM by -dt-.
[Image: dt2.0v2.png]      Happy Birthday, WDZ
11-15-2005 02:07 PM
Profile PM Web Find Quote Report
John Anderton
Elite Member
*****

Avatar

Posts: 3908
Reputation: 80
37 / Male / Flag
Joined: Nov 2004
Status: Away
O.P. RE: Url link button
quote:
Originally posted by ShawnZ
Err, what's wrong?
:dodgy:
quote:
Originally posted by John Anderton

The Problem (Different Texts Entered):
WwW.Google.ComGoogleundefined

Dz ... so what do you think ???
[

KarunAB.com
]

[img]http://gamercards.exophase.com/459422.png[
/img]
11-15-2005 05:28 PM
Profile E-Mail PM Web Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: Url link button
quote:
Originally posted by John Anderton
Dz ... so what do you think ???
I think... that I hate JavaScript. :sad:

http://shoutbox.menthix.net/codebuttons.js

Someone tell me what needs to be modified. :refuck:
11-15-2005 06:28 PM
Profile PM Web Find Quote Report
ShawnZ
Veteran Member
*****

Avatar

Posts: 3146
Reputation: 43
32 / Male / Flag
Joined: Jan 2003
RE: Url link button
function insertHyperlink() {
    var selection = (getElementbyName('message').value).substring(getElementbyName('message').selectionStart,getElementbyName('message').selectionEnd);
    if(selection)
        var url = selection

    if(!url) var url = prompt("Please enter the URL of the website.", "http://");
    if(url) {
        var urltitle = prompt("If you wish to, you may also insert a title to be shown instead of the URL.", "");
        if(urltitle) {
            doInsert("[url="+url+"]"+urltitle+"[/url]");
        } else {
            doInsert("[url]"+url+"[/url]");
        }
    } else {
        alert("Error!\n\nYou did not enter a URL for the website. Please try again.");
    }
}
Spoiler:
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
11-15-2005 10:29 PM
Profile PM Web Find Quote Report
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
35 / Male / Flag
Joined: Mar 2004
RE: Url link button
quote:
Originally posted by ShawnZ
getElementbyName('message').value
=/ theres no command named that.... *goes to the post reply page and tries that
ReferenceError on line 1: getElementbyName is not defined
yea yea just as i thought :P

anyway to get the current selected text i would use..

code:
if(document.getSelection){
text = window.getSelection().toString();
}
else if(document.selection){
text = document.selection.createRange().text;
}


so something like....

code:
function insertHyperlink() {

if(document.getSelection){
text = window.getSelection().toString();
}
else if(document.selection){
text = document.selection.createRange().text;
}

var url = text;

if(!url) var url = prompt("Please enter the URL of the website.", "http://");
if(url) {

if((typeof(text)!='string')||(!text.match(/http:\/\//))){
var urltitle = prompt("If you wish to, you may also insert a title to be shown instead of the URL.", "");
}else{
var urltitle = false;
}

if(urltitle) {
doInsert("[url="+url+"]"+urltitle+"[/url]");
} else {
doInsert("[url]"+url+"[/url]");
}
} else {
alert("Error!\n\nYou did not enter a URL for the website. Please try again.");
}
}


should work
[Image: dt2.0v2.png]      Happy Birthday, WDZ
11-16-2005 05:08 AM
Profile PM Web Find Quote Report
John Anderton
Elite Member
*****

Avatar

Posts: 3908
Reputation: 80
37 / Male / Flag
Joined: Nov 2004
Status: Away
O.P. RE: Url link button
quote:
Originally posted by -dt-
quote:
Originally posted by ShawnZ
getElementbyName('message').value
=/ theres no command named that.... *goes to the post reply page and tries that
ReferenceError on line 1: getElementbyName is not defined
yea yea just as i thought [Image: msn_tongue.gif]

anyway to get the current selected text i would use..

code:
if(document.getSelection){
text = window.getSelection().toString();
}
else if(document.selection){
text = document.selection.createRange().text;
}


so something like....

code:
function insertHyperlink() {

if(document.getSelection){
text = window.getSelection().toString();
}
else if(document.selection){
text = document.selection.createRange().text;
}

var url = text;

if(!url) var url = prompt("Please enter the URL of the website.", "http://");
if(url) {

if((typeof(text)!='string')||(!text.match(/http:\/\//))){
var urltitle = prompt("If you wish to, you may also insert a title to be shown instead of the URL.", "");
}else{
var urltitle = false;
}

if(urltitle) {
doInsert("[url="+url+"]"+urltitle+"[/url]");
} else {
doInsert("[url]"+url+"[/url]");
}
} else {
alert("Error!\n\nYou did not enter a URL for the website. Please try again.");
}
}


should work
:bow:
How can we test ..... well when dz is done with the modification testing then we can correct ??
[

KarunAB.com
]

[img]http://gamercards.exophase.com/459422.png[
/img]
11-16-2005 05:45 PM
Profile E-Mail PM Web Find Quote Report
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
35 / Male / Flag
Joined: Mar 2004
RE: Url link button
Blah i just tested it (i didnt test i before :-/ ) and document.getSelection() dosnt work quite right with textarea's (seems when the textarea looses focus it "hides" its selected text untill it refocus's)
so here the code that defintly works (i tested it :P)  , i also changed it a bit because doInsert seems to mess up sometimes (shows undefined :-/)

code:

function insertHyperlink() {

var urltitle = false;
var text;
var start = document.input.message.selectionStart;
var end = document.input.message.selectionEnd;

if(start!=end){
var string = document.input.message.value;
var startString = string.substr(0,start);
var endString = string.substr(end,string.length);
text = string.substr(start,end -start)
}


var url = text;

if(!url){
var url = prompt("Please enter the URL of the website.", "http://");
urltitle = prompt("If you wish to, you may also insert a title to be shown instead of the URL.", "");
if(urltitle){
doInsert("[url="+url+"]"+urltitle+"[/url]");
}else{
doInsert("[url]"+url+"[/url]");
}
return;
}else if(!url.match(/http:\/\//)){
var url = prompt("Please enter the URL of the website.", "http://");
urltitle = text;
}else{
url = text;
}

if(url) {
if(urltitle) {
document.input.message.value = startString + "[url="+url+"]"+urltitle+"[/url]" + endString
} else {
document.input.message.value = startString + "[url]"+url+"[/url]" + endString
}
} else {
alert("Error!\n\nYou did not enter a URL for the website. Please try again.");
}
}

and ja if you want to test install..
http://darktempler.be/gscript/msgplusforumurldifferent.user.js

This post was edited on 11-17-2005 at 02:03 AM by -dt-.
[Image: dt2.0v2.png]      Happy Birthday, WDZ
11-17-2005 01:48 AM
Profile PM Web Find Quote Report
John Anderton
Elite Member
*****

Avatar

Posts: 3908
Reputation: 80
37 / Male / Flag
Joined: Nov 2004
Status: Away
O.P. RE: Url link button
quote:
Originally posted by -dt-
and ja if you want to test install..
http://darktempler.be/gscript/msgplusforumurldifferent.user.js
My pc crashed a few times (auto reboot)
Not that im saying thats realted (A)

Ahh .... the power chord to my pc was a bit loose and it was causing the problem :P

Edit: Yup dt your script works

This post was edited on 11-17-2005 at 08:48 AM by John Anderton.
[

KarunAB.com
]

[img]http://gamercards.exophase.com/459422.png[
/img]
11-17-2005 08:45 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On