chat.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. var getplayer = function (fname) {
  2. return '<embed style="position:absolute;top:-100000px" width="0" height="0" type="application/x-shockwave-flash" swliveconnect="true" allowscriptaccess="sameDomain" menu="false" flashvars="sFile=static/pack/chat/player/' + fname + ".mp3?" + Math.random() + '" src="static/pack/chat/player/sound.swf" />';
  3. };
  4. var updateavatar = function () {
  5. $("#list_reload").click();
  6. layer.closeAll();
  7. };
  8. var f_getURL = function () {
  9. return "source/pack/chat/saverecord.php";
  10. };
  11. var f_getMAX = function () {
  12. return 60;
  13. };
  14. var f_getMIN = function () {
  15. return 3;
  16. };
  17. var f_complete = function (filename) {
  18. if (filename == "error") {
  19. $("#textarea").val($("#textarea").val() + "[语音保存失败]");
  20. } else {
  21. $("#textarea").val($("#textarea").val() + "[record:" + filename.substr(9, filename.length - 13) + "]");
  22. }
  23. $("#textarea").focus();
  24. $(".wl_faces_box8").hide();
  25. };
  26. var isIE = function () {
  27. if (!!window.ActiveXObject || "ActiveXObject" in window) {
  28. return true;
  29. } else {
  30. return false;
  31. }
  32. };
  33. var createAjax = function () {
  34. var xhr = null;
  35. try {
  36. xhr = new ActiveXObject("Msxml2.XMLHTTP");
  37. } catch (e) {
  38. try {
  39. xhr = new ActiveXObject("Microsoft.XMLHTTP");
  40. } catch (e) {
  41. xhr = new XMLHttpRequest();
  42. }
  43. }
  44. return xhr;
  45. };
  46. var ajax = function (conf) {
  47. var type = conf.type;
  48. var url = conf.url;
  49. var data = conf.data;
  50. var dataType = conf.dataType;
  51. var success = conf.success;
  52. if (type == null) {
  53. type = "get";
  54. }
  55. if (dataType == null) {
  56. dataType = "text";
  57. }
  58. var xhr = createAjax();
  59. xhr.open(type, url, true);
  60. if (!isIE()) {
  61. xhr.withCredentials = true;
  62. }
  63. if (type == "GET" || type == "get") {
  64. xhr.send(null);
  65. } else {
  66. if (type == "POST" || type == "post") {
  67. xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
  68. xhr.send(data);
  69. }
  70. }
  71. xhr.onreadystatechange = function () {
  72. if (xhr.readyState == 4 && xhr.status == 200) {
  73. if (dataType == "text" || dataType == "TEXT") {
  74. if (success != null) {
  75. success(xhr.responseText);
  76. }
  77. } else {
  78. if (dataType == "xml" || dataType == "XML") {
  79. if (success != null) {
  80. success(xhr.responseXML);
  81. }
  82. } else {
  83. if (dataType == "jsonp" || dataType == "JSONP") {
  84. if (success != null) {
  85. success(eval("(" + xhr.responseText + ")"));
  86. }
  87. }
  88. }
  89. }
  90. } else {
  91. if (xhr.readyState == 4 && xhr.status != 200) {
  92. }
  93. }
  94. };
  95. };
  96. var listenMsg = {
  97. nid: 0, mid: 0, gid: 0, queryUrl: in_ssl + "://" + in_server + "/source/pack/api/chat/", stop: function () {
  98. clearTimeout(listenMsg.nid);
  99. listenMsg.nid = 0;
  100. clearTimeout(listenMsg.mid);
  101. listenMsg.mid = 0;
  102. clearTimeout(listenMsg.gid);
  103. listenMsg.gid = 0;
  104. $(".message_box").text("");
  105. }, start: function (_uid, _type, _do) {
  106. ajax({
  107. type: "get",
  108. url: listenMsg.queryUrl + "start.php?type=" + _type + "&do=" + _do + "&uid=" + _uid,
  109. dataType: "jsonp",
  110. success: function (data) {
  111. if (data["start"] == -1) {
  112. listenMsg.stop();
  113. $("#send_tips").text("您已退出应用中心");
  114. $(".chat03_content li b").text("");
  115. $(".chat03_content li label").removeClass("online offline").addClass("offline");
  116. if ($("#list_reload").hasClass("chat02_title_t")) {
  117. $("#list_reload").removeClass("chat02_title_t").addClass("chat002_title_t");
  118. }
  119. } else {
  120. if (_type == "msg") {
  121. clearTimeout(listenMsg.mid);
  122. clearTimeout(listenMsg.gid);
  123. if (isNaN(data["start"])) {
  124. $(".close_btn").html("<span>" + getplayer("send") + "</span>");
  125. $(".message_box").append(data["start"]);
  126. $(".chat01_content").scrollTop($(".message_box")[0].scrollHeight);
  127. }
  128. listenMsg.mid = setTimeout("listenMsg.start(" + _uid + ", '" + _type + "', 0);", data["sleep"]);
  129. } else {
  130. if (data["status"] > 0) {
  131. if ($("#uid_" + _uid + " label").hasClass("offline")) {
  132. $("#uid_" + _uid + " label").html("<span>" + getplayer("online") + "</span>");
  133. $("#uid_" + _uid + " label").removeClass("offline").addClass("online");
  134. }
  135. } else {
  136. if ($("#uid_" + _uid + " label").hasClass("online")) {
  137. $("#uid_" + _uid + " label").removeClass("online").addClass("offline");
  138. }
  139. }
  140. if (data["start"] > 0) {
  141. $("#uid_" + _uid + " b").html(data["start"] + "<span>" + getplayer("msg") + "</span>");
  142. $(".chat03_content").animate({scrollTop: $("#uid_" + _uid).offset().top - $(".chat03_content").offset().top}, 100);
  143. } else {
  144. $("#uid_" + _uid + " b").text("");
  145. }
  146. listenMsg.nid = setTimeout("listenMsg.start(" + _uid + ", '" + _type + "', 0);", data["sleep"]);
  147. }
  148. }
  149. }
  150. });
  151. }, group: function (_num) {
  152. ajax({
  153. type: "get",
  154. url: listenMsg.queryUrl + "group.php?num=" + _num,
  155. dataType: "jsonp",
  156. success: function (data) {
  157. if (data["group"] != -1) {
  158. clearTimeout(listenMsg.gid);
  159. if (data["num"] > _num) {
  160. $(".close_btn").html("<span>" + getplayer("send") + "</span>");
  161. $(".talkTo").attr("num", data["num"]);
  162. $(".message_box").append(data["group"]);
  163. $(".chat01_content").scrollTop($(".message_box")[0].scrollHeight);
  164. }
  165. listenMsg.gid = setTimeout("listenMsg.group(" + data["num"] + ");", data["sleep"]);
  166. }
  167. }
  168. });
  169. }, login: function () {
  170. $(".chat03_content").html('<img src="static/admincp/image/loading.gif">');
  171. if (isIE()) {
  172. $("#send_tips").text("工具->Internet 选项->安全->自定义级别->其他->通过域访问数据源->启用");
  173. }
  174. ajax({
  175. type: "get", url: listenMsg.queryUrl + "login.php" + in_info, dataType: "jsonp", success: function (data) {
  176. if (data["uid"] == -1) {
  177. $("#send_tips").text("您的应用中心帐号已经被锁定,请咨询官方人员!");
  178. } else {
  179. listenMsg.stop();
  180. listenMsg.group($(".talkTo").attr("num"));
  181. listenMsg.list(data["uid"]);
  182. $(".talkTo").attr("verify", data["verify"]);
  183. $(".talkTo a").text("公共频道");
  184. $(".talkTo a").attr("uid", 0);
  185. $("#send_tips").text("按 Enter 键快捷发送");
  186. if ($("#list_reload").hasClass("chat002_title_t")) {
  187. $("#list_reload").removeClass("chat002_title_t").addClass("chat02_title_t");
  188. }
  189. if ($("#_bar", window.parent.document)) {
  190. $("#_bar", window.parent.document).css("background-image", "url(" + data["avatar"] + ")");
  191. }
  192. }
  193. }
  194. });
  195. }, list: function (_uid) {
  196. ajax({
  197. type: "get",
  198. url: listenMsg.queryUrl + "list.php?uid=" + _uid,
  199. dataType: "jsonp",
  200. success: function (data) {
  201. $(".chat03_content").html(data["list"]);
  202. jQuery.getScript("static/pack/chat/js/menu.js", function () {
  203. $(".chat03_content li").contextMenu("menu_list", {
  204. bindings: {
  205. space: function (t) {
  206. window.open("http://" + t.title);
  207. }, lock: function (t) {
  208. lib.away(t.id.substr(4));
  209. }
  210. }
  211. });
  212. });
  213. }
  214. });
  215. }, lock: function (_id) {
  216. ajax({
  217. type: "get",
  218. url: listenMsg.queryUrl + "lib.php/lock?id=" + _id,
  219. dataType: "jsonp",
  220. success: function (data) {
  221. if (data["lock"] == -1) {
  222. layer.msg("请先登录管理中心!", 3, 11);
  223. } else if (data["lock"] == -2) {
  224. layer.msg("请先登录应用中心!", 3, 11);
  225. } else if (data["lock"] == -3) {
  226. layer.msg("站长不存在或已被管理员锁定!", 3, 11);
  227. } else if (data["lock"] == -4) {
  228. layer.msg("您不能锁定自己!", 3, 8);
  229. } else {
  230. layer.msg("恭喜,锁定站长成功!", 3, 1);
  231. setTimeout("$('#list_reload').click();", 3e3);
  232. }
  233. }
  234. });
  235. }, first: function (_pswd) {
  236. if (_pswd.length < 6) {
  237. layer.msg("设置密码长度最短为6位!", 3, 8);
  238. return;
  239. }
  240. ajax({
  241. type: "get",
  242. url: listenMsg.queryUrl + "lib.php/first?pswd=" + escape(_pswd),
  243. dataType: "jsonp",
  244. success: function (data) {
  245. if (data["first"] == -1) {
  246. layer.msg("请先登录应用中心!", 3, 11);
  247. } else if (data["first"] == -2) {
  248. layer.msg("您已经设置过密码!", 3, 11);
  249. } else {
  250. $(".talkTo").attr("verify", data["first"]);
  251. layer.msg("密码设置成功,请继续您的操作!", 3, 1);
  252. }
  253. }
  254. });
  255. }, verify: function (_pswd) {
  256. ajax({
  257. type: "get",
  258. url: listenMsg.queryUrl + "lib.php/verify?pswd=" + escape(_pswd),
  259. dataType: "jsonp",
  260. success: function (data) {
  261. if (data["verify"] == -1) {
  262. layer.msg("请先登录应用中心!", 3, 11);
  263. } else if (data["verify"] == -2) {
  264. lib.reset();
  265. } else {
  266. $(".talkTo").attr("verify", data["verify"]);
  267. layer.msg("密码校验成功,请继续您的操作!", 3, 1);
  268. }
  269. }
  270. });
  271. }, game: function (_mid, _tid) {
  272. ajax({
  273. type: "get",
  274. url: in_ssl + "://" + in_server + "/source/pack/api/poker/enterTable.php?tableID=" + _tid,
  275. dataType: "text",
  276. success: function (data) {
  277. if (data == "failure") {
  278. layer.tips("房间人数已满员!", "#" + _mid, {
  279. style: ["background-color:#FF8901;color:#fff", "#FF8901"],
  280. maxWidth: 185,
  281. time: 3,
  282. closeBtn: [0, true]
  283. });
  284. } else {
  285. lib.poker();
  286. }
  287. }
  288. });
  289. }, send: function () {
  290. if ($("#textarea").val() == "") {
  291. $("#textarea").focus();
  292. return;
  293. }
  294. ajax({
  295. type: "get",
  296. url: listenMsg.queryUrl + "send.php?text=" + escape($("#textarea").val()) + "&uname=" + $(".talkTo a").text() + "&uid=" + $(".talkTo a").attr("uid"),
  297. dataType: "jsonp",
  298. success: function (data) {
  299. if (data["send"] == -1) {
  300. $("#send_tips").text("请先登录应用中心");
  301. } else if (data["send"] == -2) {
  302. layer.prompt({title: "发送消息前,请先设置密码"}, function (_pswd) {
  303. listenMsg.first(_pswd);
  304. });
  305. } else if (data["send"] == -3) {
  306. layer.prompt({title: "发送消息前,请先校验密码"}, function (_pswd) {
  307. listenMsg.verify(_pswd);
  308. });
  309. } else {
  310. $("#textarea").val("");
  311. if ($(".talkTo a").attr("uid") > 0) {
  312. listenMsg.start($(".talkTo a").attr("uid"), "msg", 1);
  313. } else {
  314. listenMsg.group($(".talkTo").attr("num"));
  315. }
  316. }
  317. }
  318. });
  319. }
  320. };
  321. (function () {
  322. lib = {
  323. press: function (_type, _id, _class) {
  324. var key = navigator.appName == "Netscape" ? event.which : window.event.keyCode;
  325. if (_type == "send" && key == 13) {
  326. listenMsg.send();
  327. } else if (_type == "value" && key == 27) {
  328. var val = _id == "_img" ? "[img]" + $("#_img").val() + "[/img]" : "[flash]" + $("#_flash").val() + "[/flash]";
  329. $("#textarea").val($("#textarea").val() + val);
  330. $("#textarea").focus();
  331. $("." + _class).hide();
  332. }
  333. }, disturb: function (_mode) {
  334. if (_mode > 0) {
  335. $("#list_reload").click();
  336. $("#set_disturb").attr("title", "开启免打扰");
  337. $("#set_disturb").attr("onclick", "lib.disturb(0)");
  338. $("#set_disturb").css("background", "url('static/pack/chat/icon/disturb.png') no-repeat 10px 8px");
  339. layer.tips("已关闭免打扰模式!", "#set_disturb", {
  340. style: ["background-color:#FF8901;color:#fff", "#FF8901"],
  341. maxWidth: 185,
  342. time: 1
  343. });
  344. } else {
  345. listenMsg.stop();
  346. $("#set_disturb").attr("title", "关闭免打扰");
  347. $("#set_disturb").attr("onclick", "lib.disturb(1)");
  348. $("#set_disturb").css("background", "url('static/pack/chat/icon/nodisturb.png') no-repeat 10px 8px");
  349. layer.tips("已开启免打扰模式!", "#set_disturb", {
  350. style: ["background-color:#99C521;color:#fff", "#99C521"],
  351. maxWidth: 185,
  352. closeBtn: [0, true]
  353. });
  354. }
  355. }, away: function (_id) {
  356. $.layer({
  357. shade: [0],
  358. area: ["auto", "auto"],
  359. dialog: {
  360. msg: "确认要通过锁定来踢出该站长?", btns: 2, type: 4, btn: ["确认", "取消"], yes: function () {
  361. listenMsg.lock(_id);
  362. }, no: function () {
  363. layer.msg("已取消锁定", 1, 0);
  364. }
  365. }
  366. });
  367. }, reset: function () {
  368. $.layer({
  369. shade: [0],
  370. area: ["auto", "auto"],
  371. dialog: {
  372. msg: "密码有误,是否重置密码?", btns: 2, type: 4, btn: ["确认", "取消"], yes: function () {
  373. window.open(in_ssl + "://" + in_server + "/index/setting/resetpw/");
  374. }, no: function () {
  375. layer.msg("已取消重置", 1, 0);
  376. }
  377. }
  378. });
  379. }, avatar: function () {
  380. $.layer({
  381. type: 1,
  382. title: "更新头像",
  383. area: ["auto", "auto"],
  384. page: {html: '<embed src="' + in_ssl + "://" + in_server + "/static/pack/upload/camera.swf?ucapi=" + in_avatar + "&input=uid%3D" + $(".talkTo").attr("verify") + '" width="459" height="266" wmode="transparent" allowScriptAccess="always" type="application/x-shockwave-flash"></embed>'}
  385. });
  386. }, poker: function () {
  387. $.layer({
  388. type: 2,
  389. shade: [0],
  390. maxmin: true,
  391. title: "斗地主",
  392. area: ["826px", "549px"],
  393. iframe: {src: in_ssl + "://" + in_server + "/source/pack/api/poker/game.php", scrolling: "no"}
  394. });
  395. }, shake: function (_size, _time, _id, _speed) {
  396. if ($("#_dialog", window.parent.document) && $("#_dialog", window.parent.document).is(":hidden")) {
  397. $("#_dialog", window.parent.document).show();
  398. }
  399. $(".close_btn").html("<span>" + getplayer("shake") + "</span>");
  400. var len = _size, c = _time, step = 0, shake = $("#" + _id), off = shake.offset();
  401. this.step = 0;
  402. timer = setInterval(function () {
  403. var set = lib.pos();
  404. shake.offset({top: off.top + set.y * len, left: off.left + set.x * len});
  405. if (step++ >= c) {
  406. shake.offset({top: off.top, left: off.left});
  407. clearInterval(timer);
  408. }
  409. }, _speed);
  410. }, pos: function () {
  411. this.step = this.step ? this.step : 0;
  412. this.step = this.step == 4 ? 0 : this.step;
  413. var set = {0: {x: 0, y: -1}, 1: {x: -1, y: 0}, 2: {x: 0, y: 1}, 3: {x: 1, y: 0}};
  414. return set[this.step++];
  415. }
  416. };
  417. })();
  418. $(document).ready(function () {
  419. $("body").delegate(".chat03_content li", "mouseover", function () {
  420. $(this).addClass("hover").siblings().removeClass("hover");
  421. });
  422. $("body").delegate(".chat03_content li", "mouseout", function () {
  423. $(this).removeClass("hover").siblings().removeClass("hover");
  424. });
  425. $("body").delegate(".chat03_content li", "click", function () {
  426. $(this).addClass("choosed").siblings().removeClass("choosed");
  427. $(".talkTo a").text($(this).children(".chat03_name").text());
  428. $(".talkTo a").attr("uid", $(this).children(".chat03_name").attr("uid"));
  429. $(".message_box").text("");
  430. listenMsg.start($(this).children(".chat03_name").attr("uid"), "msg", 2);
  431. });
  432. $("#_emoji").mouseover(function () {
  433. $(this).removeClass("ctb00").addClass("ctb01");
  434. $(".wl_faces_box").show();
  435. }).mouseout(function () {
  436. $(this).removeClass("ctb01").addClass("ctb00");
  437. $(".wl_faces_box").hide();
  438. });
  439. $("#_record").mouseover(function () {
  440. $(this).removeClass("ctb07").addClass("ctb08");
  441. $(".wl_faces_box8").show();
  442. }).mouseout(function () {
  443. $(this).removeClass("ctb08").addClass("ctb07");
  444. $(".wl_faces_box8").hide();
  445. });
  446. $(".ctb02").mouseover(function () {
  447. $(".wl_faces_box2").show();
  448. }).mouseout(function () {
  449. $(".wl_faces_box2").hide();
  450. });
  451. $(".ctb03").mouseover(function () {
  452. $(".wl_faces_box3").show();
  453. }).mouseout(function () {
  454. $(".wl_faces_box3").hide();
  455. });
  456. $("#_shake").mouseover(function () {
  457. $(this).removeClass("ctb04").addClass("ctb05");
  458. }).mouseout(function () {
  459. $(this).removeClass("ctb05").addClass("ctb04");
  460. });
  461. $("#_shake").click(function () {
  462. $("#textarea").val($("#textarea").val() + "[event:shake]");
  463. $("#textarea").focus();
  464. });
  465. $("#_upload").mouseover(function () {
  466. $(this).removeClass("ctb09").addClass("ctb10");
  467. }).mouseout(function () {
  468. $(this).removeClass("ctb10").addClass("ctb09");
  469. });
  470. $(".ctb06").click(function () {
  471. if ($(".talkTo").attr("verify") == "8f00b204e9800998") {
  472. layer.prompt({title: "更新头像前,请先设置密码"}, function (_pswd) {
  473. listenMsg.first(_pswd);
  474. });
  475. } else if ($(".talkTo").attr("verify").match(/\:/)) {
  476. lib.avatar();
  477. } else {
  478. layer.prompt({title: "更新头像前,请先校验密码"}, function (_pswd) {
  479. listenMsg.verify(_pswd);
  480. });
  481. }
  482. });
  483. $(".ctb11").click(function () {
  484. lib.poker();
  485. });
  486. $(".chat02_title_l").click(function () {
  487. $(".talkTo").attr("num", 0);
  488. $("#list_reload").click();
  489. });
  490. $(".wl_faces_box").mouseover(function () {
  491. $("#_emoji").removeClass("ctb00").addClass("ctb01");
  492. $(this).show();
  493. }).mouseout(function () {
  494. $("#_emoji").removeClass("ctb01").addClass("ctb00");
  495. $(this).hide();
  496. });
  497. $(".wl_faces_box8").mouseover(function () {
  498. $("#_record").removeClass("ctb07").addClass("ctb08");
  499. $(this).show();
  500. }).mouseout(function () {
  501. $("#_record").removeClass("ctb08").addClass("ctb07");
  502. $(this).hide();
  503. });
  504. $(".wl_faces_box2").mouseover(function () {
  505. $(this).show();
  506. }).mouseout(function () {
  507. $(this).hide();
  508. });
  509. $(".wl_faces_box3").mouseover(function () {
  510. $(this).show();
  511. }).mouseout(function () {
  512. $(this).hide();
  513. });
  514. $(".wl_faces_close").click(function () {
  515. $(".wl_faces_box").hide();
  516. });
  517. $(".wl_faces_close8").click(function () {
  518. $(".wl_faces_box8").hide();
  519. });
  520. $(".wl_faces_close2").click(function () {
  521. $(".wl_faces_box2").hide();
  522. });
  523. $(".wl_faces_close3").click(function () {
  524. $(".wl_faces_box3").hide();
  525. });
  526. $(".close_btn").click(function () {
  527. $(".message_box").text("");
  528. });
  529. $("#list_reload").click(function () {
  530. listenMsg.login();
  531. });
  532. $(".wl_faces_main img").click(function () {
  533. var i = $(this).attr("src");
  534. $("#textarea").val($("#textarea").val() + "[emoji:" + i.substr(i.indexOf("emoji/") + 10, 2) + "]");
  535. $("#textarea").focus();
  536. $(".wl_faces_box").hide();
  537. });
  538. });