News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

URL popup for smf 2

Started by vulic, November 03, 2011, 07:24:53 AM

Previous topic - Next topic

vulic

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.

// 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;');
                }
            }
        }
    }
}

vulic

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

// 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;');
}
}
}

ApplianceJunk

QuoteThe 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

vulic

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.

Manu.G

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

vulic

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


Advertisement: