Skip to content

Instantly share code, notes, and snippets.

@victorjonsson
Last active December 10, 2015 11:29
Show Gist options
  • Save victorjonsson/4428204 to your computer and use it in GitHub Desktop.
Save victorjonsson/4428204 to your computer and use it in GitHub Desktop.
// Make the element editable by double clicking on it
$('#some-element').editable();
// There are some options you can configure when initiating
// the editable feature as well as a callback function that
// will be called when textarea gets blurred.
$('#some-element').editable({
touch : true, // Whether or not to support touch (default true)
lineBreaks : true, // Whether or not to convert \n to <br /> (default true)
toggleFontSize : true, // Whether or not it should be possible to change font size (defualt true)
closeOnEnter : false, // Whether or not pressing the enter key should close the editor (default false)
event : 'click', // The event that triggers the editor
callback : function( data ) {
// Callback that will be called once the editor looses focus
if( data.content ) {
// Content has changed...
}
if( data.fontSize ) {
// the font size is changed
}
// data.$el gives you a reference to the element that was edited
data.$el.effect('blink');
}
});
// Call "open" to programatically turn an editable element into an editor
$('#some-element').editable('open');
// Call "close" to programatically close the editor for en element
// that's being edited
$('#some-element').editable('close');
// Call "destroy" to remove the possibility to edit an element
$('#some-element').editable('destroy');
// You can use $.is() to tell whether or not an element is editable or at
// the moment being edited
var $elem = $('#some-element');
if( $elem.is(':editing') ) {
// It's being edited right now, lets do stuff...
}
if( $elem.is(':editable') ) {
// It's editable, lets do stuff...
}
// Binding an event listener that's triggered when the
// element gets edited
$('#some-element').on('edit', function(event, $textArea) { });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment