This repository was archived by the owner on Feb 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathangular-editor.js
More file actions
61 lines (47 loc) · 1.86 KB
/
Copy pathangular-editor.js
File metadata and controls
61 lines (47 loc) · 1.86 KB
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
/*global window,location*/
(function (window) {
'use strict';
var Simditor = window.Simditor;
var directives = angular.module('simditor',[]);
directives.directive('simditor', function () {
var TOOLBAR_DEFAULT = ['title', 'bold', 'italic', 'underline', 'strikethrough', '|', 'ol', 'ul', 'blockquote', 'code', 'table', '|', 'link', 'image', 'hr', '|', 'indent', 'outdent'];
return {
require: "?^ngModel",
link: function (scope, element, attrs, ngModel) {
element.append("<div style='height:300px;'></div>");
var toolbar = scope.$eval(attrs.toolbar) || TOOLBAR_DEFAULT;
var toolbarFloat = scope.$eval(attrs.toolbarFloat);
var valToolBarFload = toolbarFloat === false ? false : true;
scope.simditor = new Simditor({
textarea: element.children()[0],
pasteImage: true,
toolbar: toolbar,
toolbarFloat : valToolBarFload,
defaultImage: 'assets/images/image.png',
upload: location.search === '?upload' ? {
url: '/upload'
} : false
});
var $target = element.find('.simditor-body');
function readViewText() {
ngModel.$setViewValue($target.html());
if (attrs.ngRequired != undefined && attrs.ngRequired != "false") {
var text = $target.text();
if(text.trim() === "") {
ngModel.$setValidity("required", false);
} else {
ngModel.$setValidity("required", true);
}
}
}
ngModel.$render = function () {
scope.simditor.focus();
$target.html(ngModel.$viewValue);
};
scope.simditor.on('valuechanged', function () {
scope.$apply(readViewText);
});
}
};
});
}(window));