Last active
November 26, 2015 08:37
-
-
Save milosdjakonovic/2923209132c2d07c76ea to your computer and use it in GitHub Desktop.
contenteditablechanged event for jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* jQuery contenteditablechanged | |
* | |
* Fires custom event named 'contenteditablechanged' when | |
* textcontent of element marked with contenteditable='true' | |
* changes. | |
* | |
* Usage: | |
* $('[contenteditable]').on('contenteditablechanged', function(e){ | |
* console.log(e); //-- Event properits | |
* console.log(this); //-- Element | |
* } ); | |
* | |
**/ | |
$( document.body ).delegate( "[contenteditable='true']", "click", function() { | |
var $this = $(this); | |
$this.data('contenteditable-prevcontent', $this.text() ).one('blur', function(){ | |
if( $this.data('contenteditable-prevcontent') !== $this.text() ){ | |
$this.trigger('contenteditablechanged'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment