Announcement

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

#1 2005-03-16 08:14:08

pee_cee
New member
Registered: 2005-03-16
Posts: 5

insertHTML question

I am using htmlarea 3 (not the xinha version - theres another thread about that!!).

I'm using several areas on one page, similar to the 2areas example. however i currently just looking at the 2areas example, removing any confusion with my code.

what i have done is changed a button to do insertHTML.

righttoleft: [ "Direction right to left", "ed_right_to_left.gif", false, function(e) {e.insertHTML("some text");} ]

when i click the button strange things happen.

if i have focus in the area, the text is inserted. If focus is in the 2nd area and i click the button on area 1, the text is inserted into area 2. if i click the button on area 2 with focus in area 1, the text is inserted in area 1. if neither have focus, the text is inserted on the main page.

what needs to be done to make the insertHTML command operate on the textarea that belongs to the button pressed - no matter where the focus is?

Thanks.

Offline

#2 2005-03-16 08:38:52

adamp
Xinha Pro
Registered: 2005-03-14
Posts: 77

Re: insertHTML question

I'm not sure it's possible to insert code away from the focus without writing a different function to do so specifically (though I'm no javascript expert).

The built-in functions like insertHTML and surroundHTML rely on focus to determine where to insert/what to surround afaik.

A solution may be to have a handler function to check where the focus is when the button is clicked. If it's not in the right area, move the focus. But as I said I'm no javascript guru, so there may be a simpler answer wink

Offline

#3 2005-03-16 09:05:41

pee_cee
New member
Registered: 2005-03-16
Posts: 5

Re: insertHTML question

ok thanks.
anyone know how to tell which textarea's button was clicked and move the focus to the textarea?

i've been poking, and the inserttable fucntion works as expected, no matter where the focus is. that seems to use pasteHTML. i'll look down that route...

Offline

#4 2005-03-16 09:28:22

pee_cee
New member
Registered: 2005-03-16
Posts: 5

Re: insertHTML question

ok it seems to be working with this code

var sel = this._getSelection();
        var range = this._createRange(sel);
        var editor = this;    // for nested functions
        var doc = editor._doc;

        var addendum = "inserted text"

        if (HTMLArea.is_ie) {
            range.pasteHTML(addendum);
        } else {
            editor.insertNodeAtSelection(addendum);
        }
        return true;

oh well!

Offline

#5 2005-03-30 13:01:07

JAC
Xinha Community Member
Registered: 2005-03-16
Posts: 11

Re: insertHTML question

What changes do I need to make to the Xinha code to get the old HTMLArea insertHTML function working?

With HTMLArea I could use:

    <a href="javascript:editor_insertHTML('content','[[month]]');">month</a>

to insert a short-cut for automatically-replaced fields in my CMS, but this no longer works with Xinha.

Any suggestions??

Thanks!
Gill

Offline

#6 2005-03-30 17:33:58

adamp
Xinha Pro
Registered: 2005-03-14
Posts: 77

Re: insertHTML question

Not so sure on using it in that context, but editor.insertHTML() should work (presuming you've declared editor as an HTMLArea somewhere)

Offline

#7 2005-03-31 03:13:38

niko
Xinha Authority
From: Salzburg/Austria
Registered: 2005-02-14
Posts: 338

Re: insertHTML question

...you use editor_inserHTML!
so do you have somewhere this function defined?
you might try editor.insertHTML (f you have editor defined)


Niko

Offline

#8 2005-03-31 06:55:59

JAC
Xinha Community Member
Registered: 2005-03-16
Posts: 11

Re: insertHTML question

Sorry, I don't understand Javascript and I've tried several different alternatives, but I don't know what I'm doing and I'm not making any progress. Any help you can give me, would be very gratefully received...

How do I declare/define editor as an HTMLarea? I've just installed Xinha by following the Newbie guide.

Does the function still exist? (It was a standard function in the old HTMLarea.)

Any other ideas about what I'm doing wrong or how to get the same result?

Thanks!

Offline

#9 2005-03-31 09:15:02

niko
Xinha Authority
From: Salzburg/Austria
Registered: 2005-02-14
Posts: 338

Re: insertHTML question

no, the functino doesn't exist, the funciton was just an example in the standard-example of htmlarea as far as i remembers.

if you used the newbieguide it may work like this:

xinha_editors['myTextArea'].insertHTML


Niko

Offline

#10 2005-03-31 09:45:52

JAC
Xinha Community Member
Registered: 2005-03-16
Posts: 11

Re: insertHTML question

Thanks Niko - much appreciated.

After much experimentation, I decided it was easier to create a plugin based on Character Map to do what I wanted.

So after a bit more experimentation, I am now the proud owner of an "InsertField" plugin. :-)

Offline

Board footer

Powered by FluxBB