Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
loeasy68
GitHub Repository: loeasy68/loeasy68.github.io
Path: blob/main/website/GAUSS/inputs-ext/wysihtml5/wysihtml5.js
2942 views
1
/**
2
Bootstrap wysihtml5 editor. Based on [bootstrap-wysihtml5](https://github.com/jhollingworth/bootstrap-wysihtml5).
3
You should include **manually** distributives of `wysihtml5` and `bootstrap-wysihtml5`:
4
5
<link href="js/inputs-ext/wysihtml5/bootstrap-wysihtml5-0.0.2/bootstrap-wysihtml5-0.0.2.css" rel="stylesheet" type="text/css"></link>
6
<script src="js/inputs-ext/wysihtml5/bootstrap-wysihtml5-0.0.2/wysihtml5-0.3.0.min.js"></script>
7
<script src="js/inputs-ext/wysihtml5/bootstrap-wysihtml5-0.0.2/bootstrap-wysihtml5-0.0.2.min.js"></script>
8
9
And also include `wysihtml5.js` from `inputs-ext` directory of x-editable:
10
11
<script src="js/inputs-ext/wysihtml5/wysihtml5.js"></script>
12
13
**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.
14
15
@class wysihtml5
16
@extends abstractinput
17
@final
18
@since 1.4.0
19
@example
20
<div id="comments" data-type="wysihtml5" data-pk="1"><h2>awesome</h2> comment!</div>
21
<script>
22
$(function(){
23
$('#comments').editable({
24
url: '/post',
25
title: 'Enter comments'
26
});
27
});
28
</script>
29
**/
30
(function ($) {
31
"use strict";
32
33
var Wysihtml5 = function (options) {
34
this.init('wysihtml5', options, Wysihtml5.defaults);
35
36
//extend wysihtml5 manually as $.extend not recursive
37
this.options.wysihtml5 = $.extend({}, Wysihtml5.defaults.wysihtml5, options.wysihtml5);
38
};
39
40
$.fn.editableutils.inherit(Wysihtml5, $.fn.editabletypes.abstractinput);
41
42
$.extend(Wysihtml5.prototype, {
43
render: function () {
44
var deferred = $.Deferred(),
45
msieOld;
46
47
//generate unique id as it required for wysihtml5
48
this.$input.attr('id', 'textarea_'+(new Date()).getTime());
49
50
this.setClass();
51
this.setAttr('placeholder');
52
53
//resolve deffered when widget loaded
54
$.extend(this.options.wysihtml5, {
55
events: {
56
load: function() {
57
deferred.resolve();
58
}
59
}
60
});
61
62
this.$input.wysihtml5(this.options.wysihtml5);
63
64
/*
65
In IE8 wysihtml5 iframe stays on the same line with buttons toolbar (inside popover).
66
The only solution I found is to add <br>. If you fine better way, please send PR.
67
*/
68
msieOld = /msie\s*(8|7|6)/.test(navigator.userAgent.toLowerCase());
69
if(msieOld) {
70
this.$input.before('<br><br>');
71
}
72
73
return deferred.promise();
74
},
75
76
value2html: function(value, element) {
77
$(element).html(value);
78
},
79
80
html2value: function(html) {
81
return html;
82
},
83
84
value2input: function(value) {
85
this.$input.data("wysihtml5").editor.setValue(value, true);
86
},
87
88
activate: function() {
89
this.$input.data("wysihtml5").editor.focus();
90
},
91
92
isEmpty: function($element) {
93
if($.trim($element.html()) === '') {
94
return true;
95
} else if($.trim($element.text()) !== '') {
96
return false;
97
} else {
98
//e.g. '<img>', '<br>', '<p></p>'
99
return !$element.height() || !$element.width();
100
}
101
}
102
});
103
104
Wysihtml5.defaults = $.extend({}, $.fn.editabletypes.abstractinput.defaults, {
105
/**
106
@property tpl
107
@default <textarea></textarea>
108
**/
109
tpl:'<textarea></textarea>',
110
/**
111
@property inputclass
112
@default editable-wysihtml5
113
**/
114
inputclass: 'editable-wysihtml5',
115
/**
116
Placeholder attribute of input. Shown when input is empty.
117
118
@property placeholder
119
@type string
120
@default null
121
**/
122
placeholder: null,
123
/**
124
Wysihtml5 default options.
125
See https://github.com/jhollingworth/bootstrap-wysihtml5#options
126
127
@property wysihtml5
128
@type object
129
@default {stylesheets: false}
130
**/
131
wysihtml5: {
132
stylesheets: false //see https://github.com/jhollingworth/bootstrap-wysihtml5/issues/183
133
}
134
});
135
136
$.fn.editabletypes.wysihtml5 = Wysihtml5;
137
138
}(window.jQuery));
139
140