Menu

#28 Sample OnKeyDown Event Capture Plug-in

open
nobody
None
5
2005-12-27
2005-12-27
No

This is a plugin (with everything you need to test it
all right there, just edit one line to set editor base
path in "test.html" top of file) that shows how I was
able to capture the onkeydown event for the editor.

This plugin looks for the enter key alone (not
ctrl+enter, not shift+enter... just the enter key) and
if captured, alerts you of the capture.

This one stops the event in it's tracks, which may or
may not be what is wanted. Check the "ContentMaxLength"
plugin for an example of basically the same thing but
with a "catch and return to the wild" tweak. (basically
just get rid of the two lines in IE and Gecko funcs
that stop the event bubble and prevent propagation (and
maybe change the return to true vs. false).)

That's it. Really this is a tiny plugin but I bulked it
out with the "Best Practice" type stuff. (langs and
test files).

I'll add the meat of the code to the wiki in a bit as well.

Happy Key Capturing!
:xD

Discussion

  • Denny Valliant

    Denny Valliant - 2005-12-27

    zipped up plugin folder with lang and test files

     
  • Maroni

    Maroni - 2007-02-22

    Logged In: YES
    user_id=1491458
    Originator: NO

    I have tried using this plugin with an FckEditor instance in an aspx document, but the FCK.EditorDocument in the plugin.js tells me it's 'undefined'.

     
  • Maroni

    Maroni - 2007-02-22

    Logged In: YES
    user_id=1491458
    Originator: NO

    To make the plugin not return the FCK.EditorDocument 'undefined', I find that the alteration in later versions (don't know from which) will fix the problem:

    Add the following method to the plugin:
    function FCKKeyPress_SetListeners()
    {
    if (document.all) {
    // If Internet Explorer.
    FCK.EditorDocument.attachEvent("onkeydown", DenIE_OnKeyDown ) ;
    } else {
    // If Gecko.
    FCK.EditorDocument.addEventListener( 'keypress', DenGecko_OnKeyDown, true ) ;
    }
    }

    Remove the previous attempts to add listeners from the plugin, and add:

    FCK.Events.AttachEvent( 'OnAfterSetHTML', FCKKeyPress_SetListeners ) ;

    FCK.Events.AttachEvent( 'OnAfterSetHTML', FCKKeyPress_SetListeners ) ;

     
  • NHD

    NHD - 2007-08-30

    Logged In: YES
    user_id=1879619
    Originator: NO

    in an aspx
    FCK.EditorDocument is 'undefined'. ???

     

Log in to post a comment.

Monday.com Logo