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

@@ -1,47 +0,0 @@
/*
jQuery autoGrowInput v1.0.3
Copyright (c) 2014 Simon Steinberger / Pixabay
Based on stackoverflow.com/questions/931207 (James Padolsey)
GitHub: https://github.com/Pixabay/jQuery-autoGrowInput
License: http://www.opensource.org/licenses/mit-license.php
*/
(function($){
var event = 'oninput' in document.createElement('input') ? 'input' : 'keydown';
$.fn.autoGrowInput = function(options){
var o = $.extend({ maxWidth: 500, minWidth: 20, comfortZone: 0 }, options);
this.each(function(){
var input = $(this),
val = ' ',
comfortZone = (options && 'comfortZone' in options) ? o.comfortZone : parseInt(input.css('fontSize')),
span = $('<span/>').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'),
textTransform: input.css('textTransform'),
whiteSpace: 'nowrap',
ariaHidden: true
}).appendTo('body'),
check = function(e){
if (val === (val = input.val()) && e.type !== 'autogrow') return;
if (!val) val = input.attr('placeholder') || '';
span.html(val.replace(/&/g, '&amp;').replace(/\s/g, '&nbsp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'));
var newWidth = span.width() + comfortZone, mw = typeof(o.maxWidth) == "function" ? o.maxWidth() : o.maxWidth;
if (newWidth > mw) newWidth = mw;
else if (newWidth < o.minWidth) newWidth = o.minWidth;
if (newWidth != input.width()) input.width(newWidth);
};
input.on(event+'.autogrow autogrow', check);
// init on page load
check();
});
return this;
}
}(jQuery));

View File

@@ -0,0 +1,211 @@
// Based off https://code.google.com/p/gaequery/source/browse/trunk/src/static/scripts/jquery.autogrow-textarea.js?r=2
// Modified by David Beck
// Mofified by kasimi (c) 2016
( function( factory ) {
// UMD wrapper
if ( typeof define === 'function' && define.amd ) {
// AMD
define( [ 'jquery' ], factory );
} else if ( typeof exports !== 'undefined' ) {
// Node/CommonJS
module.exports = factory( require( 'jquery' ) );
} else {
// Browser globals
factory( jQuery );
}
}( function( $ ) {
/*
* Auto-growing textareas; technique ripped from Facebook
*/
$.fn.autogrow = function(options) {
options = $.extend( {
vertical: true,
horizontal: false,
characterSlop: 0
}, options);
this.filter('textarea,input').each(function() {
var $this = $(this),
borderBox = $this.css( 'box-sizing' ) === 'border-box',
// minHeight = borderBox ? $this.outerHeight() : $this.height(),
maxHeight = $this.attr( "maxHeight" ),
minWidth = typeof( $this.attr( "minWidth" ) ) == "undefined" ? 0 : $this.attr( "minWidth" );
if( typeof( maxHeight ) == "undefined" ) maxHeight = 1000000;
var shadow = $('<div class="autogrow-shadow"></div>').css( {
position: 'absolute',
top: -10000,
left: -10000,
fontSize: $this.css('fontSize'),
fontFamily: $this.css('fontFamily'),
fontWeight: $this.css('fontWeight'),
lineHeight: $this.css('lineHeight'),
paddingLeft: $this.css('paddingLeft'),
paddingRight: $this.css('paddingRight'),
paddingTop: $this.css('paddingTop'),
paddingBottom: $this.css('paddingBottom'),
borderTop: $this.css('borderTop'),
borderBottom: $this.css('borderBottom'),
borderLeft: $this.css('borderLeft'),
borderRight: $this.css('borderRight'),
whiteSpace: 'pre-wrap',
resize: 'none'
} ).appendTo(document.body);
shadow.html( 'a' );
var characterWidth = shadow.width();
shadow.html( '' );
var isTextarea = $this.is('textarea');
var update = function( val ) {
var times = function(string, number) {
for (var i = 0, r = ''; i < number; i ++) r += string;
return r;
};
if( typeof val === 'undefined' ) val = this.value;
if( val === '' && $(this).attr("placeholder") ) val = $(this).attr("placeholder");
if( options.vertical )
val = val.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\n$/, '<br/>&nbsp;')
.replace(/\n/g, '<br/>')
.replace(/ {2,}/g, function(space) { return times('&nbsp;', space.length -1) + ' '; });
else
val = escapeHtml( val );
//if( options.horizontal )
// val = $.trim( val );
// if( $(this).prop( 'tagName' ).toUpperCase() === 'INPUT' )
// shadow.text(val).css( "width", "auto" );
// else
shadow.html( val ).css( "width", "auto" ); // need to use html here otherwise no way to count spaces (with html we can use &nbsp;)
if( options.horizontal )
{
var slopWidth = options.characterSlop * characterWidth + 2;
var newWidth = Math.max( shadow.width() + slopWidth, minWidth );
var maxWidth = options.maxWidth;
//if( typeof( maxWidth ) === "undefined" ) maxWidth = $this.parent().width() - 12; // not sure why we were doing this but seems like a bad idea. doesn't work with inline-block parents for one thing, since it is the text area that should be "pushing" them to be wider
if( maxWidth ) newWidth = Math.min( newWidth, maxWidth );
// Take scrollbar into account
if (isTextarea && shadow.get(0).scrollHeight > shadow.height()) {
newWidth += 20;
}
$(this).css( "width", newWidth );
}
if( options.vertical )
{
var shadowWidth = $(this).width();
if( ! borderBox ) shadowWidth = shadowWidth - parseInt($this.css('paddingLeft'),10) - parseInt($this.css('paddingRight'),10);
shadow.css( "width", shadowWidth );
var shadowHeight = borderBox ? shadow.outerHeight() : shadow.height();
$(this).css( "height", "auto" );
minHeight = borderBox ? $this.outerHeight() : $this.height();
var newHeight = Math.min( Math.max( shadowHeight, minHeight ), maxHeight );
$(this).css( "height", newHeight );
$(this).css( "overflow", newHeight == maxHeight ? "auto" : "hidden" );
}
};
$(this)
.change(function(){update.call( this );return true;})
.keyup(function(){update.call( this );return true;})
.keypress(function( event ) {
if( event.ctrlKey || event.metaKey ) return;
var val = this.value;
var caretInfo = _getCaretInfo( this );
var typedChar = event.which === 13 ? "\n" : String.fromCharCode( event.which );
var valAfterKeypress = val.slice( 0, caretInfo.start ) + typedChar + val.slice( caretInfo.end );
update.call( this, valAfterKeypress );
return true;
})
.bind( "update.autogrow", function(){ update.apply(this); } )
.bind( "remove.autogrow", function() {
shadow.remove();
} );
update.apply(this);
});
return this;
};
// comes from https://github.com/madapaja/jquery.selection/blob/master/src/jquery.selection.js
var _getCaretInfo = function(element){
var res = {
text: '',
start: 0,
end: 0
};
if (!element.value) {
/* no value or empty string */
return res;
}
try {
if (window.getSelection) {
/* except IE */
res.start = element.selectionStart;
res.end = element.selectionEnd;
res.text = element.value.slice(res.start, res.end);
} else if (doc.selection) {
/* for IE */
element.focus();
var range = doc.selection.createRange(),
range2 = doc.body.createTextRange();
res.text = range.text;
try {
range2.moveToElementText(element);
range2.setEndPoint('StartToStart', range);
} catch (e) {
range2 = element.createTextRange();
range2.setEndPoint('StartToStart', range);
}
res.start = element.value.length - range2.text.length;
res.end = res.start + range.text.length;
}
} catch (e) {
/* give up */
}
return res;
};
var entityMap = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': '&quot;',
"'": '&#39;',
"/": '&#x2F;',
" ": '&nbsp;'
};
function escapeHtml(string) {
return String(string).replace(/[&<>"'\/\ ]/g, function (s) {
return entityMap[s];
} );
}
} ) );

View File

@@ -1,2 +0,0 @@
/*! js-cookie v2.0.4 | MIT */
!function(a){if("function"==typeof define&&define.amd)define(a);else if("object"==typeof exports)module.exports=a();else{var b=window.Cookies,c=window.Cookies=a();c.noConflict=function(){return window.Cookies=b,c}}}(function(){function a(){for(var a=0,b={};a<arguments.length;a++){var c=arguments[a];for(var d in c)b[d]=c[d]}return b}function b(c){function d(b,e,f){var g;if(arguments.length>1){if(f=a({path:"/"},d.defaults,f),"number"==typeof f.expires){var h=new Date;h.setMilliseconds(h.getMilliseconds()+864e5*f.expires),f.expires=h}try{g=JSON.stringify(e),/^[\{\[]/.test(g)&&(e=g)}catch(i){}return e=encodeURIComponent(String(e)),e=e.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),b=encodeURIComponent(String(b)),b=b.replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent),b=b.replace(/[\(\)]/g,escape),document.cookie=[b,"=",e,f.expires&&"; expires="+f.expires.toUTCString(),f.path&&"; path="+f.path,f.domain&&"; domain="+f.domain,f.secure?"; secure":""].join("")}b||(g={});for(var j=document.cookie?document.cookie.split("; "):[],k=/(%[0-9A-Z]{2})+/g,l=0;l<j.length;l++){var m=j[l].split("="),n=m[0].replace(k,decodeURIComponent),o=m.slice(1).join("=");'"'===o.charAt(0)&&(o=o.slice(1,-1));try{if(o=c&&c(o,n)||o.replace(k,decodeURIComponent),this.json)try{o=JSON.parse(o)}catch(i){}if(b===n){g=o;break}b||(g[n]=o)}catch(i){}}return g}return d.get=d.set=d,d.getJSON=function(){return d.apply({json:!0},[].slice.call(arguments))},d.defaults={},d.remove=function(b,c){d(b,"",a(c,{expires:-1}))},d.withConverter=b,d}return b()});

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();
});
});