Shoutbox

Url link button - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: General (/forumdisplay.php?fid=11)
+---- Forum: Forum & Website (/forumdisplay.php?fid=13)
+----- Thread: Url link button (/showthread.php?tid=52986)

Url link button by John Anderton on 11-15-2005 at 10:20 AM

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.
RE: Url link button by ShawnZ on 11-15-2005 at 01:38 PM

Err, what's wrong?


RE: Url link button by -dt- on 11-15-2005 at 02:07 PM

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
RE: Url link button by John Anderton on 11-15-2005 at 05:28 PM

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 ???
RE: Url link button by WDZ on 11-15-2005 at 06:28 PM

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:
RE: Url link button by ShawnZ on 11-15-2005 at 10:29 PM

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.");
    }
}


RE: Url link button by -dt- on 11-16-2005 at 05:08 AM

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
RE: Url link button by John Anderton on 11-16-2005 at 05:45 PM

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 ??
RE: Url link button by -dt- on 11-17-2005 at 01:48 AM

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

RE: Url link button by John Anderton on 11-17-2005 at 08:45 AM

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