Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: Arantor on February 03, 2014, 01:52:22 PM

Title: URL Popup
Post by: Arantor on February 03, 2014, 01:52:22 PM
Link to Mod (http://custom.simplemachines.org/mods/index.php?mod=3832)

When posting in the editor, the URL bbcode is often considered unfriendly. This mod modifies it so that instead of just adding [url][/url] tags in the editor area, it prompts the user for a website address and optional name and then inserts the relevant bbcode for it.

It does not attempt to modify the WYSIWYG behaviour (but then again, the WYSIWYG behaviour is intentionally different; you're supposed to write the text, then highlight it before pressing the button to make it a link anyway)

Released under the CC0 licence (http://creativecommons.org/publicdomain/zero/1.0/)
Title: Re: URL Popup
Post by: meetdilip on February 03, 2014, 09:02:02 PM
Life saver :)
Title: Re: URL Popup
Post by: Arantor on February 03, 2014, 09:04:37 PM
The really odd thing is I wrote this almost 4 years ago just never published it here...
Title: Re: URL Popup
Post by: Jeffrey King on February 03, 2014, 09:08:26 PM
heh heh. Funny!
Title: Re: URL Popup
Post by: NekoJonez on February 04, 2014, 12:39:49 PM
I don't get this working nicely.
Title: Re: URL Popup
Post by: Arantor on February 04, 2014, 12:41:11 PM
I don't know what you mean.
Title: Re: URL Popup
Post by: NekoJonez on February 04, 2014, 12:45:50 PM
When I click on the URL button, I don't get the pop-up. And I don't get the description thing.
Title: Re: URL Popup
Post by: Arantor on February 04, 2014, 12:49:02 PM
Using WYSIWYG?
Title: Re: URL Popup
Post by: NekoJonez on February 04, 2014, 01:19:29 PM
No. But when I use it, it only give me the normal pop up and not for the description .
Title: Re: URL Popup
Post by: Arantor on February 04, 2014, 01:24:41 PM
That sounds like you're using WYSIWYG...
Title: Re: URL Popup
Post by: NekoJonez on February 04, 2014, 01:26:18 PM
I see. Well, maybe I might try to install this mod again.
Title: Re: URL Popup
Post by: Arantor on February 04, 2014, 01:29:53 PM
Or you could turn off WYSIWYG. Here's the thing: the little arrow on the far right, blue arrow inside red [] symbols, is that on or off? If it's on, you're in WYSIWYG and the mod does not touch WYSIWYG for good reason (because you're supposed to highlight text and press URL in WYSIWYG mode)
Title: Re: URL Popup
Post by: von COLLINZO on February 04, 2014, 01:35:14 PM
Nice mod, Sir Cumber....

Been looking for a way to get this fixed in my forum.....thanks alot! :D
Title: Re: URL Popup
Post by: AllMassive on February 08, 2014, 08:01:37 AM
Finally there it is - thank you !
Title: Re: URL Popup
Post by: Mr.Truckman on February 09, 2014, 08:23:18 AM
I like it ! :D
Title: Re: URL Popup
Post by: ApplianceJunk on February 09, 2014, 10:47:17 PM
Awesome, thanks!
Title: Re: URL Popup
Post by: Mike L on February 13, 2014, 10:57:27 AM
GREAT!! One of the little things I missed now I'm using SMF.

Just one question: can anyone tell me what "Prevent this page from creating additional dialogues" means in practice, and if there's a best choice?

Cheers  :)
Title: Re: URL Popup
Post by: margarett on February 13, 2014, 12:27:12 PM
That's a Firefox thing, totally unrelated to this MOD. I think it detects a certain number of JS messages and asks you if you want to now show them anymore.
But this MOD (or SMF itself, for the same reason) have nothing to do with it.
Title: Re: URL Popup
Post by: Arantor on February 13, 2014, 12:32:59 PM
Not *totally* unrelated because the URL prompt itself is one of those 'additional dialogues' it talks about. There are people out there who thought it would be funny to lock a browser up with infinite loops of such prompts.

Just don't prevent the page while you're posting to SMF, because you should not need to do so.
Title: Re: URL Popup
Post by: IMSassafras on March 20, 2014, 10:25:40 PM
I am not able to get it to work.  I checked to see if I was doing it right.  Not using WYSIWYG.  Trying to select text and click the url button.  And trying to click the url button and write text.  No pop up appears.  The only time a box appears is when I am in WYSIWYG mode which has nothing to do with your mod.  I checked by uninstalling.

Is there a trick?

Sass
Title: Re: URL Popup
Post by: radu81 on May 05, 2014, 02:19:51 PM
Simple and powerful, thank you Arantor!
Title: Re: URL Popup
Post by: Buneduggy on May 07, 2014, 09:17:29 PM
Quote from: Arantor on February 03, 2014, 09:04:37 PM
The really odd thing is I wrote this almost 4 years ago just never published it here...

I just saw this on here and wanted to thank Arantor for this mod. I have been using it for years and it has always worked flawlessly.
Title: Re: URL Popup
Post by: fapencio on July 30, 2014, 01:22:32 PM
Hi @‽  Arantor, your mod is awesome, but i have a problem, in the body post without WYSIWYG the mod write this:

[url=http://myurl.com]titleofmyurl[/url][url][/url]

i have to delete manually this: [url][/url] for the mod works, please help

Title: Re: URL Popup
Post by: Arantor on July 30, 2014, 01:24:06 PM
What other mods are you using? This does not happen when this is the only mod installed.
Title: Re: URL Popup
Post by: fapencio on August 01, 2014, 10:57:43 AM
Quote from: ‽ on July 30, 2014, 01:24:06 PM
What other mods are you using? This does not happen when this is the only mod installed.

Hi Arantor @‽  my mods:

1.   QR Code BBcode    1.0.1     
2.   IMG Popup    1.0.2     
3.   Separated Birthdays from Events    1.1.7     
4.   SMF 2.0.8 Update    1.0     
5.   Enhanced PM System    1.1     
6.   Countdown BBCode    2.0.2     
7.   Reason For Editing Mod    2.3.2     
8.   Enhanced Dropdown    1.3     
9.   Post_Board_Select    1.3     
10.   Tabbed smileys    0.3.99c 
11.   URL Popup    1.0.2 

thanks
Title: Re: URL Popup
Post by: Arantor on August 01, 2014, 10:59:37 AM
Does it behave if you uninstall img popup?
Title: Re: URL Popup
Post by: fapencio on August 01, 2014, 03:24:22 PM
Quote from: ‽ on August 01, 2014, 10:59:37 AM
Does it behave if you uninstall img popup?

yes, but a new problem emerged in the second pop-up window that appears:

(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fi39.servimg.com%2Fu%2Ff39%2F18%2F92%2F31%2F95%2Fudef10.jpg&hash=096858da1664b13aece9829437b2dc55f7ae5dfb)

help please (i uninstall img popup)
Title: Re: URL Popup
Post by: Arantor on August 01, 2014, 03:25:58 PM
o.O I have no idea what's hapened there. I'll see if I can find some time to investigate but I am pretty swamped with paid mod work right now.
Title: Re: URL Popup
Post by: fapencio on August 01, 2014, 03:46:50 PM
Quote from: ‽ on August 01, 2014, 03:25:58 PM
o.O I have no idea what's hapened there. I'll see if I can find some time to investigate but I am pretty swamped with paid mod work right now.

i uninstall your mod, url popup, and I installed again, an now work perfect!!!!!!

but now I'm afraid to install the mod img popup  :(
Title: Re: URL Popup
Post by: Steve on August 01, 2014, 04:03:33 PM
Backup your database and try it. If it doesn't work, uninstall it and live without one or the other until he gets time to look at the problem. :P
Title: Re: URL Popup
Post by: fapencio on August 01, 2014, 04:36:43 PM
Quote from: Steve on August 01, 2014, 04:03:33 PM
Backup your database and try it. If it doesn't work, uninstall it and live without one or the other until he gets time to look at the problem. :P

I tested several modifications to the code until I came to the solution, it is important and mandatory to have installed both mods, both url popup as img popup when installing the second mod installation error which should ignore appear, then open the file called editor.js found in the Themes/default/scripts/editor.js route or in your forum theme, I leave the solution:

if you installed first URL POPUP and then IMG POPUP

in editor.js
search:
// URL popup?
if (oButtonProperties.sCode == 'url')
{
// Ask them where to link to.
var sText = prompt(oEditorStrings['prompt_text_url'], 'http://');
if (!sText)
return;

var sDesc = prompt(oEditorStrings['prompt_text_desc']);
if (!sDesc || sDesc == '')
sDesc = sText;

var bbcode = '[url=' + sText + ']' + sDesc + '[/url]';
replaceText(bbcode.replace(/\\n/g, '\n'), this.oTextHandle);
}
// Replace?
else if (!('sAfter' in oButtonProperties) || oButtonProperties.sAfter == null)


replace:
// URL popup?
if (oButtonProperties.sCode == 'url')
{
// Ask them where to link to.
var sText = prompt(oEditorStrings['prompt_text_url'], 'http://');
if (!sText)
return;

var sDesc = prompt(oEditorStrings['prompt_text_desc']);
if (!sDesc || sDesc == '')
sDesc = sText;

var bbcode = '[url=' + sText + ']' + sDesc + '[/url]';
replaceText(bbcode.replace(/\\n/g, '\n'), this.oTextHandle);
}
// IMG popup?
else if (oButtonProperties.sCode == 'img')
{
// Ask them where to link to.
var sText = prompt(oEditorStrings['prompt_text_url'], 'http://');
if (!sText)
return;

var bbcode = '[img]' + sText + '[/img]';
replaceText(bbcode.replace(/\\n/g, '\n'), this.oTextHandle);
}
// Replace?
else if (!('sAfter' in oButtonProperties) || oButtonProperties.sAfter == null)


if you installed first IMG POPUP and then URL POPUP

in editor.js
search:
// IMG popup?
if (oButtonProperties.sCode == 'img')
{
// Ask them where to link to.
var sText = prompt(oEditorStrings['prompt_text_url'], 'http://');
if (!sText)
return;

var bbcode = '[img]' + sText + '[/img]';
replaceText(bbcode.replace(/\\n/g, '\n'), this.oTextHandle);
}
// Replace?
else if (!('sAfter' in oButtonProperties) || oButtonProperties.sAfter == null)


replace:
// IMG popup?
if (oButtonProperties.sCode == 'img')
{
// Ask them where to link to.
var sText = prompt(oEditorStrings['prompt_text_url'], 'http://');
if (!sText)
return;

var bbcode = '[img]' + sText + '[/img]';
replaceText(bbcode.replace(/\\n/g, '\n'), this.oTextHandle);
}

// URL popup?
else if (oButtonProperties.sCode == 'url')
{
// Ask them where to link to.
var sText = prompt(oEditorStrings['prompt_text_url'], 'http://');
if (!sText)
return;

var sDesc = prompt(oEditorStrings['prompt_text_desc']);
if (!sDesc || sDesc == '')
sDesc = sText;

var bbcode = '[url=' + sText + ']' + sDesc + '[/url]';
replaceText(bbcode.replace(/\\n/g, '\n'), this.oTextHandle);
}
// Replace?
else if (!('sAfter' in oButtonProperties) || oButtonProperties.sAfter == null)


thats all, best regards
Title: Re: URL Popup
Post by: CarefreeSadie on August 05, 2014, 04:09:21 PM
Thank you very much for creating this mod.  I like it a lot.
Title: Re: URL Popup
Post by: Taifuuni on August 18, 2014, 10:09:08 AM
Anyway to modify this to automatically input selected text to the URL name input box?

I mean this:

1. Write something.
2. Highlight a word/words.
3. Press URL button.
4. URL popup appears and you input the URL you want.
5. You press OK and in the URL name input box, you already have the word/words you have highlighted on step 2.
6. You press OK and you get the proper url bbcode.
Title: Re: URL Popup
Post by: Arantor on August 18, 2014, 10:51:58 AM
IIRC it would need a rewrite to do that and I don't have time at present, sorry.
Title: Re: URL Popup
Post by: CarefreeSadie on August 26, 2014, 03:05:12 PM
Thank you very much for this mod.  I used one before and now after moving to 2.08 I have installed this one.  It works perfectly and the users are happy.  Thank you again.
Title: Re: URL Popup
Post by: unseenua on October 01, 2014, 04:04:06 AM
Quote from: Taifuuni on August 18, 2014, 10:09:08 AM
Anyway to modify this to automatically input selected text to the URL name input box?

I mean this:

1. Write something.
2. Highlight a word/words.
3. Press URL button.
4. URL popup appears and you input the URL you want.
5. You press OK and in the URL name input box, you already have the word/words you have highlighted on step 2.
6. You press OK and you get the proper url bbcode.

You can do it by self. Here are how I did this:

1. Open editor.js and add to beginning this code:


/* Here we get selected text for URL popup when RichText is in Disabled mode */
function getSelectionText() {
    var text = "";
    if (window.getSelection) {
        text = window.getSelection().toString();
    } else if (document.selection && document.selection.type != "Control") {
        text = document.selection.createRange().text;
    }
    return text;
}


2. Find string "URL popup?" and replace the code below on this one:

// URL popup?
if (oButtonProperties.sCode == 'url')
{
// Ask them where to link to.
var sText = prompt(oEditorStrings['prompt_text_url'], 'http://');
if (!sText)
return;

var sDesc = getSelectionText();
if (!sDesc || sDesc == '')
var sDesc = prompt(oEditorStrings['prompt_text_desc']);
if (!sDesc || sDesc == '')
sDesc = sText;

var bbcode = '[url=' + sText + ']' + sDesc + '[/url]';
replaceText(bbcode.replace(/\\n/g, '\n'), this.oTextHandle);
}


How it works.
Initially, the script checks to see if the selected text. If it is, it takes it as a description. If no text has been selected, the dialog box appears in which the user is prompted to enter a description. If the user does not enter a description and click OK, script insert raw URL as link anchor.

P.S. Code of function getSelectionText I took from stackoverflow.com (http://stackoverflow.com/questions/5379120/get-the-highlighted-selected-text)
Title: Re: URL Popup
Post by: dougiefresh on December 29, 2014, 07:06:19 PM
Hey, Arantor....  I was wondering if I could get permission from you to use a variation of this mod in order to add a URL prompt to my Sports bbcode mod.  I need it to get the URL from the user, then the mod would go to that URL and get the video ID cause it's just a world of pain to try to find it manually for that particular website....

Thanks in advance for your time!
Title: Re: URL Popup
Post by: Arantor on December 29, 2014, 07:10:45 PM
Go nuts :)
Title: Re: URL Popup
Post by: dougiefresh on December 30, 2014, 04:00:58 AM
Cool!  Thanks!
Title: Re: URL Popup
Post by: bjornforum on January 26, 2015, 06:17:31 AM
The code from unseenua doesn't seem to work in Firefox and IE. I found this alternative[/url] (in the answer) that works also in IE and Firefox:

function getSelectionText() {
    if (window.getSelection) {
        try {
            var ta = $('textarea').get(0);
            return ta.value.substring(ta.selectionStart, ta.selectionEnd);
        } catch (e) {
            console.log('Cant get selection text')
        }
    }
    // For IE
    if (document.selection && document.selection.type != "Control") {
        return document.selection.createRange().text;
    }
}


P.S. I would like to link to my source but am not allowed to post external links..
Title: Re: URL Popup
Post by: live627 on January 26, 2015, 07:23:53 PM
Quote from: bjornforum on January 26, 2015, 06:17:31 AM
P.S. I would like to link to my source but am not allowed to post external links..
You can now that you've made a post.
Title: Re: URL Popup
Post by: Chas Large on May 31, 2015, 07:05:53 AM
Just been alerted to and proved that this mod causes the Safari Browser on and iPad to close when the button is clicked. Using it in Chrome on an iPad just freezes Chrome with the popup window visible, can't click OK or Cancel.

Am just installing Safari on a Win 8.1 box to test and will report.

My and my friend's iPads both show the same issue, we're both on iOS 8.3
Title: Re: URL Popup
Post by: Westwegoman on May 31, 2015, 10:01:34 PM
Just tested on Safari on iPhone running iOS 8.3 and it crashed.
Title: Re: URL Popup
Post by: Robomcd on March 01, 2016, 01:37:19 PM
Thanks, just installed it. Works great for our not-internet savvy target group   ;D
Title: Re: URL Popup
Post by: Chas Large on April 30, 2016, 01:19:58 PM
Hi Arantor,

Any way to remove the "http://" from the input box? We have many users with tablets that do not automatically overwrite it when pasting in a URL. Works OK on a PC as it's pre highlighted but with iPad and some other devices the highlighting is cancelled when pasting in the URL so you get two "http://"s and have to edit the box. Seems a bit superfluous anyway when copying and pasting a URL, as they always have the http:// included even if it does not show in the address bar.

I tried changing this:


var sText = prompt(oEditorStrings['prompt_text_url'], 'http://');


to this


var sText = prompt(oEditorStrings['prompt_text_url'], '');


but it made no difference, the http:// was still there.

I uninstalled the mod and edited the editor j script file to remove all hard coded 'http://' s but still there so gave up.

I don't use the WYSIWYG editor at all. I checked the BBC code too for the button but editing that to failed to remove the http:// from the box so reinstalled your mod and told folk to edit the dialog but it would be nice to be able to remove it.

If it's simply, no, can't be done then fair enough but had to ask.

Thanks
Chas.
Title: Re: URL Popup
Post by: Arantor on April 30, 2016, 02:15:11 PM
That should generally do it for non WYSIWYG but if you only edited the file, you might still be using an old cache version, so edit it then do a hard refresh or clear your cache manually.
Title: Re: URL Popup
Post by: Chas Large on May 02, 2016, 04:19:07 PM
Quote from: Arantor on April 30, 2016, 02:15:11 PM
That should generally do it for non WYSIWYG but if you only edited the file, you might still be using an old cache version, so edit it then do a hard refresh or clear your cache manually.

Arghhh, the dreaded cache. I did clear the browser cache but not the forum cache. Doing both and reloading did indeed do the job.

Thanks.
Title: Re: URL Popup
Post by: -Rock Lee- on May 07, 2016, 01:33:19 PM
@Arantor It looks little but here I leave the translation to the Latin Spanish ... I'll use it without hesitation to something I have in mind!

Modifications.spanish_latin-utf8.php and Modifications.spanish_latin.php
$txt['prompt_text_desc'] = 'Por favor, introduzca el texto de lo que debe decir el enlace.';


Regards!
Title: Re: URL Popup
Post by: Jade Elizabeth on September 11, 2016, 06:42:30 AM
Hmm I've installed this but I can't get it to work. I've got WYSIWYG disabled across the board because people paste some weird stuff and it is a disaster so I know it's not that. I don't have any other BBC mods installed either. Any tips? I can't find any settings either. Using Chrome if that makes a difference (but I sure hope not) :).
Title: Re: URL Popup
Post by: DJ Doena on October 30, 2016, 05:27:41 AM
Hi,

just installed it on 2.0.12. Unfortunately it simply overwrites any selected text and asks for a new description. Is there an updated version of this mod that already contains the "GetSelectedText" feature?
Title: Re: URL Popup
Post by: Kolya on March 04, 2017, 08:04:43 AM
This uses the selected text to create a link. It only prompts for linktext if no text was selected before.
Tested in Firefox, Chrome and IE 11.
Title: Re: URL Popup
Post by: Dwev on January 12, 2018, 05:58:56 AM
@ Kolya: I tested the version listed on the Mod-page and was pretty happy with it.

Luckily I checked this thread as well, because this version is even better, thank you very, very much!   ;D
Title: Re: URL Popup
Post by: franhaselden on January 14, 2018, 02:12:20 PM
Just gave the 1.0.3 and don't see any change... Using WYSIWG. Any ideas how to debug?
Title: Re: URL Popup
Post by: Kolya on January 14, 2018, 02:37:54 PM
Uninstall the previous version, install 1.0.3.
Select some text in the editor, click the link button. Enter a URL.
The text you selected is used as link-text.
Title: Re: URL Popup
Post by: -Rock Lee- on February 12, 2018, 08:10:10 PM
Luckily I found it again I had lost it from my bookmarks :'(


Regards!