sKunKbad Posted October 5, 2007 Share Posted October 5, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/71904-applying-tags-to-selected-text/ Share on other sites More sharing options...
emehrkay Posted October 5, 2007 Share Posted October 5, 2007 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); } Quote Link to comment https://forums.phpfreaks.com/topic/71904-applying-tags-to-selected-text/#findComment-362237 Share on other sites More sharing options...
sKunKbad Posted October 5, 2007 Author Share Posted October 5, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/71904-applying-tags-to-selected-text/#findComment-362758 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.