Version 2.0.2
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
// Support Opera
|
||||
if (typeof document.hasFocus === 'undefined') {
|
||||
document.hasFocus = function() {
|
||||
return document.visibilityState == 'visible';
|
||||
return document.visibilityState === 'visible';
|
||||
};
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ if (!Array.prototype.min) {
|
||||
}
|
||||
|
||||
Array.prototype.removeValue = function(value) {
|
||||
var index = -1;
|
||||
var index;
|
||||
var elementsRemoved = 0;
|
||||
while ((index = this.indexOf(value)) !== -1) {
|
||||
this.splice(index, 1);
|
||||
@@ -44,7 +44,7 @@ String.prototype.format = function() {
|
||||
return str;
|
||||
}
|
||||
var type = typeof arguments[0];
|
||||
var args = 'string' == type || 'number' == type ? arguments : 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]);
|
||||
@@ -69,7 +69,7 @@ RegExp.escape = function(s) {
|
||||
};
|
||||
|
||||
jQuery.fn.reverse = function(reverse) {
|
||||
return reverse === 'undefined' || reverse ? jQuery(this.toArray().reverse()) : this;
|
||||
return typeof reverse === 'undefined' || reverse ? jQuery(this.toArray().reverse()) : this;
|
||||
};
|
||||
|
||||
function StorageWrapper(storage, prefix) {
|
||||
@@ -102,6 +102,9 @@ jQuery(function($) {
|
||||
$.extend(mChat, {
|
||||
storage: new StorageWrapper('localStorage', mChat.cookie + 'mchat_'),
|
||||
ajaxRequest: function(mode, sendHiddenFields, data) {
|
||||
if (mChat.pageIsUnloading) {
|
||||
return;
|
||||
}
|
||||
var deferred = $.Deferred();
|
||||
if (sendHiddenFields) {
|
||||
$.extend(data, mChat.hiddenFields);
|
||||
@@ -113,7 +116,7 @@ jQuery(function($) {
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: data,
|
||||
additionalData: {
|
||||
context: {
|
||||
mode: mode,
|
||||
deferred: deferred
|
||||
}
|
||||
@@ -122,7 +125,7 @@ jQuery(function($) {
|
||||
},
|
||||
ajaxDone: function(json, status, xhr) {
|
||||
var data = {
|
||||
mode: this.additionalData.mode,
|
||||
mode: this.mode,
|
||||
json: json,
|
||||
status: status,
|
||||
xhr: xhr,
|
||||
@@ -130,10 +133,10 @@ jQuery(function($) {
|
||||
};
|
||||
$(mChat).trigger('mchat_ajax_done_before', [data]);
|
||||
if (data.handle) {
|
||||
if (json[this.additionalData.mode]) {
|
||||
this.additionalData.deferred.resolve(data.json, data.status, data.xhr);
|
||||
if (json[this.mode]) {
|
||||
this.deferred.resolve(data.json, data.status, data.xhr);
|
||||
} else {
|
||||
this.additionalData.deferred.reject(data.xhr, data.status, mChat.lang.parserErr);
|
||||
this.deferred.reject(data.xhr, data.status, mChat.lang.parserErr);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -145,14 +148,14 @@ jQuery(function($) {
|
||||
console.log('AJAX error. status: ' + textStatus + ', message: ' + errorThrown + ' (' + xhr.responseText + ')');
|
||||
}
|
||||
var data = {
|
||||
mode: this.additionalData.mode,
|
||||
mode: this.mode,
|
||||
xhr: xhr,
|
||||
textStatus: textStatus,
|
||||
errorThrown: errorThrown,
|
||||
updateSession: function() {
|
||||
if (this.xhr.status == 403) {
|
||||
if (this.xhr.status === 403) {
|
||||
mChat.endSession(true);
|
||||
} else if (this.xhr.status == 400) {
|
||||
} else if (this.xhr.status === 400) {
|
||||
mChat.resetSession();
|
||||
}
|
||||
}
|
||||
@@ -219,8 +222,8 @@ jQuery(function($) {
|
||||
$input.focus().val('').val(value);
|
||||
}
|
||||
}, 1);
|
||||
phpbb.confirm(data.container.show(), function() {
|
||||
if (typeof data.confirm === 'function') {
|
||||
phpbb.confirm(data.container.show(), function(success) {
|
||||
if (success && typeof data.confirm === 'function') {
|
||||
data.confirm.apply(this, fields);
|
||||
}
|
||||
});
|
||||
@@ -272,7 +275,7 @@ jQuery(function($) {
|
||||
mChat.ajaxRequest('edit', true, {
|
||||
message_id: $message.data('mchat-id'),
|
||||
message: $textarea.val(),
|
||||
archive: mChat.archivePage ? 1 : 0
|
||||
page: mChat.page
|
||||
}).done(function(json) {
|
||||
mChat.updateMessages($(json.edit));
|
||||
mChat.resetSession();
|
||||
@@ -289,7 +292,7 @@ jQuery(function($) {
|
||||
$container.find('p').text(mChat.lang.delConfirm)
|
||||
];
|
||||
},
|
||||
confirm: function($p) {
|
||||
confirm: function() {
|
||||
mChat.ajaxRequest('del', true, {
|
||||
message_id: delId
|
||||
}).done(function() {
|
||||
@@ -339,14 +342,14 @@ jQuery(function($) {
|
||||
});
|
||||
},
|
||||
whois: function() {
|
||||
if (mChat.customPage) {
|
||||
if (mChat.page === 'custom') {
|
||||
mChat.cached('refresh-pending').show();
|
||||
mChat.cached('refresh-explain').hide();
|
||||
}
|
||||
mChat.ajaxRequest('whois', false, {}).done(mChat.handleWhoisResponse);
|
||||
},
|
||||
handleWhoisResponse: function(json) {
|
||||
var $whois = $(json.whois);
|
||||
var $whois = $(json.container);
|
||||
var $userlist = $whois.find('#mchat-userlist');
|
||||
if (mChat.storage.get('show_userlist')) {
|
||||
$userlist.show();
|
||||
@@ -354,7 +357,7 @@ jQuery(function($) {
|
||||
mChat.cached('whois').replaceWith($whois);
|
||||
mChat.cache.whois = $whois;
|
||||
mChat.cache.userlist = $userlist;
|
||||
if (mChat.customPage) {
|
||||
if (mChat.page === 'custom') {
|
||||
mChat.cached('refresh-pending').hide();
|
||||
mChat.cached('refresh-explain').show();
|
||||
}
|
||||
@@ -533,7 +536,7 @@ jQuery(function($) {
|
||||
}
|
||||
},
|
||||
resetSession: function() {
|
||||
if (!mChat.archivePage) {
|
||||
if (mChat.page !== 'archive') {
|
||||
clearInterval(mChat.refreshInterval);
|
||||
mChat.refreshInterval = setInterval(mChat.refresh, mChat.refreshTime);
|
||||
if (mChat.timeout) {
|
||||
@@ -592,12 +595,14 @@ jQuery(function($) {
|
||||
var $container = $(this).closest('.mchat-message');
|
||||
var username = $container.data('mchat-username');
|
||||
if (mChat.allowBBCodes) {
|
||||
var usercolor = $container.data('mchat-usercolor');
|
||||
var profileUrl = $container.find(".mchat-message-header a[class^='username']").prop('href');
|
||||
if (usercolor) {
|
||||
username = '[url=' + profileUrl + '][b][color=' + usercolor + ']' + username + '[/color][/b][/url]';
|
||||
} else {
|
||||
username = '[url=' + profileUrl + '][b]' + username + '[/b][/url]';
|
||||
if (profileUrl) {
|
||||
var usercolor = $container.data('mchat-usercolor');
|
||||
if (usercolor) {
|
||||
username = '[url=' + profileUrl + '][b][color=' + usercolor + ']' + username + '[/color][/b][/url]';
|
||||
} else {
|
||||
username = '[url=' + profileUrl + '][b]' + username + '[/b][/url]';
|
||||
}
|
||||
}
|
||||
}
|
||||
insert_text(mChat.lang.mention.format({username: username}));
|
||||
@@ -643,7 +648,7 @@ jQuery(function($) {
|
||||
|
||||
mChat.isPaused = false;
|
||||
|
||||
if (!mChat.archivePage) {
|
||||
if (mChat.page !== 'archive') {
|
||||
mChat.resetSession();
|
||||
|
||||
if (!mChat.messageTop) {
|
||||
@@ -665,7 +670,7 @@ jQuery(function($) {
|
||||
'=': '-',
|
||||
'*': 'asterisk'
|
||||
});
|
||||
$('#format-buttons').find(bbCodeClass).remove();
|
||||
mChat.cached('body').find(bbCodeClass).remove();
|
||||
});
|
||||
|
||||
var $colourPalette = $('#colour_palette');
|
||||
@@ -682,7 +687,7 @@ jQuery(function($) {
|
||||
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)) {
|
||||
if ((e.which === 10 || e.which === 13) && (!mChat.isTextarea || e.ctrlKey || e.metaKey) && mChat.cached('input').is(e.target)) {
|
||||
mChat.add();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<!-- IF MCHAT_IS_ARCHIVE_PAGE or not (MCHAT_ALLOW_USE and S_BBCODE_ALLOWED) -->
|
||||
<!-- INCLUDEJS {T_ASSETS_PATH}/javascript/editor.js -->
|
||||
<!-- ENDIF -->
|
||||
{% if MCHAT_PAGE == 'archive' or not (MCHAT_ALLOW_USE and S_BBCODE_ALLOWED) %}
|
||||
{% INCLUDEJS T_ASSETS_PATH ~ '/javascript/editor.js' %}
|
||||
{% endif %}
|
||||
|
||||
<!-- INCLUDEJS @dmzx_mchat/javascript/jquery.autogrow-textarea.js -->
|
||||
<!-- INCLUDEJS @dmzx_mchat/javascript/jquery.titlealert.min.js -->
|
||||
<!-- INCLUDEJS @dmzx_mchat/javascript/mchat.js -->
|
||||
{% INCLUDEJS '@dmzx_mchat/javascript/jquery.autogrow-textarea.js' %}
|
||||
{% INCLUDEJS '@dmzx_mchat/javascript/jquery.titlealert.min.js' %}
|
||||
{% INCLUDEJS '@dmzx_mchat/javascript/mchat.js' %}
|
||||
|
||||
<script type="text/javascript">
|
||||
// <![CDATA[
|
||||
@@ -13,52 +13,50 @@
|
||||
var mChat = {
|
||||
// General settings
|
||||
actionUrls : {
|
||||
<!-- BEGIN mchaturl -->
|
||||
{mchaturl.ACTION}: '{mchaturl.URL}'<!-- IF not mchaturl.IS_LAST -->,<!-- ENDIF -->
|
||||
<!-- END mchaturl -->
|
||||
{% for mchaturl in loops.mchaturl %}
|
||||
{{ mchaturl.ACTION }}: '{{ mchaturl.URL }}'{{ loop.last ? '' : ',' }}
|
||||
{% endfor %}
|
||||
},
|
||||
page : '{MCHAT_PAGE}',
|
||||
cookie : '{A_COOKIE_NAME}',
|
||||
customPage : <!-- IF MCHAT_IS_CUSTOM_PAGE -->true<!-- ELSE -->false<!-- ENDIF -->,
|
||||
archivePage : <!-- IF MCHAT_IS_ARCHIVE_PAGE -->true<!-- ELSE -->false<!-- ENDIF -->,
|
||||
pause : <!-- IF MCHAT_PAUSE_ON_INPUT -->true<!-- ELSE -->false<!-- ENDIF -->,
|
||||
playSound : <!-- IF MCHAT_SOUND -->true<!-- ELSE -->false<!-- ENDIF -->,
|
||||
messageTop : <!-- IF MCHAT_MESSAGE_TOP -->true<!-- ELSE -->false<!-- ENDIF -->,
|
||||
allowBBCodes : <!-- IF S_BBCODE_ALLOWED -->true<!-- ELSE -->false<!-- ENDIF -->,
|
||||
liveUpdates : <!-- IF MCHAT_LIVE_UPDATES -->true<!-- ELSE -->false<!-- ENDIF -->,
|
||||
relativeTime : <!-- IF MCHAT_RELATIVE_TIME -->true<!-- ELSE -->false<!-- ENDIF -->,
|
||||
showCharCount : <!-- IF MCHAT_CHARACTER_COUNT -->true<!-- ELSE -->false<!-- ENDIF -->,
|
||||
page : '{{ MCHAT_PAGE | escape('js') }}',
|
||||
cookie : '{{ COOKIE_NAME | escape('js') }}',
|
||||
pause : {{ MCHAT_PAUSE_ON_INPUT ? 'true' : 'false' }},
|
||||
playSound : {{ MCHAT_SOUND ? 'true' : 'false' }},
|
||||
messageTop : {{ MCHAT_MESSAGE_TOP ? 'true' : 'false' }},
|
||||
allowBBCodes : {{ S_BBCODE_ALLOWED ? 'true' : 'false' }},
|
||||
liveUpdates : {{ MCHAT_LIVE_UPDATES ? 'true' : 'false' }},
|
||||
relativeTime : {{ MCHAT_RELATIVE_TIME ? 'true' : 'false' }},
|
||||
showCharCount : {{ MCHAT_CHARACTER_COUNT ? 'true' : 'false' }},
|
||||
|
||||
// Limits & timeouts
|
||||
refreshTime : {MCHAT_REFRESH_JS},
|
||||
whoisRefresh : {MCHAT_WHOIS_REFRESH},
|
||||
timeout : {MCHAT_TIMEOUT},
|
||||
mssgLngth : {MCHAT_MESSAGE_LNGTH},
|
||||
editDeleteLimit : {MCHAT_EDIT_DELETE_LIMIT},
|
||||
logId : {MCHAT_LOG_ID},
|
||||
removeBBCodes : '{A_MCHAT_DISALLOWED_BBCODES}',
|
||||
refreshTime : {{ MCHAT_REFRESH_JS }},
|
||||
whoisRefresh : {{ MCHAT_WHOIS_REFRESH }},
|
||||
timeout : {{ MCHAT_TIMEOUT }},
|
||||
mssgLngth : {{ MCHAT_MESSAGE_LNGTH }},
|
||||
editDeleteLimit : {{ MCHAT_EDIT_DELETE_LIMIT }},
|
||||
logId : {{ MCHAT_LOG_ID }},
|
||||
removeBBCodes : '{{ MCHAT_DISALLOWED_BBCODES | escape('js') }}',
|
||||
|
||||
// Language
|
||||
lang: {
|
||||
minutesAgo : {
|
||||
<!-- BEGIN mchattime -->
|
||||
{mchattime.KEY}: '{mchattime.A_LANG}'<!-- IF not mchattime.IS_LAST -->,<!-- ENDIF -->
|
||||
<!-- END mchattime -->
|
||||
{% for minute in 0..MCHAT_MINUTES_AGO_LIMIT-1 %}
|
||||
{{ minute }}: '{{ lang('MCHAT_MINUTES_AGO', minute) | escape('js') }}'{{ loop.last ? '' : ',' }}
|
||||
{% endfor %}
|
||||
},
|
||||
err : '{LA_ERROR}',
|
||||
parserErr : '{LA_AJAX_ERROR_TEXT_PARSERERROR}',
|
||||
newMessageAlert : '{LA_MCHAT_NEW_CHAT}',
|
||||
noMessageInput : '{LA_MCHAT_NOMESSAGEINPUT}',
|
||||
editInfo : '{LA_MCHAT_EDITINFO}',
|
||||
delConfirm : '{LA_MCHAT_DELCONFIRM}',
|
||||
sessOut : '{LA_MCHAT_SESSION_OUT}',
|
||||
sessEnds : '{LA_MCHAT_SESSION_ENDS_JS}',
|
||||
mention : '{LA_MCHAT_MENTION}',
|
||||
refreshYes : '{A_MCHAT_REFRESH_YES}',
|
||||
refreshNo : '{LA_MCHAT_REFRESH_NO}',
|
||||
charCount : '<!-- IF MCHAT_MESSAGE_LNGTH -->{LA_MCHAT_CHARACTER_COUNT_LIMIT}<!-- ELSE -->{LA_MCHAT_CHARACTER_COUNT}<!-- ENDIF -->',
|
||||
mssgLngthLong : '{A_MCHAT_MESS_LONG}',
|
||||
likes : '{LA_MCHAT_LIKES}'
|
||||
err : '{{ lang('ERROR') | escape('js') }}',
|
||||
parserErr : '{{ lang('AJAX_ERROR_TEXT_PARSERERROR') | escape('js') }}',
|
||||
newMessageAlert : '{{ lang('MCHAT_NEW_CHAT') | escape('js') }}',
|
||||
noMessageInput : '{{ lang('MCHAT_NOMESSAGEINPUT') | escape('js') }}',
|
||||
editInfo : '{{ lang('MCHAT_EDITINFO') | escape('js') }}',
|
||||
delConfirm : '{{ lang('MCHAT_DELCONFIRM') | escape('js') }}',
|
||||
sessOut : '{{ lang('MCHAT_SESSION_OUT') | escape('js') }}',
|
||||
sessEnds : '{{ lang('MCHAT_SESSION_ENDS_JS') | escape('js') }}',
|
||||
mention : '{{ lang('MCHAT_MENTION') | escape('js') }}',
|
||||
refreshYes : '{{ lang('MCHAT_REFRESH_YES', MCHAT_REFRESH_RATE) | escape('js') }}',
|
||||
refreshNo : '{{ lang('MCHAT_REFRESH_NO') | escape('js') }}',
|
||||
charCount : '{{ lang(MCHAT_MESSAGE_LNGTH ? 'MCHAT_CHARACTER_COUNT_LIMIT' : 'MCHAT_CHARACTER_COUNT') | escape('js') }}',
|
||||
mssgLngthLong : '{{ lang('MCHAT_MESS_LONG', MCHAT_MAX_MESSAGE_LENGTH) | escape('js') }}',
|
||||
likes : '{{ lang('MCHAT_LIKES') | escape('js') }}'
|
||||
}
|
||||
};
|
||||
// ]]>
|
||||
|
||||
Reference in New Issue
Block a user