// Bootstrap Editable
//= require bootstrap-wysihtml5
//= require bootstrap-editable
//= require bootstrap-editable-rails
//= require_tree ./hicube/public
// Copied this from https://github.com/vitalets/x-editable/blob/master/src/inputs-ext/wysihtml5/wysihtml5.js
(function ($) {
"use strict";
var Wysihtml5 = function (options) {
this.init('wysihtml5', options, Wysihtml5.defaults);
//extend wysihtml5 manually as $.extend not recursive
this.options.wysihtml5 = $.extend({}, Wysihtml5.defaults.wysihtml5, options.wysihtml5);
};
$.fn.editableutils.inherit(Wysihtml5, $.fn.editabletypes.abstractinput);
$.extend(Wysihtml5.prototype, {
render: function () {
var deferred = $.Deferred(),
msieOld;
//generate unique id as it required for wysihtml5
this.$input.attr('id', 'textarea_'+(new Date()).getTime());
this.setClass();
this.setAttr('placeholder');
//resolve deffered when widget loaded
$.extend(this.options.wysihtml5, {
events: {
load: function() {
deferred.resolve();
}
}
});
this.$input.wysihtml5(this.options.wysihtml5);
/*
In IE8 wysihtml5 iframe stays on the same line with buttons toolbar (inside popover).
The only solution I found is to add
. If you fine better way, please send PR.
*/
msieOld = /msie\s*(8|7|6)/.test(navigator.userAgent.toLowerCase());
if(msieOld) {
this.$input.before('
');
}
return deferred.promise();
},
value2html: function(value, element) {
$(element).html(value);
},
html2value: function(html) {
return html;
},
value2input: function(value) {
this.$input.data("wysihtml5").editor.setValue(value, true);
},
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. '', '
', '