为Angular-UEditor增加工具栏属性
感谢胡大大分享的的开源项目
Angular 的 UEditor 插件 Angular-UEditor
本文只是修改了angular-ueditor.js,加入了对工具栏的定制,方便项目使用
1 (function() {
2 "use strict";
3 (function() {
4 var NGUeditor;
5 NGUeditor = angular.module("ng.ueditor", []);
6 NGUeditor.directive("ueditor", [
7 function() {
8 return {
9 restrict: "C",
10 require: "ngModel",
11 scope: {
12 config: "=",
13 ready: "="
14 },
15 link: function($S, element, attr, ctrl) {
16 var _NGUeditor, _updateByRender;
17 _updateByRender = false;
18 _NGUeditor = (function() {
19 function _NGUeditor() {
20 this.bindRender();
21 this.initEditor();
22 return;
23 }
24
25
26 /**
27 * 初始化编辑器
28 * @return {[type]} [description]
29 */
30
31 _NGUeditor.prototype.initEditor = function() {
32 var _UEConfig, _editorId, _self;
33 _self = this;
34 if (typeof UE === 'undefined') {
35 console.error("Please import the local resources of ueditor!");
36 return;
37 }
38 _UEConfig = $S.config ? $S.config : {};
39 _UEConfig.initialFrameHeight = 160;
40 if (attr.toolbars === 'basic') {
41 _UEConfig.toolbars = basic;
42 } else if (attr.toolbars === 'full')
43 {
44 _UEConfig.toolbars = full;
45 }
46 _editorId = attr.id ? attr.id : "_editor" + (Date.now());
47 element[0].id = _editorId;
48 this.editor = new UE.getEditor(_editorId, _UEConfig);
49 return this.editor.ready(function() {
50 _self.editorReady = true;
51 _self.editor.addListener("contentChange", function() {
52 ctrl.$setViewValue(_self.editor.getContent());
53 if (!_updateByRender) {
54 if (!$S.$$phase) {
55 $S.$apply();
56 }
57 }
58 _updateByRender = false;
59 });
60 if (_self.modelContent.length > 0) {
61 _self.setEditorContent();
62 }
63 if (typeof $S.ready === "function") {
64 $S.ready(_self.editor);
65 }
66 $S.$on("$destroy", function() {
67 var _ref;
68 if ((_ref = _self.editor && _self.editor.destory) != null) {
69 _ref.destory();
70 }
71 });
72 });
73 };
74
75 _NGUeditor.prototype.setEditorContent = function(content) {
76 if (content == null) {
77 content = this.modelContent;
78 }
79 if (this.editor && this.editorReady) {
80 this.editor.setContent(content);
81 }
82 };
83
84 _NGUeditor.prototype.bindRender = function() {
85 var _self;
86 _self = this;
87 ctrl.$render = function() {
88 _self.modelContent = (ctrl.$isEmpty(ctrl.$viewValue) ? "" : ctrl.$viewValue);
89 _updateByRender = true;
90 _self.setEditorContent();
91 };
92 };
93
94 return _NGUeditor;
95
96 })();
97 new _NGUeditor();
98 }
99