| 776 |
lars |
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 |
|
|
|
93 |
Wysihtml5.defaults = $.extend({}, $.fn.editabletypes.abstractinput.defaults, {
|
|
|
94 |
/**
|
|
|
95 |
@property tpl
|
|
|
96 |
@default <textarea></textarea>
|
|
|
97 |
**/
|
|
|
98 |
tpl:'<textarea></textarea>',
|
|
|
99 |
/**
|
|
|
100 |
@property inputclass
|
|
|
101 |
@default editable-wysihtml5
|
|
|
102 |
**/
|
|
|
103 |
inputclass: 'editable-wysihtml5',
|
|
|
104 |
/**
|
|
|
105 |
Placeholder attribute of input. Shown when input is empty.
|
|
|
106 |
|
|
|
107 |
@property placeholder
|
|
|
108 |
@type string
|
|
|
109 |
@default null
|
|
|
110 |
**/
|
|
|
111 |
placeholder: null,
|
|
|
112 |
/**
|
|
|
113 |
Wysihtml5 default options.
|
|
|
114 |
See https://github.com/jhollingworth/bootstrap-wysihtml5#options
|
|
|
115 |
|
|
|
116 |
@property wysihtml5
|
|
|
117 |
@type object
|
|
|
118 |
@default {stylesheets: false}
|
|
|
119 |
**/
|
|
|
120 |
wysihtml5: {
|
|
|
121 |
stylesheets: false //see https://github.com/jhollingworth/bootstrap-wysihtml5/issues/183
|
|
|
122 |
}
|
|
|
123 |
});
|
|
|
124 |
|
|
|
125 |
$.fn.editabletypes.wysihtml5 = Wysihtml5;
|
|
|
126 |
|
|
|
127 |
}(window.jQuery));
|