IMChat_wev8.js
6.57 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
function bindCloseBtnHover(targettype, targetid){
var chatwin=$("#chatWin_"+targettype+"_"+targetid);
chatwin.live("hover",function(event){
if(event.type=='mouseenter'){
$(this).find(".imCloseSpan").css("display", "inline-block");
}else{
$(this).find(".imCloseSpan").css("display", "none");
}
});
chatwin.find(".chatList,.noteList,.icrList").hover(
function(){
},
function(){
var curChatwin = $(this).parents(".chatWin");
curChatwin.find(".imCloseSpan").css("display", "none");
}
);
chatwin.find(".imtitle").hover(
function(){
var curChatwin = $(this).parents(".chatWin");
curChatwin.find(".imCloseSpan").css("display", "inline-block");
},
function(){
}
);
chatwin.find(".chattop").hover(
function(){
var curChatwin = $(this).parents(".chatWin");
curChatwin.find(".imCloseSpan").css("display", "inline-block");
},
function(){
}
);
}
//border: 1px solid #7f878a
/*切换模式*/
function changeEditMode(obj) {
var isTaskMode = false;
var sw = $(obj);
if(sw.hasClass("modeChangeSwitchActive")){
sw.removeClass("modeChangeSwitchActive");
$(sw.parents(".chatbottom")[0]).removeClass("chatbottomtaskmode");
isTaskMode = false;
sw.attr("title", "切换到任务输入");
sw.parent().find(".chatcontent").attr("_istaskmode", "0").html("<span class='modehint'>输入您要发送的内容,Enter键发送,Shift+Enter键换行</span>");
sw.parent().addClass("chatContentActive").removeClass("chatContentActiveTask");
}else{
sw.addClass("modeChangeSwitchActive");
$(sw.parents(".chatbottom")[0]).addClass("chatbottomtaskmode");
isTaskMode = true;
sw.attr("title", "切换到普通输入");
sw.parent().find(".chatcontent").attr("_istaskmode", "1").html("<span class='modehint'>添加一个新的任务</span>");
sw.parent().addClass("chatContentActiveTask").removeClass("chatContentActive");
}
var appdivs = sw.parents(".chatbottom").find(".chatAppdiv .chatapp");
if(isTaskMode){
//禁用chatappdiv
addDisabledLayer(appdivs);
}else{
removeDisabledLayer(appdivs);
}
}
function addDisabledLayer(appdivs){
appdivs.each(function(){
var maskLayer = IMUtil.getLayer(IMUtil.getPageOffset(this),"maskLayer");
$(this).parent().append(maskLayer);
});
}
function removeDisabledLayer(appdivs){
appdivs.each(function(){
$(this).parent().find(".maskLayer").remove();
});
}
/*自适应窗口高度*/
function ajustChatWin(obj){
var chatct = $(obj);
chatct.perfectScrollbar('update');
var chatbottom = chatct.parents(".chatbottom");
var ht = chatbottom.height();
console.log("聊天窗口底部高度:"+ht);
var chatdiv = ChatUtil.getchatdiv(obj);
var chatlist = chatdiv.find(".chatList");
chatlist.perfectScrollbar('update');
scrollTOBottom(chatlist);
chatlist.css("bottom", ht);
}
/*处理编辑时联动*/
function toggleWithEditing(obj, evt) {
evt = evt || window.event;
var chatct = $(obj);
var htm = chatct.html();
var orgHt = chatct.data("orgHeight");
if(htm != "" && htm != "<br>"){
chatct.parent().find(".immodeChangeSwitch").hide();
}else{
chatct.parent().find(".immodeChangeSwitch").show();
}
}
/*处理enter发送消息*/
function doEnterSend(obj, evt){
evt = evt || window.event;
var keynum;
if(window.event)
keynum=evt.keyCode;
else
keynum=evt.which;
var tempContent = $(obj).html();
var ht = $(obj).height();
$(obj).data("orgHeight", ht);
if(evt.shiftKey&&(keynum==13||keynum==10)){
evt.returnvalue = true;
return true;
}
else if(keynum==13||keynum==10){
var atwhoid="atwho-ground-"+$(obj).attr("id");
if($("#"+atwhoid+" .atwho-view").is(":visible")){
event.keyCode = 0;//屏蔽回车键
event.returnvalue = false;
stopEvent();
return false;
}
var mode = getEditMode(obj);
if(tempContent == "" || tempContent == "<br>"){
return false;
}
if(mode == "normal")
ChatUtil.enterIMSend(obj,evt);
else if(mode == "task"){
enterSendTask(obj, evt);
}
//清空编辑器
$(obj).html("").focus();
evt.keyCode = 0;//屏蔽回车键
evt.returnvalue = false;
stopEvent();
return false;
}else if(event.ctrlKey&&(keynum==90)){
//ctrl+z
var cacheContent = ChatUtil.cache.chatContents;
if(cacheContent.length > 0){
var cot = cacheContent.pop();
ChatUtil.cache.cache4ctrlz.push( $(obj).html());
$(obj).html(cot);
IMUtil.moveToEndPos(obj)
}
}else if(event.ctrlKey&&(keynum==89)){
//ctrl+y
var cache4ctrlz = ChatUtil.cache.cache4ctrlz;
if(cache4ctrlz.length > 0){
var cot = cache4ctrlz.pop();
ChatUtil.cache.chatContents.push( $(obj).html());
$(obj).html(cot);
IMUtil.moveToEndPos(obj)
}
}else if(keynum==8){
var chds =obj.childNodes;
if(chds.length == 0) return true;
$(obj).find("A.hrmecho").each(function(index, elem){
if(index > 0){
$(elem).before(" ");
}
});
}
}
/*获取当前编辑模式*/
function getEditMode(chatcontentdiv){
var istaskmode = $(chatcontentdiv).attr("_istaskmode");
if(istaskmode == '1') return "task";
else return "normal";
}
/*发送创建任务的消息*/
function enterSendTask(obj, evt) {
var chatdiv = $(obj).parents(".chatdiv")[0];
var tempContent = IMUtil.cleanBR($(obj).html());
tempContent = tempContent.replace(/ /gi, ' ');
//创建任务接口(bugy)
var shareids = "";
var chatWin = $(obj).parents('.chatWin').first();
var targetid = chatWin.attr('id').substring(10);
var targettype = chatWin.attr('id').substring(8,9);
ChatUtil.getDiscussionInfo(targetid, true, function(){
shareids = ChatUtil.getMemberids(targettype, targetid);
$.post("/mobile/plugin/social/SocialMobileOperation.jsp?operation=addtask&tasktitle="+tempContent+"&shareids="+shareids, function(taskinfo){
taskinfo = $.trim(taskinfo);
if(taskinfo != ""){
taskinfo = $.parseJSON(taskinfo);
}
var data = {
"objectName":"FW:CustomShareMsg",
"shareid":taskinfo.taskid,
"sharetype":"task",
"sharetitle":tempContent,
"createdate":taskinfo.createdate,
"status":taskinfo.status,
"creatorid":taskinfo.creatorid};
var tempdiv = ChatUtil.sendIMMsgAuto(chatdiv, 6, data);
var resourcetype = 2;
var resourceid = taskid;
var sharegroupid = targettype=='1'?targettype:"";
var resourceids=ChatUtil.getMemberids(targettype, targetid, true);
$.post("/mobile/plugin/chat/addShare.jsp?resourcetype="+resourcetype+"&resourceid="+resourceid+"&sharegroupid="+sharegroupid,{"resourceids":resourceids},function(){
});
});
});
}