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
https://forums.phpfreaks.com/topic/71904-applying-tags-to-selected-text/
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);	
}

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.