Path: blob/main/website/GAUSS/inputs-ext/wysihtml5/wysihtml5.js
2942 views
/**1Bootstrap wysihtml5 editor. Based on [bootstrap-wysihtml5](https://github.com/jhollingworth/bootstrap-wysihtml5).2You should include **manually** distributives of `wysihtml5` and `bootstrap-wysihtml5`:34<link href="js/inputs-ext/wysihtml5/bootstrap-wysihtml5-0.0.2/bootstrap-wysihtml5-0.0.2.css" rel="stylesheet" type="text/css"></link>5<script src="js/inputs-ext/wysihtml5/bootstrap-wysihtml5-0.0.2/wysihtml5-0.3.0.min.js"></script>6<script src="js/inputs-ext/wysihtml5/bootstrap-wysihtml5-0.0.2/bootstrap-wysihtml5-0.0.2.min.js"></script>78And also include `wysihtml5.js` from `inputs-ext` directory of x-editable:910<script src="js/inputs-ext/wysihtml5/wysihtml5.js"></script>1112**Note:** It's better to use fresh bootstrap-wysihtml5 from it's [master branch](https://github.com/jhollingworth/bootstrap-wysihtml5/tree/master/src) as there is update for correct image insertion.1314@class wysihtml515@extends abstractinput16@final17@since 1.4.018@example19<div id="comments" data-type="wysihtml5" data-pk="1"><h2>awesome</h2> comment!</div>20<script>21$(function(){22$('#comments').editable({23url: '/post',24title: 'Enter comments'25});26});27</script>28**/29(function ($) {30"use strict";3132var Wysihtml5 = function (options) {33this.init('wysihtml5', options, Wysihtml5.defaults);3435//extend wysihtml5 manually as $.extend not recursive36this.options.wysihtml5 = $.extend({}, Wysihtml5.defaults.wysihtml5, options.wysihtml5);37};3839$.fn.editableutils.inherit(Wysihtml5, $.fn.editabletypes.abstractinput);4041$.extend(Wysihtml5.prototype, {42render: function () {43var deferred = $.Deferred(),44msieOld;4546//generate unique id as it required for wysihtml547this.$input.attr('id', 'textarea_'+(new Date()).getTime());4849this.setClass();50this.setAttr('placeholder');5152//resolve deffered when widget loaded53$.extend(this.options.wysihtml5, {54events: {55load: function() {56deferred.resolve();57}58}59});6061this.$input.wysihtml5(this.options.wysihtml5);6263/*64In IE8 wysihtml5 iframe stays on the same line with buttons toolbar (inside popover).65The only solution I found is to add <br>. If you fine better way, please send PR.66*/67msieOld = /msie\s*(8|7|6)/.test(navigator.userAgent.toLowerCase());68if(msieOld) {69this.$input.before('<br><br>');70}7172return deferred.promise();73},7475value2html: function(value, element) {76$(element).html(value);77},7879html2value: function(html) {80return html;81},8283value2input: function(value) {84this.$input.data("wysihtml5").editor.setValue(value, true);85},8687activate: function() {88this.$input.data("wysihtml5").editor.focus();89},9091isEmpty: function($element) {92if($.trim($element.html()) === '') {93return true;94} else if($.trim($element.text()) !== '') {95return false;96} else {97//e.g. '<img>', '<br>', '<p></p>'98return !$element.height() || !$element.width();99}100}101});102103Wysihtml5.defaults = $.extend({}, $.fn.editabletypes.abstractinput.defaults, {104/**105@property tpl106@default <textarea></textarea>107**/108tpl:'<textarea></textarea>',109/**110@property inputclass111@default editable-wysihtml5112**/113inputclass: 'editable-wysihtml5',114/**115Placeholder attribute of input. Shown when input is empty.116117@property placeholder118@type string119@default null120**/121placeholder: null,122/**123Wysihtml5 default options.124See https://github.com/jhollingworth/bootstrap-wysihtml5#options125126@property wysihtml5127@type object128@default {stylesheets: false}129**/130wysihtml5: {131stylesheets: false //see https://github.com/jhollingworth/bootstrap-wysihtml5/issues/183132}133});134135$.fn.editabletypes.wysihtml5 = Wysihtml5;136137}(window.jQuery));138139140