Skip to content

Instantly share code, notes, and snippets.

@958
Created January 22, 2009 02:26
Show Gist options
  • Save 958/50381 to your computer and use it in GitHub Desktop.
Save 958/50381 to your computer and use it in GitHub Desktop.
[Sleipnir]Cancel Action
try{(function(){
// Stop Action
sleipnir.API.ExecuteAction('Stop');
// Closed SuperView
sleipnir.API.ExecuteAction('SuperDragCloseSuperView');
if ((!document) || (!document.body)) return;
// Get active flame
var win = (function(win) {
var doc = win.document; var ae = doc.activeElement;
if (ae.tagName.match(/FRAME|IFRAME/i)) {
var fw = doc.frames; var fe = doc.getElementsByTagName(ae.tagName);
for (var i = 0; i < fw.length; i++)
if (fe.item(i) == ae) { try { return arguments.callee(fw.item(i)); } catch (e) { return null; } }
} else return win;
})(_window), doc = win.document;
// make event
var e = doc.createEventObject(); e.keyCode = 27;
// get active element
var act = doc.activeElement;
// event to active element
if (act) { act.fireEvent('onkeydown', e);act.fireEvent('onkeypress', e);act.fireEvent('onkeyup', e); }
// event to document.body
if (doc.body) { doc.body.fireEvent('onkeydown', e);doc.body.fireEvent('onkeypress', e);doc.body.fireEvent('onkeyup', e); }
// evet to document
if (doc) { doc.fireEvent('onkeydown', e);doc.fireEvent('onkeypress', e);doc.fireEvent('onkeyup', e); }
// clear selection
doc.selection.empty();
// set focus to document.body
doc.body.focus();
})()}catch(e){}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment