Version 2.0.0-RC6

This commit is contained in:
dmzx
2016-09-20 22:38:19 +02:00
parent aac8ce6f58
commit 233dc89a8a
73 changed files with 2722 additions and 1336 deletions

View File

@@ -28,95 +28,172 @@ if (!Array.prototype.min) {
};
}
if (!String.prototype.format) {
String.prototype.format = function() {
var str = this.toString();
if (!arguments.length) {
return str;
}
var type = typeof arguments[0];
var args = 'string' == type || 'number' == type ? arguments : arguments[0];
jQuery.each(args, function(arg, value) {
str = str.replace(RegExp('\\{' + arg + '\\}', 'gi'), value);
});
Array.prototype.removeValue = function(value) {
var index = -1;
var elementsRemoved = 0;
while ((index = this.indexOf(value)) !== -1) {
this.splice(index, 1);
elementsRemoved++;
}
return elementsRemoved;
};
String.prototype.format = function() {
var str = this.toString();
if (!arguments.length) {
return str;
}
}
var type = typeof arguments[0];
var args = 'string' == type || 'number' == type ? arguments : arguments[0];
for (var arg in args) {
if (args.hasOwnProperty(arg)) {
str = str.replace(new RegExp("\\{" + arg + "\\}", "gi"), args[arg]);
}
}
return str;
};
String.prototype.replaceMany = function() {
var result = this;
var args = arguments[0];
for (var arg in args) {
if (args.hasOwnProperty(arg)) {
result = result.replace(new RegExp(RegExp.escape(arg), "g"), args[arg]);
}
}
return result;
};
RegExp.escape = function(s) {
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
};
jQuery.fn.reverse = function(reverse) {
return reverse === 'undefined' || reverse ? jQuery(this.toArray().reverse()) : this;
};
jQuery(function($) {
var ajaxRequest = function(mode, sendHiddenFields, data) {
var deferred = $.Deferred();
if (sendHiddenFields) {
$.extend(data, mChat.hiddenFields);
}
$.ajax({
url: mChat.actionUrls[mode],
timeout: Math.min(mChat.refreshTime, 10000),
type: 'POST',
dataType: 'json',
data: data
}).done(function(json, status, xhr) {
if (json[mode]) {
deferred.resolve(json, status, xhr);
} else {
deferred.reject(xhr, status, xhr.responseJSON ? 'session' : 'unexpected format');
}
}).fail(function(xhr, status, error) {
deferred.reject(xhr, status, error);
});
return deferred.promise().fail(function(xhr, textStatus, errorThrown) {
mChat.sound('error');
mChat.cached('status-load', 'status-ok', 'status-paused').hide();
mChat.cached('status-error').show();
if (errorThrown == 'session') {
mChat.endSession(true);
alert(mChat.sessOut);
} else if (xhr.status == 400) {
mChat.resetSession();
alert(mChat.flood);
} else if (xhr.status == 403) {
mChat.endSession(true);
alert(mChat.noAccess);
} else if (xhr.status == 413) {
mChat.resetSession();
alert(mChat.mssgLngthLong);
} else if (xhr.status == 501) {
mChat.resetSession();
alert(mChat.noMessageInput);
} else if (typeof console !== 'undefined' && console.log) {
console.log('AJAX error. status: ' + textStatus + ', message: ' + errorThrown);
}
});
};
"use strict";
$.extend(mChat, {
ajaxRequest: function(mode, sendHiddenFields, data) {
var deferred = $.Deferred();
if (sendHiddenFields) {
$.extend(data, mChat.hiddenFields);
}
$(mChat).trigger('mchat_send_request_before', [mode, data]);
$.ajax({
url: mChat.actionUrls[mode],
timeout: Math.min(mChat.refreshTime, 10000),
type: 'POST',
dataType: 'json',
data: data
}).done(function(json, status, xhr) {
var data = {
mode: mode,
json: json,
status: status,
xhr: xhr,
handle: true
};
$(mChat).trigger('mchat_ajax_done_before', [data]);
if (data.handle) {
if (json[mode]) {
deferred.resolve(data.json, data.status, data.xhr);
} else {
deferred.reject(data.xhr, data.status, mChat.lang.parserErr);
}
}
}).fail(function(xhr, status, error) {
deferred.reject(xhr, status, error);
});
return deferred.promise().fail(function(xhr, textStatus, errorThrown) {
if (mChat.pageIsUnloading) {
return;
}
if (typeof console !== 'undefined' && console.log) {
console.log('AJAX error. status: ' + textStatus + ', message: ' + errorThrown + ' (' + xhr.responseText + ')');
}
var data = {
mode: mode,
xhr: xhr,
textStatus: textStatus,
errorThrown: errorThrown,
updateSession: function(xhr) {
if (xhr.status == 403) {
mChat.endSession(true);
} else if (xhr.status == 400) {
mChat.resetSession();
}
}
};
$(mChat).trigger('mchat_ajax_fail_before', [data]);
mChat.sound('error');
mChat.cached('status-load', 'status-ok', 'status-paused').hide();
mChat.cached('status-error').show();
var responseText;
try {
responseText = xhr.responseJSON.message || errorThrown;
} catch (e) {
responseText = errorThrown;
}
phpbb.alert(mChat.lang.err, responseText);
data.updateSession(data.xhr);
});
},
sound: function(file) {
if (!mChat.pageIsUnloading && !Cookies.get('mchat_no_sound')) {
var audio = mChat.cached('sound-' + file).get(0);
if (audio.duration) {
audio.pause();
audio.currentTime = 0;
audio.play();
if (!mChat.pageIsUnloading && !localStorage.getItem(mChat.cookie + 'mchat_no_sound')) {
var data = {
audio: mChat.cached('sound-' + file).get(0),
file: file,
play: true
};
$(mChat).trigger('mchat_sound_before', [data]);
if (data.play && data.audio.duration) {
data.audio.pause();
data.audio.currentTime = 0;
data.audio.play();
}
}
},
notice: function() {
if (!document.hasFocus()) {
$.titleAlert(mChat.newMessageAlert, {interval: 1000});
titleAlert: function() {
var data = {
doAlert: !document.hasFocus(),
interval: 1000
};
$(mChat).trigger('mchat_titlealert_before', [data]);
if (data.doAlert) {
$.titleAlert(mChat.lang.newMessageAlert, data);
}
},
toggle: function(name) {
var $elem = mChat.cached(name);
$elem.stop().slideToggle(function() {
var cookieName = 'mchat_show_' + name;
$elem.stop().slideToggle('fast', function() {
if ($elem.is(':visible')) {
Cookies.set(cookieName, 'yes');
localStorage.setItem(mChat.cookie + 'mchat_show_' + name, 'yes');
} else {
Cookies.remove(cookieName);
localStorage.removeItem(mChat.cookie + 'mchat_show_' + name);
}
});
},
confirm: function(data) {
var $confirmFields = data.container.find('.mchat-confirm-fields');
$confirmFields.children().hide();
var fields = data.fields($confirmFields);
$.each(fields, function() {
$(this).show();
});
setTimeout(function() {
var $input = $confirmFields.find(':input:visible:enabled:first');
if ($input.length) {
var value = $input.val();
$input.focus().val('').val(value);
}
}, 1);
phpbb.confirm(data.container.show(), function() {
if (typeof data.confirm === 'function') {
data.confirm.apply(this, fields);
}
});
},
@@ -124,23 +201,34 @@ jQuery(function($) {
if (mChat.cached('add').prop('disabled')) {
return;
}
var messageLength = mChat.inputMessageLength();
var messageLength = mChat.cached('input').val().length;
if (!messageLength) {
alert(mChat.noMessageInput);
phpbb.alert(mChat.lang.err, mChat.lang.noMessageInput);
return;
}
if (mChat.mssgLngth && messageLength > mChat.mssgLngth) {
alert(mChat.mssgLngthLong);
phpbb.alert(mChat.lang.err, mChat.lang.mssgLngthLong);
return;
}
mChat.cached('add').prop('disabled', true);
mChat.pauseSession();
mChat.lastInputValue = mChat.cached('input').val();
mChat.cached('input').val('').keyup().trigger('autogrow');
mChat.refresh(mChat.lastInputValue).done(function() {
var originalInputValue = mChat.cached('input').val();
var inputValue = originalInputValue;
var color = localStorage.getItem(mChat.cookie + 'mchat_color');
if (color && inputValue.indexOf('[color=') === -1) {
inputValue = '[color=#' + color + '] ' + inputValue + ' [/color]';
}
mChat.cached('input').val('');
if (mChat.showCharCount) {
mChat.updateCharCount();
}
mChat.refresh(inputValue).done(function() {
mChat.resetSession();
}).fail(function() {
mChat.cached('input').val(mChat.lastInputValue).keyup().trigger('autogrow');
mChat.cached('input').val(originalInputValue);
if (mChat.showCharCount) {
mChat.updateCharCount();
}
}).always(function() {
mChat.cached('add').prop('disabled', false);
setTimeout(function() {
@@ -149,90 +237,65 @@ jQuery(function($) {
});
},
edit: function() {
var $container = $(this).closest('.mchat-message');
var $message = mChat.cached('confirm').find('textarea').show().val($container.data('mchat-message'));
mChat.cached('confirm').find('p').text(mChat.editInfo);
phpbb.confirm(mChat.cached('confirm'), function() {
ajaxRequest('edit', true, {
message_id: $container.data('mchat-id'),
message: $message.val(),
archive: mChat.archivePage ? 1 : 0
}).done(function(json) {
mChat.updateMessages($(json.edit));
mChat.resetSession();
});
var $message = $(this).closest('.mchat-message');
mChat.confirm({
container: mChat.cached('confirm'),
fields: function($container) {
return [
$container.find('p').text(mChat.lang.editInfo),
$container.find('textarea').val($message.data('mchat-message'))
];
},
confirm: function($p, $textarea) {
mChat.ajaxRequest('edit', true, {
message_id: $message.data('mchat-id'),
message: $textarea.val(),
archive: mChat.archivePage ? 1 : 0
}).done(function(json) {
mChat.updateMessages($(json.edit));
mChat.resetSession();
});
}
});
},
del: function() {
var $container = $(this).closest('.mchat-message');
mChat.cached('confirm').find('textarea').hide();
mChat.cached('confirm').find('p').text(mChat.delConfirm);
phpbb.confirm(mChat.cached('confirm'), function() {
var delId = $container.data('mchat-id');
ajaxRequest('del', true, {
message_id: delId
}).done(function() {
mChat.removeMessages([delId]);
mChat.resetSession();
});
var delId = $(this).closest('.mchat-message').data('mchat-id');
mChat.confirm({
container: mChat.cached('confirm'),
fields: function($container) {
return [
$container.find('p').text(mChat.lang.delConfirm)
];
},
confirm: function($p) {
mChat.ajaxRequest('del', true, {
message_id: delId
}).done(function() {
mChat.removeMessages([delId]);
mChat.resetSession();
});
}
});
},
refresh: function(message) {
if (mChat.isPaused && !message) {
return false;
}
var $messages = mChat.cached('messages').children();
var data = {
message_last_id: mChat.messageIds.length ? mChat.messageIds.max() : 0
last: mChat.messageIds.length ? mChat.messageIds.max() : 0
};
if (message) {
data.message = message;
}
if (mChat.liveUpdates) {
data.message_first_id = mChat.messageIds.length ? mChat.messageIds.min() : 0;
data.message_edits = {};
var now = Math.floor(Date.now() / 1000);
$.each($messages, function() {
var $message = $(this);
var editTime = $message.data('mchat-edit-time');
if (editTime && (!mChat.editDeleteLimit || $message.data('mchat-message-time') >= now - mChat.editDeleteLimit / 1000)) {
data.message_edits[$message.data('mchat-id')] = editTime;
}
});
data.log = mChat.logId;
}
mChat.cached('status-ok', 'status-error', 'status-paused').hide();
mChat.cached('status-load').show();
return ajaxRequest(message ? 'add' : 'refresh', !!message, data).done(function(json) {
return mChat.ajaxRequest(message ? 'add' : 'refresh', !!message, data).done(function(json) {
$(mChat).trigger('mchat_response_handle_data_before', [json]);
if (json.add) {
var $html = $(json.add);
$('.mchat-no-messages').remove();
$html.reverse(mChat.messageTop).hide().each(function(i) {
var $message = $(this);
if ($.inArray($message.data('mchat-id'), mChat.messageIds) !== -1) {
return;
}
mChat.messageIds.push($message.data('mchat-id'));
setTimeout(function() {
if (mChat.messageTop) {
mChat.cached('messages').prepend($message);
} else {
mChat.cached('messages').append($message);
}
$message.css('opacity', 0).slideDown().animate({opacity: 1}, {queue: false});
mChat.cached('messages').animate({scrollTop: mChat.messageTop ? 0 : mChat.cached('messages')[0].scrollHeight});
}, i * 400);
if (mChat.editDeleteLimit && $message.data('mchat-edit-delete-limit') && $message.find('[data-mchat-action="edit"], [data-mchat-action="del"]').length > 0) {
var id = $message.prop('id');
setTimeout(function() {
$('#' + id).find('[data-mchat-action="edit"], [data-mchat-action="del"]').fadeOut(function() {
$(this).closest('li').remove();
});
}, mChat.editDeleteLimit);
}
mChat.startRelativeTimeUpdate($message);
});
mChat.sound('add');
mChat.notice();
mChat.addMessages($(json.add));
}
if (json.edit) {
mChat.updateMessages($(json.edit));
@@ -241,12 +304,16 @@ jQuery(function($) {
mChat.removeMessages(json.del);
}
if (json.whois) {
mChat.whois();
mChat.handleWhoisResponse(json);
}
if (json.log) {
mChat.logId = json.log;
}
if (mChat.refreshInterval) {
mChat.cached('status-load', 'status-error', 'status-paused').hide();
mChat.cached('status-ok').show();
}
$(mChat).trigger('mchat_response_handle_data_after', [json]);
});
},
whois: function() {
@@ -254,51 +321,133 @@ jQuery(function($) {
mChat.cached('refresh-pending').show();
mChat.cached('refresh-explain').hide();
}
ajaxRequest('whois', false, {}).done(function(json) {
var $whois = $(json.whois);
var $userlist = $whois.find('#mchat-userlist');
if (Cookies.get('mchat_show_userlist')) {
$userlist.show();
mChat.ajaxRequest('whois', false, {}).done(mChat.handleWhoisResponse);
},
handleWhoisResponse: function(json) {
var $whois = $(json.whois);
var $userlist = $whois.find('#mchat-userlist');
if (localStorage.getItem(mChat.cookie + 'mchat_show_userlist')) {
$userlist.show();
}
mChat.cached('whois').replaceWith($whois);
mChat.cache.whois = $whois;
mChat.cache.userlist = $userlist;
if (mChat.customPage) {
mChat.cached('refresh-pending').hide();
mChat.cached('refresh-explain').show();
}
if (json.navlink) {
$('.mchat-nav-link').html(json.navlink);
}
if (json.navlink_title) {
$('.mchat-nav-link-title').prop('title', json.navlink_title);
}
},
addMessages: function($messages) {
var playSound = true;
mChat.cached('messages').find('.mchat-no-messages').remove();
$messages.reverse(mChat.messageTop).hide().each(function(i) {
var $message = $(this);
var data = {
message: $message,
delay: mChat.refreshInterval ? 400 : 0,
abort: $.inArray($message.data('mchat-id'), mChat.messageIds) !== -1,
playSound: playSound
};
$(mChat).trigger('mchat_add_message_before', [data]);
if (data.abort) {
return;
}
mChat.cached('whois').replaceWith($whois);
mChat.cache.whois = $whois;
mChat.cache.userlist = $userlist;
if (mChat.customPage) {
mChat.cached('refresh-pending').hide();
mChat.cached('refresh-explain').show();
if (data.playSound) {
mChat.sound('add');
mChat.titleAlert();
playSound = false;
}
mChat.messageIds.push($message.data('mchat-id'));
setTimeout(function() {
var $container = mChat.cached('messages');
var data = {
container: $container,
message: $message,
add: function() {
if (mChat.messageTop) {
this.container.prepend(this.message);
} else {
this.container.append(this.message);
}
},
show: function() {
var scrollTop, scrollHeight = mChat.messageTop ? 0 : $container.get(0).scrollHeight;
if (mChat.messageTop && (scrollTop = this.container.scrollTop()) > 0) {
this.message.show();
this.container.scrollTop(scrollTop + this.message.outerHeight());
} else {
this.message.css('opacity', 0).slideDown('fast').animate({opacity: 1}, {duration: 'fast', queue: false});
}
if (!mChat.messageTop && this.container.scrollTop() >= scrollHeight - this.container.height()) {
this.container.animate({
scrollTop: scrollHeight,
easing: 'swing',
duration: 'slow'
});
}
}
};
$(mChat).trigger('mchat_add_message_animate_before', [data]);
data.add();
data.show();
}, i * data.delay);
if (mChat.editDeleteLimit && $message.data('mchat-edit-delete-limit') && $message.find('[data-mchat-action="edit"], [data-mchat-action="del"]').length > 0) {
var id = $message.prop('id');
setTimeout(function() {
$('#' + id).find('[data-mchat-action="edit"], [data-mchat-action="del"]').fadeOut(function() {
$(this).closest('li').remove();
});
}, mChat.editDeleteLimit);
}
mChat.startRelativeTimeUpdate($message);
});
},
updateMessages: function($messages) {
var soundPlayed = false;
var playSound = true;
$messages.each(function() {
var $newMessage = $(this);
var $oldMessage = $('#mchat-message-' + $newMessage.data('mchat-id'));
mChat.stopRelativeTimeUpdate($oldMessage);
mChat.startRelativeTimeUpdate($newMessage);
$oldMessage.fadeOut(function() {
$oldMessage.replaceWith($newMessage.hide().fadeIn());
var data = {
newMessage: $newMessage,
oldMessage: $('#mchat-message-' + $newMessage.data('mchat-id')),
playSound: playSound
};
$(mChat).trigger('mchat_edit_message_before', [data]);
mChat.stopRelativeTimeUpdate(data.oldMessage);
mChat.startRelativeTimeUpdate(data.newMessage);
data.oldMessage.fadeOut(function() {
data.oldMessage.replaceWith(data.newMessage.hide().fadeIn());
});
if (!soundPlayed) {
soundPlayed = true;
if (data.playSound) {
mChat.sound('edit');
playSound = false;
}
});
},
removeMessages: function(ids) {
var soundPlayed = false;
var playSound = true;
$.each(ids, function(i, id) {
var index = 0;
while ((index = $.inArray(id, mChat.messageIds, index)) !== -1) {
mChat.messageIds.splice(index, 1);
var $message = $('#mchat-message-' + id);
mChat.stopRelativeTimeUpdate($message);
$message.fadeOut(function() {
$message.remove();
});
if (!soundPlayed) {
soundPlayed = true;
if (mChat.messageIds.removeValue(id)) {
var data = {
id: id,
message: $('#mchat-message-' + id),
playSound: playSound
};
$(mChat).trigger('mchat_delete_message_before', [data]);
mChat.stopRelativeTimeUpdate(data.message);
(function($message) {
$message.fadeOut(function() {
$message.remove();
});
})(data.message);
if (data.playSound) {
mChat.sound('del');
playSound = false;
}
}
});
@@ -318,7 +467,7 @@ jQuery(function($) {
},
relativeTimeUpdate: function($time) {
var minutesAgo = $time.data('mchat-minutes-ago') + 1;
var langMinutesAgo = mChat.minutesAgo[minutesAgo];
var langMinutesAgo = mChat.lang.minutesAgo[minutesAgo];
if (langMinutesAgo) {
$time.text(langMinutesAgo).data('mchat-minutes-ago', minutesAgo);
} else {
@@ -335,14 +484,14 @@ jQuery(function($) {
},
countDown: function() {
mChat.sessionTime -= 1;
mChat.cached('session').html(mChat.sessEnds.format({timeleft: mChat.timeLeft(mChat.sessionTime)}));
mChat.cached('session').html(mChat.lang.sessEnds.format({timeleft: mChat.timeLeft(mChat.sessionTime)}));
if (mChat.sessionTime < 1) {
mChat.endSession();
}
},
pauseSession: function() {
clearInterval(mChat.refreshInterval);
if (mChat.userTimeout) {
if (mChat.timeout) {
clearInterval(mChat.sessionCountdown);
}
if (mChat.whoisRefresh) {
@@ -353,10 +502,10 @@ jQuery(function($) {
if (!mChat.archivePage) {
clearInterval(mChat.refreshInterval);
mChat.refreshInterval = setInterval(mChat.refresh, mChat.refreshTime);
if (mChat.userTimeout) {
mChat.sessionTime = mChat.userTimeout / 1000;
if (mChat.timeout) {
mChat.sessionTime = mChat.timeout / 1000;
clearInterval(mChat.sessionCountdown);
mChat.cached('session').html(mChat.sessEnds.format({timeleft: mChat.timeLeft(mChat.sessionTime)}));
mChat.cached('session').html(mChat.lang.sessEnds.format({timeleft: mChat.timeLeft(mChat.sessionTime)}));
mChat.sessionCountdown = setInterval(mChat.countDown, 1000);
}
if (mChat.whoisRefresh) {
@@ -365,15 +514,15 @@ jQuery(function($) {
}
mChat.cached('status-ok').show();
mChat.cached('status-load', 'status-error', 'status-paused').hide();
mChat.cached('refresh-text').html(mChat.refreshYes);
mChat.cached('refresh-text').html(mChat.lang.refreshYes);
}
},
endSession: function(skipUpdateWhois) {
clearInterval(mChat.refreshInterval);
mChat.refreshInterval = false;
if (mChat.userTimeout) {
if (mChat.timeout) {
clearInterval(mChat.sessionCountdown);
mChat.cached('session').html(mChat.sessOut);
mChat.cached('session').html(mChat.lang.sessOut);
}
if (mChat.whoisRefresh) {
clearInterval(mChat.whoisInterval);
@@ -383,23 +532,31 @@ jQuery(function($) {
}
mChat.cached('status-load', 'status-ok', 'status-error').hide();
mChat.cached('status-paused').show();
mChat.cached('refresh-text').html(mChat.refreshNo);
mChat.cached('refresh-text').html(mChat.lang.refreshNo);
},
pauseStart: function() {
mChat.isPaused = true;
mChat.cached('refresh-text').html(mChat.refreshNo);
mChat.cached('refresh-text').html(mChat.lang.refreshNo);
mChat.cached('status-load', 'status-ok', 'status-error').hide();
mChat.cached('status-paused').show();
},
pauseEnd: function() {
mChat.cached('refresh-text').html(mChat.refreshYes);
mChat.cached('refresh-text').html(mChat.lang.refreshYes);
mChat.cached('status-load', 'status-error', 'status-paused').hide();
mChat.cached('status-ok').show();
mChat.isPaused = false;
},
updateCharCount: function() {
var count = mChat.cached('input').val().length;
var charCount = mChat.lang.charCount.format({current: count, max: mChat.mssgLngth});
var $elem = mChat.cached('character-count').html(charCount).toggleClass('hidden', count === 0);
if (mChat.mssgLngth) {
$elem.toggleClass('error', count > mChat.mssgLngth);
}
},
mention: function() {
var $container = $(this).closest('.mchat-message');
var username = mChat.entityDecode($container.data('mchat-username'));
var username = $container.data('mchat-username');
var usercolor = $container.data('mchat-usercolor');
if (usercolor) {
username = '[b][color=' + usercolor + ']' + username + '[/color][/b]';
@@ -410,32 +567,19 @@ jQuery(function($) {
},
quote: function() {
var $container = $(this).closest('.mchat-message');
var username = mChat.entityDecode($container.data('mchat-username'));
var quote = mChat.entityDecode($container.data('mchat-message'));
var username = $container.data('mchat-username');
var quote = $container.data('mchat-message');
insert_text('[quote="' + username + '"] ' + quote + '[/quote]');
},
like: function() {
var $container = $(this).closest('.mchat-message');
var username = mChat.entityDecode($container.data('mchat-username'));
var quote = mChat.entityDecode($container.data('mchat-message'));
insert_text(mChat.likes + '[quote="' + username + '"] ' + quote + '[/quote]');
var username = $container.data('mchat-username');
var quote = $container.data('mchat-message');
insert_text('[i]' + mChat.lang.likes + '[/i][quote="' + username + '"] ' + quote + '[/quote]');
},
ip: function() {
popup(this.href, 750, 500);
},
entityDecode: function(text) {
var s = decodeURIComponent(text.toString().replace(/\+/g, ' '));
s = s.replace(/&lt;/g, '<');
s = s.replace(/&gt;/g, '>');
s = s.replace(/&#58;/g, ':');
s = s.replace(/&#46;/g, '.');
s = s.replace(/&amp;/g, '&');
s = s.replace(/&quot;/g, "'");
return s;
},
inputMessageLength: function() {
return $.trim(mChat.cached('input').val()).replace(/\[\/?[^\[\]]+\]/g, '').length;
},
cached: function() {
return $($.map(arguments, function(name) {
if (!mChat.cache[name]) {
@@ -449,8 +593,6 @@ jQuery(function($) {
});
mChat.cache = {};
mChat.cached('confirm').detach().show();
mChat.messageIds = mChat.cached('messages').children().map(function() {
return $(this).data('mchat-id');
}).get();
@@ -469,44 +611,43 @@ jQuery(function($) {
mChat.cached('messages').animate({scrollTop: mChat.cached('messages')[0].scrollHeight, easing: 'swing', duration: 'slow'});
}
if (!mChat.cached('user-sound').prop('checked')) {
Cookies.set('mchat_no_sound', 'yes');
}
mChat.cached('user-sound').prop('checked', mChat.playSound && !Cookies.get('mchat_no_sound')).change(function() {
mChat.cached('user-sound').prop('checked', mChat.playSound && !localStorage.getItem(mChat.cookie + 'mchat_no_sound')).change(function() {
if (this.checked) {
Cookies.remove('mchat_no_sound');
localStorage.removeItem(mChat.cookie + 'mchat_no_sound');
} else {
Cookies.set('mchat_no_sound', 'yes');
localStorage.setItem(mChat.cookie + 'mchat_no_sound', 'yes');
}
});
}).change();
$.each(mChat.removeBBCodes.split('|'), function(i, bbcode) {
$('#format-buttons .bbcode-' + bbcode).remove();
var bbCodeClass = '.bbcode-' + bbcode.replaceMany({
'=': '-',
'*': 'asterisk'
});
$('#format-buttons').find(bbCodeClass).remove();
});
var $colourPalette = $('#colour_palette');
$colourPalette.appendTo($colourPalette.parent()).wrap('<div id="mchat-colour"></div>').show();
$('#bbpalette,#abbc3_bbpalette').prop('onclick', null).attr('data-mchat-toggle', 'colour');
$('#bbpalette,#abbc3_bbpalette,#color_wheel').prop('onclick', null).attr('data-mchat-toggle', 'colour');
$.each(['userlist', 'smilies', 'bbcodes', 'colour'], function(i, elem) {
if (Cookies.get('mchat_show_' + elem)) {
if (localStorage.getItem(mChat.cookie + 'mchat_show_' + elem)) {
mChat.cached(elem).toggle();
}
});
if (mChat.cached('input').is('input')) {
mChat.cached('form').keypress(function(e) {
if (e.which == 13) {
mChat.add();
e.preventDefault();
e.stopImmediatePropagation();
}
});
}
mChat.isTextarea = mChat.cached('input').is('textarea');
mChat.cached('form').submit(function(e){
e.preventDefault();
}).keypress(function(e) {
if ((e.which == 10 || e.which == 13) && (!mChat.isTextarea || e.ctrlKey || e.metaKey) && mChat.cached('input').is(e.target)) {
mChat.add();
}
});
if (mChat.pause) {
mChat.cached('form').keyup(function(e) {
mChat.cached('form').on('input', function() {
if (mChat.refreshInterval !== false) {
var val = mChat.cached('input').val();
if (mChat.isPaused && val === '') {
@@ -519,21 +660,12 @@ jQuery(function($) {
}
if (mChat.showCharCount) {
mChat.cached('form').keyup(function(e) {
var count = mChat.inputMessageLength();
var $elem = mChat.cached('character-count');
$elem.html(mChat.charCount.format({current: count, max: mChat.mssgLngth})).css('visibility', count > 0 ? 'visible' : 'hidden');
if (mChat.mssgLngth) {
$elem.toggleClass('error', count > mChat.mssgLngth);
}
});
mChat.cached('form').on('input', mChat.updateCharCount);
}
mChat.cached('form').one('keypress', function() {
mChat.cached('input').autoGrowInput({
minWidth: mChat.cached('input').width(),
maxWidth: mChat.cached('form').width() - (mChat.cached('input').outerWidth(true) - mChat.cached('input').width())
});
mChat.cached('input').autogrow({
vertical: false,
horizontal: true
});
}
@@ -543,13 +675,34 @@ jQuery(function($) {
mChat.pageIsUnloading = true;
});
mChat.cached('colour').find('.colour-palette').on('click', 'a', function(e) {
if (e.ctrlKey || e.metaKey) {
e.preventDefault();
e.stopImmediatePropagation();
var $this = $(this);
var newColor = $this.data('color');
if (localStorage.getItem(mChat.cookie + 'mchat_color') === newColor) {
localStorage.removeItem(mChat.cookie + 'mchat_color');
} else {
localStorage.setItem(mChat.cookie + 'mchat_color', newColor);
mChat.cached('colour').find('.colour-palette a').removeClass('remember-color');
}
$this.toggleClass('remember-color');
}
});
var color = localStorage.getItem(mChat.cookie + 'mchat_color');
if (color) {
mChat.cached('colour').find('.colour-palette a[data-color="' + color + '"]').addClass('remember-color');
}
$('#phpbb').on('click', '[data-mchat-action]', function(e) {
e.preventDefault();
var action = $(this).data('mchat-action');
mChat[action].call(this);
e.preventDefault();
}).on('click', '[data-mchat-toggle]', function(e) {
e.preventDefault();
var elem = $(this).data('mchat-toggle');
mChat.toggle(elem);
e.preventDefault();
});
});