How To Make This URL Popup Box Do What I want

Discussion in 'JavaScript' started by touchAshley, Jan 16, 2009.

  1. #1
    I am using this mod on my SMF forum.

    what it does is it creates a popup box to enter a url and some text for that url when people are posting/replying to a thread. Just like here on DP when using the "[​IMG]" button.

    However, it doesn't allow you to write something and highlight the text, and THEN click the url button to enter just the url.

    It always makes you enter the url, then the text for the url(even when highlighting text). How can I make it so that people are able to highlight text and then just enter the url? without it asking to enter the text? Just like here on DP :)

    Note: I still want it to ask for the text when people are not highlighting.

    Here is the two different codes that is being used (same file)

    
        // Java script to handle URL input boxes ...
        echo '<script language="JavaScript" type="text/javascript">
              // <!' . '--
              function urlINPT()
    		  {
              		// Enter URL .........................................
              		var urlLINK = prompt("Please enter URL address:","http://");
              		if (urlLINK == null )
    				{ 
    				 	//cancel pressed . . .
              		}
              		else if (urlLINK == "" || urlLINK == " ")
    				{ 
    				 	//ok pressed but with Notext . . .
              	        alert("Sorry no text entered!");
              		}
              		else
              		{	 
    				   	//ok pressed and there is something :)
              			// Enter Description ...................................
              			var urlNAME = prompt("Please enter URL name:","");
              			if (urlNAME == null )
    					{ 
    			 			//cancel pressed . . .
              			}
              			else if (urlNAME == "" || urlNAME == " ")
    					{  
    					 	//ok pressed but with notext so use URL only!
                        	surroundText(\'[url]\'+urlLINK+\'\', \'[/url]\', document.', $context['post_form'], '.', $context['post_box_name'], ');
              			}
              			else //ok pressed with text so use URL and Name!
                        surroundText(\'[url=\'+urlLINK+\']\'+urlNAME+\'\', \'[/url]\', document.', $context['post_form'], '.', $context['post_box_name'], ');
              		}
              }
              // --' . '>
              </script>';
    
    Code (markup):
    
          			// only replace the URL tag! . . . . . . . . . . .
          			if (isset($tag['code']) && $tag['code'] == 'url')
    				{
              			echo '<a href="javascript:void(0);" onclick="urlINPT(); return false;"><img onmouseover="bbc_highlight(this, true);" onmouseout="if (window.bbc_highlight) bbc_highlight(this, false);" src="', $settings['images_url'], '/bbc/', $image, '.gif" align="bottom" width="23" height="22" alt="', $tag['description'], '" title="', $tag['description'], '" border="0" style="background-image: url(', $settings['images_url'], '/bbc/bbc_bg.gif); margin: 1px 2px 1px 1px;" /></a>';
    					continue;
    				}
    
    Code (markup):
    Help is highly appreciated!
     
    touchAshley, Jan 16, 2009 IP
  2. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #2
    Is that from the file that is also used to do other BBcode functions? If so, maybe we can look into that and find out how they do it for other tags, and copy it.

    Want to post that whole file?

    Thanks :)
     
    crath, Jan 16, 2009 IP
  3. touchAshley

    touchAshley Active Member

    Messages:
    1,762
    Likes Received:
    85
    Best Answers:
    0
    Trophy Points:
    90
    #3
    Here's the code of the entire file for the post page

    
    http://www.stratocastertalk.com/view/Posttemplate.txt
    
    Code (markup):
     
    touchAshley, Jan 16, 2009 IP
  4. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #4
    I found this example out on the net, and they say it works
    <script type="text/javascript">
    function blah() {
       var ta = document.getElementById("test");
       if (document.selection) {
          str = document.selection.createRange().text
          document.selection.createRange().text = "[b]" + str + "[/b]";
          return true;
       }
       else if (ta.selectionStart) {
          var startPos = ta.selectionStart;
          var endPos = ta.selectionEnd;
          var str = ta.value.substring(startPos, endPos);
          ta.value = ta.value.substring(0, startPos) + "[b]" + str + "[/b]" + ta.value.substring(endPos, ta.value.length);
          return true;
       }
       else {
          return false;
       }
    }
    </script>
    <input type="button" value="Bold" onclick="blah()" />
    <br />
    <textarea id="test" style="height:150px">
    This is a test to see if the bold tags will work.
    </textarea>
    Code (markup):
    Maybe you can use the javascript functions they use to mod your current code to check for selected text? I'm not sure how javascript savvy you are so Good luck!

    also, it looks like around line 847 is where you want to look for the current url function
     
    crath, Jan 16, 2009 IP
  5. touchAshley

    touchAshley Active Member

    Messages:
    1,762
    Likes Received:
    85
    Best Answers:
    0
    Trophy Points:
    90
    #5
    Ah. I'm not exactly a java guy. Looking at the code, I really have no idea what I could do. Maybe if someone could tell me which part of that code makes it so that you can highlight text, click the button, and enter the url, then your're done
     
    touchAshley, Jan 16, 2009 IP
  6. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #6
    crath, Jan 16, 2009 IP