News:

Wondering if this will always be free?  See why free is better.

Main Menu

URL Popup

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

Previous topic - Next topic

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

Advertisement: