Connecting Tech Pros Worldwide Forums | Help | Site Map

cancelling keydown event in designmode(rich text editing) in firefox

pvsundarram@gmail.com
Guest
 
Posts: n/a
#1: May 2 '07
hey,
i am trying to cancel the keydown event for certain keycodes( for eg:-
enter key ).But the cancelling of this event is not happening in
firefox. Is there any way to cancel the event in the iframe.
CODE
=====
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US"
xml:lang="en_US">
<HEAD>
<SCRIPT>
var isIE = document.all;
function chgSpan() {
var newState;
var currentState;
var oSpan = GetObject( "oSpan" );
var oBtn = GetObject( "oBtn" );
InitEventListener();
currentState = (isIE)? oSpan.isContentEditable :
(oSpan.contentDocument.designMode == "on") ;
newState = !currentState;
if(isIE)
oSpan.contentEditable = newState;
else
oSpan.contentDocument.designMode = (newState)? "on" : "off";
newState==false ? oBtn.value="Enable Editing" :
oBtn.value="Disable Editing";
}
function onEnterEvent(e)
{
if(!e)
e = window.event;
var key = (isIE)? e.keyCode : e.which;
alert("onkeydown");
if(key == 13)
{
alert("enter");
return false;
}
}

function InitEventListener()
{
if(isIE)
{
window.document.body.attachEvent("onkeydown",onEnt erEvent);
}
else
{

document.getElementById("oSpan").contentWindow.add EventListener("keydown",
onEnterEvent, false);
}
}


function a(ev){
var e = (ev!=undefined)?ev :event;
alert(e);
}

function Init()
{
var EditorBox = (isIE)?
document.createElement("div"):document.createEleme nt("iframe");
EditorBox.id = "oSpan";
EditorBox.name = "oSpan";
document.body.appendChild(EditorBox);
}
function GetObject(idString)
{
return document.getElementById(idString);
}
</SCRIPT>
</HEAD>
<BODY onload="Init();">
<P>Click the button to enable or disable SPAN content editing.</P>
<P>
<input type="button" id="oBtn" value="Enable Editing"
onclick="chgSpan();"/>
</P>
<P></P>
</BODY>
</html>

Thanks in advance....
--
keep klickin',
P V Sundarram.


scripts.contact
Guest
 
Posts: n/a
#2: May 2 '07

re: cancelling keydown event in designmode(rich text editing) in firefox



pvsundarram@gmail.com wrote:
Quote:
hey,
i am trying to cancel the keydown event for certain keycodes( for eg:-
enter key ).But the cancelling of this event is not happening in
firefox. Is there any way to cancel the event in the iframe.
CODE
http://developer.mozilla.org/en/docs...er_Differences

[-- A further difference for Mozilla is that once a document is
switched to designMode, all events on that particular document are
disabled. Once designMode is turned off however (as this now seems
possible in Mozilla 1.5) the events become active again. --]


Quote:
var isIE = document.all;
var isIEOrOpera = document.all

pvsundarram@gmail.com
Guest
 
Posts: n/a
#3: May 2 '07

re: cancelling keydown event in designmode(rich text editing) in firefox


hey,

On May 2, 9:52 am, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
Quote:
[-- A further difference for Mozilla is that once a document is
switched to designMode, all events on that particular document are
disabled. Once designMode is turned off however (as this now seems
possible in Mozilla 1.5) the events become active again. --]
>
i am running firefox(2.0.0.3/Mozilla 5.0), the events are always
active and they get reported....
the problem i am facing is, the eventhandler is getting called after
the character is getting rendered, and in the end i am unable to
suppress that event.

is there any other way by which one can suppress the event....
Quote:
var isIEOrOpera = document.all
Noted.... ;-)

Thanx again.....

keep clickin',
P V Sundarram.

rf
Guest
 
Posts: n/a
#4: May 2 '07

re: cancelling keydown event in designmode(rich text editing) in firefox



<pvsundarram@gmail.comwrote in message
news:1178094048.882937.123470@q75g2000hsh.googlegr oups.com...
Quote:
hey,
i am trying to cancel the keydown event for certain keycodes( for eg:-
enter key ).But the cancelling of this event is not happening in
firefox. Is there any way to cancel the event in the iframe.
e.preventDefault();

<snip rather irregular code>

--
Richard.


pvsundarram@gmail.com
Guest
 
Posts: n/a
#5: May 2 '07

re: cancelling keydown event in designmode(rich text editing) in firefox


hey,
On May 2, 10:32 am, "rf" <r...@invalid.comwrote:
Quote:
>
e.preventDefault();
>
it doesnt work....the eventhandler is getting called after the
character is getting rendered.....

Thanx again.....

keep clickin',
P V Sundarram.

Randy Webb
Guest
 
Posts: n/a
#6: May 2 '07

re: cancelling keydown event in designmode(rich text editing) in firefox


scripts.contact said the following on 5/2/2007 5:52 AM:
Quote:
pvsundarram@gmail.com wrote:
<snip>
Quote:
Quote:
>var isIE = document.all;
>
var isIEOrOpera = document.all
var isIEOrOperaOrAnyOtherBrowserThatSupportsDocumentDo tAll = document.all



--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
rf
Guest
 
Posts: n/a
#7: May 2 '07

re: cancelling keydown event in designmode(rich text editing) in firefox



<pvsundarram@gmail.comwrote in message
news:1178103764.159980.146470@n76g2000hsh.googlegr oups.com...
Quote:
hey,
On May 2, 10:32 am, "rf" <r...@invalid.comwrote:
Quote:
>>
>e.preventDefault();
>>
it doesnt work....the eventhandler is getting called after the
character is getting rendered.....
Hmmm.

Where did you preventDefault();?

I am currently writing a an RT editor and it works for me.

Ok. Timeout. <copy/paste>

Did you notice that a single enter produces two "enter"s (that is <br>'s)
in the iframe?

I removed the alert(onkeydown) and added, in its place, e.preventDefault();

That changed the rules. No keystrokes at all are passed on to the iframe,
*except* the enter key. It's being passed to the iframe from somewhere else.
This should give you something to work on.

BTW your code is very hard to read/debug. Layout is bad, but that could be
my newsreader. Some comments might help.

You are doing some things that you should not do, for example relying on
document.all to suggest IE and only IE. Check for the feature you are just
about to use, not some random other one.

BTW 2, intercepting the enter key and trying to duplicate what browsers do
(so as to presumably make them all work like IE, which gets it right in this
instance) is not the way to go for a RT editor. You will end up with lots
and lots of convoluted DOM manipulations. I know. I have been there. Look at
fckeditor or tinymce etc for example. Dreadfull code.

Simply let the browser do whatever it wants to do with the enter key and
then sneak in afterwards and clean up the mess. WYMeditor takes this
approach.

--
Richard.


brunascle
Guest
 
Posts: n/a
#8: May 2 '07

re: cancelling keydown event in designmode(rich text editing) in firefox


On May 2, 8:59 am, Randy Webb <HikksNotAtH...@aol.comwrote:
Quote:
var isIEOrOperaOrAnyOtherBrowserThatSupportsDocumentDo tAll = document.all
var isBrowserThatReturnsTrueForDocumentDotAll = document.all;

// because some browsers support it but return false, to help with
browser identification and/or to help choose the right implementation
to use

Randy Webb
Guest
 
Posts: n/a
#9: May 2 '07

re: cancelling keydown event in designmode(rich text editing) in firefox


brunascle said the following on 5/2/2007 10:39 AM:
Quote:
On May 2, 8:59 am, Randy Webb <HikksNotAtH...@aol.comwrote:
Quote:
>var isIEOrOperaOrAnyOtherBrowserThatSupportsDocumentDo tAll = document.all
>
var isBrowserThatReturnsTrueForDocumentDotAll = document.all;
>
// because some browsers support it but return false,
The above does not set a variable equal to true or false.
Quote:
to help with browser identification
That isn't browser identification, even though the original variable
name implies it is, it is feature detection.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
pvsundarram@gmail.com
Guest
 
Posts: n/a
#10: May 3 '07

re: cancelling keydown event in designmode(rich text editing) in firefox


hey,
On May 2, 1:20 pm, "rf" <r...@invalid.comwrote:

Quote:
Where did you preventDefault();?
>
if(key == 13)
{
e.preventDefault();
return false;
}
and it works...... but it doesnt work when you put an alert there....

any idea why it would behave in this fashion????
Quote:
>
I removed the alert(onkeydown) and added, in its place, e.preventDefault();
>
That changed the rules. No keystrokes at all are passed on to the iframe,
*except* the enter key. It's being passed to the iframe from somewhere else.
This should give you something to work on.
>
BTW your code is very hard to read/debug. Layout is bad, but that could be
my newsreader.
something to do with ur reader i guess....;-)

keep klickin',
P.V. Sundarram

Closed Thread