forked from hartvig/umbraco-trix-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trix.directive.js
62 lines (54 loc) · 2.25 KB
/
trix.directive.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
// https://github.com/sachinchoolur/angular-trix
(function() {
'use strict';
angular.module('angularTrix', []).directive('angularTrix', function() {
return {
restrict: 'A',
require: 'ngModel',
scope: {
trixInitialize: '&',
trixChange: '&',
trixSelectionChange: '&',
trixFocus: '&',
trixBlur: '&',
trixFileAccept: '&',
trixAttachmentAdd: '&',
trixAttachmentRemove: '&'
},
link: function(scope, element, attrs, ngModel) {
element.on('trix-initialize', function() {
if (ngModel.$modelValue) {
element[0].editor.loadHTML(ngModel.$modelValue);
}
});
ngModel.$render = function() {
if (element[0].editor) {
element[0].editor.loadHTML(ngModel.$modelValue);
}
element.on('trix-change', function() {
ngModel.$setViewValue(element.html());
});
};
var registerEvents = function(type, method) {
element[0].addEventListener(type, function(e) {
if (type === 'trix-file-accept' && attrs.preventTrixFileAccept === 'true') {
e.preventDefault();
}
scope[method]({
e: e,
editor: element[0].editor
});
});
};
registerEvents('trix-initialize', 'trixInitialize');
registerEvents('trix-change', 'trixChange');
registerEvents('trix-selection-change', 'trixSelectionChange');
registerEvents('trix-focus', 'trixFocus');
registerEvents('trix-blur', 'trixBlur');
registerEvents('trix-file-accept', 'trixFileAccept');
registerEvents('trix-attachment-add', 'trixAttachmentAdd');
registerEvents('trix-attachment-remove', 'trixAttachmentRemove');
}
};
});
}());