Version 0.3.2
This commit is contained in:
@@ -8,493 +8,432 @@
|
||||
* @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
|
||||
});
|
||||
**/
|
||||
*/
|
||||
if (!String.prototype.startsWith) {
|
||||
String.prototype.startsWith = function(searchString, position) {
|
||||
position = position || 0;
|
||||
return this.indexOf(searchString, position) === position;
|
||||
};
|
||||
}
|
||||
|
||||
if (!String.prototype.capitalize) {
|
||||
String.prototype.capitalize = function() {
|
||||
return this.charAt(0).toUpperCase() + this.slice(1);
|
||||
};
|
||||
}
|
||||
|
||||
// Support Opera
|
||||
if (typeof document.hasFocus === 'undefined') {
|
||||
document.hasFocus = function() {
|
||||
return document.visibilityState == 'visible';
|
||||
};
|
||||
}
|
||||
|
||||
jQuery(function($) {
|
||||
var hasFocus = true;
|
||||
if (!mChat.archiveMode) {
|
||||
if (!mChat.messageTop) {
|
||||
$("#mChatmain").animate({
|
||||
scrollTop: $("#mChatmain")[0].scrollHeight
|
||||
}, 1000, "swing");
|
||||
var ajaxOptions = {
|
||||
url: mChat.file,
|
||||
timeout: 10000,
|
||||
type: 'POST',
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
if (xhr.status == 400) {
|
||||
alert(mChat.flood);
|
||||
} else if (xhr.status == 403) {
|
||||
alert(mChat.noAccess);
|
||||
} else if (xhr.status == 501) {
|
||||
alert(mChat.noMessageInput);
|
||||
} else if (typeof console !== 'undefined' && console.log) {
|
||||
console.log('AJAX error. status: ' + textStatus + ', message: ' + errorThrown);
|
||||
}
|
||||
}
|
||||
if (!mChat.archiveMode && mChat.pause) {
|
||||
$("#mChatMessage").on("keypress", function() {
|
||||
clearInterval(mChat.interval);
|
||||
$("#mChatLoadIMG,#mChatOkIMG,#mChatErrorIMG").hide();
|
||||
$("#mChatRefreshText").html(mChat.refreshNo).addClass("mchat-alert");
|
||||
$("#mChatPauseIMG").show();
|
||||
});
|
||||
}
|
||||
$([window, document]).blur(function() {
|
||||
hasFocus = false;
|
||||
}).focus(function() {
|
||||
hasFocus = true;
|
||||
});
|
||||
$.fn.preventDoubleSubmit = function() {
|
||||
var alreadySubmitted = false;
|
||||
return $(this).submit(function() {
|
||||
if (alreadySubmitted) {
|
||||
return false;
|
||||
} else {
|
||||
alreadySubmitted = true;
|
||||
}
|
||||
});
|
||||
};
|
||||
$.fn.autoGrowInput = function(o) {
|
||||
var width = $(".mChatPanel").width();
|
||||
o = $.extend({
|
||||
maxWidth: width - 20,
|
||||
minWidth: 0,
|
||||
comfortZone: 20
|
||||
}, o);
|
||||
this.filter("input:text").each(function() {
|
||||
var minWidth = o.minWidth || $(this).width(),
|
||||
val = "",
|
||||
input = $(this),
|
||||
testSubject = $("<div/>").css({
|
||||
position: "absolute",
|
||||
top: -9999,
|
||||
left: -9999,
|
||||
width: "auto",
|
||||
fontSize: input.css("fontSize"),
|
||||
fontFamily: input.css("fontFamily"),
|
||||
fontWeight: input.css("fontWeight"),
|
||||
letterSpacing: input.css("letterSpacing"),
|
||||
whiteSpace: "nowrap"
|
||||
}),
|
||||
check = function() {
|
||||
if (val === (val = input.val())) {
|
||||
return;
|
||||
}
|
||||
var escaped = val.replace(/&/g, "&").replace(/\s/g, " ").replace(/</g, "<").replace(/>/g, ">");
|
||||
testSubject.html(escaped);
|
||||
var testerWidth = testSubject.width(),
|
||||
newWidth = (testerWidth + o.comfortZone) >= minWidth ? testerWidth + o.comfortZone : minWidth,
|
||||
currentWidth = input.width(),
|
||||
isValidWidthChange = (newWidth < currentWidth && newWidth >= minWidth) || (newWidth > minWidth && newWidth < o.maxWidth);
|
||||
if (isValidWidthChange) {
|
||||
input.width(newWidth);
|
||||
}
|
||||
};
|
||||
testSubject.insertAfter(input);
|
||||
$(this).on("keypress blur change submit focus", check);
|
||||
});
|
||||
return this;
|
||||
};
|
||||
$("input.mChatText").autoGrowInput();
|
||||
$("#postform").preventDoubleSubmit();
|
||||
if (mChat.playSound && $.cookie("mChatNoSound") != "yes") {
|
||||
$.cookie("mChatNoSound", null);
|
||||
$("#mChatUseSound").attr("checked", "checked");
|
||||
} else {
|
||||
$.cookie("mChatNoSound", "yes");
|
||||
$("#mChatUseSound").removeAttr("checked");
|
||||
}
|
||||
if ($("#mChatUserList").length && ($.cookie("mChatShowUserList") == "yes" || mChat.customPage)) {
|
||||
$("#mChatUserList").show();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var formatRemainingSessionTime = function(time) {
|
||||
return (new Date(time * 1000)).toUTCString().match(/(\d\d:\d\d:\d\d)/)[0];
|
||||
};
|
||||
|
||||
$.extend(mChat, {
|
||||
countDown: function() {
|
||||
$("#mChatSessMess").removeClass("mchat-alert");
|
||||
mChat.sessionTime = mChat.sessionTime - 1;
|
||||
var sec = Math.floor(mChat.sessionTime);
|
||||
var min = Math.floor(sec / 60);
|
||||
var hrs = Math.floor(min / 60);
|
||||
sec = (sec % 60);
|
||||
if (sec <= 9) {
|
||||
sec = "0" + sec;
|
||||
}
|
||||
min = (min % 60);
|
||||
if (min <= 9) {
|
||||
min = "0" + min;
|
||||
}
|
||||
hrs = (hrs % 60);
|
||||
if (hrs <= 9) {
|
||||
hrs = "0" + hrs;
|
||||
}
|
||||
var time_left = hrs + ":" + min + ":" + sec;
|
||||
$("#mChatSessMess").html(mChat.sessEnds + " " + time_left);
|
||||
if (mChat.sessionTime <= 0) {
|
||||
clearInterval(mChat.counter);
|
||||
$("#mChatSessMess").html(mChat.sessOut).addClass("mchat-alert");
|
||||
}
|
||||
},
|
||||
clear: function() {
|
||||
if ($("#mChatMessage").val() === "") {
|
||||
return false;
|
||||
}
|
||||
var answer = confirm(mChat.reset);
|
||||
if (answer) {
|
||||
$("#mChatRefreshText").removeClass("mchat-alert");
|
||||
if (!mChat.archiveMode && mChat.pause) {
|
||||
mChat.interval = setInterval(mChat.refresh, mChat.refreshTime);
|
||||
if (mChat.$$('input').val() !== '') {
|
||||
if (confirm(mChat.clearConfirm)) {
|
||||
mChat.resetSession();
|
||||
mChat.$$('input').val('');
|
||||
}
|
||||
$("#mChatOkIMG").show();
|
||||
$("#mChatLoadIMG,#mChatErrorIMG,#mChatPauseIMG").hide();
|
||||
$("#mChatRefreshText").html(mChat.refreshYes);
|
||||
$("#mChatMessage").val("").focus();
|
||||
} else {
|
||||
$("#mChatMessage").focus();
|
||||
mChat.$$('input').focus();
|
||||
}
|
||||
},
|
||||
sound: function(file) {
|
||||
if ($.cookie("mChatNoSound") == "yes") {
|
||||
if (Cookies.get('mChatNoSound')) {
|
||||
return;
|
||||
}
|
||||
file = mChat.extUrl + "sounds/" + file + ".swf";
|
||||
file = mChat.extUrl + 'sounds/' + file + '.swf';
|
||||
if (navigator.userAgent.match(/MSIE ([0-9]+)\./) || navigator.userAgent.match(/Trident\/7.0; rv 11.0/)) {
|
||||
$("#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="' + file + '"></object>');
|
||||
mChat.$$('sound').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="' + file + '"></object>');
|
||||
} else {
|
||||
$("#mChatSound").html('<embed src="' + file + '" width="0" height="0" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>');
|
||||
mChat.$$('sound').html('<embed src="' + file + '" width="0" height="0" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>');
|
||||
}
|
||||
},
|
||||
notice: function() {
|
||||
if (!hasFocus || !document.hasFocus()) {
|
||||
if (!document.hasFocus()) {
|
||||
$.titleAlert(mChat.newMessageAlert, {interval: 1000});
|
||||
}
|
||||
},
|
||||
toggle: function(id) {
|
||||
$("#mChat" + id).slideToggle("normal", function() {
|
||||
if ($("#mChat" + id).is(":visible")) {
|
||||
$.cookie("mChatShow" + id, "yes");
|
||||
} else if ($("#mChat" + id).is(":hidden")) {
|
||||
$.cookie("mChatShow" + id, null);
|
||||
toggle: function(name) {
|
||||
var $elem = mChat.$$(name);
|
||||
$elem.stop().slideToggle(function() {
|
||||
var cookieName = 'mChatShow' + name.capitalize();
|
||||
if ($elem.is(':visible')) {
|
||||
Cookies.set(cookieName, 'yes');
|
||||
} else {
|
||||
Cookies.remove(cookieName);
|
||||
}
|
||||
});
|
||||
},
|
||||
add: function() {
|
||||
if ($("#mChatMessage").val() === "") {
|
||||
return false;
|
||||
if (mChat.submitting) {
|
||||
return;
|
||||
}
|
||||
var messChars = $("#mChatMessage").val().replace(/ /g, "");
|
||||
if (mChat.$$('input').val() === '') {
|
||||
return;
|
||||
}
|
||||
var messChars = mChat.$$('input').val().replace(/ /g, '');
|
||||
if (mChat.mssgLngth && messChars.length > mChat.mssgLngth) {
|
||||
alert(mChat.mssgLngthLong);
|
||||
return;
|
||||
}
|
||||
$.ajax({
|
||||
url: mChat.file,
|
||||
timeout: 10000,
|
||||
type: "POST",
|
||||
data: $("#postform").serialize(),
|
||||
dataType: "text",
|
||||
var $formElems = $('#' + form_name + ' :input[name]').filter(function(i, elem) {
|
||||
return !elem.name.startsWith('addbbcode');
|
||||
});
|
||||
$.ajax($.extend({}, ajaxOptions, {
|
||||
data: $formElems.serialize(),
|
||||
beforeSend: function() {
|
||||
$("#submit_button").attr("disabled", "disabled");
|
||||
if (mChat.userTimeout) {
|
||||
clearInterval(mChat.activeInterval);
|
||||
clearInterval(mChat.counter);
|
||||
}
|
||||
clearInterval(mChat.interval);
|
||||
mChat.$$('add').attr('disabled', 'disabled');
|
||||
mChat.pauseSession();
|
||||
},
|
||||
success: function() {
|
||||
mChat.refresh();
|
||||
},
|
||||
error: function(e) {
|
||||
if (e.status == 400) {
|
||||
alert(mChat.flood);
|
||||
} else if (e.status == 403) {
|
||||
alert(mChat.noAccess);
|
||||
} else if (e.status == 501) {
|
||||
alert(mChat.noMessageInput);
|
||||
success: function(json) {
|
||||
if (json.add) {
|
||||
mChat.$$('input').val('');
|
||||
mChat.refresh();
|
||||
}
|
||||
},
|
||||
complete: function() {
|
||||
$("#mChatNoMessage").remove();
|
||||
$("#submit_button").removeAttr("disabled");
|
||||
mChat.interval = setInterval(mChat.refresh, mChat.refreshTime);
|
||||
if (mChat.userTimeout) {
|
||||
mChat.sessionTime = mChat.userTimeout / 1000;
|
||||
mChat.counter = setInterval(mChat.countDown, 1000);
|
||||
mChat.activeInterval = setInterval(mChat.active, mChat.userTimeout);
|
||||
}
|
||||
$("#mChatMessage").val("").focus();
|
||||
mChat.resetSession();
|
||||
mChat.$$('input').focus();
|
||||
mChat.$$('add').removeAttr('disabled');
|
||||
}
|
||||
});
|
||||
}));
|
||||
},
|
||||
edit: function() {
|
||||
var id = $(this).closest(".mChatHover").data("id");
|
||||
var $message = mChat.confirmContainer.find("textarea").show().val($("#mess" + id).data("edit"));
|
||||
mChat.confirmContainer.find("p").text(mChat.editInfo);
|
||||
phpbb.confirm(mChat.confirmContainer, function() {
|
||||
$.ajax({
|
||||
url: mChat.file,
|
||||
timeout: 10000,
|
||||
type: "POST",
|
||||
var $container = $(this).closest('.mchat-message');
|
||||
var $message = mChat.$$('confirm').find('textarea').show().val($container.data('edit'));
|
||||
mChat.$$('confirm').find('p').text(mChat.editInfo);
|
||||
phpbb.confirm(mChat.$$('confirm'), function() {
|
||||
$.ajax($.extend({}, ajaxOptions, {
|
||||
data: {
|
||||
mode: "edit",
|
||||
message_id: id,
|
||||
mode: 'edit',
|
||||
message_id: $container.data('id'),
|
||||
message: $message.val()
|
||||
},
|
||||
dataType: "text",
|
||||
beforeSend: function() {
|
||||
clearInterval(mChat.interval);
|
||||
if (mChat.userTimeout) {
|
||||
clearInterval(mChat.activeInterval);
|
||||
clearInterval(mChat.counter);
|
||||
$("#mChatSessTimer").html(mChat.refreshing);
|
||||
}
|
||||
},
|
||||
success: function(html) {
|
||||
$("#mess" + id).fadeOut("slow", function() {
|
||||
$(this).replaceWith(html);
|
||||
$("#mess" + id).css("display", "none").fadeIn("slow");
|
||||
success: function(json) {
|
||||
$container.fadeOut('slow', function() {
|
||||
$container.replaceWith($(json.edit).hide().fadeIn('slow'));
|
||||
});
|
||||
},
|
||||
error: function(resp) {
|
||||
if (resp.status == 403) {
|
||||
alert(mChat.noAccess);
|
||||
} else if (resp.status == 501) {
|
||||
alert(mChat.noMessageInput);
|
||||
}
|
||||
},
|
||||
complete: function() {
|
||||
mChat.interval = setInterval(mChat.refresh, mChat.refreshTime);
|
||||
if (mChat.userTimeout) {
|
||||
mChat.sessionTime = mChat.userTimeout ? mChat.userTimeout / 1000 : false;
|
||||
mChat.counter = setInterval(mChat.countDown, 1000);
|
||||
mChat.activeInterval = setInterval(mChat.active, mChat.userTimeout);
|
||||
}
|
||||
$message.val('');
|
||||
mChat.resetSession();
|
||||
if (!mChat.archiveMode && !mChat.messageTop) {
|
||||
setTimeout(function() {
|
||||
$("#mChatmain").animate({scrollTop: $("#mChatmain")[0].scrollHeight}, 1000, "swing");
|
||||
}, 1500);
|
||||
mChat.$$('main').animate({scrollTop: mChat.$$('main')[0].scrollHeight}, 'slow', 'swing');
|
||||
}, 250);
|
||||
}
|
||||
}
|
||||
});
|
||||
}));
|
||||
});
|
||||
},
|
||||
del: function() {
|
||||
var id = $(this).closest(".mChatHover").data("id");
|
||||
mChat.confirmContainer.find("textarea").hide();
|
||||
mChat.confirmContainer.find("p").text(mChat.delConfirm);
|
||||
phpbb.confirm(mChat.confirmContainer, function() {
|
||||
$.ajax({
|
||||
url: mChat.file,
|
||||
timeout: 10000,
|
||||
type: "POST",
|
||||
var $container = $(this).closest('.mchat-message');
|
||||
mChat.$$('confirm').find('textarea').hide();
|
||||
mChat.$$('confirm').find('p').text(mChat.delConfirm);
|
||||
phpbb.confirm(mChat.$$('confirm'), function() {
|
||||
$.ajax($.extend({}, ajaxOptions, {
|
||||
data: {
|
||||
mode: "delete",
|
||||
message_id: id
|
||||
mode: 'del',
|
||||
message_id: $container.data('id')
|
||||
},
|
||||
beforeSend: function() {
|
||||
clearInterval(mChat.interval);
|
||||
if (mChat.userTimeout) {
|
||||
clearInterval(mChat.activeInterval);
|
||||
clearInterval(mChat.counter);
|
||||
$("#mChatSessTimer").html(mChat.refreshing);
|
||||
success: function(json) {
|
||||
if (json.del) {
|
||||
mChat.sound('del');
|
||||
$container.fadeOut('slow', function() {
|
||||
$container.remove();
|
||||
});
|
||||
}
|
||||
},
|
||||
success: function() {
|
||||
$("#mess" + id).fadeOut("slow", function() {
|
||||
$(this).remove();
|
||||
});
|
||||
mChat.sound("del");
|
||||
},
|
||||
error: function() {
|
||||
alert(mChat.noAccess);
|
||||
},
|
||||
complete: function() {
|
||||
mChat.interval = setInterval(mChat.refresh, mChat.refreshTime);
|
||||
if (mChat.userTimeout) {
|
||||
mChat.sessionTime = mChat.userTimeout ? mChat.userTimeout / 1000 : false;
|
||||
mChat.counter = setInterval(mChat.countDown, 1000);
|
||||
mChat.activeInterval = setInterval(mChat.active, mChat.userTimeout);
|
||||
}
|
||||
}
|
||||
});
|
||||
complete: mChat.resetSession
|
||||
}));
|
||||
});
|
||||
},
|
||||
refresh: function() {
|
||||
if (mChat.archiveMode) {
|
||||
return;
|
||||
}
|
||||
var firstLastSelector = mChat.messageTop ? ":first" : ":last";
|
||||
var messId = 0;
|
||||
if ($("#mChatData").children().not("#mChatNoMessage").length) {
|
||||
$("#mChatNoMessage").remove();
|
||||
var attr = $("#mChatData").children(firstLastSelector).not("#mChatNoMessage").attr("id");
|
||||
if (attr) {
|
||||
messId = attr.replace("mess", "");
|
||||
}
|
||||
}
|
||||
$.ajax({
|
||||
url: mChat.file,
|
||||
timeout: 10000,
|
||||
type: "POST",
|
||||
var firstLastSelector = mChat.messageTop ? ':first' : ':last';
|
||||
var id = mChat.$$('messages').children(firstLastSelector).data('id');
|
||||
$.ajax($.extend({}, ajaxOptions, {
|
||||
data: {
|
||||
mode: "read",
|
||||
message_last_id: messId
|
||||
mode: 'refresh',
|
||||
message_last_id: id
|
||||
},
|
||||
dataType: "html",
|
||||
beforeSend: function() {
|
||||
$("#mChatOkIMG,#mChatErrorIMG,#mChatPauseIMG").hide();
|
||||
$("#mChatLoadIMG").show();
|
||||
mChat.$$('refresh-ok', 'refresh-error', 'refresh-paused').hide();
|
||||
mChat.$$('refresh-load').show();
|
||||
},
|
||||
success: function(html) {
|
||||
var $html = $($.trim(html));
|
||||
success: function(json) {
|
||||
var $html = $(json.refresh);
|
||||
if ($html.length) {
|
||||
$("#mChatRefreshText").removeClass("mchat-alert");
|
||||
$html.hide();
|
||||
if (mChat.messageTop) {
|
||||
$("#mChatData").prepend($html);
|
||||
} else {
|
||||
$("#mChatData").append($html);
|
||||
}
|
||||
$html.fadeIn("slow");
|
||||
$("#mChatmain").stop().animate({scrollTop: mChat.messageTop ? 0 : $("#mChatmain")[0].scrollHeight}, 2000);
|
||||
mChat.sound("add");
|
||||
mChat.$$('no-messages').remove();
|
||||
mChat.$$('messages')[mChat.messageTop ? 'prepend' : 'append']($html.hide());
|
||||
$html.css('opacity', 0).slideDown('slow').animate({opacity: 1}, {queue: false, duration: 'slow'});
|
||||
mChat.$$('main').animate({scrollTop: mChat.messageTop ? 0 : mChat.$$('main')[0].scrollHeight}, 'slow');
|
||||
mChat.sound('add');
|
||||
mChat.notice();
|
||||
}
|
||||
setTimeout(function() {
|
||||
$("#mChatLoadIMG,#mChatErrorIMG,#mChatPauseIMG").hide();
|
||||
$("#mChatOkIMG").show();
|
||||
$("#mChatRefreshText").html(mChat.refreshYes);
|
||||
}, 500);
|
||||
mChat.$$('refresh-load', 'refresh-error', 'refresh-paused').hide();
|
||||
mChat.$$('refresh-ok').show();
|
||||
mChat.$$('refresh-text').html(mChat.refreshYes);
|
||||
}, 250);
|
||||
},
|
||||
error: function() {
|
||||
$("#mChatLoadIMG,#mChatOkIMG,#mChatPauseIMG,#mChatRefreshTextNo").hide();
|
||||
$("#mChatErrorIMG").show();
|
||||
mChat.sound("error");
|
||||
},
|
||||
complete: function() {
|
||||
if (!$("#mChatData").children(firstLastSelector).length) {
|
||||
$("#mChatData").append('<div id="mChatNoMessage">' + mChat.noMessages + "</div>").show("slow");
|
||||
}
|
||||
mChat.$$('refresh-load', 'refresh-ok', 'refresh-paused').hide();
|
||||
mChat.$$('refresh-error').show();
|
||||
mChat.sound('error');
|
||||
}
|
||||
});
|
||||
}));
|
||||
},
|
||||
stats: function() {
|
||||
$.ajax({
|
||||
url: mChat.file,
|
||||
timeout: 10000,
|
||||
type: "POST",
|
||||
whois: function() {
|
||||
$.ajax($.extend({}, ajaxOptions, {
|
||||
data: {
|
||||
mode: "stats"
|
||||
mode: 'whois'
|
||||
},
|
||||
dataType: "html",
|
||||
beforeSend: function() {
|
||||
if (mChat.customPage) {
|
||||
$("#mChatRefreshN").show();
|
||||
$("#mChatRefresh").hide();
|
||||
mChat.$$('refresh-pending').show();
|
||||
mChat.$$('refresh').hide();
|
||||
}
|
||||
},
|
||||
success: function(data) {
|
||||
var json = $.parseJSON(data);
|
||||
$("#mChatStats").replaceWith(json.message);
|
||||
success: function(json) {
|
||||
var $whois = $(json.whois);
|
||||
var $userlist = $whois.find('#mchat-userlist');
|
||||
if (Cookies.get('mChatShowUserlist')) {
|
||||
$userlist.show();
|
||||
}
|
||||
mChat.$$('whois').replaceWith($whois);
|
||||
mChat.cache['whois'] = $whois;
|
||||
mChat.cache['userlist'] = $userlist;
|
||||
if (mChat.customPage) {
|
||||
setTimeout(function() {
|
||||
$("#mChatRefreshN").hide();
|
||||
$("#mChatRefresh").show();
|
||||
}, 500);
|
||||
mChat.$$('refresh-pending').hide();
|
||||
mChat.$$('refresh').show();
|
||||
}, 250);
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
mChat.sound("error");
|
||||
},
|
||||
complete: function() {
|
||||
if ($("#mChatUserList").length && ($.cookie("mChatShowUserList") == "yes" || mChat.customPage)) {
|
||||
$("#mChatUserList").css("display", "block");
|
||||
}
|
||||
mChat.sound('error');
|
||||
}
|
||||
});
|
||||
}));
|
||||
},
|
||||
active: function() {
|
||||
if (mChat.archiveMode || !mChat.userTimeout) {
|
||||
return;
|
||||
countDown: function() {
|
||||
mChat.sessionTime -= 1;
|
||||
var timeLeft = formatRemainingSessionTime(mChat.sessionTime);
|
||||
mChat.$$('session').html(mChat.sessEnds + ' ' + timeLeft);
|
||||
if (mChat.sessionTime <= 0) {
|
||||
mChat.endSession();
|
||||
}
|
||||
clearInterval(mChat.interval);
|
||||
$("#mChatLoadIMG,#mChatOkIMG,#mChatErrorIMG").hide();
|
||||
$("#mChatPauseIMG").show();
|
||||
$("#mChatRefreshText").html(mChat.refreshNo).addClass("mchat-alert");
|
||||
$("#mChatSessMess").html(mChat.sessOut).addClass("mchat-alert");
|
||||
},
|
||||
insertMention: function() {
|
||||
var $msg = $(this).closest(".mChatHover");
|
||||
var username = mChat.entityDecode($msg.data("username"));
|
||||
var usercolor = $msg.data("usercolor");
|
||||
pauseSession: function() {
|
||||
mChat.submitting = true;
|
||||
clearInterval(mChat.refreshInterval);
|
||||
if (mChat.userTimeout) {
|
||||
clearInterval(mChat.sessionCountdown);
|
||||
}
|
||||
if (mChat.whoisRefresh) {
|
||||
clearInterval(mChat.whoisInterval);
|
||||
}
|
||||
},
|
||||
resetSession: function() {
|
||||
clearInterval(mChat.refreshInterval);
|
||||
mChat.refreshInterval = setInterval(mChat.refresh, mChat.refreshTime);
|
||||
if (mChat.userTimeout) {
|
||||
mChat.sessionTime = mChat.userTimeout / 1000;
|
||||
clearInterval(mChat.sessionCountdown);
|
||||
mChat.sessionCountdown = setInterval(mChat.countDown, 1000);
|
||||
mChat.$$('session').html(mChat.sessEnds + ' ' + formatRemainingSessionTime(mChat.sessionTime));
|
||||
}
|
||||
if (mChat.whoisRefresh) {
|
||||
clearInterval(mChat.whoisInterval);
|
||||
mChat.whoisInterval = setInterval(mChat.whois, mChat.whoisRefresh);
|
||||
}
|
||||
if (mChat.pause) {
|
||||
mChat.$$('input').one('keypress', mChat.endSession);
|
||||
}
|
||||
mChat.$$('refresh-ok').show();
|
||||
mChat.$$('refresh-load', 'refresh-error', 'refresh-paused').hide();
|
||||
mChat.$$('refresh-text').html(mChat.refreshYes);
|
||||
mChat.submitting = false;
|
||||
},
|
||||
endSession: function() {
|
||||
clearInterval(mChat.refreshInterval);
|
||||
if (mChat.userTimeout) {
|
||||
clearInterval(mChat.sessionCountdown);
|
||||
mChat.$$('session').html(mChat.sessOut);
|
||||
}
|
||||
if (mChat.whoisRefresh) {
|
||||
clearInterval(mChat.whoisInterval);
|
||||
}
|
||||
mChat.$$('refresh-load', 'refresh-ok', 'refresh-error').hide();
|
||||
mChat.$$('refresh-paused').show();
|
||||
mChat.$$('refresh-text').html(mChat.refreshNo);
|
||||
mChat.whois();
|
||||
},
|
||||
mention: function() {
|
||||
var $container = $(this).closest('.mchat-message');
|
||||
var username = mChat.entityDecode($container.data('username'));
|
||||
var usercolor = $container.data('usercolor');
|
||||
if (usercolor) {
|
||||
username = "[b][color=" + usercolor + "]" + username + "[/color][/b]";
|
||||
username = '[b][color=' + usercolor + ']' + username + '[/color][/b]';
|
||||
} else if (mChat.allowBBCodes) {
|
||||
username = "[b]" + username + "[/b]";
|
||||
username = '[b]' + username + '[/b]';
|
||||
}
|
||||
insert_text("@ " + username + ", ");
|
||||
insert_text('@ ' + username + ', ');
|
||||
},
|
||||
insertQuote: function() {
|
||||
var $msg = $(this).closest(".mChatHover");
|
||||
var username = mChat.entityDecode($msg.data("username"));
|
||||
var id = $msg.data("id");
|
||||
var quote = mChat.entityDecode($("#mess" + id).data("edit"));
|
||||
insert_text('[quote="' + username + '"]' + quote + '[/quote]');
|
||||
quote: function() {
|
||||
var $container = $(this).closest('.mchat-message');
|
||||
var username = mChat.entityDecode($container.data('username'));
|
||||
var quote = mChat.entityDecode($container.data('edit'));
|
||||
insert_text('[quote="' + username + '"] ' + quote + '[/quote]');
|
||||
},
|
||||
insertLike: function() {
|
||||
var $msg = $(this).closest(".mChatHover");
|
||||
var username = mChat.entityDecode($msg.data("username"));
|
||||
var quote = mChat.entityDecode($msg.data("edit"));
|
||||
insert_text(mChat.likes + '[quote="' + username + '"]' + quote + "[/quote]");
|
||||
like: function() {
|
||||
var $container = $(this).closest('.mchat-message');
|
||||
var username = mChat.entityDecode($container.data('username'));
|
||||
var quote = mChat.entityDecode($container.data('edit'));
|
||||
insert_text(mChat.likes + '[quote="' + username + '"] ' + quote + '[/quote]');
|
||||
},
|
||||
entityDecode: function(text) {
|
||||
var s = decodeURIComponent(text.replace(/\+/g, " "));
|
||||
s = s.replace(/</g, "<");
|
||||
s = s.replace(/>/g, ">");
|
||||
s = s.replace(/:/g, ":");
|
||||
s = s.replace(/./g, ".");
|
||||
s = s.replace(/&/g, "&");
|
||||
s = s.replace(/"/g, '"');
|
||||
var s = decodeURIComponent(text.toString().replace(/\+/g, ' '));
|
||||
s = s.replace(/</g, '<');
|
||||
s = s.replace(/>/g, '>');
|
||||
s = s.replace(/:/g, ':');
|
||||
s = s.replace(/./g, '.');
|
||||
s = s.replace(/&/g, '&');
|
||||
s = s.replace(/"/g, "'");
|
||||
return s;
|
||||
},
|
||||
$$: function() {
|
||||
return $($.map(arguments, function(name) {
|
||||
if (!mChat.cache[name]) {
|
||||
mChat.cache[name] = $('#mchat-' + name);
|
||||
}
|
||||
return mChat.cache[name];
|
||||
})).map(function() {
|
||||
return this.toArray();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
mChat.interval = setInterval(mChat.refresh, mChat.refreshTime);
|
||||
mChat.activeInterval = setInterval(mChat.active, mChat.userTimeout);
|
||||
mChat.sessionTime = mChat.userTimeout ? mChat.userTimeout / 1000 : false;
|
||||
mChat.confirmContainer = $("#mChatConfirm").detach().show();
|
||||
mChat.cache = {};
|
||||
mChat.$$('confirm').detach().show();
|
||||
|
||||
if (mChat.userTimeout) {
|
||||
mChat.counter = setInterval(mChat.countDown, 1000);
|
||||
if (!mChat.archiveMode) {
|
||||
$.fn.autoGrowInput = function() {
|
||||
this.filter('input:text').each(function() {
|
||||
var comfortZone = 20;
|
||||
var minWidth = $(this).width();
|
||||
var val = '';
|
||||
var input = $(this);
|
||||
var testSubject = $('<div>').css({
|
||||
position: 'absolute',
|
||||
top: -9999,
|
||||
left: -9999,
|
||||
width: 'auto',
|
||||
fontSize: input.css('fontSize'),
|
||||
fontFamily: input.css('fontFamily'),
|
||||
fontWeight: input.css('fontWeight'),
|
||||
letterSpacing: input.css('letterSpacing'),
|
||||
whiteSpace: 'nowrap'
|
||||
});
|
||||
testSubject.insertAfter(input);
|
||||
$(this).on('keypress blur change submit focus', function() {
|
||||
if (val === (val = input.val())) {
|
||||
return;
|
||||
}
|
||||
var escaped = val.replace(/&/g, '&').replace(/\s/g, ' ').replace(/</g, '<').replace(/>/g, '>');
|
||||
var testerWidth = testSubject.html(escaped).width();
|
||||
var newWidth = (testerWidth + comfortZone) >= minWidth ? testerWidth + comfortZone : minWidth;
|
||||
if ((newWidth < input.width() && newWidth >= minWidth) || (newWidth > minWidth && newWidth < $('.mchat-panel').width() - comfortZone)) {
|
||||
input.width(newWidth);
|
||||
}
|
||||
});
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
mChat.resetSession();
|
||||
|
||||
if (!mChat.messageTop) {
|
||||
mChat.$$('main').animate({scrollTop: mChat.$$('main')[0].scrollHeight}, 'slow', 'swing');
|
||||
}
|
||||
|
||||
if (mChat.playSound && Cookies.get('mChatNoSound')) {
|
||||
mChat.$$('user-sound').removeAttr('checked');
|
||||
} else {
|
||||
mChat.$$('user-sound').attr('checked', 'checked');
|
||||
Cookies.remove('mChatNoSound');
|
||||
}
|
||||
|
||||
if (Cookies.get('mChatShowSmilies')) {
|
||||
mChat.$$('smilies').slideToggle('slow');
|
||||
}
|
||||
|
||||
if (Cookies.get('mChatShowBbcodes')) {
|
||||
mChat.$$('bbcodes').slideToggle('slow', function() {
|
||||
if (Cookies.get('mChatShowColour')) {
|
||||
mChat.$$('colour').slideToggle('slow');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (Cookies.get('mChatShowUserlist')) {
|
||||
mChat.$$('userlist').slideToggle('slow');
|
||||
}
|
||||
|
||||
mChat.$$('colour').html(phpbb.colorPalette('h', 15, 10)).on('click', 'a', function(e) {
|
||||
var color = $(this).data('color');
|
||||
bbfontstyle('[color=#' + color + ']', '[/color]');
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
mChat.$$('user-sound').change(function() {
|
||||
if (this.checked) {
|
||||
Cookies.remove('mChatNoSound');
|
||||
} else {
|
||||
Cookies.set('mChatNoSound', 'yes');
|
||||
}
|
||||
});
|
||||
|
||||
$('#postform').on('keypress', function(e) {
|
||||
if (e.which == 13) {
|
||||
mChat.add();
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
mChat.$$('input').autoGrowInput();
|
||||
}
|
||||
|
||||
if (mChat.whois) {
|
||||
mChat.statsInterval = setInterval(mChat.stats, mChat.whoisRefresh);
|
||||
}
|
||||
|
||||
if ($.cookie("mChatShowSmiles") == "yes" && $("#mChatSmiles").css("display", "none")) {
|
||||
$("#mChatSmiles").slideToggle("slow");
|
||||
}
|
||||
|
||||
if ($.cookie("mChatShowBBCodes") == "yes" && $("#mChatBBCodes").css("display", "none")) {
|
||||
$("#mChatBBCodes").slideToggle("slow");
|
||||
}
|
||||
|
||||
if ($.cookie("mChatShowUserList") == "yes" && $("#mChatUserList").length) {
|
||||
$("#mChatUserList").slideToggle("slow");
|
||||
}
|
||||
|
||||
if ($.cookie("mChatShowColour") == "yes" && $("#mChatColour").css("display", "none")) {
|
||||
$("#mChatColour").slideToggle("slow");
|
||||
}
|
||||
|
||||
$("#mChatUseSound").change(function() {
|
||||
$.cookie("mChatNoSound", $(this).is(":checked") ? null : "yes");
|
||||
$('#page-body').on('click', '[data-mchat-action]', function(e) {
|
||||
var action = $(this).data('mchat-action');
|
||||
mChat[action].call(this);
|
||||
e.preventDefault();
|
||||
}).on('click', '[data-mchat-toggle]', function(e) {
|
||||
var elem = $(this).data('mchat-toggle');
|
||||
mChat.toggle(elem);
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user