2014-08-13 00:14:00 +08:00
|
|
|
|
define(function (require, exports, module) {
|
|
|
|
|
var EventObject = require("../../platform/EventObject.js");
|
|
|
|
|
var ep = require("../../platform/extensionPort.js");
|
|
|
|
|
var port = ep.port;
|
2014-08-14 21:33:47 +08:00
|
|
|
|
var mp = require("../widget_message_popup.js");
|
|
|
|
|
var sessMgr = require("../../account/sessionMgr.js");
|
|
|
|
|
var param = require("../../data.js");
|
|
|
|
|
var page = $("#chat_container");
|
|
|
|
|
var user = sessMgr.current;
|
2014-08-18 23:12:35 +08:00
|
|
|
|
var utility = require("../../utility.js");
|
2015-07-08 17:24:45 +08:00
|
|
|
|
var coder = require("../../platform/messageCoder.js");
|
|
|
|
|
var cmds = require("./actionCommand.js");
|
|
|
|
|
var securityCheck = require("../../platform/securityCheck.js");
|
2015-08-10 19:28:33 +08:00
|
|
|
|
var emojiRoot = "/images/emoji/";
|
|
|
|
|
var media = require("../../platform/media.js");
|
|
|
|
|
var lastPopupTip = parseInt(sessionStorage["lastRoomMstAt"] || "0", 10);
|
2015-03-13 19:25:08 +08:00
|
|
|
|
|
2015-07-08 17:24:45 +08:00
|
|
|
|
var checkPrivilege = function () {
|
|
|
|
|
securityCheck.isAdmin = user && (user.username === 'imfish' || user.username === 'iccfish');
|
2015-03-13 19:25:08 +08:00
|
|
|
|
};
|
2014-08-08 20:46:37 +08:00
|
|
|
|
|
2014-08-14 21:33:47 +08:00
|
|
|
|
sessMgr.on("sessionChanged", function () {
|
2015-07-08 20:49:11 +08:00
|
|
|
|
|
|
|
|
|
if (!sessMgr.current) {
|
|
|
|
|
session.exitRoom();
|
|
|
|
|
} else {
|
|
|
|
|
user = sessMgr.current;
|
|
|
|
|
checkPrivilege();
|
|
|
|
|
}
|
2014-08-14 21:33:47 +08:00
|
|
|
|
});
|
2015-03-13 19:25:08 +08:00
|
|
|
|
checkPrivilege();
|
2014-08-13 00:14:00 +08:00
|
|
|
|
|
|
|
|
|
var RoomSession = function () {
|
|
|
|
|
EventObject.apply(this);
|
|
|
|
|
var that = this;
|
|
|
|
|
var room;
|
2014-08-14 21:33:47 +08:00
|
|
|
|
var chatListContainer = page.find("article.chat-items");
|
|
|
|
|
var chatListContainerDom = chatListContainer[0];
|
|
|
|
|
var roomStateTemplate = $("#chat_connect_server").doT();
|
|
|
|
|
var roomSystemNoticeTemplate = $("#chat_sys_alert").doT();
|
2015-07-08 17:24:45 +08:00
|
|
|
|
var roomSysMessage = $("#chat_sys_message").doT();
|
2014-08-18 23:12:35 +08:00
|
|
|
|
var chatMsgItem = $("#chat_msg_item").doT();
|
2014-08-13 00:14:00 +08:00
|
|
|
|
|
2014-09-16 21:40:29 +08:00
|
|
|
|
//init pic send.
|
|
|
|
|
var fileReader = new FileReader();
|
|
|
|
|
fileReader.onload = function (fe) {
|
|
|
|
|
that.sendMsg({
|
|
|
|
|
color: user.options.chatColor,
|
|
|
|
|
text: "[贴图]",
|
|
|
|
|
target: []
|
2014-09-17 21:46:05 +08:00
|
|
|
|
}, [
|
|
|
|
|
{
|
|
|
|
|
type: "image",
|
|
|
|
|
data: fe.target.result
|
|
|
|
|
}]);
|
2014-09-16 21:40:29 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.sendPic = function (file) {
|
|
|
|
|
if (!/^image\//i.test(file.type) || file.size > 100 * 1024) {
|
|
|
|
|
mp.showMessagePopup("error", "只能发送小于100K的图片哦!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fileReader.readAsDataURL(file);
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-30 01:32:27 +08:00
|
|
|
|
this.clearConnectingState = function () {
|
|
|
|
|
chatListContainer.find(".chat-state").remove();
|
|
|
|
|
};
|
2014-08-13 00:14:00 +08:00
|
|
|
|
this.enterRoom = function (targetRoom) {
|
2015-08-10 19:28:33 +08:00
|
|
|
|
if (targetRoom === room || (targetRoom && room && targetRoom.id === room.id))
|
2014-08-13 00:14:00 +08:00
|
|
|
|
return;
|
|
|
|
|
room = targetRoom;
|
2014-08-14 21:33:47 +08:00
|
|
|
|
|
|
|
|
|
//UI
|
|
|
|
|
$("#chat_frame>section").removeClass("chat-page-current");
|
|
|
|
|
page.addClass("chat-page-current");
|
|
|
|
|
page.find(">header>span:eq(0)").html(room.name);
|
|
|
|
|
chatListContainer.empty();
|
|
|
|
|
that.refreshOnlineCount();
|
|
|
|
|
page.find("button.button-primary").prop("disabled", true);
|
|
|
|
|
|
|
|
|
|
that.fireEvent("enterRoom");
|
2014-08-30 01:32:27 +08:00
|
|
|
|
if (!room.url) {
|
|
|
|
|
that.appendMessageItem(roomStateTemplate({ state: "connecting", stateIcon: "fa-spin fa-spinner", msg: "正在获得房间地址..." }));
|
|
|
|
|
$.post(param.chatServerGetAddressApi, { roomId: room.id }, "json").done(function (result) {
|
|
|
|
|
if (!result.url) {
|
|
|
|
|
that.clearConnectingState();
|
|
|
|
|
that.appendMessageItem(roomStateTemplate({ state: "disconnect", stateIcon: "fa-times", msg: "无法进入房间,请重试。", exinfo: "<a href='javascript:;' class='chat-frame-reconnect'>重新连接</a>" }));
|
|
|
|
|
that.exitRoom();
|
|
|
|
|
mp.showMessagePopup("error", "无法进入房间,请稍后重试。");
|
|
|
|
|
} else {
|
|
|
|
|
room.url = result.url;
|
|
|
|
|
room.heartbeat = result.heartbeat;
|
|
|
|
|
|
|
|
|
|
that.clearConnectingState();
|
|
|
|
|
port.postMessage("enterChatRoom", room);
|
|
|
|
|
}
|
|
|
|
|
}).fail(function () {
|
|
|
|
|
that.clearConnectingState();
|
|
|
|
|
that.appendMessageItem(roomStateTemplate({ state: "disconnect", stateIcon: "fa-times", msg: "无法进入房间,请重试。", exinfo: "<a href='javascript:;' class='chat-frame-reconnect'>重新连接</a>" }));
|
|
|
|
|
that.exitRoom();
|
|
|
|
|
mp.showMessagePopup("error", "无法进入房间,请稍后重试。");
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2015-07-08 17:24:45 +08:00
|
|
|
|
if (!room.orgUrl) {
|
|
|
|
|
room.orgUrl = room.url;
|
|
|
|
|
room.url = room.orgUrl.replace(/#uid#/, user.username + "/" + user.dispname);
|
|
|
|
|
}
|
2014-08-30 01:32:27 +08:00
|
|
|
|
port.postMessage("enterChatRoom", room);
|
|
|
|
|
}
|
2014-09-02 23:15:40 +08:00
|
|
|
|
|
2014-09-03 23:20:12 +08:00
|
|
|
|
ep.track(param.trackTypes.JOIN_CHAT);
|
2014-08-14 21:33:47 +08:00
|
|
|
|
};
|
|
|
|
|
this.refreshOnlineCount = function () {
|
|
|
|
|
page.find(">header>span:eq(1)").html("当前在线 " + room.onlinecount + " 人");
|
2014-08-19 21:33:26 +08:00
|
|
|
|
page.find(".chat-online-count").html(room.onlinecount);
|
2014-08-13 00:14:00 +08:00
|
|
|
|
};
|
|
|
|
|
this.exitRoom = function () {
|
2014-08-14 21:33:47 +08:00
|
|
|
|
room = null;
|
2014-08-13 00:14:00 +08:00
|
|
|
|
port.postMessage("disconnectChatRoom");
|
|
|
|
|
that.fireEvent("exitRoom");
|
2014-09-02 23:15:40 +08:00
|
|
|
|
|
2014-09-03 23:20:12 +08:00
|
|
|
|
ep.track(param.trackTypes.EXIT_CHAT);
|
2014-08-13 00:14:00 +08:00
|
|
|
|
};
|
2014-08-14 21:33:47 +08:00
|
|
|
|
this.appendMessageItem = function (html) {
|
|
|
|
|
chatListContainer.append(html);
|
2014-09-13 03:44:02 +08:00
|
|
|
|
|
|
|
|
|
if (sessMgr.current.options.autoScroll !== 0)
|
|
|
|
|
chatListContainerDom.scrollTop = chatListContainerDom.scrollHeight;
|
2014-08-14 21:33:47 +08:00
|
|
|
|
};
|
|
|
|
|
this.clearDisplay = function () {
|
|
|
|
|
chatListContainer.empty();
|
|
|
|
|
};
|
2014-09-17 21:46:05 +08:00
|
|
|
|
this.sendMsg = function (msg, media) {
|
2015-07-08 17:24:45 +08:00
|
|
|
|
var errormsg = securityCheck.checkIllegalWords(msg.text);
|
2014-12-16 23:31:53 +08:00
|
|
|
|
if (errormsg) {
|
|
|
|
|
alert(errormsg);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-14 21:33:47 +08:00
|
|
|
|
var data = {
|
2015-07-08 17:24:45 +08:00
|
|
|
|
content: msg.text,
|
|
|
|
|
color: /([a-f\d]{6})/i.exec(msg.color || "") && RegExp.$1 || "",
|
|
|
|
|
images: [],
|
|
|
|
|
fromUser: {
|
2014-08-14 21:33:47 +08:00
|
|
|
|
realname: user.dispname,
|
|
|
|
|
username: user.username
|
|
|
|
|
},
|
2015-07-08 17:24:45 +08:00
|
|
|
|
toUsers: msg.target || [],
|
|
|
|
|
time: new Date(),
|
|
|
|
|
action: "sendMsg",
|
|
|
|
|
systemMessage: false,
|
|
|
|
|
userMsgType: cmds.USER_SENDMSG,
|
|
|
|
|
success: true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (securityCheck.checkIllegalUserName(data.toUsers.realname)) {
|
2015-03-13 19:25:08 +08:00
|
|
|
|
mp.showMessagePopup("error", "发言失败!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-08 17:24:45 +08:00
|
|
|
|
if (media && media.length) {
|
2015-07-30 16:01:49 +08:00
|
|
|
|
var tip = new mp.MessagePopup("loading", "正在上传图片,请稍等...");
|
|
|
|
|
tip.show();
|
|
|
|
|
|
2014-12-18 23:03:04 +08:00
|
|
|
|
//带有图片
|
2015-07-08 17:24:45 +08:00
|
|
|
|
$.post("http://12306.liebao.cn/index.php?r=UpdateImage/GetImageUrl", { data: media[0].data })
|
2014-12-18 23:03:04 +08:00
|
|
|
|
.done(function (json) {
|
2015-07-30 16:01:49 +08:00
|
|
|
|
tip.close();
|
2014-12-18 23:03:04 +08:00
|
|
|
|
if (json.resCode === 0) {
|
2015-07-08 17:24:45 +08:00
|
|
|
|
data.images.push(json.data.img_url);
|
|
|
|
|
port.postMessage("chatRoomSendMsg", coder.encode(data));
|
2014-12-18 23:03:04 +08:00
|
|
|
|
}
|
2015-07-30 16:01:49 +08:00
|
|
|
|
}).fail(function () {
|
|
|
|
|
tip.setState("error", "图片上传失败:服务器开小差了....");
|
|
|
|
|
tip.delayClose();
|
2014-12-18 23:03:04 +08:00
|
|
|
|
});
|
|
|
|
|
} else {
|
2015-07-08 17:24:45 +08:00
|
|
|
|
port.postMessage("chatRoomSendMsg", coder.encode(data));
|
2014-12-18 23:03:04 +08:00
|
|
|
|
}
|
2014-08-14 21:33:47 +08:00
|
|
|
|
};
|
2014-08-19 21:33:26 +08:00
|
|
|
|
this.reconnect = function () {
|
|
|
|
|
if (!room)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
port.postMessage("enterChatRoom", room);
|
|
|
|
|
};
|
2015-07-08 17:24:45 +08:00
|
|
|
|
this.processSysMessage = function (msg) {
|
|
|
|
|
if (msg.sysMsgType === cmds.SYS_USERENTER) {
|
|
|
|
|
//用户进入
|
|
|
|
|
var info = msg.content.split('\t');
|
|
|
|
|
room.onlinecount = parseInt(info[0]);
|
|
|
|
|
that.refreshOnlineCount();
|
|
|
|
|
|
|
|
|
|
if (info[1] === user.username) {
|
|
|
|
|
//自己进入
|
|
|
|
|
that.appendMessageItem(roomSysMessage({ stateIcon: "fa-info-circle", state: "system", msg: "您已进入房间,当前房间在线 " + room.onlinecount + " 人。" }));
|
|
|
|
|
} else {
|
2015-08-10 19:28:33 +08:00
|
|
|
|
if (sessMgr.current.options.showRoomEnter)
|
|
|
|
|
that.appendMessageItem(roomSysMessage({ stateIcon: "fa-info-circle", state: "system", msg: '<a href="javascript:;" class="chat-item-at" data-un="' + utility.htmlEncode(info[1]) + '">' + utility.htmlEncode(info[2]) + '</a> 已进入房间,当前房间在线 ' + room.onlinecount + " 人。" }));
|
2015-07-08 17:24:45 +08:00
|
|
|
|
}
|
|
|
|
|
} else if (msg.sysMsgType === cmds.SYS_USEREXIT) {
|
|
|
|
|
//用户退出
|
|
|
|
|
var info = msg.content.split('\t');
|
|
|
|
|
room.onlinecount = parseInt(info[0]);
|
|
|
|
|
that.refreshOnlineCount();
|
|
|
|
|
|
|
|
|
|
if (info[1] === user.username) {
|
|
|
|
|
//自己进入
|
|
|
|
|
that.appendMessageItem(roomSysMessage({ stateIcon: "fa-info-circle", state: "system", msg: "您已离开房间,当前房间在线 " + room.onlinecount + " 人。" }));
|
|
|
|
|
} else {
|
2015-08-10 19:28:33 +08:00
|
|
|
|
if (sessMgr.current.options.showRoomEnter)
|
|
|
|
|
that.appendMessageItem(roomSysMessage({ stateIcon: "fa-info-circle", state: "system", msg: '<a href="javascript:;" class="chat-item-at" data-un="' + utility.htmlEncode(info[1]) + '">' + utility.htmlEncode(info[2]) + '</a> 已离开房间,当前房间在线 ' + room.onlinecount + " 人。" }));
|
2015-07-08 17:24:45 +08:00
|
|
|
|
}
|
|
|
|
|
} else if (msg.sysMsgType === cmds.SYS_SENDFAILED) {
|
|
|
|
|
} else if (msg.sysMsgType === cmds.SYS_OPERATIONBLOCKED) {
|
2015-07-09 21:06:30 +08:00
|
|
|
|
mp.showMessagePopup("error", msg.content);
|
2015-07-08 17:24:45 +08:00
|
|
|
|
} else if (msg.sysMsgType === cmds.SYS_UPDATEONLINECOUNT) {
|
|
|
|
|
that.appendMessageItem(roomSysMessage({ stateIcon: "fa-info-circle", state: "system", msg: "您已离开房间,当前房间在线 " + room.onlinecount + " 人。" }));
|
2015-07-09 21:06:30 +08:00
|
|
|
|
} else if (msg.sysMsgType === cmds.SYS_REPORTABUSERESULT) {
|
|
|
|
|
that.appendMessageItem(roomSysMessage({ stateIcon: "fa-info-circle", state: "system", msg: msg.content }));
|
2015-07-08 17:24:45 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
this.processUserMessage = function (msg) {
|
|
|
|
|
//安全检测
|
|
|
|
|
if (securityCheck.checkIllegalUserName(msg.fromUser.username) || securityCheck.checkIllegalWords(msg.content))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
msg.self = msg.fromUser.username === sessMgr.current.username;
|
|
|
|
|
if (msg.color)
|
|
|
|
|
msg.color = "#" + msg.color;
|
|
|
|
|
//咩哈哈哈哈
|
|
|
|
|
if (msg.fromUser === "iccfish" || msg.fromUser.username === "imfish") {
|
|
|
|
|
msg.fromUser.realname = "木魚";
|
|
|
|
|
msg.fromUser.exStyle = "font-weight:bold;";
|
|
|
|
|
}
|
|
|
|
|
if (msg.fromUser.username === "*") {
|
|
|
|
|
msg.fromUser.realname = "<系统管理员>";
|
|
|
|
|
msg.fromUser.exStyle = "font-weight:bold;";
|
|
|
|
|
msg.sys = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
msg.tome = false;
|
|
|
|
|
if (msg.toUsers && msg.toUsers.length) {
|
|
|
|
|
var selfTarget = _.findWhere(msg.toUsers, { username: sessMgr.current.username });
|
|
|
|
|
if (selfTarget) {
|
|
|
|
|
msg.tome = true;
|
|
|
|
|
selfTarget.username = null;
|
|
|
|
|
selfTarget.realname = "我";
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-10 19:28:33 +08:00
|
|
|
|
|
|
|
|
|
if (msg.tome && lastPopupTip < msg.id && sessMgr.current.options.popupAt) {
|
|
|
|
|
sessionStorage["lastRoomMstAt"] = msg.id;
|
|
|
|
|
media.notify("聊天室@提醒", msg.fromUser.realname + " 对你说:" + msg.content);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//replace icon
|
|
|
|
|
msg.content = utility.htmlEncode(msg.content || "");
|
|
|
|
|
msg.content = msg.content.replace(/:([a-z\d-+_]+):/gi, function ($0, $1) {
|
|
|
|
|
return "<img src='" + emojiRoot + "/" + $1 + ".png' />";
|
|
|
|
|
});
|
2015-07-08 17:24:45 +08:00
|
|
|
|
that.appendMessageItem(chatMsgItem(msg));
|
|
|
|
|
};
|
2014-08-13 00:14:00 +08:00
|
|
|
|
|
|
|
|
|
Object.defineProperty(this, "room", {
|
|
|
|
|
get: function () {
|
|
|
|
|
return room;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
port.on("chatRoomConnecting", function () {
|
2014-08-14 21:33:47 +08:00
|
|
|
|
that.appendMessageItem(roomStateTemplate({ state: "connecting", stateIcon: "fa-spin fa-spinner", msg: "正在连接服务器中..." }));
|
2014-08-13 00:14:00 +08:00
|
|
|
|
that.fireEvent("chatRoomConnecting");
|
|
|
|
|
});
|
|
|
|
|
port.on("chatRoomConnected", function () {
|
2014-08-14 21:33:47 +08:00
|
|
|
|
page.find("button.button-primary").prop("disabled", false);
|
2014-08-30 01:32:27 +08:00
|
|
|
|
that.clearConnectingState();
|
2014-08-14 21:33:47 +08:00
|
|
|
|
that.appendMessageItem(roomSystemNoticeTemplate(room));
|
2014-08-13 00:14:00 +08:00
|
|
|
|
that.fireEvent("chatRoomConnected");
|
|
|
|
|
});
|
2015-07-08 17:24:45 +08:00
|
|
|
|
port.on("chatRoomReceiveMsg", function (e, evd) {
|
2014-08-14 21:33:47 +08:00
|
|
|
|
that.fireEvent("chatRoomReceiveMsg");
|
2014-08-18 23:12:35 +08:00
|
|
|
|
|
2015-07-08 17:24:45 +08:00
|
|
|
|
var data = coder.decode(evd.buffer);
|
|
|
|
|
if (!data)
|
|
|
|
|
return;
|
2014-09-16 21:40:29 +08:00
|
|
|
|
|
2015-07-08 17:24:45 +08:00
|
|
|
|
//check
|
|
|
|
|
if (data.images) {
|
|
|
|
|
if (_.some(data.images, function (m) {
|
|
|
|
|
return !/^http:\/\/www\.liebao\.cn\/.*/.test(m);
|
2014-09-16 21:40:29 +08:00
|
|
|
|
}))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-18 23:12:35 +08:00
|
|
|
|
if (data.time) {
|
|
|
|
|
data.timeStr = utility.formatDate(data.time, "hh:mm:ss");
|
|
|
|
|
}
|
2014-09-10 21:49:46 +08:00
|
|
|
|
|
2015-07-08 17:24:45 +08:00
|
|
|
|
if (data.systemMessage)
|
|
|
|
|
that.processSysMessage(data);
|
|
|
|
|
else that.processUserMessage(data);
|
2014-08-13 00:14:00 +08:00
|
|
|
|
});
|
|
|
|
|
port.on("chatRoomDisconnected", function () {
|
2014-08-30 01:32:27 +08:00
|
|
|
|
that.clearConnectingState();
|
2014-08-18 23:12:35 +08:00
|
|
|
|
that.appendMessageItem(roomStateTemplate({ state: "disconnect", stateIcon: "fa-times", msg: "服务器已断开连接。", exinfo: "<a href='javascript:;' class='chat-frame-reconnect'>重新连接</a>" }));
|
2014-08-13 00:14:00 +08:00
|
|
|
|
that.fireEvent("chatRoomDisconnected");
|
2014-08-14 21:33:47 +08:00
|
|
|
|
page.find("button.button-primary").prop("disabled", true);
|
2014-08-13 00:14:00 +08:00
|
|
|
|
});
|
2015-02-08 23:31:05 +08:00
|
|
|
|
port.on("chatUpdateOnline", function (e, d) {
|
2014-08-18 23:12:35 +08:00
|
|
|
|
if (!room)
|
|
|
|
|
return;
|
2015-02-08 23:31:05 +08:00
|
|
|
|
room.onlinecount = d.count;
|
2014-08-19 21:33:26 +08:00
|
|
|
|
//更新显示
|
|
|
|
|
that.refreshOnlineCount();
|
2014-09-05 20:55:54 +08:00
|
|
|
|
|
|
|
|
|
//更新显示
|
|
|
|
|
$("#chat_server_select li[data-id='" + room.id + "'] span").html("(" + d.count + "人)");
|
2014-08-18 23:12:35 +08:00
|
|
|
|
});
|
2014-09-02 15:35:51 +08:00
|
|
|
|
port.on("sendMessageFailed", function (e, data) {
|
2014-09-01 20:24:57 +08:00
|
|
|
|
that.appendMessageItem(roomStateTemplate({ state: "error", stateIcon: "fa-times", msg: "消息发送失败:" + data, exinfo: "" }));
|
2014-08-30 01:32:27 +08:00
|
|
|
|
});
|
2014-08-13 00:14:00 +08:00
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
};
|
|
|
|
|
RoomSession.prototype = Object.create(EventObject);
|
|
|
|
|
RoomSession.constructor = RoomSession;
|
|
|
|
|
|
|
|
|
|
var session = new RoomSession();
|
|
|
|
|
|
2014-08-14 21:33:47 +08:00
|
|
|
|
(function chatEditor() {
|
|
|
|
|
var editor = page.find("section.chat-editor");
|
|
|
|
|
var sendBtn = editor.find(">footer>button.button-primary");
|
2014-08-18 23:12:35 +08:00
|
|
|
|
var editorArea = editor.find(".chat-editor-container");
|
2015-08-10 19:28:33 +08:00
|
|
|
|
var emojiIcons = "-p1|-1|angry|anguished|astonished|baby_chick|bear|beetle|bird|blush|cat|chicken|cold_sweat|confounded|confused|congratulations|construction_worker|cry|crying_cat_face|disappointed|disappointed_relieved|dizzy_face|dog|dog2|expressionless|fearful|flushed|frowning|grimacing|grin|grinning|hatched_chick|heart_eyes|heart_eyes_cat|hushed|innocent|joy|joy_cat|kissing|kissing_cat|kissing_closed_eyes|kissing_heart|kissing_smiling_eyes|laughing|mask|mouse|neutral_face|no_good|no_mouth|open_mouth|point_down|point_left|point_right|point_up|point_up_2|pouting_cat|rage|relaxed|relieved|satisfied|scream|scream_cat|sleeping|sleepy|smile|smiley|smiley_cat|smile_cat|smirk|smirk_cat|sob|stuck_out_tongue|stuck_out_tongue_closed_eyes|stuck_out_tongue_winking_eye|sunglasses|sweat|sweat_smile|tired_face|triumph|tropical_fish|unamused|warning|wave|weary|wink|worried|yellow_heart|yum".split('|');
|
|
|
|
|
//var specChars = "(^.^)\n(;_;)\n(¬_¬)\n(u_u)\n♪(´ε`)\n♪(´▽`)\n*_*\n⊙﹏⊙!\n(ーー;)\n(-_-)zz\n↖(^ω^)↗\n囧rz\n^_^\n`(*∩_∩*)′\n ̄□ ̄||\nO(∩_∩)O\n*^_^* \n^_^#\n(☆_☆)/~~\n→_→ \n(~ o ~)~zZ\n(^ω^) \n(ˇ^ˇ)\no(>_<)o ~~\n>_<#\n⊙▂⊙\n╰_╯\n`(*>﹏<*)′\n(⊙o⊙)\no(╯□╰)o\n::>_<:: \n=_=\nT_T\no(>_<)o ~~\n(#‵′)凸\n:-x\n{{{(>_< )}}} \n(╯-╰)/ \nY(^o^)Y~\nY(^o^)Y~\n($ _ $)\no(︶︿︶)o\n⊙△⊙?\n~~~^o^~~~\n╮(╯_╰)╭\n^_^#\n`(*∩_∩*)′\n(⊙_⊙;)\n>_<||| \n@_@\n(⊙⊙?)\n^_~ \n(ˉ(∞)ˉ) \n^(oo)^ \n(◦ \"̮ ◦)\nヽミ ´∀`ミノ< \nヽ〔゚Д゚〕丿\nヽ(●´ε`●)ノ \nヽ(≧Д≦)ノ\nヽ(^0^)ノ\nヾ(@^▽^@)ノ \nヽ(*´∀`)ノ\nヾ ^_^♪\n━(゚∀゚)━!\n(^▽^)コ祝贺你\nლ(╹ε╹ლ) \nლ(╹◡╹ლ)\nლ(^o^ლ) \nΣ(゚д゚lll)\nΣ(゚д゚;)\nΣ(TωT)努力--\nσ(´┰`=)\nε=┌(;・∀・)┘\nε=(・д・`*)ハァ…\nY(・∀・)Y 蟹\nY(>_<、)Y\nw(^_^)ン\nv(=^0^=)v\nT(;_;)T\np(^^)q\no(TヘTo)\no(^∀^)o\nm(-_-m)~ \nm(__)m\n♪~(´ε` )\n☆彡\n☆ミ\n☆⌒(>。≪)\n☆⌒(*^-゜)v\n≡(( ´Д`)/≡=\n∑(O_O;)\n∑(・∀・) コ坏了 !!\n<(ToT)>\n{[(-_-)(-_-)]}zzz\n\(・o・)/!\n\(◎o◎)/!\n\(^o^)/了解!\n(つд⊂)伤心\n(゚Θ゚ )< \n(T▽T)\n(T_T)/~~\n(o・・o)/~\n(๑╹ڡ╹)╭ ~ ♡\n(・。・)\n(・(仝)・)\n(・(ェ)・)\n(¬з¬)\n(=゚Д゚=)\n(=-ω-)zzZZ乙乙\n(--〆)\n( ̄Д ̄)ノ\n(-_-メ) \n(^^♪\n(^。^)y\n-.。o○\n(^ _ ^)/~~\n(-。-)y-゜゜゜\n(*゚Д゚)つミ匚___\n(*°∀°)=3\n(ー_ー)!!\n( ^ω^)\n( ^∀^)".split('\n');
|
|
|
|
|
var faceSelector = editor.find(">header>.chat-btn-emoji");
|
2014-09-17 21:46:05 +08:00
|
|
|
|
var filereader = new FileReader();
|
|
|
|
|
filereader.onload = function (fe) {
|
|
|
|
|
editor.find(".chat-editor-container").append("<img src='" + fe.target.result + "' />");
|
|
|
|
|
};
|
2014-08-14 21:33:47 +08:00
|
|
|
|
|
2015-08-10 19:28:33 +08:00
|
|
|
|
var loadImgIcons = function () {
|
|
|
|
|
var emojiHtml = [];
|
|
|
|
|
emojiIcons.forEach(function (code) {
|
|
|
|
|
emojiHtml.push("<li><img src='" + emojiRoot + "/" + code + ".png' data-emoji='" + code + "' /></li>");
|
|
|
|
|
});
|
|
|
|
|
editor.find(">header>.popup-smail").html(emojiHtml.join(""));
|
|
|
|
|
loadImgIcons = function () { };
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-14 21:33:47 +08:00
|
|
|
|
var initEditor = function () {
|
|
|
|
|
if (!sessMgr.current)
|
|
|
|
|
return;
|
|
|
|
|
var color = sessMgr.current.options.chatColor || "#000000";
|
|
|
|
|
editor.find(">header .chat-editor-color").val(color);
|
|
|
|
|
editor.find(".chat-editor-container").css("color", color);
|
2014-09-09 14:55:30 +08:00
|
|
|
|
|
2015-08-10 19:28:33 +08:00
|
|
|
|
faceSelector.click(function () {
|
|
|
|
|
editor.find(">header>.popup-smail").toggleClass("popup-smail-on");
|
|
|
|
|
loadImgIcons();
|
2014-09-09 14:55:30 +08:00
|
|
|
|
});
|
2015-08-10 19:28:33 +08:00
|
|
|
|
$(document).on("click", ".popup-smail>li", function () {
|
|
|
|
|
var img = this.childNodes[0];
|
|
|
|
|
pasteHtml(" <img data-emoji='" + img.dataset.emoji + "' src='" + img.src + "' /> ");
|
|
|
|
|
editor.find(">header>.popup-smail-on").removeClass("popup-smail-on");
|
2014-09-09 14:55:30 +08:00
|
|
|
|
});
|
2015-08-10 19:28:33 +08:00
|
|
|
|
//specChars.forEach(function (f) {
|
|
|
|
|
// var x = new Option(f, f);
|
|
|
|
|
// faceDom.options[faceDom.options.length] = x;
|
|
|
|
|
//});
|
|
|
|
|
//faceSelector.change(function () {
|
|
|
|
|
// var v = faceSelector.val();
|
|
|
|
|
// if (v) {
|
|
|
|
|
// pasteHtml(v);
|
|
|
|
|
// }
|
|
|
|
|
// faceSelector[0].selectedIndex = 0;
|
|
|
|
|
//});
|
2014-09-16 21:40:29 +08:00
|
|
|
|
$(".chat-items").on("click", ".chat-item > section > img", function () {
|
|
|
|
|
$(this).colorbox({ html: this.outerHTML });
|
|
|
|
|
});
|
2014-08-14 21:33:47 +08:00
|
|
|
|
};
|
|
|
|
|
var delayEnableSend = function () {
|
|
|
|
|
sendBtn.prop("disabled", true);
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
sendBtn.prop("disabled", false);
|
|
|
|
|
}, param.chatSendMsgDelay);
|
|
|
|
|
};
|
2014-09-10 21:49:46 +08:00
|
|
|
|
var pasteHtml = function (html) {
|
2014-09-09 14:55:30 +08:00
|
|
|
|
editorArea.append(html);
|
|
|
|
|
|
|
|
|
|
var range = document.createRange();
|
|
|
|
|
range.selectNodeContents(editorArea[0]);
|
|
|
|
|
range.collapse(false);
|
|
|
|
|
var selection = window.getSelection();
|
|
|
|
|
selection.removeAllRanges();
|
|
|
|
|
selection.addRange(range);
|
|
|
|
|
editorArea[0].focus();
|
|
|
|
|
|
|
|
|
|
};
|
2014-08-14 21:33:47 +08:00
|
|
|
|
initEditor();
|
|
|
|
|
|
2014-08-18 23:12:35 +08:00
|
|
|
|
editor.find(".chat-editor-container").keyup(function (e) {
|
2014-09-11 22:19:33 +08:00
|
|
|
|
if (e.keyCode === 13 && sendBtn.is(":enabled")) {
|
2014-08-14 21:33:47 +08:00
|
|
|
|
sendBtn.click();
|
|
|
|
|
}
|
2014-09-17 21:46:05 +08:00
|
|
|
|
})[0].addEventListener("paste", function (e) {
|
|
|
|
|
if (e.clipboardData) {
|
|
|
|
|
var items = e.clipboardData.items;
|
|
|
|
|
if (items) {
|
|
|
|
|
for (var i = 0; i < items.length; i++) {
|
|
|
|
|
if (items[i].type.indexOf("image") === 0) {
|
|
|
|
|
var blob = items[i].getAsFile();
|
|
|
|
|
filereader.readAsDataURL(blob);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-14 21:33:47 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
sessMgr.on("sessionChanged", function () {
|
|
|
|
|
initEditor();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
editor.find(">header .chat-btn-cls").click(function () {
|
|
|
|
|
session.clearDisplay();
|
|
|
|
|
});
|
|
|
|
|
editor.find(">header .chat-editor-color").change(function () {
|
|
|
|
|
user.options.chatColor = this.value;
|
|
|
|
|
editor.find(".chat-editor-container").css("color", this.value);
|
|
|
|
|
sessMgr.save();
|
|
|
|
|
});
|
2014-09-16 21:40:29 +08:00
|
|
|
|
editor.find("#chat_file").change(function () {
|
|
|
|
|
var file = this;
|
|
|
|
|
if (file.files.length > 0) {
|
|
|
|
|
session.sendPic(this.files[0]);
|
|
|
|
|
}
|
|
|
|
|
file.value = "";
|
|
|
|
|
});
|
2014-08-14 21:33:47 +08:00
|
|
|
|
editor.find(">footer>button.button-default").click(function () {
|
|
|
|
|
session.exitRoom();
|
|
|
|
|
});
|
|
|
|
|
editor.find(">footer>button.button-primary").click(function () {
|
2014-08-18 23:12:35 +08:00
|
|
|
|
var editorObj = editor.find(".chat-editor-container");
|
|
|
|
|
var target = [];
|
|
|
|
|
var addedUser = [];
|
|
|
|
|
editorObj.find("span.chat-editor-at").each(function () {
|
|
|
|
|
var username = this.dataset.un;
|
|
|
|
|
if (addedUser[username])
|
|
|
|
|
return;
|
|
|
|
|
addedUser[username] = true;
|
|
|
|
|
target.push({
|
|
|
|
|
realname: $.trim($(this).text()).substr(1),
|
|
|
|
|
username: username
|
|
|
|
|
});
|
|
|
|
|
}).remove();
|
2015-08-10 19:28:33 +08:00
|
|
|
|
|
|
|
|
|
//msg
|
|
|
|
|
editorObj.find("img[data-emoji]").each(function () {
|
|
|
|
|
$(this).replaceWith(":" + this.dataset.emoji + ":");
|
|
|
|
|
});
|
|
|
|
|
//emoji
|
|
|
|
|
|
2014-08-14 21:33:47 +08:00
|
|
|
|
var msg = {
|
|
|
|
|
color: user.options.chatColor,
|
2014-09-02 15:35:51 +08:00
|
|
|
|
text: $.trim(editorObj.text()).replace(/\u00a0/g, ""),
|
2014-08-18 23:12:35 +08:00
|
|
|
|
target: target
|
2014-08-14 21:33:47 +08:00
|
|
|
|
}
|
2014-09-17 21:46:05 +08:00
|
|
|
|
var media = editorObj.find("img").toBase64Data();
|
|
|
|
|
if (!msg.text && !media.length)
|
2014-08-14 21:33:47 +08:00
|
|
|
|
return;
|
2014-09-17 21:46:05 +08:00
|
|
|
|
|
|
|
|
|
msg.text = msg.text || "[贴图]";
|
2014-08-14 21:33:47 +08:00
|
|
|
|
editor.find(".chat-editor-container").empty();
|
2014-09-17 21:46:05 +08:00
|
|
|
|
session.sendMsg(msg, media);
|
2014-08-14 21:33:47 +08:00
|
|
|
|
delayEnableSend();
|
|
|
|
|
});
|
2014-08-18 23:12:35 +08:00
|
|
|
|
$(document).on("click", "a.chat-item-at", function () {
|
|
|
|
|
var un = this.dataset.un;
|
|
|
|
|
var name = this.innerHTML;
|
2014-08-19 21:33:26 +08:00
|
|
|
|
if (!un)
|
|
|
|
|
return;
|
2014-08-18 23:12:35 +08:00
|
|
|
|
|
|
|
|
|
var html = "<span class='chat-editor-at' contenteditable='false' data-un='" + un + "'>@" + name + "</span> ";
|
2014-09-09 14:55:30 +08:00
|
|
|
|
pasteHtml(html);
|
2014-08-18 23:12:35 +08:00
|
|
|
|
});
|
2015-07-08 17:24:45 +08:00
|
|
|
|
$(document).on("click", "a.chat-reportabuse", function () {
|
2015-03-13 19:25:08 +08:00
|
|
|
|
var a = $(this);
|
|
|
|
|
var item = a.closest(".chat-item");
|
|
|
|
|
var chatid = parseInt(item[0].dataset.chatid);
|
2015-07-09 21:06:30 +08:00
|
|
|
|
var authorlink = item.find(".chat-item-at:eq(0)")[0];
|
|
|
|
|
var username = authorlink.dataset.un;
|
2015-03-13 19:25:08 +08:00
|
|
|
|
|
2015-07-08 17:24:45 +08:00
|
|
|
|
if (username === '*') {
|
2015-03-13 19:25:08 +08:00
|
|
|
|
mp.showMessagePopup("error", "亲,不可以举报我们伟大的管理员哦 ♪(´ε`)");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-09 21:06:30 +08:00
|
|
|
|
if (!confirm("确定要举报 " + (authorlink.innerText) + " 吗?"))
|
2015-03-13 19:25:08 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2015-07-08 17:24:45 +08:00
|
|
|
|
var data = {
|
2015-07-09 21:06:30 +08:00
|
|
|
|
systemMessage: false,
|
|
|
|
|
userMsgType: cmds.USER_REPORTABUSE,
|
|
|
|
|
content: chatid + "",
|
2015-07-08 17:24:45 +08:00
|
|
|
|
time: new Date()
|
|
|
|
|
};
|
2015-03-13 19:25:08 +08:00
|
|
|
|
|
2015-07-09 21:06:30 +08:00
|
|
|
|
port.postMessage("chatRoomSendMsg", coder.encode(data));
|
2015-03-13 19:25:08 +08:00
|
|
|
|
});
|
2014-08-30 01:32:27 +08:00
|
|
|
|
$(document).on("click", "a.chat-frame-reconnect", function () {
|
2014-08-19 21:33:26 +08:00
|
|
|
|
$(".chat-item").remove();
|
|
|
|
|
session.reconnect();
|
|
|
|
|
});
|
2014-08-14 21:33:47 +08:00
|
|
|
|
})();
|
|
|
|
|
|
2014-08-13 00:14:00 +08:00
|
|
|
|
return {
|
|
|
|
|
session: session,
|
|
|
|
|
enterRoom: session.enterRoom
|
|
|
|
|
}
|
2014-08-08 20:46:37 +08:00
|
|
|
|
});
|