WIP: Note editing, markdown to html
[oweals/karmaworld.git] / karmaworld / apps / wysihtml5 / static / wysihtml5 / wysihtml-0.4.17 / src / quirks / ensure_proper_clearing.js
1 /**
2  * IE and Opera leave an empty paragraph in the contentEditable element after clearing it
3  *
4  * @param {Object} contentEditableElement The contentEditable element to observe for clearing events
5  * @exaple
6  *    wysihtml5.quirks.ensureProperClearing(myContentEditableElement);
7  */
8 wysihtml5.quirks.ensureProperClearing = (function() {
9   var clearIfNecessary = function() {
10     var element = this;
11     setTimeout(function() {
12       var innerHTML = element.innerHTML.toLowerCase();
13       if (innerHTML == "<p>&nbsp;</p>" ||
14           innerHTML == "<p>&nbsp;</p><p>&nbsp;</p>") {
15         element.innerHTML = "";
16       }
17     }, 0);
18   };
19
20   return function(composer) {
21     wysihtml5.dom.observe(composer.element, ["cut", "keydown"], clearIfNecessary);
22   };
23 })();