News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

URL Popup

Started by Arantor, February 03, 2014, 01:52:22 PM

Previous topic - Next topic

Arantor

Link to Mod

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

meetdilip


Arantor

The really odd thing is I wrote this almost 4 years ago just never published it here...

Jeffrey King


NekoJonez

I don't get this working nicely.
Retro video game blogger, writer, actor, podcaster and general amazing dude.

Twitter
My Blog

Arantor

I don't know what you mean.

NekoJonez

When I click on the URL button, I don't get the pop-up. And I don't get the description thing.
Retro video game blogger, writer, actor, podcaster and general amazing dude.

Twitter
My Blog

Arantor


NekoJonez

No. But when I use it, it only give me the normal pop up and not for the description .
Retro video game blogger, writer, actor, podcaster and general amazing dude.

Twitter
My Blog

Arantor

That sounds like you're using WYSIWYG...

NekoJonez

I see. Well, maybe I might try to install this mod again.
Retro video game blogger, writer, actor, podcaster and general amazing dude.

Twitter
My Blog

Arantor

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)

von COLLINZO

Nice mod, Sir Cumber....

Been looking for a way to get this fixed in my forum.....thanks alot! :D

AllMassive

Finally there it is - thank you !

Mr.Truckman


ApplianceJunk


Mike L

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  :)

margarett

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.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor

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.

IMSassafras

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
It is not for him to pride himself who loveth his own country, but rather for him who loveth the whole world. The earth is but one country, and mankind its citizens. ~ Bahá'u'lláh
________________________
MisFiT City Forum - Where Attitudes are Nourished and Being a MisFiT is Just Part of the Day!
Say NO to MSG.com - Dedicated to creating public awareness of Monosodium Glutamate and other excitotoxins.

radu81

Simple and powerful, thank you Arantor!
sorry for my bad english

Buneduggy

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.

fapencio

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

My smf forum is 2.0.10 version
my theme is default
language spanish es utf8

Arantor

What other mods are you using? This does not happen when this is the only mod installed.

fapencio

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
My smf forum is 2.0.10 version
my theme is default
language spanish es utf8

Arantor

Does it behave if you uninstall img popup?

fapencio

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:



help please (i uninstall img popup)
My smf forum is 2.0.10 version
my theme is default
language spanish es utf8

Arantor

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.

fapencio

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  :(
My smf forum is 2.0.10 version
my theme is default
language spanish es utf8

Steve

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
DO NOT pm me for support!

fapencio

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
My smf forum is 2.0.10 version
my theme is default
language spanish es utf8

CarefreeSadie

Thank you very much for creating this mod.  I like it a lot.

Taifuuni

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.

Arantor

IIRC it would need a rewrite to do that and I don't have time at present, sorry.

CarefreeSadie

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.

unseenua

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 hxxp:stackoverflow.com/questions/5379120/get-the-highlighted-selected-text [nonactive]

dougiefresh

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!

Arantor


dougiefresh


bjornforum

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..

live627

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.

Chas Large

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
My Modifications :)  My Forum

Please DO NOT PM me with support requests. Post the problem in the appropriate Support Board so everyone can benefit from the advice given.

Westwegoman

Just tested on Safari on iPhone running iOS 8.3 and it crashed.

Robomcd

Thanks, just installed it. Works great for our not-internet savvy target group   ;D

Chas Large

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.
My Modifications :)  My Forum

Please DO NOT PM me with support requests. Post the problem in the appropriate Support Board so everyone can benefit from the advice given.

Arantor

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.

Chas Large

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.
My Modifications :)  My Forum

Please DO NOT PM me with support requests. Post the problem in the appropriate Support Board so everyone can benefit from the advice given.

-Rock Lee-

@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!
¡Regresando como cual Fenix! ~ Bomber Code
Ayudas - Aportes - Tutoriales - Y mucho mas!!!

Jade Elizabeth

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) :).
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

DJ Doena

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?

Kolya

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.

Dwev

@ 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

franhaselden

Just gave the 1.0.3 and don't see any change... Using WYSIWG. Any ideas how to debug?

Kolya

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.

-Rock Lee-

Luckily I found it again I had lost it from my bookmarks :'(


Regards!
¡Regresando como cual Fenix! ~ Bomber Code
Ayudas - Aportes - Tutoriales - Y mucho mas!!!

Advertisement: