Menu

#99 OnChange() functionality

Version 2.x
open
nobody
Editor (144)
6
2005-04-08
2005-04-08
virmaior
No

I was in need of an OnChange functionality in
FCKEditor, being unable to find one, I wrote one:

changes need to be made to three files:

1. FCKeditor.HTML

insert the following before the </HEAD> tag and
</SCRIPT> from fck_startup.js

<script language="JavaScript" type="text/javascript">
foo = function() {
//this is the onchange evaluated function
top.document.getElementById("monkey").innerHTML =
FCK.GetHTML();
}
setTimeout('delayHook();',1000);
function delayHook()
{
FCK.SetOnChange(foo);
}
</script>

2. fckeditorcode_gecko_1.js:

2a. add the following line:
FCK.SetOnChange=function(x)
{FCK.Events.AttachEvent("OnKeyDown", x);};

2b. insert the following after: "var
oOnKeyDown=function(e){"

FCK.Events.FireEvent("OnKeyDown");

(right before "if (e.ctrlKey&&!e.shiftKey&&!e.altKey) );")

3. fckeditorcode_ie_1.js:

3a. add the following line:
FCK.SetOnChange=function(x)
{FCK.Events.AttachEvent("OnKeyDown", x);};

3b. insert the following after "function Doc_OnKeyDown()"

FCK.Events.FireEvent("OnKeyDown");

(right before "var e=FCK.EditorWindow.event;")

and there you have it, functional OnChange (actually
onaltered since it doesn't compare the two).

Discussion

  • virmaior

    virmaior - 2005-04-08
    • priority: 5 --> 6
     
  • Kosh

    Kosh - 2005-04-14

    Logged In: YES
    user_id=1259562

    Hmmm...

    I'm not sure how to insert this code but it is exactly what I
    need :(

    And which function is called if there something in the box
    changed? I don't know :(

    Can you help me?

    Greets
    Kosh

     
  • virmaior

    virmaior - 2005-04-14

    Logged In: YES
    user_id=1152592

    the files are under FCKeditor/

    the HTML file is /FCKeditor/editor/fckeditor.html

    the two js files you need to edit are:
    FCKeditor\editor\js\fckeditorcode_ie_1.js
    and
    FCKeditor\editor\js\fckeditorcode_gecko_1.js

    I'm not sure how I else I can really help at this point.

    there's still some misisng functionality from the onchange
    function. you have to put the function you call for
    onchange inside of the fckeditor.html file... I don't know
    how to break out of this yet.

     
  • Kosh

    Kosh - 2005-04-14

    Logged In: YES
    user_id=1259562

    Thanks for the very fast (!!!) answer.

    I see where I should edit the files but in the HTML-File I don't
    know where or which function is called if something is
    changed...

    Can you write an example code how it should look like in the
    html-file javascript part when I want to give an alertbox
    whenever someone typed a char?

    Thanks in advance!
    Kosh

     
  • virmaior

    virmaior - 2005-04-14

    Logged In: YES
    user_id=1152592

    the function that gets called right now is
    foo

    it will call whatever the contents of the FCK.SetOnChange()
    function is.

    I don't know how to get it out of the editor,

    the one that I'm using right now is:

    foo = function() {
    if (top.document.getElementById("altered")) {
    top.document.getElementById("altered").value = 1; }
    }

    the delayhook is necessary so that the variable will
    actually be there in time to do the connecting.

    in my own page (the top document), I have a hidden input
    named altered that I check to see if it's -1, if it isn't -1
    then it's changed.

     
  • Kosh

    Kosh - 2005-04-14

    Logged In: YES
    user_id=1259562

    I don't know what I do wrong but it does not work...

    It alway gives an error out.. whatever I try :/

    Greets
    Kosh

     
  • Kosh

    Kosh - 2005-04-14

    Logged In: YES
    user_id=1259562

    Now I've found out that it works with Netscape 7 and Firefox...
    But it does not work with Internet Explorer... some ideas ?

     
  • virmaior

    virmaior - 2005-04-19

    Logged In: YES
    user_id=1152592

    sorry, I missed your comments...
    (this probably won't be helpful but ...) what is the error
    message on IE?

    also, did you remember to clear the cache (the FCK editor js
    files have a horrid tendency to never leave the computer)

     
  • Kosh

    Kosh - 2005-04-20

    Logged In: YES
    user_id=1259562

    Hi :)

    There wasn't an error... But I checked the source of fckeditor
    and found the reason:

    https://sourceforge.net/forum/message.php?msg_id=3104445

    Thanks anyway for your support...

     
  • Nobody/Anonymous

    Logged In: NO

    Do you know if I can execute onChange the execute method
    of some plugin or button?

    Thanks.

     
  • Nobody/Anonymous

    Logged In: NO

    In 2.0 FC the instructions don't work.
    2a is fine, but 2b should be:

    paste

    var oOnKeyDown = function( e
    ){FCK.Events.FireEvent("OnKeyDown");}this.EditorDocument.addEventListener(
    'keydown', oOnKeyDown, true ) ;

    between
    this.EditorDocument.addEventListener('contextmenu',oOnContextMenu,true);

    and
    this.ExecOnSelectionChange=function(){FCK.Events.FireEvent("OnSelectionChange");}

     

Log in to post a comment.

MongoDB Logo MongoDB