Skip to content

Instantly share code, notes, and snippets.

@gcr
Created January 17, 2009 05:18
Show Gist options
  • Save gcr/48269 to your computer and use it in GitHub Desktop.
Save gcr/48269 to your computer and use it in GitHub Desktop.
/* This is a VERY heavily abridged part of my code for event
handlers and editable DIVs.
The full code can be found here: http://github.com/hotdog003/gutenborg/tree/master */
function gbDocument(docname) {
// This creates a new document then subscribes us to it.
this.jqedit = $("<div class='gb-editor'></div>"); // Our jQuery text editor
// ...
this.enable_editing = function() {
this.jqedit.attr("contentEditable", true);
// Save the document object
doc = this;
this.jqedit.keypress(function(event) {
doc.keyevent(event);
});
// FILTHY IE workaround
if ($.browser.msie) {
this.jqedit.keydown(function(event) {
if (event.which == 8 || event.which == 46) {
doc.keyevent(event);
}
});
}
}
this.keyevent = function(event) {
// What to do when we get a keypress
alert(event.which);
event.preventDefault();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment