Cetanu Posted December 9, 2009 Share Posted December 9, 2009 So, I am working on this very small editing feature that I would like to behave like forums' BBCode insert things. I have searched high and low for a tutorial or something of the sort to detect where a caret is and then insert my code there.... ...I really want it to be slim, and it should work with a textarea. Any help? Thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/184576-insert-tags-at-caret/ Share on other sites More sharing options...
Cetanu Posted December 10, 2009 Author Share Posted December 10, 2009 Edit, I'm searching the forums...but additional help is welcome. Quote Link to comment https://forums.phpfreaks.com/topic/184576-insert-tags-at-caret/#findComment-974415 Share on other sites More sharing options...
.josh Posted December 10, 2009 Share Posted December 10, 2009 of course, this sort of assumes there's gonna be only 1 caret in the textarea... if not, you're going to be having something insert at every caret found... but you weren't very specific in your request, now were you. <textarea id='blah'>some ^ example</textarea> <script type='text/javascript'> var something = "random"; document.getElementById('blah').value = String(document.getElementById('blah').value).split('^').join(something); </script> Quote Link to comment https://forums.phpfreaks.com/topic/184576-insert-tags-at-caret/#findComment-974422 Share on other sites More sharing options...
Cetanu Posted December 10, 2009 Author Share Posted December 10, 2009 I meant the blinky caret that marks where the text is written (that's what it's called in several forum topics I've found). Quote Link to comment https://forums.phpfreaks.com/topic/184576-insert-tags-at-caret/#findComment-974465 Share on other sites More sharing options...
.josh Posted December 10, 2009 Share Posted December 10, 2009 oh. I call that a cursor. hmmmm.... Quote Link to comment https://forums.phpfreaks.com/topic/184576-insert-tags-at-caret/#findComment-974466 Share on other sites More sharing options...
.josh Posted December 10, 2009 Share Posted December 10, 2009 hmm well after some research, there's no "thin" way to do this. I would suggest you start by looking at the js for <insert forum of your choice here>. For instance, here is the js file for this board: http://www.phpfreaks.com/forums/Themes/default/scripts/script.js?rc2 starting around line 338 function storeCaret(..) Quote Link to comment https://forums.phpfreaks.com/topic/184576-insert-tags-at-caret/#findComment-974478 Share on other sites More sharing options...
Cetanu Posted December 10, 2009 Author Share Posted December 10, 2009 hmm well after some research, there's no "thin" way to do this. I would suggest you start by looking at the js for <insert forum of your choice here>. For instance, here is the js file for this board: http://www.phpfreaks.com/forums/Themes/default/scripts/script.js?rc2 starting around line 338 function storeCaret(..) Cool! That's helpful, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/184576-insert-tags-at-caret/#findComment-974481 Share on other sites More sharing options...
optikalefx Posted December 10, 2009 Share Posted December 10, 2009 Yes there is a way to easily do this go to google and type in MDC Selection anchorNode anchorOffset focusNode focusOffset You can use these 4 properties of the window.selection (even if there is no selection) and work it out that way. I don't remember exactly but i did this before and it worked. Maybe also take a look at MDC Range Quote Link to comment https://forums.phpfreaks.com/topic/184576-insert-tags-at-caret/#findComment-974548 Share on other sites More sharing options...
Cetanu Posted December 10, 2009 Author Share Posted December 10, 2009 Okay, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/184576-insert-tags-at-caret/#findComment-974770 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.