26 lines
14 KiB
JavaScript
26 lines
14 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){function e(e,a,s){e='<span style="font-weight:bold; font-size:1.2em;">'+e+"</span>";var o={confirm:!1,verify:!1,input:!1,textarea:!1,animate:!1,textOk:"Ok",textCancel:"Cancel",textYes:"Yes",textNo:"No",position:"center"};if(a)for(var n in o)"undefined"==typeof a[n]&&(a[n]=o[n]);var m=t(document).height(),h=t(document).width(),i=t('<div class="appriseOuter"></div>'),r=t('<div class="appriseOverlay" id="aOverlay"></div>'),c=t('<div class="appriseInner"></div>'),l=t('<div class="aButtons"></div>'),u=300;if(r.css({height:m,width:h}).appendTo("body").fadeIn(100,function(){t(this).css("filter","alpha(opacity=70)")}),i.prependTo("body"),c.append(e).appendTo(i),a&&(a.input&&("string"==typeof a.input?c.append('<div class="aInput"><input type="text" class="aTextbox" t="aTextbox" value="'+a.input+'" /></div>'):c.append('<div class="aInput"><input type="text" class="aTextbox" t="aTextbox" /></div>'),t(".aTextbox").focus()),"string"==typeof a.textarea&&(c.append('<div class="aInput"><textarea name="message" class="aEdit" style="height: 9em;" rows="5" cols="180">'+a.textarea+"</textarea></div>"),t(".aEdit").focus())),c.append(l),a?a.confirm||a.input?(l.append('<button value="ok">'+a.textOk+"</button>"),l.append('<button value="cancel">'+a.textCancel+"</button>")):a.verify?(l.append('<button value="ok">'+a.textYes+"</button>"),l.append('<button value="cancel">'+a.textNo+"</button>")):l.append('<button value="ok">'+a.textOk+"</button>"):l.append('<button value="ok">Ok</button>'),i.css("left",(t(window).width()-t(".appriseOuter").width())/2+t(window).scrollLeft()+"px"),a)if(a.position&&"center"===a.position&&(u=(m-i.height())/2),a.animate){var C=a.animate;isNaN(C)&&(C=400),i.css("top","-200px").show().animate({top:u},C)}else i.css("top",u).fadeIn(200);else i.css("top",u).fadeIn(200);t(document).keydown(function(e){r.is(":visible")&&(e.shiftKey&&13==e.keyCode?t(".aEdit").append("<br />"):13==e.keyCode?t('.aButtons > button[value="ok"]').click():27==e.keyCode&&t('.aButtons > button[value="cancel"]').click())});var d=t(".aTextbox").val();d||(d=!1),t(".aTextbox").on("keydown blur",function(){d=t(this).val()});var f=t(".aEdit").val();f||(f=!1),t(".aEdit").on("keydown blur",function(){f=t(this).val()}),t(".aButtons > button").click(function(){if(r.remove(),i.remove(),s){t(this).text("");var e=t(this).attr("value");"ok"==e?(s(a?a.input?d:a.textarea?f:!0:!0),t("#mChatMessage").focus()):"cancel"==e&&(s(!1),t("#mChatMessage").focus())}})}var a=!0;mChat.archiveMode||(mChat.messageTop||t("#mChatmain").animate({scrollTop:t("#mChatmain")[0].scrollHeight},1e3,"swing"),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(){a=!1}).focus(function(){a=!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="",o=t(this),n=t("<div/>").css({position:"absolute",top:-9999,left:-9999,width:"auto",fontSize:o.css("fontSize"),fontFamily:o.css("fontFamily"),fontWeight:o.css("fontWeight"),letterSpacing:o.css("letterSpacing"),whiteSpace:"nowrap"}),m=function(){if(s!==(s=o.val())){var t=s.replace(/&/g,"&").replace(/\s/g," ").replace(/</g,"<").replace(/>/g,">");n.html(t);var m=n.width(),h=m+e.comfortZone>=a?m+e.comfortZone:a,i=o.width(),r=i>h&&h>=a||h>a&&h<e.maxWidth;r&&o.width(h)}};n.insertAfter(o),t(this).on("keypress blur change submit focus",m)}),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 o=s+":"+a+":"+e;t("#mChatSessMess").html(mChat.sessEnds+" "+o),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.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")&&(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(){a&&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?mChat.userTimeout/1e3:!1,mChat.counter=setInterval(mChat.countDown,1e3),mChat.activeInterval=setInterval(mChat.active,mChat.userTimeout)),t("#mChatMessage").val("").focus()}})},edit:function(a){var s=t("#mess"+a).data("edit");e(mChat.editInfo,{textarea:s,animate:!0,position:200,confirm:!0},function(e){e&&t.ajax({url:mChat.file,timeout:1e4,type:"POST",data:{mode:"edit",message_id:a,message:e},dataType:"text",beforeSend:function(){clearInterval(mChat.interval),mChat.userTimeout&&(clearInterval(mChat.activeInterval),clearInterval(mChat.counter),t("#mChatSessTimer").html(mChat.refreshing))},success:function(e){t("#mess"+a).fadeOut("slow",function(){t(this).replaceWith(e),t("#mess"+a).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(a){e(mChat.delConfirm,{position:200,animate:!0,confirm:!0},function(e){return e?void t.ajax({url:mChat.file,timeout:1e4,type:"POST",data:{mode:"delete",message_id:a},beforeSend:function(){clearInterval(mChat.interval),mChat.userTimeout&&(clearInterval(mChat.activeInterval),clearInterval(mChat.counter),t("#mChatSessTimer").html(mChat.refreshing))},success:function(){t("#mess"+a).fadeOut("slow",function(){t(this).remove()}),mChat.sound(mChat.forumRoot+"ext/dmzx/mchat/sounds/del.swf")},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))}}):!1})},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(mChat.forumRoot+"ext/dmzx/mchat/sounds/add.swf"),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(mChat.forumRoot+"ext/dmzx/mchat/sounds/error.swf")},complete:function(){t("#mChatData").children(e).length||t("#mChatData").append('<div id="mChatNoMessage">'+mChat.noMessages+"</div>").show("slow")}})}},stats:function(){mChat.whois&&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(mChat.forumRoot+"ext/dmzx/mchat/sounds/error.swf")},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"))},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.statsInterval=setInterval(mChat.stats,mChat.whoisRefresh),mChat.activeInterval=setInterval(mChat.active,mChat.userTimeout),mChat.sessionTime=mChat.userTimeout?mChat.userTimeout/1e3:!1,mChat.userTimeout&&(mChat.counter=setInterval(mChat.countDown,1e3)),"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("#mChatmain").on("click","span.mChatInsertMention",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+", ")}),t("#mChatData").on("click","img.mChatInsertQuote",function(){var e=t(this).closest(".mChatHover"),a=mChat.entityDecode(e.data("username")),s=e.data("id"),o=mChat.entityDecode(t("#mess"+s).data("edit"));insert_text('[quote="'+a+'"]'+o+"[/quote]")}),t("#mChatData").on("click","img.mChatInsertLike",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]")}),t("#mChatData").on("click","img.mChatEdit",function(){var e=t(this).closest(".mChatHover");mChat.edit(e.data("id"))}),t("#mChatData").on("click","img.mChatDelete",function(){var e=t(this).closest(".mChatHover");mChat.del(e.data("id"))})});
|