Announcement

Do not use the forums to submit bug reports, feature requests or patches, submit a New Ticket instead.

#1 2007-12-17 09:19:47

returner
New member
Registered: 2007-12-17
Posts: 2

method to replace contents within specified DIV?

Hi,

A few things I would like to achieve but don't know which method to use;


(1) To be able replace the entire contents within a specified DIV;

<div id="content">
To dynamically replace anything within this div with another chunk of contents.
</div>

In the same fashion of insertHTML, where codes could be inserted from the cursor position in wysiwyg mode, but in this case, the cursor position is not important.  We just need to replace *all* contents within the specified DIV based on its id.


(2) Is there a method to clear *all html* in the xinha editor?

(3) Like insertHTML method where cursor position is used, but what I need now is to insert HTML codes *appending* after the position of the last item in a specified DIV.

Would appreciate any advise on these areas... many thanks in advance...


Regards,
Samuel

Offline

#2 2007-12-19 16:59:09

Practicality
Xinha Community Member
Registered: 2007-02-15
Posts: 24

Re: method to replace contents within specified DIV?

For #1 and #3,
These appear to be some decent custom functions. Not too difficult to do in JavaScript. However, I don't believe they already exist. Why not write add them to your local copy?

For #2: Why not just use CTRL-A + DELETE?

Offline

#3 2007-12-19 22:19:55

returner
New member
Registered: 2007-12-17
Posts: 2

Re: method to replace contents within specified DIV?

Practicality... many thanks for your writing;

We tried for a while trying some of the xinha methods using javascript, but to no avail. For example, methods like insertHTML is rather straight forward and works well.  But other methods like selectNodecontents simply would not work.  I wonder if there are issues with the syntax in the way we use these methods, especially those that are used to do text manipulation within xinha. 

I think what we need is to select that chunk of text first, and then use the insertHTML method to replace them with our own contents.  Could anyone post a workable piece of code that could work?  Really appreciate it.  Thanks again...

Offline

#4 2007-12-20 18:03:57

Practicality
Xinha Community Member
Registered: 2007-02-15
Posts: 24

Re: method to replace contents within specified DIV?

I don't exactly understand what you are trying to do with the interface, but there are some functions for finding a cursor location in a textarea.

Here is a function to set the selection range (Not my code though):

function setSelRange(inputEl, selStart, selEnd) { 
 if (inputEl.setSelectionRange) { 
  inputEl.focus(); 
  inputEl.setSelectionRange(selStart, selEnd); 
 } else if (inputEl.createTextRange) { 
  var range = inputEl.createTextRange(); 
  range.collapse(true); 
  range.moveEnd('character', selEnd); 
  range.moveStart('character', selStart); 
  range.select(); 
 } 
}

Or you could try looking into this:
http://alexking.org/blog/2003/06/02/ins … avascript/

That should at least get you started in the right direction.

Last edited by Practicality (2007-12-20 18:10:27)

Offline

Board footer

Powered by FluxBB