SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Javascript PHPBB editor problem

    Somehow the code below invokes a prompt asking for the url and text when u click the URL button, while in the orginal editor, it doesn't.

    BTW i cleared all the caches...

    Can someone help me figure out whats wrong?

    Code:
    // Startup variables
    var imageTag = false;
    var theSelection = false;
    
    var bbcodeEnabled = true;
    // Check for Browser & Platform for PC & IE specific bits
    // More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
    var clientPC = navigator.userAgent.toLowerCase(); // Get client info
    var clientVer = parseInt(navigator.appVersion); // Get browser version
    
    var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1));
    var is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1));
    var baseHeight;
    
    /**
    * Shows the help messages in the helpline window
    */
    function helpline(help)
    {
    	document.forms[form_name].helpbox.value = help_line[help];
    }
    
    /**
    * Fix a bug involving the TextRange object. From
    * http://www.frostjedi.com/terra/scripts/demo/caretBug.html
    */ 
    function initInsertions() 
    {
    	var doc;
    
    	if (document.forms[form_name])
    	{
    		doc = document;
    	}
    	else 
    	{
    		doc = opener.document;
    	}
    
    	var textarea = doc.forms[form_name].elements[text_name];
    
    	if (is_ie && typeof(baseHeight) != 'number')
    	{
    		textarea.focus();
    		baseHeight = doc.selection.createRange().duplicate().boundingHeight;
    
    		if (!document.forms[form_name])
    		{
    			document.body.focus();
    		}
    	}
    }
    
    /**
    * bbstyle
    */
    function bbstyle(bbnumber)
    {	
    	if (bbnumber != -1)
    	{
    		bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]);
    	} 
    	else 
    	{
    		insert_text('[*]');
    		document.forms[form_name].elements[text_name].focus();
    	}
    }
    
    /**
    * Apply bbcodes
    */
    function bbfontstyle(bbopen, bbclose)
    {
    	theSelection = false;
    
    	var textarea = document.forms[form_name].elements[text_name];
    
    	textarea.focus();
    
    	if ((clientVer >= 4) && is_ie && is_win)
    	{
    		// Get text selection
    		theSelection = document.selection.createRange().text;
    
    		if (theSelection)
    		{
    			// Add tags around selection
    			document.selection.createRange().text = bbopen + theSelection + bbclose;
    			document.forms[form_name].elements[text_name].focus();
    			theSelection = '';
    			return;
    		}
    	}
    	else if (document.forms[form_name].elements[text_name].selectionEnd && (document.forms[form_name].elements[text_name].selectionEnd - document.forms[form_name].elements[text_name].selectionStart > 0))
    	{
    		mozWrap(document.forms[form_name].elements[text_name], bbopen, bbclose);
    		document.forms[form_name].elements[text_name].focus();
    		theSelection = '';
    		return;
    	}
    	
    	//The new position for the cursor after adding the bbcode
    	var caret_pos = getCaretPosition(textarea).start;
    	var new_pos = caret_pos + bbopen.length;		
    
    	// Open tag
    	if (bbopen == '[img]')
    	{
    		var IMG = prompt('Insert Image URL' , 'http://');
    		if (IMG) {
    			insert_text(bbopen + IMG + bbclose);
    		}
    		else {
    			insert_text(bbopen + bbclose);
    		}
    	}
    	else {
    	insert_text(bbopen + bbclose);
            }
    
    	// Center the cursor when we don't have a selection
    	// Gecko and proper browsers
    	if (!isNaN(textarea.selectionStart))
    	{
    		textarea.selectionStart = new_pos;
    		textarea.selectionEnd = new_pos;
    	}	
    	// IE
    	else if (document.selection)
    	{
    		var range = textarea.createTextRange(); 
    		range.move("character", new_pos); 
    		range.select();
    		storeCaret(textarea);
    	}
    
    	textarea.focus();
    	return;
    }
    
    /**
    * Insert text at position
    */
    function insert_text(text, spaces, popup)
    {
    	var textarea;
    	
    	if (!popup) 
    	{
    		textarea = document.forms[form_name].elements[text_name];
    	} 
    	else 
    	{
    		textarea = opener.document.forms[form_name].elements[text_name];
    	}
    	if (spaces) 
    	{
    		text = ' ' + text + ' ';
    	}
    	
    	if (!isNaN(textarea.selectionStart))
    	{
    		var sel_start = textarea.selectionStart;
    		var sel_end = textarea.selectionEnd;
    
    		mozWrap(textarea, text, '')
    		textarea.selectionStart = sel_start + text.length;
    		textarea.selectionEnd = sel_end + text.length;
    	}
    	else if (textarea.createTextRange && textarea.caretPos)
    	{
    		if (baseHeight != textarea.caretPos.boundingHeight) 
    		{
    			textarea.focus();
    			storeCaret(textarea);
    		}
    
    		var caret_pos = textarea.caretPos;
    		caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text;
    	}
    	else
    	{
    		textarea.value = textarea.value + text;
    	}
    	if (!popup) 
    	{
    		textarea.focus();
    	}
    }
    
    /**
    * Add inline attachment at position
    */
    function attach_inline(index, filename)
    {
    	insert_text('[attachment=' + index + ']' + filename + '[/attachment]');
    	document.forms[form_name].elements[text_name].focus();
    }
    
    /**
    * Add quote text to message
    */
    function addquote(post_id, username)
    {
    	var message_name = 'message_' + post_id;
    	var theSelection = '';
    	var divarea = false;
    
    	if (document.all)
    	{
    		divarea = document.all[message_name];
    	}
    	else
    	{
    		divarea = document.getElementById(message_name);
    	}
    
    	// Get text selection - not only the post content :(
    	if (window.getSelection)
    	{
    		theSelection = window.getSelection().toString();
    	}
    	else if (document.getSelection)
    	{
    		theSelection = document.getSelection();
    	}
    	else if (document.selection)
    	{
    		theSelection = document.selection.createRange().text;
    	}
    
    	if (theSelection == '' || typeof theSelection == 'undefined' || theSelection == null)
    	{
    		if (divarea.innerHTML)
    		{
    			theSelection = divarea.innerHTML.replace(/<br>/ig, '\n');
    			theSelection = theSelection.replace(/<br\/>/ig, '\n');
    			theSelection = theSelection.replace(/&lt\;/ig, '<');
    			theSelection = theSelection.replace(/&gt\;/ig, '>');
    			theSelection = theSelection.replace(/&amp\;/ig, '&');
    			theSelection = theSelection.replace(/&nbsp\;/ig, ' ');
    		}
    		else if (document.all)
    		{
    			theSelection = divarea.innerText;
    		}
    		else if (divarea.textContent)
    		{
    			theSelection = divarea.textContent;
    		}
    		else if (divarea.firstChild.nodeValue)
    		{
    			theSelection = divarea.firstChild.nodeValue;
    		}
    	}
    
    	if (theSelection)
    	{
    		if (bbcodeEnabled)
    		{
    			insert_text('
    Quote Originally Posted by ' + username + '
    ' + theSelection + '
    '); } else { var lines = split_lines(theSelection); for (i = 0; i < lines.length; i++) { insert_text('> ' + lines[i] + '\n') } } } return; } function split_lines(text) { var lines = text.split('\n'); var splitLines = new Array(); var j = 0; for(i = 0; i < lines.length; i++) { if (lines[i].length <= 80) { splitLines[j] = lines[i]; j++; } else { var line = lines[i]; do { var splitAt = line.indexOf(' ', 80); if (splitAt == -1) { splitLines[j] = line; j++ } else { splitLines[j] = line.substring(0, splitAt); line = line.substring(splitAt); j++; } } while(splitAt != -1) } } return splitLines; } /** * From http://www.massless.org/mozedit/ */ function mozWrap(txtarea, open, close) { var selLength = (typeof(txtarea.textLength) == 'undefined') ? txtarea.value.length : txtarea.textLength; var selStart = txtarea.selectionStart; var selEnd = txtarea.selectionEnd; var scrollTop = txtarea.scrollTop; if (selEnd == 1 || selEnd == 2) { selEnd = selLength; } var s1 = (txtarea.value).substring(0,selStart); var s2 = (txtarea.value).substring(selStart, selEnd) var s3 = (txtarea.value).substring(selEnd, selLength); txtarea.value = s1 + open + s2 + close + s3; txtarea.selectionStart = selStart + open.length; txtarea.selectionEnd = selEnd + open.length; txtarea.focus(); txtarea.scrollTop = scrollTop; return; } /** * Insert at Caret position. Code from * http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130 */ function storeCaret(textEl) { if (textEl.createTextRange) { textEl.caretPos = document.selection.createRange().duplicate(); } } /** * Color pallette */ function colorPalette(dir, width, height) { var r = 0, g = 0, b = 0; var numberList = new Array(6); var color = ''; numberList[0] = '00'; numberList[1] = '40'; numberList[2] = '80'; numberList[3] = 'BF'; numberList[4] = 'FF'; document.writeln('<table cellspacing="1" cellpadding="0" border="0">'); for (r = 0; r < 5; r++) { if (dir == 'h') { document.writeln('<tr>'); } for (g = 0; g < 5; g++) { if (dir == 'v') { document.writeln('<tr>'); } for (b = 0; b < 5; b++) { color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]); document.write('<td bgcolor="#' + color + '" style="width: ' + width + 'px; height: ' + height + 'px;">'); document.write('<a href="#" onclick="bbfontstyle(\'[color=#' + color + ']\', \'[/color]\'); return false;"><img src="images/spacer.gif" width="' + width + '" height="' + height + '" alt="#' + color + '" title="#' + color + '" /></a>'); document.writeln('</td>'); } if (dir == 'v') { document.writeln('</tr>'); } } if (dir == 'h') { document.writeln('</tr>'); } } document.writeln('</table>'); } /** * Caret Position object */ function caretPosition() { var start = null; var end = null; } /** * Get the caret position in an textarea */ function getCaretPosition(txtarea) { var caretPos = new caretPosition(); // simple Gecko/Opera way if(txtarea.selectionStart || txtarea.selectionStart == 0) { caretPos.start = txtarea.selectionStart; caretPos.end = txtarea.selectionEnd; } // dirty and slow IE way else if(document.selection) { // get current selection var range = document.selection.createRange(); // a new selection of the whole textarea var range_all = document.body.createTextRange(); range_all.moveToElementText(txtarea); // calculate selection start point by moving beginning of range_all to beginning of range var sel_start; for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++) { range_all.moveStart('character', 1); } txtarea.sel_start = sel_start; // we ignore the end value for IE, this is already dirty enough and we don't need it caretPos.start = txtarea.sel_start; caretPos.end = txtarea.sel_start; } return caretPos; }
    Thanks

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Where did you source the code form, and do you have a test page?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the source is here: http://pn0.ru/styles/prosilver/template/editor-js.html

    sure ill make a dummy account for you to test making a post

    user: pmw57
    pass: test123

    then go to http://gameinfiniti.com/forum/posting.php?mode=post&f=5

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    When creating a test post, the url button requests the url and url text without apparent issue.

    What do you suggest that I do to experience the problem that you're facing?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Zealot
    Join Date
    Apr 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the problem is exactly that, it is so weird how theirs the url and text prompt when there is supposedly no backend code for that, i just want u to check the code.

    the only mention on the popup in the code is for images specifically, so i dont kno whats goin on here...

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    That particular code appears to be inline within the page.

    Code javascript:
    function BBCurl()
    {
       var FoundErrors = '';
       var enterURL   = prompt("Enter the URL", "http://");
       var enterTITLE = prompt("Enter the url text", "URL Text");
       if (!enterURL)    {
          FoundErrors += "You never wrote the URL ";
       }
       if (!enterTITLE)
       {
          FoundErrors += "You never wrote the URL Text";
       }
       if (FoundErrors)
       {
          alert("Error : "+FoundErrors);
          return;
       }
       var bbtags = "[url="+enterURL+"]"+enterTITLE+"[/url]";
       document.forms[form_name].elements[text_name].value+=bbtags;
       document.forms[form_name].elements[text_name].focus();
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Zealot
    Join Date
    Apr 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so where can i get rid of it?

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    If you are wanting to remove the ability for people to add urls, there are a couple of things you'll need to do.

    First, remove that BBCurl function mentioned above, and anything that relates to it, such as this URL button in the toolbar.

    Code html4strict:
    <input type="button" class="button2" accesskey="w" name="addbbcode16" value="URL" style="text-decoration: underline; width: 40px" onclick="BBCurl()" title="Insert URL: [url]http://url[/url] or [url=http://url]URL text[/url]" />

    Then there are other parts of that page that relate to urls, such as in the bbtags array

    Code javascript:
    var bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]','[flash=]', '[/flash]','[size=]','[/size]');

    and the helpline message

    Code javascript:
    w: 'Insert URL: [url]http://url[/url] or [url=http://url]URL text[/url]',

    and in the following message

    Code html4strict:
    [url] is <em>ON</em><br />
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    SitePoint Zealot
    Join Date
    Apr 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry to bother you but i dont want to remove the url function, just revert it back to normal, so when u click url u should get (url][/url)

  10. #10
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    In that case, you should be able to replace that BBCurl function with something like:

    Code javascript:
    function BBCurl()
    {
       var bbtags = '[url][/url]';
       document.forms[form_name].elements[text_name].value+=bbtags;
       document.forms[form_name].elements[text_name].focus();
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  11. #11
    SitePoint Zealot
    Join Date
    Apr 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i cant find the page where this is all located?

  12. #12
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    It is in the source code for http://gameinfiniti.com/forum/posting.php
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  13. #13
    SitePoint Zealot
    Join Date
    Apr 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so complicated, all i did was edit the editor.js and somehow it reflected on another file which i cant seem to find because of all the includes???

    >.<

  14. #14
    SitePoint Zealot
    Join Date
    Apr 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cool i got it, it turned out to be in another file, and i just copy and pasted ur code

    thanks =D


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •