forked from dev4dev/knockoutjs-tinymce-binding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathko.tinymce.js
55 lines (49 loc) · 1.57 KB
/
ko.tinymce.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
/*
KnocjoutJS TinyMCE Binding
Copyright 2011 .DeV!L
*/
ko.bindingHandlers.tinymce = {
init: function(element, valueAccessor, allBindingsAccessor, viewModel) {
var editor = $(element).tinymce();
var options = allBindingsAccessor().tinymceOptions || {};
var va = valueAccessor();
var mce_config = {
theme : "advanced",
// Theme options
theme_advanced_buttons1 : "save,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,image,cleanup,code,|,forecolor,backcolor",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
setup: function(ed) {
ed.addButton('save', {
title : 'save.desc',
onclick : function() {
if(!ed.isDirty()){
// return false;
}
var html = ed.getContent({format : 'raw'});
if (ko.isWriteableObservable(va)) {
va(html);
}
ed.isNotDirty = true;
}
});
}
};
mce_config = $.extend(mce_config, options);
if (editor) {
editor.remove();
editor = null;
};
setTimeout(function(){
$(element).tinymce(mce_config);
}, 0);
},
update: function(element, valueAccessor, allBindingsAccessor, viewModel) {
var value = ko.utils.unwrapObservable(valueAccessor());
$(element).html(value);
}
}