From 2ae824cada1a296a566a37747e107e32fa25a134 Mon Sep 17 00:00:00 2001 From: Karuhut Komol Date: Thu, 27 Jul 2023 17:44:54 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20remove=20delay=20check=20from=20?= =?UTF-8?q?client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- th_chat/js/th_chat.js | 104 ++++++++++++++++++-------------------- th_chat/js/th_chat.min.js | 2 +- 2 files changed, 49 insertions(+), 57 deletions(-) diff --git a/th_chat/js/th_chat.js b/th_chat/js/th_chat.js index c6ea932..4e66a0d 100644 --- a/th_chat/js/th_chat.js +++ b/th_chat/js/th_chat.js @@ -1,8 +1,6 @@ var nzchatobj = jQuery.noConflict(); var nzsid = getcookie("sid", true); -var nztime1 = new Date().getTime(); -var nztime2 = 0; var nztouid = 0; var nzquota = 0; var nzlastid = 0; @@ -195,64 +193,58 @@ function nzSend() { if (data === "") { return false; } - nztime1 = new Date().getTime(); - if (nztime1 > nztime2) { - nzchatobj("#nzchatmessage").val(""); - nztime2 = nztime1 + nzsetting.delay; - nzchatobj.post( - "plugin.php?id=th_chat:post" + formhash, - { - text: data, - lastid: nzlastid, - touid: nztouid, - quota: nzquota, - command: nzcommandz, - room: nzChatRoom, - }, - function (data) { - if ( - nzquota > 0 || - nzcommandz == "notice" || - nzcommandz.substring(0, 4) == "edit" - ) { - nzTouid(nztouid); + nzchatobj("#nzchatmessage").val(""); + nzchatobj.post( + "plugin.php?id=th_chat:post" + formhash, + { + text: data, + lastid: nzlastid, + touid: nztouid, + quota: nzquota, + command: nzcommandz, + room: nzChatRoom, + }, + function (data) { + if ( + nzquota > 0 || + nzcommandz == "notice" || + nzcommandz.substring(0, 4) == "edit" + ) { + nzTouid(nztouid); + } + data = JSON.parse(data); + if (data.type == 1) { + nzalert(data.error); + if (data.script) { + eval(data.script); } - data = JSON.parse(data); - if (data.type == 1) { - nzalert(data.error); - if (data.script) { - eval(data.script); - } - } else { - if (nztouid == nzChatRoom) { - var listmess = sortObject(data); - nzReadyForScroll(); - nzchatobj.each(listmess, function (k, v) { - k = parseInt(k); - if (k > nzlastid) { - nzlastid = k; - nzchatobj("#afterme").before(v); - nzScrollChat(); - } - }); - nzchatobj(".nzinnercontent img").one("load", function () { + } else { + if (nztouid == nzChatRoom) { + var listmess = nzSortObject(data); + nzReadyForScroll(); + nzchatobj.each(listmess, function (k, v) { + k = parseInt(k); + if (k > nzlastid) { + nzlastid = k; + nzchatobj("#afterme").before(v); nzScrollChat(); - }); - if (nzsetting.iscleardata == 1) { - var nzchatrr = nzchatobj(".nzchatrow"); - if (nzchatrr.size() > nzsetting.chatrowmax) { - nzchatrr.first().remove(); - } } - } else { - nzChangeChatRoom(nztouid); + }); + nzchatobj(".nzinnercontent img").one("load", function () { + nzScrollChat(); + }); + if (nzsetting.iscleardata == 1) { + var nzchatrr = nzchatobj(".nzchatrow"); + if (nzchatrr.size() > nzsetting.chatrowmax) { + nzchatrr.first().remove(); + } } + } else { + nzChangeChatRoom(nztouid); } } - ); - } else { - nzalert("ส่งข้อความบ่อยไป"); - } + } + ); } function nzCommand(command, xid) { @@ -390,7 +382,7 @@ function nzLoadText() { }, function (data) { data = JSON.parse(data); - var listmess = sortObject(data.chat_row); + var listmess = nzSortObject(data.chat_row); nzReadyForScroll(); nzchatobj.each(listmess, function (k, v) { k = parseInt(k); @@ -564,7 +556,7 @@ function nzCheckImg(i) { } } -function sortObject(a) { +function nzSortObject(a) { var b = {}, c, d = []; diff --git a/th_chat/js/th_chat.min.js b/th_chat/js/th_chat.min.js index 005eb28..0c5c43d 100644 --- a/th_chat/js/th_chat.min.js +++ b/th_chat/js/th_chat.min.js @@ -1 +1 @@ -var nzchatobj=jQuery.noConflict();var nzsid=getcookie("sid",true);var nztime1=new Date().getTime();var nztime2=0;var nztouid=0;var nzquota=0;var nzlastid=0;var nzonol=false;var nzcommandz="";var formhash="";var nzscroll=true;var nzChatRoom=0;var nzChatList=0;var nzInterval;function nzolover(){nzonol=true}function nzolout(){nzonol=false}function nzalert(text){nzchatobj("#nzalertbox").text(text);nzchatobj("#nzalertbox").slideDown(200);setTimeout(function(){nzchatobj("#nzalertbox").slideUp(200)},2000)}nzchatobj.ajaxSetup({timeout:3000,error:function(jqXHR,textStatus,errorThrown){nzalert("ขาดเชื่อมต่อกับเซิฟเวอร์ กำลังลองใหม่...");nzResetInterval()}});nzchatobj(function(){nzchatobj("#nzchatmessage").on("keydown",function(event){if(event.key=="Enter"){nzSend()}else if(event.key=="Escape"){nzTouid(0)}else if(event.key=="ArrowUp"){if(nzchatobj(".nzchatrow:last").length){nzCommand("edit",nzchatobj(".nzchatrow:last").attr("id").substring(7))}}});nzchatobj("#nzchatmessage").on("paste",function(e){if(e.originalEvent.clipboardData.files.length!==1){return}nzchatobj("#nzimguploadl").text("กำลังอัปโหลด...");nzchatobj("#nzimgupload").prop("disabled",true);var nzFormData=new FormData();nzFormData.append("pictures",e.originalEvent.clipboardData.files[0]);nzchatobj("#nzimgupload").val("");nzchatobj.ajax({url:"plugin.php?id=th_chat:img",type:"POST",data:nzFormData,cache:false,dataType:"json",processData:false,contentType:false,success:function(data,textStatus,jqXHR){if(typeof data.error==="undefined"){seditor_insertunit("nzchat","[img]"+data.url+"[/img]","");nzchatobj("#nzchatmessage").focus()}else{nzalert(data.error)}},error:function(jqXHR,textStatus,errorThrown){nzalert("เกิดข้อผิดพลาด: "+textStatus)},complete:function(jqXHR,textStatus,errorThrown){nzchatobj("#nzimguploadl").text("อัปโหลดไฟล์ภาพ");nzchatobj("#nzimgupload").prop("disabled",false)}})});nzchatobj("#nzimgup").on("click",function(){nzchatobj("#nzimgupload").trigger("click")});nzchatobj("#nzimgupload").on("change",function(){if(nzchatobj("#nzimgupload").val()){nzchatobj("#nzimguploadl").text("กำลังอัปโหลด...");nzchatobj("#nzimgupload").prop("disabled",true);var nzFormData=new FormData();nzFormData.append("pictures",nzchatobj("#nzimgupload").prop("files")[0]);nzchatobj("#nzimgupload").val("");nzchatobj.ajax({url:"plugin.php?id=th_chat:img",type:"POST",data:nzFormData,cache:false,dataType:"json",processData:false,contentType:false,success:function(data,textStatus,jqXHR){if(typeof data.error==="undefined"){seditor_insertunit("nzchat","[img]"+data.url+"[/img]","");nzchatobj("#nzchatmessage").focus()}else{nzalert(data.error)}},error:function(jqXHR,textStatus,errorThrown){nzalert("เกิดข้อผิดพลาด: "+textStatus)},complete:function(jqXHR,textStatus,errorThrown){nzchatobj("#nzimguploadl").text("อัปโหลดไฟล์ภาพ");nzchatobj("#nzimgupload").prop("disabled",false)}})}});nzchatobj(".nzchat_general").on("click",function(){nzChatList=0;nzTouid(0);nzchatobj("#nzchatolcontent").html('
');nzLoadTextInit();nzchatobj(".nzchat_room").removeClass("nzactive");nzchatobj(this).addClass("nzactive")});nzchatobj(".nzchat_whisper").on("click",function(){nzChatList=1;nzchatobj("#nzchatolcontent").html('
');nzLoadTextInit();nzchatobj(".nzchat_room").removeClass("nzactive");nzchatobj(this).addClass("nzactive")});if(nzsetting.autoconnect==1){nzLoadTextInit()}const nzemoji=document.querySelector("#nzemoji");const nzpicker=picmoPopup.createPopup({rootElement:document.querySelector("#nzchat"),theme:`picmo__${nzsetting.theme }`},{referenceElement:nzemoji,triggerElement:nzemoji});nzpicker.addEventListener("emoji:select",(selection)=>{nzchatobj("#nzchatmessage").val(nzchatobj("#nzchatmessage").val()+selection.emoji)});nzchatobj("#nzemoji").on("click",function(){nzpicker.toggle()});nzchatobj("#nznewmessage").on("click",function(){nzScrollChat(true)});nzchatobj("#nzchatcontent").on("scroll",function(){var objDiv=document.getElementById("nzchatcontent");if(objDiv.scrollHeight-objDiv.scrollTop==nzsetting.chatheight){nzchatobj("#nznewmessage").hide();objDiv.scrollTop=objDiv.scrollHeight}})});function nzNotice(){nzcommandz="notice";nzchatobj(".nzquoteboxi").html('
แก้ไขประกาศ: '+nzchatobj("#nzchatnotice").html()+'
');nzchatobj(".nzquoteboxo").show();nzchatobj("#nzchatcontent").css("height",nzsetting.chatheight-nzchatobj(".nzquoteboxo").height());nzScrollChat(true);nzchatobj("#nzchatmessage").val(nzchatobj("#nzchatnotice").text());nzchatobj("#nzchatmessage").trigger("focus")}function nzSend(){var data=nzchatobj("#nzchatmessage").val().trim();if(data===""){return false}nztime1=new Date().getTime();if(nztime1>nztime2){nzchatobj("#nzchatmessage").val("");nztime2=nztime1+nzsetting.delay;nzchatobj.post("plugin.php?id=th_chat:post"+formhash,{text:data,lastid:nzlastid,touid:nztouid,quota:nzquota,command:nzcommandz,room:nzChatRoom},function(data){if(nzquota>0||nzcommandz=="notice"||nzcommandz.substring(0,4)=="edit"){nzTouid(nztouid)}data=JSON.parse(data);if(data.type==1){nzalert(data.error);if(data.script){eval(data.script)}}else{if(nztouid==nzChatRoom){var listmess=sortObject(data);nzReadyForScroll();nzchatobj.each(listmess,function(k,v){k=parseInt(k);if(k>nzlastid){nzlastid=k;nzchatobj("#afterme").before(v);nzScrollChat()}});nzchatobj(".nzinnercontent img").one("load",function(){nzScrollChat()});if(nzsetting.iscleardata==1){var nzchatrr=nzchatobj(".nzchatrow");if(nzchatrr.size()>nzsetting.chatrowmax){nzchatrr.first().remove()}}}else{nzChangeChatRoom(nztouid)}}})}else{nzalert("ส่งข้อความบ่อยไป")}}function nzCommand(command,xid){if(command==""){nzalert("คำสั่งผิดพลาด")}else{if(command=="del"){var show="ลบข้อความ";var showid=" "+nzchatobj("#nzchatcontent"+xid).text()}else if(command=="edit"){nzquota=0;nzcommandz="edit "+xid;nzchatobj(".nzquoteboxi").html('
แก้ไขข้อความ
'+nzchatobj("#nzrows_"+xid+" .nzinnercontent")[0].outerHTML+'
');nzchatobj(".nzquoteboxi .nzcq").remove();nzchatobj(".nzquoteboxi .nzblockquote").remove();nzchatobj(".nzquoteboxi .nztag").remove();nzchatobj(".nzquoteboxi .nztag2").remove();nzchatobj(".nzquoteboxi .nztag3").remove();nzchatobj(".nzquoteboxi").show();nzchatobj(".nzquoteboxo").show();nzchatobj("#nzchatcontent").css("height",nzsetting.chatheight-nzchatobj(".nzquoteboxo").height());nzScrollChat(true);nzchatobj("#nzchatmessage").val(nzchatobj(".nzquoteboxi .nzinnercontent").text().trim());nzchatobj("#nzchatmessage").trigger("focus");return}else if(command=="ban"){var show="แบน";var showid=" "+nzchatobj("#nzolpro_"+xid).text()+"(UID: "+xid+")"}else if(command=="unban"){var show="ปลดแบน";var showid=" "+nzchatobj("#nzolpro_"+xid).text()+"(UID: "+xid+")"}else if(command=="clear"){var show="ล้างห้องแชท";var showid=""}if(confirm("คุณต้องการที่จะ"+show+showid+" ?")==true){nzchatobj("#nzchatmessage").val("!"+command+" "+xid);nzSend()}}}function nzLoadTextInit(){nzchatobj.post("plugin.php?id=th_chat:newinit",{room:nzChatRoom,list:nzChatList},function(data){data=JSON.parse(data);nzlastid=data.lastid;nzchatobj("#nzchatcontent").html('
'+data.datahtml+'
');nzScrollChat(true);nzchatobj(".nzinnercontent img").one("load",function(){nzScrollChat()});nzchatobj("#nzchatolcontent").html(data.datachatonline);nzchatobj("#nzoltotal").html(data.chat_online_total);if(data.chat_unread&&data.chat_unread>0){nzchatobj("#nzunread").html(data.chat_unread);nzchatobj("#nzunread").show()}else{nzchatobj("#nzunread").hide()}nzchatobj("#nzchatnotice").html(data.welcometext);nzResetInterval()})}function nzResetInterval(){clearInterval(nzInterval);nzInterval=setInterval(nzLoadText,nzsetting.reload)}function nzChangeChatRoom(id){if(nzChatRoom!==id){nzChatRoom=id;nzchatobj("#nzchatcontent").html('
');nzLoadTextInit()}}function nzScrollChat(force=false){var objDiv=document.getElementById("nzchatcontent");if(force){nzscroll=true;nzchatobj("#nznewmessage").hide()}if(nzscroll){objDiv.scrollTop=objDiv.scrollHeight}else{nzchatobj("#nznewmessage").show()}}function nzReadyForScroll(){var objDiv=document.getElementById("nzchatcontent");if(nzchatobj(".nzquoteboxo:visible")){nzscroll=true}else{if(objDiv.scrollHeight-objDiv.scrollTop==nzsetting.chatheight){nzscroll=true}else{nzscroll=false}}}function nzLoadText(){nzchatobj.post("plugin.php?id=th_chat:new",{room:nzChatRoom,list:nzChatList,lastid:nzlastid},function(data){data=JSON.parse(data);var listmess=sortObject(data.chat_row);nzReadyForScroll();nzchatobj.each(listmess,function(k,v){k=parseInt(k);if(k>nzlastid){nzlastid=k;nzchatobj("#afterme").before(v);nzScrollChat()}});nzchatobj(".nzinnercontent img").one("load",function(){nzScrollChat()});if(nzsetting.iscleardata==1){var nzchatrr=nzchatobj(".nzchatrow");if(nzchatrr.size()>nzsetting.chatrowmax){nzchatrr.first().remove()}}if(data.chat_online){if(!nzonol){nzchatobj("#nzchatolcontent").html(data.chat_online)}nzchatobj("#nzoltotal").html(data.chat_online_total)}if(data.chat_unread&&data.chat_unread>0){nzchatobj("#nzunread").html(data.chat_unread);nzchatobj("#nzunread").show()}else{nzchatobj("#nzunread").hide()}nzResetInterval()})}function nzQuota(i){nzcommandz="";if(nzchatobj("#nzrows_"+i+" .nzuserat2")[0]){nzchatobj(".nzquoteboxi").html('
'+nzchatobj("#nzrows_"+i+" .nzuserat2")[0].outerHTML+": "+nzchatobj("#nzchatcontent"+i).html()+'
')}else{nzchatobj(".nzquoteboxi").html('
'+nzchatobj("#nzchatcontent"+i).html()+'
')}nzchatobj(".nzquoteboxi .nzcq").remove();nzchatobj(".nzquoteboxi .nzuserat2").toggleClass("nzuserat2 nzuserat");nzchatobj(".nzquoteboxi").show();nzchatobj(".nzquoteboxo").show();nzchatobj("#nzchatcontent").css("height",nzsetting.chatheight-nzchatobj(".nzquoteboxo").height());nzScrollChat(true);nzquota=i;nzchatobj("#nzchatmessage").focus()}function nzAt(i){seditor_insertunit("nzchat","@"+i+" ","");nzchatobj("#nzchatmessage").trigger("focus")}function nzTouid(i){nzquota=0;nzcommandz="";nzchatobj(".nzquoteboxi").hide();if(i>0){nzchatobj(".nzquoteboxp").html('
แชทส่วนตัวกับ '+nzchatobj(".nzat_"+i).last()[0].outerHTML+'
');nzchatobj(".nzquoteboxp").show();nzchatobj(".nzquoteboxo").show();nzchatobj("#nzchatcontent").css("height",nzsetting.chatheight-nzchatobj(".nzquoteboxo").height());nztouid=i;if(nzChatRoom!==i){nzChangeChatRoom(i)}}else{nzchatobj("#nzchatcontent").css("height",nzsetting.chatheight);nzchatobj(".nzquoteboxp").hide();nzchatobj(".nzquoteboxo").hide();nztouid=0;if(nzChatRoom>0){nzChangeChatRoom(0)}}}function nzCancelCommand(){nzchatobj(".nzquoteboxi").hide();if(nzcommandz.substring(0,4)=="edit"){if(nzchatobj(".nzquoteboxi .nzinnercontent").text()==nzchatobj("#nzchatmessage").val()){nzchatobj("#nzchatmessage").val("")}}else if(nzcommandz=="notice"){if(nzchatobj("#nzchatmessage").val()==nzchatobj("#nzchatnotice").text()){nzchatobj("#nzchatmessage").val("")}}if(i>0){nzchatobj("#nzchatcontent").css("height",nzsetting.chatheight-nzchatobj(".nzquoteboxo").height())}else{nzchatobj("#nzchatcontent").css("height",nzsetting.chatheight);nzchatobj(".nzquoteboxo").hide()}nzquota=0;nzcommandz=""}function nzReload(){nzalert("กำลังรีโหลด...");nzChatList=0;nzChatRoom=0;nzTouid(0);nzchatobj(".nzchat_room").removeClass("nzactive");nzchatobj(".nzchat_general").addClass("nzactive");nzLoadTextInit()}function nzClean(){nzchatobj(".nzchatrow").fadeOut("slow")}function nzCheckImg(i){var maxheight=240;var maxwidth=500;var w=parseInt(i.width);var h=parseInt(i.height);if(w>maxwidth){i.style.cursor="pointer";i.onclick=function(){var iw=window.open(this.src,"ImageViewer","resizable=1");iw.focus()};h=(maxwidth/w)*h;w=maxwidth;i.height=h;i.width=w}if(h>maxheight){i.style.cursor="pointer";i.onclick=function(){var iw=window.open(this.src,"ImageViewer","resizable=1");iw.focus()};i.width=(maxheight/h)*w;i.height=maxheight}}function sortObject(a){var b={},c,d=[];for(c in a){if(a.hasOwnProperty(c)){d.push(c)}}d.sort();for(c=0;c');nzLoadTextInit();nzchatobj(".nzchat_room").removeClass("nzactive");nzchatobj(this).addClass("nzactive")});nzchatobj(".nzchat_whisper").on("click",function(){nzChatList=1;nzchatobj("#nzchatolcontent").html('
');nzLoadTextInit();nzchatobj(".nzchat_room").removeClass("nzactive");nzchatobj(this).addClass("nzactive")});if(nzsetting.autoconnect==1){nzLoadTextInit()}const nzemoji=document.querySelector("#nzemoji");const nzpicker=picmoPopup.createPopup({rootElement:document.querySelector("#nzchat"),theme:`picmo__${nzsetting.theme }`},{referenceElement:nzemoji,triggerElement:nzemoji});nzpicker.addEventListener("emoji:select",(selection)=>{nzchatobj("#nzchatmessage").val(nzchatobj("#nzchatmessage").val()+selection.emoji)});nzchatobj("#nzemoji").on("click",function(){nzpicker.toggle()});nzchatobj("#nznewmessage").on("click",function(){nzScrollChat(true)});nzchatobj("#nzchatcontent").on("scroll",function(){var objDiv=document.getElementById("nzchatcontent");if(objDiv.scrollHeight-objDiv.scrollTop==nzsetting.chatheight){nzchatobj("#nznewmessage").hide();objDiv.scrollTop=objDiv.scrollHeight}})});function nzNotice(){nzcommandz="notice";nzchatobj(".nzquoteboxi").html('
แก้ไขประกาศ: '+nzchatobj("#nzchatnotice").html()+'
');nzchatobj(".nzquoteboxo").show();nzchatobj("#nzchatcontent").css("height",nzsetting.chatheight-nzchatobj(".nzquoteboxo").height());nzScrollChat(true);nzchatobj("#nzchatmessage").val(nzchatobj("#nzchatnotice").text());nzchatobj("#nzchatmessage").trigger("focus")}function nzSend(){var data=nzchatobj("#nzchatmessage").val().trim();if(data===""){return false}nzchatobj("#nzchatmessage").val("");nzchatobj.post("plugin.php?id=th_chat:post"+formhash,{text:data,lastid:nzlastid,touid:nztouid,quota:nzquota,command:nzcommandz,room:nzChatRoom},function(data){if(nzquota>0||nzcommandz=="notice"||nzcommandz.substring(0,4)=="edit"){nzTouid(nztouid)}data=JSON.parse(data);if(data.type==1){nzalert(data.error);if(data.script){eval(data.script)}}else{if(nztouid==nzChatRoom){var listmess=nzSortObject(data);nzReadyForScroll();nzchatobj.each(listmess,function(k,v){k=parseInt(k);if(k>nzlastid){nzlastid=k;nzchatobj("#afterme").before(v);nzScrollChat()}});nzchatobj(".nzinnercontent img").one("load",function(){nzScrollChat()});if(nzsetting.iscleardata==1){var nzchatrr=nzchatobj(".nzchatrow");if(nzchatrr.size()>nzsetting.chatrowmax){nzchatrr.first().remove()}}}else{nzChangeChatRoom(nztouid)}}})}function nzCommand(command,xid){if(command==""){nzalert("คำสั่งผิดพลาด")}else{if(command=="del"){var show="ลบข้อความ";var showid=" "+nzchatobj("#nzchatcontent"+xid).text()}else if(command=="edit"){nzquota=0;nzcommandz="edit "+xid;nzchatobj(".nzquoteboxi").html('
แก้ไขข้อความ
'+nzchatobj("#nzrows_"+xid+" .nzinnercontent")[0].outerHTML+'
');nzchatobj(".nzquoteboxi .nzcq").remove();nzchatobj(".nzquoteboxi .nzblockquote").remove();nzchatobj(".nzquoteboxi .nztag").remove();nzchatobj(".nzquoteboxi .nztag2").remove();nzchatobj(".nzquoteboxi .nztag3").remove();nzchatobj(".nzquoteboxi").show();nzchatobj(".nzquoteboxo").show();nzchatobj("#nzchatcontent").css("height",nzsetting.chatheight-nzchatobj(".nzquoteboxo").height());nzScrollChat(true);nzchatobj("#nzchatmessage").val(nzchatobj(".nzquoteboxi .nzinnercontent").text().trim());nzchatobj("#nzchatmessage").trigger("focus");return}else if(command=="ban"){var show="แบน";var showid=" "+nzchatobj("#nzolpro_"+xid).text()+"(UID: "+xid+")"}else if(command=="unban"){var show="ปลดแบน";var showid=" "+nzchatobj("#nzolpro_"+xid).text()+"(UID: "+xid+")"}else if(command=="clear"){var show="ล้างห้องแชท";var showid=""}if(confirm("คุณต้องการที่จะ"+show+showid+" ?")==true){nzchatobj("#nzchatmessage").val("!"+command+" "+xid);nzSend()}}}function nzLoadTextInit(){nzchatobj.post("plugin.php?id=th_chat:newinit",{room:nzChatRoom,list:nzChatList},function(data){data=JSON.parse(data);nzlastid=data.lastid;nzchatobj("#nzchatcontent").html('
'+data.datahtml+'
');nzScrollChat(true);nzchatobj(".nzinnercontent img").one("load",function(){nzScrollChat()});nzchatobj("#nzchatolcontent").html(data.datachatonline);nzchatobj("#nzoltotal").html(data.chat_online_total);if(data.chat_unread&&data.chat_unread>0){nzchatobj("#nzunread").html(data.chat_unread);nzchatobj("#nzunread").show()}else{nzchatobj("#nzunread").hide()}nzchatobj("#nzchatnotice").html(data.welcometext);nzResetInterval()})}function nzResetInterval(){clearInterval(nzInterval);nzInterval=setInterval(nzLoadText,nzsetting.reload)}function nzChangeChatRoom(id){if(nzChatRoom!==id){nzChatRoom=id;nzchatobj("#nzchatcontent").html('
');nzLoadTextInit()}}function nzScrollChat(force=false){var objDiv=document.getElementById("nzchatcontent");if(force){nzscroll=true;nzchatobj("#nznewmessage").hide()}if(nzscroll){objDiv.scrollTop=objDiv.scrollHeight}else{nzchatobj("#nznewmessage").show()}}function nzReadyForScroll(){var objDiv=document.getElementById("nzchatcontent");if(nzchatobj(".nzquoteboxo:visible")){nzscroll=true}else{if(objDiv.scrollHeight-objDiv.scrollTop==nzsetting.chatheight){nzscroll=true}else{nzscroll=false}}}function nzLoadText(){nzchatobj.post("plugin.php?id=th_chat:new",{room:nzChatRoom,list:nzChatList,lastid:nzlastid},function(data){data=JSON.parse(data);var listmess=nzSortObject(data.chat_row);nzReadyForScroll();nzchatobj.each(listmess,function(k,v){k=parseInt(k);if(k>nzlastid){nzlastid=k;nzchatobj("#afterme").before(v);nzScrollChat()}});nzchatobj(".nzinnercontent img").one("load",function(){nzScrollChat()});if(nzsetting.iscleardata==1){var nzchatrr=nzchatobj(".nzchatrow");if(nzchatrr.size()>nzsetting.chatrowmax){nzchatrr.first().remove()}}if(data.chat_online){if(!nzonol){nzchatobj("#nzchatolcontent").html(data.chat_online)}nzchatobj("#nzoltotal").html(data.chat_online_total)}if(data.chat_unread&&data.chat_unread>0){nzchatobj("#nzunread").html(data.chat_unread);nzchatobj("#nzunread").show()}else{nzchatobj("#nzunread").hide()}nzResetInterval()})}function nzQuota(i){nzcommandz="";if(nzchatobj("#nzrows_"+i+" .nzuserat2")[0]){nzchatobj(".nzquoteboxi").html('
'+nzchatobj("#nzrows_"+i+" .nzuserat2")[0].outerHTML+": "+nzchatobj("#nzchatcontent"+i).html()+'
')}else{nzchatobj(".nzquoteboxi").html('
'+nzchatobj("#nzchatcontent"+i).html()+'
')}nzchatobj(".nzquoteboxi .nzcq").remove();nzchatobj(".nzquoteboxi .nzuserat2").toggleClass("nzuserat2 nzuserat");nzchatobj(".nzquoteboxi").show();nzchatobj(".nzquoteboxo").show();nzchatobj("#nzchatcontent").css("height",nzsetting.chatheight-nzchatobj(".nzquoteboxo").height());nzScrollChat(true);nzquota=i;nzchatobj("#nzchatmessage").focus()}function nzAt(i){seditor_insertunit("nzchat","@"+i+" ","");nzchatobj("#nzchatmessage").trigger("focus")}function nzTouid(i){nzquota=0;nzcommandz="";nzchatobj(".nzquoteboxi").hide();if(i>0){nzchatobj(".nzquoteboxp").html('
แชทส่วนตัวกับ '+nzchatobj(".nzat_"+i).last()[0].outerHTML+'
');nzchatobj(".nzquoteboxp").show();nzchatobj(".nzquoteboxo").show();nzchatobj("#nzchatcontent").css("height",nzsetting.chatheight-nzchatobj(".nzquoteboxo").height());nztouid=i;if(nzChatRoom!==i){nzChangeChatRoom(i)}}else{nzchatobj("#nzchatcontent").css("height",nzsetting.chatheight);nzchatobj(".nzquoteboxp").hide();nzchatobj(".nzquoteboxo").hide();nztouid=0;if(nzChatRoom>0){nzChangeChatRoom(0)}}}function nzCancelCommand(){nzchatobj(".nzquoteboxi").hide();if(nzcommandz.substring(0,4)=="edit"){if(nzchatobj(".nzquoteboxi .nzinnercontent").text()==nzchatobj("#nzchatmessage").val()){nzchatobj("#nzchatmessage").val("")}}else if(nzcommandz=="notice"){if(nzchatobj("#nzchatmessage").val()==nzchatobj("#nzchatnotice").text()){nzchatobj("#nzchatmessage").val("")}}if(i>0){nzchatobj("#nzchatcontent").css("height",nzsetting.chatheight-nzchatobj(".nzquoteboxo").height())}else{nzchatobj("#nzchatcontent").css("height",nzsetting.chatheight);nzchatobj(".nzquoteboxo").hide()}nzquota=0;nzcommandz=""}function nzReload(){nzalert("กำลังรีโหลด...");nzChatList=0;nzChatRoom=0;nzTouid(0);nzchatobj(".nzchat_room").removeClass("nzactive");nzchatobj(".nzchat_general").addClass("nzactive");nzLoadTextInit()}function nzClean(){nzchatobj(".nzchatrow").fadeOut("slow")}function nzCheckImg(i){var maxheight=240;var maxwidth=500;var w=parseInt(i.width);var h=parseInt(i.height);if(w>maxwidth){i.style.cursor="pointer";i.onclick=function(){var iw=window.open(this.src,"ImageViewer","resizable=1");iw.focus()};h=(maxwidth/w)*h;w=maxwidth;i.height=h;i.width=w}if(h>maxheight){i.style.cursor="pointer";i.onclick=function(){var iw=window.open(this.src,"ImageViewer","resizable=1");iw.focus()};i.width=(maxheight/h)*w;i.height=maxheight}}function nzSortObject(a){var b={},c,d=[];for(c in a){if(a.hasOwnProperty(c)){d.push(c)}}d.sort();for(c=0;c