views:

93

answers:

2

Hi there,

I'd like to be able to create a type of folding in xhtml textareas using Javascript/jQuery. For example, given the following text:

ABC [123] DEF

I'd like to have [123] reduce to [] when the cursor is not over it - i.e. for a cursor |:

ABC [] DEF|
AB|C [] DEF
ABC [|123] DEF
ABC [12|3] DEF

I want the content within the braces to be preserved, of course, when the item is folded in (ie when cursor exits the braces), and restored when it's folded out (cursor enters the braces).

I'd be very much obliged for thoughts on this.

Thank you.

Brian

+1  A: 

You might want to look at some Rich Text Editors implemented in JavaScript. If you look at the folding as an inline style sort of thing ( css display:none; }, I'm sure you could just add a rule to their syntax highlighting to get the folding to work without much effort.

10 jQuery and non-jQuery RTEs

You could also take a look at Mozilla's bespin Project (http://mozillalabs.com/bespin/). Can't post more links, little new to SO.

Scott R
A: 
$(function(){
  //Format on load
  $(".folding").html('[]');

  //Wire up load
  $(".folding").mouseover(function(){
    $(this).html('[' + $(this).attr("original") + ']');
  }).mouseout(function(){
    $(this).html('[]');
  });                   
});


<BODY>ABC <span class="folding" original='123'>[123]</span> DEF</BODY>

This should work for you. Not the most eloquent but delivers desired results.

jaredmroberts
@jaredmroberts: Thanks for the thoughts. While this allows folding for *mousover* of a **span**. This doesn't solve the *caret* over a section of a **textarea** problem though.
Brian M. Hunt