Version 2.1.1

This commit is contained in:
dmzx
2018-10-05 11:24:44 +02:00
parent 006a4e404e
commit 698db04f9e
17 changed files with 305 additions and 120 deletions

View File

@@ -106,9 +106,10 @@ jQuery(function($) {
return;
}
var deferred = $.Deferred();
if (sendHiddenFields) {
$.extend(data, mChat.hiddenFields);
}
$.extend(data,
{_referer: mChat.currentUrl},
sendHiddenFields ? mChat.hiddenFields : {}
);
$(mChat).trigger('mchat_send_request_before', [mode, data]);
$.ajax({
url: mChat.actionUrls[mode],
@@ -427,6 +428,7 @@ jQuery(function($) {
playSound = false;
}
mChat.messageIds.push($message.data('mchat-id'));
mChat.fixJumpToUrl.call($message);
setTimeout(function() {
var dataAddMessageAnimateBefore = {
container: mChat.cached('messages'),
@@ -453,7 +455,7 @@ jQuery(function($) {
} else {
animateOptions.complete = function() {
var scrollHeight = container.get(0).scrollHeight;
if (container.scrollTop() + container.height() < scrollHeight) {
if (container.scrollTop() + container.innerHeight() < scrollHeight) {
container.animate({scrollTop: scrollHeight}, animateOptions);
}
};
@@ -480,7 +482,7 @@ jQuery(function($) {
});
}, mChat.editDeleteLimit);
}
mChat.startRelativeTimeUpdate($message);
mChat.startRelativeTimeUpdate.call($message);
});
},
updateMessages: function($messages) {
@@ -494,7 +496,8 @@ jQuery(function($) {
};
$(mChat).trigger('mchat_edit_message_before', [data]);
mChat.stopRelativeTimeUpdate(data.oldMessage);
mChat.startRelativeTimeUpdate(data.newMessage);
mChat.startRelativeTimeUpdate.call(data.newMessage);
mChat.fixJumpToUrl.call(data.newMessage);
data.oldMessage.fadeOut(function() {
data.oldMessage.replaceWith(data.newMessage.hide().fadeIn());
});
@@ -527,9 +530,9 @@ jQuery(function($) {
}
});
},
startRelativeTimeUpdate: function($messages) {
startRelativeTimeUpdate: function() {
if (mChat.relativeTime) {
$messages.find('.mchat-time[data-mchat-relative-update]').each(function() {
$(this).find('.mchat-time[data-mchat-relative-update]').each(function() {
var $time = $(this);
setTimeout(function() {
mChat.relativeTimeUpdate($time);
@@ -634,27 +637,67 @@ jQuery(function($) {
}
mChat.appendText(mChat.lang.mention.format({username: username}));
},
quote: function() {
var $container = $(this).closest('.mchat-message');
var username = $container.data('mchat-username');
fixJumpToUrl: function() {
var $message = $(this);
var $elem = $message.find('blockquote [data-post-id]');
var messageId = $elem.data('post-id');
var data = {
message: $message,
elem: $elem,
url: mChat.getArchiveQuoteUrl(messageId)
};
$(mChat).trigger('mchat_fix_jump_to_url_before', [data]);
if (data.url) {
data.elem.attr('href', data.url);
}
},
getArchiveQuoteUrl: function(messageId) {
var archiveUrl = $('.mchat-nav-archive').find('a').prop('href');
return archiveUrl ? mChat.addUrlParam(archiveUrl, 'jumpto=' + messageId) : false;
},
jumpToMessage: function() {
var messageId = $(this).data('post-id');
var data = {
container: mChat.cached('messages'),
messageId: messageId,
message: $('#mchat-message-' + messageId),
jump: function() {
if (data.message.length) {
var scrollTop = data.message.offset().top - data.container.offset().top + data.container.scrollTop();
data.container.scrollTop(scrollTop);
data.message.removeClass('mchat-message-flash');
data.message.offset();
data.message.addClass('mchat-message-flash');
} else {
var url = mChat.getArchiveQuoteUrl(data.messageId);
if (url) {
window.open(url, '_blank');
}
}
}
};
$(mChat).trigger('mchat_jump_to_message_before', [data]);
data.jump();
},
getQuoteText: function($container) {
var quote = $container.data('mchat-message');
mChat.appendText('[quote="' + username + '"] ' + quote + '[/quote]');
var quoteAttributes = [
'"' + $container.data('mchat-username') + '"',
'post_id=' + $container.data('mchat-id'),
'time=' + $container.data('mchat-message-time'),
'user_id=' + $container.data('mchat-user-id')
];
return '[quote=' + quoteAttributes.join(' ') + '] ' + quote + ' [/quote]';
},
quote: function() {
mChat.appendText(mChat.getQuoteText($(this).closest('.mchat-message')));
},
like: function() {
var $container = $(this).closest('.mchat-message');
var username = $container.data('mchat-username');
var quote = $container.data('mchat-message');
mChat.appendText('[i]' + mChat.lang.likes + '[/i][quote="' + username + '"] ' + quote + '[/quote]');
mChat.appendText('[i]' + mChat.lang.likes + '[/i]' + mChat.getQuoteText($(this).closest('.mchat-message')));
},
ip: function() {
popup(this.href, 750, 500);
},
custom: function() {
window.location.href = this.href;
},
archive: function() {
window.location.href = this.href;
},
setText: function(text) {
mChat.cached('input').val('');
mChat.appendText(text);
@@ -670,6 +713,9 @@ jQuery(function($) {
$input.scrollLeft($input[0].scrollWidth - $input[0].clientWidth);
}
},
addUrlParam: function(url, keyEqualsValue) {
return url + (url.indexOf('?') === -1 ? '?' : '&') + keyEqualsValue;
},
cached: function(name) {
if (!mChat.cache) {
mChat.cache = {};
@@ -681,16 +727,24 @@ jQuery(function($) {
}
});
mChat.messageIds = mChat.cached('messages').children().map(function() {
return $(this).data('mchat-id');
}).get();
mChat.messageIds = mChat.cached('messages').children()
.each(mChat.startRelativeTimeUpdate)
.each(mChat.fixJumpToUrl)
.map(function() { return $(this).data('mchat-id'); }).get();
mChat.hiddenFields = {};
mChat.cached('form').find('input[type=hidden]').each(function() {
mChat.hiddenFields[this.name] = this.value;
});
if (mChat.page !== 'archive') {
if (mChat.page === 'archive') {
if (mChat.jumpTo) {
var fragment = '#mchat-message-' + mChat.jumpTo;
if ($(fragment).addClass('mchat-message-flash').length) {
window.location.hash = fragment;
}
}
} else {
mChat.resetSession();
if (!mChat.messageTop) {
@@ -768,8 +822,6 @@ jQuery(function($) {
}
}
mChat.startRelativeTimeUpdate(mChat.cached('messages'));
mChat.registerNavItem('sound', mChat.playSound);
if (mChat.maxInputHeight) {
mChat.registerNavItem('enter', true);
@@ -783,6 +835,9 @@ jQuery(function($) {
e.preventDefault();
var action = $(this).data('mchat-action');
mChat[action].call(this, e);
}).on('click', '#mchat-messages blockquote [data-post-id]', function(e) {
e.preventDefault();
mChat.jumpToMessage.call(this);
}).on('click', '.mchat-panel-buttons button', function() {
var $this = $(this).blur();
if ($this.hasClass('mchat-button-down')) {

View File

@@ -14,10 +14,11 @@
// General settings
actionUrls : {
{% for mchaturl in loops.mchaturl %}
{{ mchaturl.ACTION }}: '{{ mchaturl.URL }}'{{ loop.last ? '' : ',' }}
{{ mchaturl.ACTION }}: '{{ mchaturl.URL }}'{{ not loop.last ? ',' }}
{% endfor %}
},
page : '{{ MCHAT_PAGE | escape('js') }}',
currentUrl : '{{ MCHAT_CURRENT_URL | escape('js') }}',
cookie : '{{ COOKIE_NAME | escape('js') }}',
playSound : {{ MCHAT_SOUND ? 'true' : 'false' }},
messageTop : {{ MCHAT_MESSAGE_TOP ? 'true' : 'false' }},
@@ -25,6 +26,7 @@
liveUpdates : {{ MCHAT_LIVE_UPDATES ? 'true' : 'false' }},
relativeTime : {{ MCHAT_RELATIVE_TIME ? 'true' : 'false' }},
showCharCount : {{ MCHAT_CHARACTER_COUNT ? 'true' : 'false' }},
jumpTo : {{ MCHAT_JUMP_TO }},
// Limits & timeouts
refreshTime : {{ MCHAT_REFRESH_JS }},
@@ -41,7 +43,7 @@
minutesAgo : {
{% if MCHAT_RELATIVE_TIME %}
{% for minute in 0..MCHAT_MINUTES_AGO_LIMIT-1 %}
{{ minute }}: '{{ lang('MCHAT_MINUTES_AGO', minute) | escape('js') }}'{{ loop.last ? '' : ',' }}
{{ minute }}: '{{ lang('MCHAT_MINUTES_AGO', minute) | escape('js') }}'{{ not loop.last ? ',' }}
{% endfor %}
{% endif %}
},

View File

@@ -107,7 +107,7 @@
{% EVENT dmzx_mchat_after %}
{% if MCHAT_PAGE == 'archive' %}
{% if MCHAT_PAGE == 'archive' and (loops.pagination|length or MCHAT_TOTAL_MESSAGES) %}
<div class="action-bar bottom">
{% EVENT dmzx_mchat_action_bar_bottom_before %}
<div class="pagination">

View File

@@ -1,7 +1,7 @@
{%- EVENT dmzx_mchat_messages_before -%}
{%- for mchatrow in loops.mchatrow -%}
<li id="mchat-message-{{ mchatrow.MCHAT_MESSAGE_ID }}" class="row mchat-message{% if mchatrow.MCHAT_IS_NOTIFICATION %} mchat-notification-message{% endif %}" data-mchat-id="{{ mchatrow.MCHAT_MESSAGE_ID }}" data-mchat-username="{{ mchatrow.MCHAT_USERNAME }}"{% if mchatrow.MCHAT_USERNAME_COLOR %} data-mchat-usercolor="{{ mchatrow.MCHAT_USERNAME_COLOR }}"{% endif %} data-mchat-message="{{ mchatrow.MCHAT_MESSAGE_EDIT }}" data-mchat-message-time="{{ mchatrow.MCHAT_MESSAGE_TIME }}"{% if MCHAT_EDIT_DELETE_LIMIT and not MCHAT_EDIT_DELETE_IGNORE and (mchatrow.MCHAT_ALLOW_EDIT or mchatrow.MCHAT_ALLOW_DEL) %} data-mchat-edit-delete-limit="1"{% endif %} {% EVENT dmzx_mchat_message_attributes %}>
<li id="mchat-message-{{ mchatrow.MCHAT_MESSAGE_ID }}" class="row mchat-message{% if mchatrow.MCHAT_IS_NOTIFICATION %} mchat-notification-message{% endif %}" data-mchat-id="{{ mchatrow.MCHAT_MESSAGE_ID }}" data-mchat-user-id="{{ mchatrow.MCHAT_USER_ID }}" data-mchat-username="{{ mchatrow.MCHAT_USERNAME }}"{% if mchatrow.MCHAT_USERNAME_COLOR %} data-mchat-usercolor="{{ mchatrow.MCHAT_USERNAME_COLOR }}"{% endif %} data-mchat-message="{{ mchatrow.MCHAT_MESSAGE_EDIT }}" data-mchat-message-time="{{ mchatrow.MCHAT_MESSAGE_TIME }}"{% if MCHAT_EDIT_DELETE_LIMIT and not MCHAT_EDIT_DELETE_IGNORE and (mchatrow.MCHAT_ALLOW_EDIT or mchatrow.MCHAT_ALLOW_DEL) %} data-mchat-edit-delete-limit="1"{% endif %} {% EVENT dmzx_mchat_message_attributes %}>
{% if S_MCHAT_AVATARS %}
<div class="mchat-avatar">
{% if mchatrow.U_VIEWPROFILE %}<a href="{{ mchatrow.U_VIEWPROFILE }}" title="{{ lang('READ_PROFILE') }}">{% endif %}

View File

@@ -14,7 +14,7 @@
{% EVENT dmzx_mchat_nav_items_before %}
{% if U_MCHAT_CUSTOM_PAGE %}
<li class="mchat-nav-custom-page">
<a href="{{ U_MCHAT_CUSTOM_PAGE }}" title="{{ lang('MCHAT_NAVBAR_CUSTOM_PAGE') }}" role="menuitem" data-mchat-action="custom">
<a href="{{ U_MCHAT_CUSTOM_PAGE }}" title="{{ lang('MCHAT_NAVBAR_CUSTOM_PAGE') }}" role="menuitem">
<i class="icon fa fa-weixin fa-fw" aria-hidden="true"></i><span>{{ lang('MCHAT_NAVBAR_CUSTOM_PAGE') }}</span>
</a>
</li>
@@ -22,7 +22,7 @@
{% EVENT dmzx_mchat_nav_items_custom_page_after %}
{% if U_MCHAT_ARCHIVE %}
<li class="mchat-nav-archive">
<a href="{{ U_MCHAT_ARCHIVE }}" title="{{ lang('MCHAT_NAVBAR_ARCHIVE') }}" role="menuitem" data-mchat-action="archive">
<a href="{{ U_MCHAT_ARCHIVE }}" title="{{ lang('MCHAT_NAVBAR_ARCHIVE') }}" role="menuitem">
<i class="icon fa fa-history fa-fw" aria-hidden="true"></i><span>{{ lang('MCHAT_NAVBAR_ARCHIVE') }}</span>
</a>
</li>

View File

@@ -97,15 +97,6 @@
</dd>
</dl>
{% endif %}
{% if MCHAT_INPUT_AREA_AUTH and MCHAT_ALLOW_USE %}
<dl>
<dt><label for="user_mchat_input_area">{{ lang('MCHAT_CHAT_AREA') ~ lang('COLON') }}</label></dt>
<dd>
<label><input type="radio" name="user_mchat_input_area" value="1"{% if MCHAT_INPUT_AREA %} id="user_mchat_input_area" checked="checked"{% endif %}> {{ lang('MCHAT_INPUT_AREA') }}</label>
<label><input type="radio" name="user_mchat_input_area" value="0"{% if not MCHAT_INPUT_AREA %} id="user_mchat_input_area" checked="checked"{% endif %}> {{ lang('MCHAT_TEXT_AREA') }}</label>
</dd>
</dl>
{% endif %}
{% if MCHAT_CHARACTER_COUNT_AUTH and MCHAT_ALLOW_USE %}
<dl>
<dt><label for="user_mchat_character_count">{{ lang('MCHAT_DISPLAY_CHARACTER_COUNT') ~ lang('COLON') }}</label></dt>

View File

@@ -77,16 +77,18 @@
animation-timing-function: ease-out;
}
.mchat-message-flash:target {
animation-duration: 2s;
}
@keyframes flash-message {
0% {
background-color: #FFD070;
opacity: 0;
background-color: #FFDC95;
}
100% {
background-color: transparent;
opacity: 1;
}
}
@@ -143,6 +145,10 @@
font-size: 1.2em;
}
.mchat-text .postlink {
display: unset;
}
.mchat-notification-message .mchat-text {
font-style: italic;
}