directives.js
5.97 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**
* Created by Administrator on 2015/2/27.
*/
(function() {
var xnKindEditor = function ($timeout) {
alert("hhhhhh");
return {
restrict: "AC",
scope: {
content: '=ngModel'
},
template:"<div>"+
"<textarea id=\"{{id}}\" name=\"kindEdit\"></textarea>"+
" <div xn-img-box ng-Model=\"attachmentPopupMuch\" data-is-open=\"isOpenMuch\" " +
" data-type='image' ></div>"+
"<div xn-img-box-single data-type='image' ng-Model=\"attachmentPopup\" data-is-open-single=\"isOpen\"></div>"+
"</div>",
require: "?ngModel",
link: function (scope, elem,atter,ngModel) {
if(!atter.url){
return ;
}
scope.height="500px";
if(atter.height){
scope.height=atter.height;
}
scope.isOpen = false;
scope.isOpenMuch = false;
//图片预览
scope.newData={
newData:""
};
scope.attachmentPopupMuch = {
idList: [],
attachmentList:[]
};
scope.attachmentPopup = {
idList: "",
attachmentList: ""
};
scope.id="editor"+new Date().getTime();
var editor;
var hasLoad = false;
$timeout(function(){
editor=KindEditor.create('#'+scope.id,{
basePath:atter.url,
width:"100%",
height:scope.height,
resizeType : 1,
/* items:[
'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
'anchor', 'link', 'unlink', '|', 'about'
],*/
items:[
'source', '|', 'undo', 'redo', '|', 'preview', 'cut', 'copy', 'paste',
'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
'superscript', 'clearhtml', 'quickformat', 'selectall',
'formatblock', 'fontname', '|', 'forecolor', 'hilitecolor', 'bold',
'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|','xn-image', 'xn-multiimage',
/* 'insertfile',*/ 'table', 'hr', 'pagebreak',
'anchor', 'link', 'unlink'
],
afterBlur: function(){
getVal(editor.html());
}
});
scope.$watch("content",function(data){
if(!hasLoad && data){
hasLoad = true;
editor.html(data);
}
});
elem.find(".ke-icon-xn-image").on("click",function(){
scope.isOpen=true;
scope.$apply();
});
elem.find(".ke-icon-xn-multiimage").on("click",function(){
scope.isOpenMuch=true;
scope.$apply();
});
},0);
//监控单选
scope.$watch(function(){
return scope.isOpen;
},function(newdata){
if(!newdata){
if(scope.attachmentPopup.idList){
if(editor){
editor.insertHtml("<img src="+scope.attachmentPopup.attachmentList.path+" alt="+scope.attachmentPopup.attachmentList.fileName+" >");
}
}else{
}
}
});
//监控多选
scope.$watch(function(){
return scope.isOpenMuch;
},function(newdata){
if(!newdata){
if(scope.attachmentPopupMuch.idList.length>0){
var newDome="";
for(var i=0;i<scope.attachmentPopupMuch.idList.length;i++){
newDome=newDome+"<img src="+scope.attachmentPopupMuch.attachmentList[i].path+" alt="+scope.attachmentPopupMuch.attachmentList[i].fileName+">"
}
if(editor){
editor.insertHtml(newDome);
}
}else{
}
}
});
//同步数据
function getVal(data){
hasLoad = true;
scope.content=angular.copy(data);
scope.$apply();
}
}
};
};
angular.module("xn.kindeditor",[])
.directive('xnKindEditor',["$timeout",xnKindEditor]);
})();