Jump to content

applying tags to selected text


sKunKbad

Recommended Posts

I'm making a database-less CMS and would like buttons in the text editor to apply bold, italic, underline, and make hyperlinks. The functionality would be similar to buttons when posting here on phpfreaks, however, the tags will be html, not bbcode. Does anyone know of a tutorial of applying tags to selected text using javascript?

 

Thank you for any help or links.

Link to comment
Share on other sites

here is the code that i use to listen for key combos. the important code is inside of the if(sel) block

 

/*
* bold alt+7
*/
if(e.alt && (e.key == 7)){
	if(element){
		var start 		= element.selectionStart;
		var end			= element.selectionEnd;
		var sel 		= element.value.substring(start, end);
		if(sel == '')	sel = 'BOLD TEXT';
		var rep			= "<b>::</b>";
	}		
}

if(sel){
	var	parts		= rep.split('::');
	var content 	= parts[0] + sel + parts[1];
	element.value 	= element.value.substring(0, start) + content + element.value.substring(end, element.value.length);	
}

Link to comment
Share on other sites

I will check this out, but I found a couple of awesome scripts that will work perfectly for me. Actually, I already got both of them working last night. One is called FCKeditor, but it doesn't work on Win Safari when I tried it, so I'm not sure if it will work on other Safari browsers. The other is called TinyMCE, and it does work with Safari, but it is a bit clunky.

 

Thanks for your post emehrkay. I will try to make this work too, since I want to know what is best for me and my customers.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.