Advertisement:

Author Topic: URL popup for smf 2  (Read 3045 times)

Offline vulic

  • Newbie
  • *
  • Posts: 4
URL popup for smf 2
« on: November 03, 2011, 07:24:53 AM »
This is small code modification to show popup windows for http url and ftp url and then for the name of the url.

The modification is inspired by URL popup for smf 1.


My first message was little messy so I change the post.

The smf 2.0.1 default behavior.

1. When text selected and click on hyperlink button show popup window to enter the URL.The result look like this SMF forum.
2. When no text selected and click on hyperlink button show popup window to enter the URL. The result look like this http://www.simplemachines.org/community/index.php.

Behavior with the code modification.

1. When text selected and click on hyperlink button show popup window to enter the URL.The result look like this SMF forum.
2a. When no text selected and click on hyperlink button show popup window to enter the URL. Then show another popup window to enter the name for URL. If some text is entered the result look like this SMF forum.
2b. When no text selected and click on hyperlink button show popup window to enter the URL. Then show another popup window to enter the name for URL. If no text is entered the result look like this http://www.simplemachines.org/community/index.php.

The same, changed behavior is for the FTP link.

If you ask why change the default behavior. Answer is question. How many user no that he/she should select some text for pretty naming URL?
And in the end. Modification of the code does not destroy the default behavior. It adds the new option.


I change the code in file /Themes/default/scripts/editor.js line 807-842.

Code: [Select]
// Insert a URL link.
smc_Editor.prototype.insertLink = function(sType)
{
    if (sType == 'email')
        var sPromptText = oEditorStrings['prompt_text_email'];
    else if (sType == 'ftp')
        var sPromptText = oEditorStrings['prompt_text_ftp'];
    else
        var sPromptText = oEditorStrings['prompt_text_url'];

    // IE has a nice prompt for this - others don't.
    if (sType != 'email' && sType != 'ftp' && is_ie)
        this.smf_execCommand('createlink', true, sText);

    else
    {
        // Ask them where to link to.
        var sText = prompt(sPromptText, sType == 'email' ? '' : (sType == 'ftp' ? 'ftp://' : 'http://'));
        if (!sText)
            return;

        if (sType == 'email' && sText.indexOf('mailto:') != 0)
            {
            sText = 'mailto:' + sText;
            this.insertText('<a href="' + sText + '">' + sText + '</a>' + '&nbsp;');
            }
        else
        {
        // Check if we have text selected and if not force us to have some.
            var oCurText = this.getSelect(true, true);
            if (oCurText.toString().length != 0)
            {
                this.smf_execCommand('unlink');
                this.smf_execCommand('createlink', false, sText);
            }
            else // If no text selected show popup window to enter text.
            {
                var urlNAME = prompt('Enter URL name.Leave blank for straight URL.','');
                if (urlNAME == null )  //Cancel pressed.
                {
                }
                 else if (urlNAME == '' || urlNAME == ' ')  // OK pressed but with no text so use URL only.
                {
                    this.insertText('<a href="' + sText + '">' + sText + '</a>' + '&nbsp;');
                }
                else // OK pressed with text so use name for the URL.
                {
                    this.insertText('<a href="' + sText + '">' + urlNAME + '</a>' + '&nbsp;');
                }
            }
        }
    }
}
« Last Edit: November 04, 2011, 07:03:28 AM by vulic »

Offline vulic

  • Newbie
  • *
  • Posts: 4
Re: URL popup for smf 2
« Reply #1 on: November 04, 2011, 03:24:17 PM »
OK, I screw up text selecting for mail in previous code.
And second issue is IE. My code modification does not change default behavior for Internet Explorer.
My operating system is Debian stable and I have no Windows install. So I test Internet Explorer 7 under Wine in Debian.

This is fixed version of code. I fixed selecting text for mail and IE issue.
Code: [Select]
// Insert a URL link.
smc_Editor.prototype.insertLink = function(sType)
{
if (sType == 'email')
var sPromptText = oEditorStrings['prompt_text_email'];
else if (sType == 'ftp')
var sPromptText = oEditorStrings['prompt_text_ftp'];
else
var sPromptText = oEditorStrings['prompt_text_url'];
// Ask them where to link to.
var sText = prompt(sPromptText, sType == 'email' ? '' : (sType == 'ftp' ? 'ftp://' : 'http://'));
if (!sText)
return;
if (sType == 'email' && sText.indexOf('mailto:') != 0)
{
sText = 'mailto:' + sText;
}
// Check if we have text selected and if not ask for some text in second popup window.
var oCurText = this.getSelect(true, true);
if (oCurText.toString().length != 0)
{
this.smf_execCommand('unlink');
this.smf_execCommand('createlink', false, sText);
}
else if (sType == 'email')
{
this.insertText('<a href="' + sText + '">' + sText + '</a>' + '&nbsp');
}
else
{
var urlNAME = prompt('Enter URL name.Leave blank for straight URL.','');
if (urlNAME == null )  // Cancel pressed.
{
}
else if (urlNAME == '' || urlNAME == ' ')  // OK pressed but with no text so use URL only.
{
this.insertText('<a href="' + sText + '">' + sText + '</a>' + '&nbsp;');
}
else // OK pressed with text so use name for the URL.
{
this.insertText('<a href="' + sText + '">' + urlNAME + '</a>' + '&nbsp;');
}
}
}
« Last Edit: November 04, 2011, 03:29:57 PM by vulic »

Offline ApplianceJunk

  • SMF Hero
  • ******
  • Posts: 3,491
    • ApplianceJunk.com
Re: URL popup for smf 2
« Reply #2 on: November 04, 2011, 04:47:23 PM »
Quote
The modification is inspired by URL popup for smf 1.

Did you try to install that mod on SMF 2?
I think it may still work with 2.0

Offline vulic

  • Newbie
  • *
  • Posts: 4
Re: URL popup for smf 2
« Reply #3 on: November 04, 2011, 05:27:52 PM »
Yes I did. And it did't work. Then I try installing by hand but with no success. Code has changed a lot since version 1.

Offline Manu.G

  • Full Member
  • ***
  • Posts: 448
  • Gender: Female
  • Angel by Day, Devil by Night
    • http://facebook.com/manuela.guth on Facebook
    • Fan Community
Re: URL popup for smf 2
« Reply #4 on: November 11, 2011, 06:15:14 PM »
I was searching for this little popup, because my forum members screaming for it.
My problem is at the moment, what exactly did you replace with your code?

Is it possible to post a little instruction for it? For stupid cows like me :)
Version SMF 2.0.8
SimplePortal 2.3.5

Offline vulic

  • Newbie
  • *
  • Posts: 4
Re: URL popup for smf 2
« Reply #5 on: November 12, 2011, 03:34:20 PM »
 I explained everything in my first message. I don't know how to be more specific. English is not my native language.
 Default behavior is intact. I just added second pop up window to enter some text for URL address if no text is selected before. See again my first post section 2a and 2b.

edit: The correct code with modifications is in my second message.

edit 2: The modifications is for WYSIWYG editor. To change to WYSIWYG editor click on selected button.

« Last Edit: November 12, 2011, 04:12:53 PM by vulic »