Ups I problem with the code above..
The line
this.eventParent.stopPropagation(event)
should be:
classKP.stopPropagation(event);
var classKeyPressOverride = function(){}
classKeyPressOverride.prototype.toString = function(){ return " Class
Key Press Override "; }
classKeyPressOverride.prototype.attachListener = function( type,
functionCode ){
//Register the listener
var obj = window.document;
if ('addEventListener' in obj) {
obj.addEventListener( type, functionCode, true);
} else if ('attachEvent' in obj) {
obj.attachEvent('on' + type, functionCode );
} else {
alert("Could not add listener");
}
}
classKeyPressOverride.prototype.addListener = function(obj, evt, fun,
b) {
var eventPhase = (typeof(b)=='boolean') ? b : false;
if ('addEventListener' in obj) {
obj.addEventListener(evt, fun, eventPhase);
} else if ('attachEvent' in obj) {
obj.attachEvent(evt, fun);
} else {
alert("Could not add listener");
}
}
classKeyPressOverride.prototype.stopPropagation = function(ev){
if ('stopPropagation' in ev) {
ev.stopPropagation();
ev.preventDefault();
}else{
ev.keyCode = 0;
ev.cancelBubble = true;
ev.returnValue = false;
}
}
//Create an instance and add attach a lister tpe of keydown
var classKP = new classKeyPressOverride();
classKP.attachListener('help', classKP.stopPropagation );
classKP.attachListener('keydown', function(event){
var ev = event || window.event;
var keyCode = ev.keyCode || ev.which;
var fKeyPressed = false;
//ev.DOM_VK_F1
if (keyCode == 112) {
fKeyPressed = true;
//alert("ev F1 Pressed");
}else if (keyCode == 113) {
fKeyPressed = true;
//alert("F2 Pressed");
}else if (keyCode == 114) {
fKeyPressed = true;
//alert("F3 Pressed");
}else if (keyCode == 115) {
fKeyPressed = true;
//alert("F4 Pressed");
}
if (fKeyPressed == true){
//new classKeyPressOverride().stopPropagation(event);
//Use the variable name of the class instance
//Since it is within the scopt of this function code
// "this" and "parent" refer to the object that the key lister is
run on ie window.document
classKP.stopPropagation(event);
}
}
);
On Apr 9, 11:04 am, "bla...@worldweb.com" <bla...@worldweb.comwrote:
I just wanted to post the solution for anyone that is interested.
1) If you want to override the 'F1' button in IE you need to attach an
event listener to stop
the default action.
classKP.attachListener('help', classKP.stopPropagation );
2) In IE cancelBubble and returnValue were not stopping the default
actions as specified in the docs, setting the keyCode to 0 then
running the actions stops all the defaults
ev.keyCode = 0;
Below is a working example.
var classKeyPressOverride = function(){}
classKeyPressOverride.prototype.toString = function(){ return " Class
Key Press Override "; }
classKeyPressOverride.prototype.attachListener = function( type,
functionCode ){
//Register the listener
var obj = window.document;
obj.eventParent = this;
if ('addEventListener' in obj) {
obj.addEventListener( type, functionCode, true);
} else if ('attachEvent' in obj) {
obj.attachEvent('on' + type, functionCode );
} else {
alert("Could not add listener");
}}
classKeyPressOverride.prototype.stopPropagation = function(ev){
if ('stopPropagation' in ev) {
ev.stopPropagation();
ev.preventDefault();
}else{
ev.keyCode = 0;
ev.cancelBubble = true;
ev.returnValue = false;
}
}
//Create an instance and add attach a lister tpe of keydown
var classKP = new classKeyPressOverride();
classKP.attachListener('help', classKP.stopPropagation );
classKP.attachListener('keydown', function(event,parentClass){
var ev = event || window.event;
var keyCode = ev.keyCode || ev.which;
var fKeyPressed = false;
//ev.DOM_VK_F1
if (keyCode == 112) {
fKeyPressed = true;
//alert("ev F1 Pressed");
}else if (keyCode == 113) {
fKeyPressed = true;
//alert("F2 Pressed");
}else if (keyCode == 114) {
fKeyPressed = true;
//alert("F3 Pressed");
}else if (keyCode == 115) {
fKeyPressed = true;
//alert("F4 Pressed");
}
if (fKeyPressed == true){
this.eventParent.stopPropagation(event);
}
}
);
On Apr 7, 10:35 pm, Gérard Talbot <newsblahgr...@gtalbot.orgwrote:
bla...@worldweb.com wrote :
Hey Gérard,
Thanks for your concern.
Thank you for not top-posting in comp.lang.javascript newsgroup.
If you would have thought about it a little longer you may have
realized that this if for a web application that the general public
does not have access to.
Are you actually saying that you did not think of including such vital
info in your original post or are you saying that you assumed that
readers of your post would have been able (or should be able) to read
your mind over the internet, figure out your intentions and missing
information and then establish that your intentions are sound, fair,
legitimate, level-headed and that your application requirements are all
balanced, sensible and above any reproach?
Since users a trained to press the K-Keys for help.
I read your post several times and still don't understand how or why the
F1 key should be replaced by the "K-Keys" for help or why it is a good
idea to replace the F1 key in an intranet application with the "K-keys".
Maybe one day there will be an original urbanist who will redesign color
for street lights and he will use purple or gray for stop instead of red
and he will choose yellow for going across street intersection instead
of green and such colors will only apply to his town, not outside such town.
It makes perfect
sense to override the Help menu of the browser with the Help Menu of
the application.
Your words up there. Not mine.
Sincerely,
Blaine
Fair enough. Good luck.
Gérard
--
Using Web Standards in your Web Pages (Updated Dec. 2006)http://developer.mozilla.org/en/docs...s_in_your_Web_...