-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap-editable.ckeditor.js
94 lines (78 loc) · 2.14 KB
/
bootstrap-editable.ckeditor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Extensão do plugin X-Editable para permitir a edição de textos utilizando o componente CkEditor
// Criado por Thiago G. Miranda em 21/12/2015
(function ($) {
"use strict";
var CkEditable = function (options) {
this.init('ckeditor', options, CkEditable.defaults);
options.ckeditor = options.ckeditor || {};
this.options.ckeditor = $.extend({}, CkEditable.defaults.ckeditor, options.ckeditor);
};
$.fn.editableutils.inherit(CkEditable, $.fn.editabletypes.textarea);
$.extend(CkEditable.prototype, {
render: function () {
this.setClass();
CKEDITOR.replace('editor_input');
},
//using `white-space: pre-wrap` solves \n <--> BR conversion very elegant!
value2html: function(value, element) {
var html = '', lines;
if(value) {
lines = value.split("\n");
for (var i = 0; i < lines.length; i++) {
lines[i] = $('<div>').html(lines[i]).html();
}
html = lines.join('<br />');
}
$(element).html(html);
},
html2value: function(html) {
if(!html) {
return '';
}
return html;
},
value2input: function (value) {
CKEDITOR.on("instanceReady", function(event)
{
CKEDITOR.instances.editor_input.setData(value);
});
},
input2value: function () {
return CKEDITOR.instances.editor_input.getData();
},
destroy: function () {
if (this.$input) {
if (CKEDITOR.instances.editor_input) {
CKEDITOR.instances.editor_input.destroy();
}
}
}
});
CkEditable.defaults = $.extend({}, $.fn.editabletypes.abstractinput.defaults, {
/**
@property tpl
@default <textarea></textarea>
**/
tpl: '<textarea id="editor_input"></textarea>',
/**
@property inputclass
@default input-large
**/
inputclass: 'ckeditor-input',
/**
Placeholder attribute of input. Shown when input is empty.
@property placeholder
@type string
@default null
**/
placeholder: null,
/**
Number of rows in textarea
@property rows
@type integer
@default 7
**/
rows: 7
});
$.fn.editabletypes.ckeditor = CkEditable;
}(window.jQuery));