diff --git a/src/element/editable-element.js b/src/element/editable-element.js index 0f2e6ca..c80b0de 100644 --- a/src/element/editable-element.js +++ b/src/element/editable-element.js @@ -284,13 +284,12 @@ Makes editable any HTML element on the page. Applied as jQuery method. this.isEmpty = isEmpty; } else { //detect empty - if($.trim(this.$element.html()) === '') { - this.isEmpty = true; - } else if($.trim(this.$element.text()) !== '') { - this.isEmpty = false; + //for some inputs we need more smart check + //e.g. wysihtml5 may have <br>, <p></p>, <img> + if(typeof(this.input.isEmpty) === 'function') { + this.isEmpty = this.input.isEmpty(this.$element); } else { - //e.g. '<img>' - this.isEmpty = !this.$element.height() || !this.$element.width(); + this.isEmpty = $.trim(this.$element.html()) === ''; } } diff --git a/src/inputs-ext/wysihtml5/wysihtml5.js b/src/inputs-ext/wysihtml5/wysihtml5.js index 8e00647..998f840 100644 --- a/src/inputs-ext/wysihtml5/wysihtml5.js +++ b/src/inputs-ext/wysihtml5/wysihtml5.js @@ -87,6 +87,17 @@ $(function(){ activate: function() { this.$input.data("wysihtml5").editor.focus(); + }, + + isEmpty: function($element) { + if($.trim($element.html()) === '') { + return true; + } else if($.trim($element.text()) !== '') { + return false; + } else { + //e.g. '<img>', '<br>', '<p></p>' + return !$element.height() || !$element.width(); + } } }); diff --git a/test/unit/wysihtml5.js b/test/unit/wysihtml5.js index 9b01d66..bd9145c 100644 --- a/test/unit/wysihtml5.js +++ b/test/unit/wysihtml5.js @@ -6,13 +6,14 @@ $(function () { $.support.transition = false; } }); + + //skip test for ie7 as it is not supported by wysihtml5 + var msieOld = /msie\s*(7|6)/i.test(navigator.userAgent); //note: sometimes it throws 'nativeSelection is null' error asyncTest("should load correct value and save new entered value", function () { - - //skip test for ie7 as it is not supported by wysihtml5 - var msieOld = /msie\s*(7|6)/i.test(navigator.userAgent); + if(msieOld) { expect(0); start(); @@ -76,5 +77,26 @@ $(function () { }); }); + + asyncTest("empty value", function () { + + if(msieOld) { + expect(0); + start(); + return; + } + + var v1 = '<p></p><br>', + e = $('<a href="#" data-pk="1" data-url="post.php">'+v1+'</a>').appendTo(fx).editable({ + type: 'wysihtml5' + }); + + setTimeout(function() { + equal(e.html(), 'Empty', '`Empty` shown'); + e.remove(); + start(); + }, timeout); + + }); }); \ No newline at end of file