directives.js
10.3 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/**
* Created by Administrator on 2015/2/27.
*/
(function() {
var xnKindEditor = function ($timeout,xnConfig,kindeditorService) {
return {
restrict: "AC",
scope: {
content: '=ngModel',
readonly:"=",
diskId:"=",
filterMode:"="
},
template:"<div>"+
"<textarea id=\"{{id}}\" name=\"kindEdit\"></textarea>"+
" <div xn-img-box ng-Model=\"attachmentPopupMuch\" data-is-open=\"isOpenMuch\" " +
" data-type='image' data-disk-id='diskId' ></div>"+
"<div xn-img-box-single data-type='image' ng-Model=\"attachmentPopup\" data-is-open-single=\"isOpen\" data-disk-id='diskId' ></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()+Math.ceil(Math.random()*1000);
var editor;
var hasLoad = false;
var filterMode= true;
if(scope.filterMode===false){
filterMode=scope.filterMode;
}
$timeout(function(){
editor=KindEditor.create('#'+scope.id,{
basePath:atter.url,
// uploadJson:xnConfig.myUrl+"api/diskFileUpload.do",
uploadJson:atter.diskUpload||"/api/diskFileUpload.do",
width:"100%",
height:scope.height,
resizeType : 1,
filterMode:filterMode,
readonlyMode : scope.readonly,
/* 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','fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|','xn-image', 'xn-multiimage',"flash",
/* '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);
}
});
scope.$watch("diskId",function(newData){
if(newData){
kindeditorService.apiFoundationDiskGet({id:newData}).then(function(data) {
if (data.errors === null || data.errors.length > 0) {
dialogService.tip(data.errors);
}else{
editor.diskId=data.disk.id;
editor.folderId=data.disk.rootFolderId;
}
});
}
});
if(!scope.readonly){
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",[])
.config(['$httpProvider',
function ($httpProvider) {
$httpProvider.defaults.headers.post['Content-Type'] = 'text/plain';
$httpProvider.defaults.withCredentials=true;
/* // Override $http service's default transformRequest
$httpProvider.defaults.transformRequest = [function(data)
{
/!**
* The workhorse; converts an object to x-www-form-urlencoded serialization.
* @param {Object} obj
* @return {String}
*!/
var param = function(obj){
var query = '';
var name, value, fullSubName, subName, subValue, innerObj, i;
console.log(obj);
for(name in obj)
{
value = obj[name];
console.log(value);
if(value instanceof Array)
{
console.log("Array");
for(i=0; i<value.length; ++i)
{
subValue = value[i];
fullSubName = name + '[' + i + ']';
innerObj = {};
innerObj[fullSubName] = subValue;
query += param(innerObj) + '&';
}
}
else if(value instanceof Object)
{
console.log("object");
for(subName in value)
{
subValue = value[subName];
if(subValue != null){
// fullSubName = name + '[' + subName + ']';
//user.userName = hmm & user.userPassword = 111
fullSubName = name + '.' + subName;
// fullSubName = subName;
innerObj = {};
innerObj[fullSubName] = subValue;
query += param(innerObj) + '&';
}
}
}
else if(value !== undefined ) //&& value !== null
{
console.log("undefined");
query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
}
}
return query.length ? query.substr(0, query.length - 1) : query;
};
return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
}]
*/
$httpProvider.defaults.useXDomain = true;
}])
.directive('xnKindEditor',["$timeout","xnConfig","kindeditorService",xnKindEditor])
.factory('kindeditorService', ['$http',"xnConfig", function ($http,xnConfig ) {
var service = {};
var url = xnConfig.myUrl + "api/foundation.do";
/*获取网盘*/
service.apiFoundationDiskGet = function (data) {
return $http({
method: 'POST',
url: url,
data: data,
params: {"method": "api.foundation.disk.get"} });
};
return service;
}]);
})();