26 lines
12 KiB
JavaScript
26 lines
12 KiB
JavaScript
/**
|
|
*
|
|
* @package mChat JavaScript Code mini
|
|
* @version 1.4.4 of 2013-11-03
|
|
* @copyright (c) 2009 By Shapoval Andrey Vladimirovich (AllCity) ~ http://allcity.net.ru/
|
|
* @copyright (c) 2013 By Rich McGirr (RMcGirr83) http://rmcgirr83.org
|
|
* @copyright (c) 2015 By dmzx - http://www.dmzx-web.net
|
|
* @copyright (c) 2015 By kasimi
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
*
|
|
Code uses the titlealert jQuery plugin, options are below
|
|
interva 500 The flashing interval in milliseconds.
|
|
originalTitleInterval null Time in milliseconds that the original title is diplayed for. If null the time is the same as interval.
|
|
duration 0 The total lenght of the flashing before it is automatically stopped. Zero means infinite.
|
|
stopOnFocus true If true, the flashing will stop when the window gets focus.
|
|
stopOnMouseMove false If true, the flashing will stop when the document recieves a mousemove event (i.e. when the user moves the mouse over the document area, regardless of what window is active).
|
|
To use find titlealert in the code and make as so
|
|
$.titleAlert(mChatNewMessageAlert, {
|
|
requireBlur:false,
|
|
stopOnFocus:false,
|
|
duration:4000,
|
|
interval:700
|
|
});
|
|
**/
|
|
jQuery(function(t){var e=!0;mChat.archiveMode||(mChat.messageTop||t("#mChatmain").animate({scrollTop:t("#mChatmain")[0].scrollHeight},1e3,"swing"),!mChat.archiveMode&&mChat.pause&&t("#mChatMessage").on("keypress",function(){clearInterval(mChat.interval),t("#mChatLoadIMG,#mChatOkIMG,#mChatErrorIMG").hide(),t("#mChatRefreshText").html(mChat.refreshNo).addClass("mchat-alert"),t("#mChatPauseIMG").show()}),t([window,document]).blur(function(){e=!1}).focus(function(){e=!0}),t.fn.preventDoubleSubmit=function(){var e=!1;return t(this).submit(function(){return e?!1:void(e=!0)})},t.fn.autoGrowInput=function(e){var a=t(".mChatPanel").width();return e=t.extend({maxWidth:a-20,minWidth:0,comfortZone:20},e),this.filter("input:text").each(function(){var a=e.minWidth||t(this).width(),s="",m=t(this),o=t("<div/>").css({position:"absolute",top:-9999,left:-9999,width:"auto",fontSize:m.css("fontSize"),fontFamily:m.css("fontFamily"),fontWeight:m.css("fontWeight"),letterSpacing:m.css("letterSpacing"),whiteSpace:"nowrap"}),h=function(){if(s!==(s=m.val())){var t=s.replace(/&/g,"&").replace(/\s/g," ").replace(/</g,"<").replace(/>/g,">");o.html(t);var h=o.width(),n=h+e.comfortZone>=a?h+e.comfortZone:a,r=m.width(),i=r>n&&n>=a||n>a&&n<e.maxWidth;i&&m.width(n)}};o.insertAfter(m),t(this).on("keypress blur change submit focus",h)}),this},t("input.mChatText").autoGrowInput(),t("#postform").preventDoubleSubmit(),mChat.playSound&&"yes"!=t.cookie("mChatNoSound")?(t.cookie("mChatNoSound",null),t("#mChatUseSound").attr("checked","checked")):(t.cookie("mChatNoSound","yes"),t("#mChatUseSound").removeAttr("checked")),t("#mChatUserList").length&&("yes"==t.cookie("mChatShowUserList")||mChat.customPage)&&t("#mChatUserList").show()),t.extend(mChat,{countDown:function(){t("#mChatSessMess").removeClass("mchat-alert"),mChat.sessionTime=mChat.sessionTime-1;var e=Math.floor(mChat.sessionTime),a=Math.floor(e/60),s=Math.floor(a/60);e%=60,9>=e&&(e="0"+e),a%=60,9>=a&&(a="0"+a),s%=60,9>=s&&(s="0"+s);var m=s+":"+a+":"+e;t("#mChatSessMess").html(mChat.sessEnds+" "+m),mChat.sessionTime<=0&&(clearInterval(mChat.counter),t("#mChatSessMess").html(mChat.sessOut).addClass("mchat-alert"))},clear:function(){if(""===t("#mChatMessage").val())return!1;var e=confirm(mChat.reset);e?(t("#mChatRefreshText").removeClass("mchat-alert"),!mChat.archiveMode&&mChat.pause&&(mChat.interval=setInterval(mChat.refresh,mChat.refreshTime)),t("#mChatOkIMG").show(),t("#mChatLoadIMG,#mChatErrorIMG,#mChatPauseIMG").hide(),t("#mChatRefreshText").html(mChat.refreshYes),t("#mChatMessage").val("").focus()):t("#mChatMessage").focus()},sound:function(e){"yes"!=t.cookie("mChatNoSound")&&(e=mChat.extUrl+"sounds/"+e+".swf",navigator.userAgent.match(/MSIE ([0-9]+)\./)||navigator.userAgent.match(/Trident\/7.0; rv 11.0/)?t("#mChatSound").html('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" height="0" width="0" type="application/x-shockwave-flash"><param name="movie" value="'+e+'"></object>'):t("#mChatSound").html('<embed src="'+e+'" width="0" height="0" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>'))},notice:function(){e&&document.hasFocus()||t.titleAlert(mChat.newMessageAlert,{interval:1e3})},toggle:function(e){t("#mChat"+e).slideToggle("normal",function(){t("#mChat"+e).is(":visible")?t.cookie("mChatShow"+e,"yes"):t("#mChat"+e).is(":hidden")&&t.cookie("mChatShow"+e,null)})},add:function(){if(""===t("#mChatMessage").val())return!1;var e=t("#mChatMessage").val().replace(/ /g,"");return mChat.mssgLngth&&e.length>mChat.mssgLngth?void alert(mChat.mssgLngthLong):void t.ajax({url:mChat.file,timeout:1e4,type:"POST",data:t("#postform").serialize(),dataType:"text",beforeSend:function(){t("#submit_button").attr("disabled","disabled"),mChat.userTimeout&&(clearInterval(mChat.activeInterval),clearInterval(mChat.counter)),clearInterval(mChat.interval)},success:function(){mChat.refresh()},error:function(t){400==t.status?alert(mChat.flood):403==t.status?alert(mChat.noAccess):501==t.status&&alert(mChat.noMessageInput)},complete:function(){t("#mChatNoMessage").remove(),t("#submit_button").removeAttr("disabled"),mChat.interval=setInterval(mChat.refresh,mChat.refreshTime),mChat.userTimeout&&(mChat.sessionTime=mChat.userTimeout/1e3,mChat.counter=setInterval(mChat.countDown,1e3),mChat.activeInterval=setInterval(mChat.active,mChat.userTimeout)),t("#mChatMessage").val("").focus()}})},edit:function(){var e=t(this).closest(".mChatHover").data("id"),a=mChat.confirmContainer.find("textarea").show().val(t("#mess"+e).data("edit"));mChat.confirmContainer.find("p").text(mChat.editInfo),phpbb.confirm(mChat.confirmContainer,function(){t.ajax({url:mChat.file,timeout:1e4,type:"POST",data:{mode:"edit",message_id:e,message:a.val()},dataType:"text",beforeSend:function(){clearInterval(mChat.interval),mChat.userTimeout&&(clearInterval(mChat.activeInterval),clearInterval(mChat.counter),t("#mChatSessTimer").html(mChat.refreshing))},success:function(a){t("#mess"+e).fadeOut("slow",function(){t(this).replaceWith(a),t("#mess"+e).css("display","none").fadeIn("slow")})},error:function(t){403==t.status?alert(mChat.noAccess):501==t.status&&alert(mChat.noMessageInput)},complete:function(){mChat.interval=setInterval(mChat.refresh,mChat.refreshTime),mChat.userTimeout&&(mChat.sessionTime=mChat.userTimeout?mChat.userTimeout/1e3:!1,mChat.counter=setInterval(mChat.countDown,1e3),mChat.activeInterval=setInterval(mChat.active,mChat.userTimeout)),mChat.archiveMode||mChat.messageTop||setTimeout(function(){t("#mChatmain").animate({scrollTop:t("#mChatmain")[0].scrollHeight},1e3,"swing")},1500)}})})},del:function(){var e=t(this).closest(".mChatHover").data("id");mChat.confirmContainer.find("textarea").hide(),mChat.confirmContainer.find("p").text(mChat.delConfirm),phpbb.confirm(mChat.confirmContainer,function(){t.ajax({url:mChat.file,timeout:1e4,type:"POST",data:{mode:"delete",message_id:e},beforeSend:function(){clearInterval(mChat.interval),mChat.userTimeout&&(clearInterval(mChat.activeInterval),clearInterval(mChat.counter),t("#mChatSessTimer").html(mChat.refreshing))},success:function(){t("#mess"+e).fadeOut("slow",function(){t(this).remove()}),mChat.sound("del")},error:function(){alert(mChat.noAccess)},complete:function(){mChat.interval=setInterval(mChat.refresh,mChat.refreshTime),mChat.userTimeout&&(mChat.sessionTime=mChat.userTimeout?mChat.userTimeout/1e3:!1,mChat.counter=setInterval(mChat.countDown,1e3),mChat.activeInterval=setInterval(mChat.active,mChat.userTimeout))}})})},refresh:function(){if(!mChat.archiveMode){var e=mChat.messageTop?":first":":last",a=0;if(t("#mChatData").children().not("#mChatNoMessage").length){t("#mChatNoMessage").remove();var s=t("#mChatData").children(e).not("#mChatNoMessage").attr("id");s&&(a=s.replace("mess",""))}t.ajax({url:mChat.file,timeout:1e4,type:"POST",data:{mode:"read",message_last_id:a},dataType:"html",beforeSend:function(){t("#mChatOkIMG,#mChatErrorIMG,#mChatPauseIMG").hide(),t("#mChatLoadIMG").show()},success:function(e){var a=t(t.trim(e));a.length&&(t("#mChatRefreshText").removeClass("mchat-alert"),a.hide(),mChat.messageTop?t("#mChatData").prepend(a):t("#mChatData").append(a),a.fadeIn("slow"),t("#mChatmain").stop().animate({scrollTop:mChat.messageTop?0:t("#mChatmain")[0].scrollHeight},2e3),mChat.sound("add"),mChat.notice()),setTimeout(function(){t("#mChatLoadIMG,#mChatErrorIMG,#mChatPauseIMG").hide(),t("#mChatOkIMG").show(),t("#mChatRefreshText").html(mChat.refreshYes)},500)},error:function(){t("#mChatLoadIMG,#mChatOkIMG,#mChatPauseIMG,#mChatRefreshTextNo").hide(),t("#mChatErrorIMG").show(),mChat.sound("error")},complete:function(){t("#mChatData").children(e).length||t("#mChatData").append('<div id="mChatNoMessage">'+mChat.noMessages+"</div>").show("slow")}})}},stats:function(){t.ajax({url:mChat.file,timeout:1e4,type:"POST",data:{mode:"stats"},dataType:"html",beforeSend:function(){mChat.customPage&&(t("#mChatRefreshN").show(),t("#mChatRefresh").hide())},success:function(e){var a=t.parseJSON(e);t("#mChatStats").replaceWith(a.message),mChat.customPage&&setTimeout(function(){t("#mChatRefreshN").hide(),t("#mChatRefresh").show()},500)},error:function(){mChat.sound("error")},complete:function(){t("#mChatUserList").length&&("yes"==t.cookie("mChatShowUserList")||mChat.customPage)&&t("#mChatUserList").css("display","block")}})},active:function(){!mChat.archiveMode&&mChat.userTimeout&&(clearInterval(mChat.interval),t("#mChatLoadIMG,#mChatOkIMG,#mChatErrorIMG").hide(),t("#mChatPauseIMG").show(),t("#mChatRefreshText").html(mChat.refreshNo).addClass("mchat-alert"),t("#mChatSessMess").html(mChat.sessOut).addClass("mchat-alert"))},insertMention:function(){var e=t(this).closest(".mChatHover"),a=mChat.entityDecode(e.data("username")),s=e.data("usercolor");s?a="[b][color="+s+"]"+a+"[/color][/b]":mChat.allowBBCodes&&(a="[b]"+a+"[/b]"),insert_text("@ "+a+", ")},insertQuote:function(){var e=t(this).closest(".mChatHover"),a=mChat.entityDecode(e.data("username")),s=e.data("id"),m=mChat.entityDecode(t("#mess"+s).data("edit"));insert_text('[quote="'+a+'"]'+m+"[/quote]")},insertLike:function(){var e=t(this).closest(".mChatHover"),a=mChat.entityDecode(e.data("username")),s=mChat.entityDecode(e.data("edit"));insert_text(mChat.likes+'[quote="'+a+'"]'+s+"[/quote]")},entityDecode:function(t){var e=decodeURIComponent(t.replace(/\+/g," "));return e=e.replace(/</g,"<"),e=e.replace(/>/g,">"),e=e.replace(/:/g,":"),e=e.replace(/./g,"."),e=e.replace(/&/g,"&"),e=e.replace(/"/g,'"')}}),mChat.interval=setInterval(mChat.refresh,mChat.refreshTime),mChat.activeInterval=setInterval(mChat.active,mChat.userTimeout),mChat.sessionTime=mChat.userTimeout?mChat.userTimeout/1e3:!1,mChat.confirmContainer=t("#mChatConfirm").detach().show(),mChat.userTimeout&&(mChat.counter=setInterval(mChat.countDown,1e3)),mChat.whois&&(mChat.statsInterval=setInterval(mChat.stats,mChat.whoisRefresh)),"yes"==t.cookie("mChatShowSmiles")&&t("#mChatSmiles").css("display","none")&&t("#mChatSmiles").slideToggle("slow"),"yes"==t.cookie("mChatShowBBCodes")&&t("#mChatBBCodes").css("display","none")&&t("#mChatBBCodes").slideToggle("slow"),"yes"==t.cookie("mChatShowUserList")&&t("#mChatUserList").length&&t("#mChatUserList").slideToggle("slow"),"yes"==t.cookie("mChatShowColour")&&t("#mChatColour").css("display","none")&&t("#mChatColour").slideToggle("slow"),t("#mChatUseSound").change(function(){t.cookie("mChatNoSound",t(this).is(":checked")?null:"yes")}),t("#mChatData").on("click","span.mChatInsertMention",mChat.insertMention).on("click","img.mChatInsertQuote",mChat.insertQuote).on("click","img.mChatInsertLike",mChat.insertLike).on("click","img.mChatEdit",mChat.edit).on("click","img.mChatDelete",mChat.del)});
|