Version 2.1.1
This commit is contained in:
@@ -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')) {
|
||||
|
||||
Reference in New Issue
Block a user