Version 2.1.0

This commit is contained in:
dmzx
2018-08-02 11:34:39 +02:00
parent cd0f139598
commit 006a4e404e
140 changed files with 2695 additions and 2699 deletions

View File

@@ -0,0 +1,6 @@
/*!
autosize 4.0.1
license: MIT
http://www.jacklmoore.com/autosize
*/
!function(e,t){if("function"==typeof define&&define.amd)define(["module","exports"],t);else if("undefined"!=typeof exports)t(module,exports);else{var n={exports:{}};t(n,n.exports),e.autosize=n.exports}}(this,function(e,t){"use strict";var n,o,p="function"==typeof Map?new Map:(n=[],o=[],{has:function(e){return-1<n.indexOf(e)},get:function(e){return o[n.indexOf(e)]},set:function(e,t){-1===n.indexOf(e)&&(n.push(e),o.push(t))},delete:function(e){var t=n.indexOf(e);-1<t&&(n.splice(t,1),o.splice(t,1))}}),c=function(e){return new Event(e,{bubbles:!0})};try{new Event("test")}catch(e){c=function(e){var t=document.createEvent("Event");return t.initEvent(e,!0,!1),t}}function r(r){if(r&&r.nodeName&&"TEXTAREA"===r.nodeName&&!p.has(r)){var e,n=null,o=null,i=null,d=function(){r.clientWidth!==o&&a()},l=function(t){window.removeEventListener("resize",d,!1),r.removeEventListener("input",a,!1),r.removeEventListener("keyup",a,!1),r.removeEventListener("autosize:destroy",l,!1),r.removeEventListener("autosize:update",a,!1),Object.keys(t).forEach(function(e){r.style[e]=t[e]}),p.delete(r)}.bind(r,{height:r.style.height,resize:r.style.resize,overflowY:r.style.overflowY,overflowX:r.style.overflowX,wordWrap:r.style.wordWrap});r.addEventListener("autosize:destroy",l,!1),"onpropertychange"in r&&"oninput"in r&&r.addEventListener("keyup",a,!1),window.addEventListener("resize",d,!1),r.addEventListener("input",a,!1),r.addEventListener("autosize:update",a,!1),r.style.overflowX="hidden",r.style.wordWrap="break-word",p.set(r,{destroy:l,update:a}),"vertical"===(e=window.getComputedStyle(r,null)).resize?r.style.resize="none":"both"===e.resize&&(r.style.resize="horizontal"),n="content-box"===e.boxSizing?-(parseFloat(e.paddingTop)+parseFloat(e.paddingBottom)):parseFloat(e.borderTopWidth)+parseFloat(e.borderBottomWidth),isNaN(n)&&(n=0),a()}function s(e){var t=r.style.width;r.style.width="0px",r.offsetWidth,r.style.width=t,r.style.overflowY=e}function u(){if(0!==r.scrollHeight){var e=function(e){for(var t=[];e&&e.parentNode&&e.parentNode instanceof Element;)e.parentNode.scrollTop&&t.push({node:e.parentNode,scrollTop:e.parentNode.scrollTop}),e=e.parentNode;return t}(r),t=document.documentElement&&document.documentElement.scrollTop;r.style.height="",r.style.height=r.scrollHeight+n+"px",o=r.clientWidth,e.forEach(function(e){e.node.scrollTop=e.scrollTop}),t&&(document.documentElement.scrollTop=t)}}function a(){u();var e=Math.round(parseFloat(r.style.height)),t=window.getComputedStyle(r,null),n="content-box"===t.boxSizing?Math.round(parseFloat(t.height)):r.offsetHeight;if(n!==e?"hidden"===t.overflowY&&(s("scroll"),u(),n="content-box"===t.boxSizing?Math.round(parseFloat(window.getComputedStyle(r,null).height)):r.offsetHeight):"hidden"!==t.overflowY&&(s("hidden"),u(),n="content-box"===t.boxSizing?Math.round(parseFloat(window.getComputedStyle(r,null).height)):r.offsetHeight),i!==n){i=n;var o=c("autosize:resized");try{r.dispatchEvent(o)}catch(e){}}}}function i(e){var t=p.get(e);t&&t.destroy()}function d(e){var t=p.get(e);t&&t.update()}var l=null;"undefined"==typeof window||"function"!=typeof window.getComputedStyle?((l=function(e){return e}).destroy=function(e){return e},l.update=function(e){return e}):((l=function(e,t){return e&&Array.prototype.forEach.call(e.length?e:[e],function(e){return r(e)}),e}).destroy=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],i),e},l.update=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],d),e}),t.default=l,e.exports=t.default});

View File

@@ -1,211 +0,0 @@
// 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

@@ -0,0 +1,53 @@
/**
*
* mchat.collapse.js - Collapse mChat container for styles by Arty
*
* @package phpBB Extension - mChat
* @copyright (c) 2017 kasimi - https://kasimi.net
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
jQuery(function($) {
"use strict";
// Most code below copied from elegance/template/forum_fn.js for phpBB 3.2.2
var $this = $('.mchat-wrapper li.header').first(),
forum = $this.closest('.topiclist').next(),
id = 'mchat',
toggled = false,
toggle;
// Add toggle code
$this.append('<a class="forum-toggle" href="#"></a>');
toggle = $this.find('.forum-toggle');
toggle.click(function(event) {
event.preventDefault();
$(mChat).trigger('mchat_collapse_toggle_before', [{collapsed: !toggle}]);
if (toggled) {
forum.stop(true, true).slideDown(200, function() {
$(mChat).trigger('mchat_collapse_toggle_after', [{collapsed: toggle}]);
});
toggled = false;
toggle.removeClass('toggled');
phpbb.deleteCookie('toggled-' + id, styleConfig.cookieConfig);
return;
}
forum.stop(true, true).slideUp(200, function() {
$(mChat).trigger('mchat_collapse_toggle_after', [{collapsed: toggle}]);
});
toggled = true;
toggle.addClass('toggled');
phpbb.setCookie('toggled-' + id, '1', styleConfig.cookieConfig);
});
// Check default state
if (phpbb.getCookie('toggled-' + id, styleConfig.cookieConfig) === '1') {
forum.stop(true, true).slideUp(0);
toggled = true;
toggle.addClass('toggled');
}
});

View File

@@ -112,7 +112,7 @@ jQuery(function($) {
$(mChat).trigger('mchat_send_request_before', [mode, data]);
$.ajax({
url: mChat.actionUrls[mode],
timeout: Math.min(mChat.refreshTime, 10000),
timeout: Math.min(mChat.refreshTime, 10000) - 100,
type: 'POST',
dataType: 'json',
data: data,
@@ -133,7 +133,7 @@ jQuery(function($) {
};
$(mChat).trigger('mchat_ajax_done_before', [data]);
if (data.handle) {
if (json[this.mode]) {
if (json[data.mode]) {
this.deferred.resolve(data.json, data.status, data.xhr);
} else {
this.deferred.reject(data.xhr, data.status, mChat.lang.parserErr);
@@ -144,6 +144,7 @@ jQuery(function($) {
if (mChat.pageIsUnloading) {
return;
}
mChat.skipNextRefresh = true;
if (typeof console !== 'undefined' && console.log) {
console.log('AJAX error. status: ' + textStatus + ', message: ' + errorThrown + ' (' + xhr.responseText + ')');
}
@@ -162,24 +163,52 @@ jQuery(function($) {
};
$(mChat).trigger('mchat_ajax_fail_before', [data]);
mChat.sound('error');
mChat.cached('status-load', 'status-ok', 'status-paused').hide();
mChat.cached('status-error').show();
mChat.status('error');
var title = mChat.lang.err;
var responseText;
try {
responseText = data.xhr.responseJSON.message || data.errorThrown;
var json = data.xhr.responseJSON;
if (json.S_USER_WARNING || json.S_USER_NOTICE) {
title = json.MESSAGE_TITLE;
responseText = json.MESSAGE_TEXT;
data.xhr.status = 403;
} else {
responseText = json.message || data.errorThrown;
}
} catch (e) {
responseText = data.errorThrown;
}
if (responseText && responseText !== 'timeout') {
phpbb.alert(mChat.lang.err, responseText);
phpbb.alert(title, responseText);
}
data.updateSession();
},
registerNavItem: function(id, canEnable, onToggle) {
var isEnabled = canEnable && !mChat.storage.get('no_' + id);
var classEnabled = 'mchat-nav-item-enabled';
var classDisabled = 'mchat-nav-item-disabled';
mChat.cached(id).toggleClass(classEnabled, isEnabled).toggleClass(classDisabled, !isEnabled);
if (typeof onToggle === 'function') {
onToggle(isEnabled);
}
mChat['toggle_' + id] = function(e) {
e.preventDefault();
var hasClass = mChat.cached(id).toggleClass(classEnabled + ' ' + classDisabled).hasClass(classEnabled);
if (hasClass) {
mChat.storage.remove('no_' + id);
} else {
mChat.storage.set('no_' + id, 'yes');
}
if (typeof onToggle === 'function') {
onToggle(hasClass);
}
};
},
sound: function(file) {
var data = {
audio: mChat.cached('sound-' + file).get(0),
file: file,
play: !mChat.pageIsUnloading && mChat.cached('user-sound').is(':checked')
play: !mChat.pageIsUnloading && mChat.cached('sound').hasClass('mchat-nav-item-enabled')
};
$(mChat).trigger('mchat_sound_before', [data]);
if (data.play && data.audio && data.audio.duration) {
@@ -198,7 +227,8 @@ jQuery(function($) {
$.titleAlert(mChat.lang.newMessageAlert, data);
}
},
toggle: function(name) {
toggle: function() {
var name = $(this).data('mchat-element');
var $elem = mChat.cached(name);
$elem.stop().slideToggle(200, function() {
if ($elem.is(':visible')) {
@@ -229,36 +259,35 @@ jQuery(function($) {
});
},
add: function() {
if (mChat.cached('add').prop('disabled')) {
var $add = mChat.cached('add');
if ($add.prop('disabled')) {
return;
}
var messageLength = mChat.cached('input').val().length;
var $input = mChat.cached('input');
var originalInputValue = mChat.cleanMessage($input.val()).trim();
var messageLength = originalInputValue.length;
if (!messageLength) {
phpbb.alert(mChat.lang.err, mChat.lang.noMessageInput);
return;
}
if (mChat.mssgLngth && messageLength > mChat.mssgLngth) {
phpbb.alert(mChat.lang.err, mChat.lang.mssgLngthLong);
return;
}
mChat.cached('add').prop('disabled', true);
$add.prop('disabled', true);
mChat.pauseSession();
var originalInputValue = mChat.cached('input').val();
var inputValue = originalInputValue;
var color = mChat.storage.get('color');
if (color && inputValue.indexOf('[color=') === -1) {
inputValue = '[color=#' + color + '] ' + inputValue + ' [/color]';
}
mChat.cached('input').val('').trigger('update.autogrow').focus();
mChat.setText('');
mChat.refresh(inputValue).done(function() {
mChat.resetSession();
}).fail(function() {
mChat.cached('input').val(originalInputValue).trigger('update.autogrow');
mChat.setText(originalInputValue);
}).always(function() {
mChat.cached('add').prop('disabled', false);
setTimeout(function() {
mChat.cached('input').focus();
}, 1);
$add.prop('disabled', false);
$input.delay(1).focus();
});
},
edit: function() {
@@ -276,13 +305,14 @@ jQuery(function($) {
message_id: $message.data('mchat-id'),
message: $textarea.val(),
page: mChat.page
}).done(function(json) {
mChat.updateMessages($(json.edit));
mChat.resetSession();
});
}).done(mChat.editDone);
}
});
},
editDone: function(json) {
mChat.updateMessages($(json.edit));
mChat.resetSession();
},
del: function() {
var delId = $(this).closest('.mchat-message').data('mchat-id');
mChat.confirm({
@@ -295,60 +325,68 @@ jQuery(function($) {
confirm: function() {
mChat.ajaxRequest('del', true, {
message_id: delId
}).done(function() {
mChat.removeMessages([delId]);
mChat.resetSession();
});
}).done(mChat.delDone);
}
});
},
delDone: function(json) {
mChat.removeMessages([json.del]);
mChat.resetSession();
},
refresh: function(message) {
if (mChat.isPaused && !message) {
return false;
var isAdd = typeof message !== 'undefined';
if (!isAdd) {
mChat.sessionLength += mChat.refreshTime;
if (mChat.timeout && mChat.sessionLength >= mChat.timeout) {
mChat.endSession();
return;
} else if (mChat.skipNextRefresh) {
mChat.skipNextRefresh = false;
return;
}
}
var data = {
last: mChat.messageIds.length ? mChat.messageIds.max() : 0
last: mChat.messageIds.length ? mChat.messageIds.max() : 0,
log: mChat.liveUpdates ? mChat.logId : undefined,
message: isAdd ? message : undefined
};
if (message) {
data.message = message;
mChat.status('load');
return mChat.ajaxRequest(isAdd ? 'add' : 'refresh', isAdd, data).done(mChat.refreshDone);
},
refreshDone: function(json) {
$(mChat).trigger('mchat_response_handle_data_before', [json]);
if (json.add) {
mChat.addMessages($(json.add));
}
if (mChat.liveUpdates) {
data.log = mChat.logId;
if (json.edit) {
mChat.updateMessages($(json.edit));
}
mChat.cached('status-ok', 'status-error', 'status-paused').hide();
mChat.cached('status-load').show();
return mChat.ajaxRequest(message ? 'add' : 'refresh', !!message, data).done(function(json) {
$(mChat).trigger('mchat_response_handle_data_before', [json]);
if (json.add) {
mChat.addMessages($(json.add));
}
if (json.edit) {
mChat.updateMessages($(json.edit));
}
if (json.del) {
mChat.removeMessages(json.del);
}
if (json.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]);
});
if (json.del) {
mChat.removeMessages(json.del);
}
if (json.whois) {
mChat.whoisDone(json);
}
if (json.log) {
mChat.logId = json.log;
}
if (mChat.refreshInterval) {
mChat.status('ok');
}
$(mChat).trigger('mchat_response_handle_data_after', [json]);
},
rules: function() {
$('.mchat-nav-link-title').each(phpbb.toggleDropdown);
popup(this.href, 450, 275);
},
whois: function() {
if (mChat.page === 'custom') {
mChat.cached('refresh-pending').show();
mChat.cached('refresh-explain').hide();
}
mChat.ajaxRequest('whois', false, {}).done(mChat.handleWhoisResponse);
mChat.ajaxRequest('whois', false, {}).done(mChat.whoisDone);
},
handleWhoisResponse: function(json) {
whoisDone: function(json) {
var $whois = $(json.container);
var $userlist = $whois.find('#mchat-userlist');
if (mChat.storage.get('show_userlist')) {
@@ -413,12 +451,13 @@ jQuery(function($) {
if (mChat.messageTop) {
container.animate({scrollTop: 0}, animateOptions);
} else {
(animateOptions.complete = function() {
animateOptions.complete = function() {
var scrollHeight = container.get(0).scrollHeight;
if (container.scrollTop() + container.height() < scrollHeight) {
container.animate({scrollTop: scrollHeight}, animateOptions);
}
})();
};
animateOptions.complete();
}
} else {
this.message.show();
@@ -515,81 +554,69 @@ jQuery(function($) {
var selector = '.mchat-time[data-mchat-relative-update]';
clearInterval($message.find(selector).addBack(selector).data('mchat-relative-interval'));
},
timeLeftRegex: /\d\d:(\d\d:\d\d)/,
timeLeft: function(sessionTime) {
return (new Date(sessionTime * 1000)).toUTCString().match(mChat.timeLeftRegex)[mChat.timeout >= 3600000 ? 0 : 1];
},
countDown: function() {
mChat.sessionTime -= 1;
mChat.cached('session').html(mChat.lang.sessEnds.format({timeleft: mChat.timeLeft(mChat.sessionTime)}));
if (mChat.sessionTime < 1) {
mChat.endSession();
status: function(status) {
var data = {
status: status,
container: mChat.cached('status')
};
$(mChat).trigger('mchat_status_before', [data]);
var $activeStatus = data.container.find('.mchat-status-' + data.status).removeClass('hidden');
if ($activeStatus.length) {
data.container.find('.mchat-status').not($activeStatus).addClass('hidden');
}
},
pauseSession: function() {
clearInterval(mChat.refreshInterval);
if (mChat.timeout) {
clearInterval(mChat.sessionCountdown);
}
mChat.refreshInterval = false;
if (mChat.whoisRefresh) {
clearInterval(mChat.whoisInterval);
mChat.whoisInterval = false;
}
},
resetSession: function() {
if (mChat.page !== 'archive') {
clearInterval(mChat.refreshInterval);
mChat.refreshInterval = setInterval(mChat.refresh, mChat.refreshTime);
if (mChat.timeout) {
mChat.sessionTime = mChat.timeout / 1000;
clearInterval(mChat.sessionCountdown);
mChat.cached('session').html(mChat.lang.sessEnds.format({timeleft: mChat.timeLeft(mChat.sessionTime)}));
mChat.sessionCountdown = setInterval(mChat.countDown, 1000);
}
if (mChat.whoisRefresh) {
clearInterval(mChat.whoisInterval);
mChat.whoisInterval = setInterval(mChat.whois, mChat.whoisRefresh);
}
mChat.cached('status-ok').show();
mChat.cached('status-load', 'status-error', 'status-paused').hide();
mChat.cached('refresh-text').html(mChat.lang.refreshYes);
if (mChat.page === 'archive') {
return;
}
mChat.pauseSession();
mChat.sessionLength = 0;
mChat.refreshInterval = setInterval(mChat.refresh, mChat.refreshTime);
if (mChat.whoisRefresh) {
mChat.whoisInterval = setInterval(mChat.whois, mChat.whoisRefresh);
}
mChat.status('ok');
},
endSession: function(skipUpdateWhois) {
clearInterval(mChat.refreshInterval);
mChat.refreshInterval = false;
if (mChat.timeout) {
clearInterval(mChat.sessionCountdown);
mChat.cached('session').html(mChat.lang.sessOut);
mChat.pauseSession();
if (mChat.whoisRefresh && !skipUpdateWhois) {
mChat.whois();
}
if (mChat.whoisRefresh) {
clearInterval(mChat.whoisInterval);
if (!skipUpdateWhois) {
mChat.whois();
}
}
mChat.cached('status-load', 'status-ok', 'status-error').hide();
mChat.cached('status-paused').show();
mChat.cached('refresh-text').html(mChat.lang.refreshNo);
},
pauseStart: function() {
mChat.isPaused = true;
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.lang.refreshYes);
mChat.cached('status-load', 'status-error', 'status-paused').hide();
mChat.cached('status-ok').show();
mChat.isPaused = false;
mChat.status('paused');
},
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('invisible', count === 0);
if (mChat.mssgLngth) {
$elem.toggleClass('error', count > mChat.mssgLngth);
var count = mChat.cleanMessage(mChat.cached('input').val()).length;
var exceedCount = Math.max(mChat.mssgLngth - count, -999);
if (mChat.showCharCount) {
var charCount = mChat.lang.charCount.format({current: count, max: mChat.mssgLngth});
var $elem = mChat.cached('character-count').html(charCount).toggleClass('invisible', count === 0);
if (mChat.mssgLngth) {
$elem.toggleClass('error', count > mChat.mssgLngth);
}
}
mChat.cached('exceed-character-count').text(exceedCount).toggleClass('hidden', exceedCount >= 0);
mChat.cached('input').parent().toggleClass('mchat-input-error', exceedCount < 0);
mChat.cached('add').toggleClass('hidden', exceedCount < 0);
},
cleanMessage: function(message) {
if (!mChat.maxInputHeight) {
message = message.replace(/\s+/g, ' ');
}
return message;
},
smiley: function() {
mChat.appendText($(this).data('smiley-code'), true);
},
smileyPopup: function() {
popup(this.href, 300, 350, '_phpbbsmilies');
},
mention: function() {
var $container = $(this).closest('.mchat-message');
@@ -605,38 +632,55 @@ jQuery(function($) {
}
}
}
insert_text(mChat.lang.mention.format({username: username}));
mChat.appendText(mChat.lang.mention.format({username: username}));
},
quote: function() {
var $container = $(this).closest('.mchat-message');
var username = $container.data('mchat-username');
var quote = $container.data('mchat-message');
insert_text('[quote="' + username + '"] ' + quote + '[/quote]');
mChat.cached('input').trigger('update.autogrow');
mChat.appendText('[quote="' + username + '"] ' + quote + '[/quote]');
},
like: function() {
var $container = $(this).closest('.mchat-message');
var username = $container.data('mchat-username');
var quote = $container.data('mchat-message');
insert_text('[i]' + mChat.lang.likes + '[/i][quote="' + username + '"] ' + quote + '[/quote]');
mChat.cached('input').trigger('update.autogrow');
mChat.appendText('[i]' + mChat.lang.likes + '[/i][quote="' + username + '"] ' + quote + '[/quote]');
},
ip: function() {
popup(this.href, 750, 500);
},
cached: function() {
return $($.map(arguments, function(name) {
if (!mChat.cache[name]) {
mChat.cache[name] = $('#mchat-' + name);
}
return mChat.cache[name];
})).map(function() {
return this.toArray();
});
custom: function() {
window.location.href = this.href;
},
archive: function() {
window.location.href = this.href;
},
setText: function(text) {
mChat.cached('input').val('');
mChat.appendText(text);
},
appendText: function(text, spaces, popup) {
var $input = mChat.cached('input');
if (text) {
insert_text(text, spaces, popup);
}
if (mChat.maxInputHeight) {
autosize.update($input);
} else {
$input.scrollLeft($input[0].scrollWidth - $input[0].clientWidth);
}
},
cached: function(name) {
if (!mChat.cache) {
mChat.cache = {};
}
if (!mChat.cache.hasOwnProperty(name)) {
mChat.cache[name] = $('#mchat-' + name);
}
return mChat.cache[name];
}
});
mChat.cache = {};
mChat.messageIds = mChat.cached('messages').children().map(function() {
return $(this).data('mchat-id');
}).get();
@@ -646,25 +690,13 @@ jQuery(function($) {
mChat.hiddenFields[this.name] = this.value;
});
mChat.isPaused = false;
if (mChat.page !== 'archive') {
mChat.resetSession();
if (!mChat.messageTop) {
setTimeout(function() {
mChat.cached('messages').scrollTop(mChat.cached('messages')[0].scrollHeight);
}, 1);
mChat.cached('messages').delay(1).scrollTop(mChat.cached('messages')[0].scrollHeight);
}
mChat.cached('user-sound').prop('checked', mChat.playSound && !mChat.storage.get('no_sound')).change(function() {
if (this.checked) {
mChat.storage.remove('no_sound');
} else {
mChat.storage.set('no_sound', 'yes');
}
});
$.each(mChat.removeBBCodes.split('|'), function(i, bbcode) {
var bbCodeClass = '.bbcode-' + bbcode.replaceMany({
'=': '-',
@@ -673,87 +705,88 @@ jQuery(function($) {
mChat.cached('body').find(bbCodeClass).remove();
});
var $colourPalette = $('#colour_palette');
var $colourPalette = $('#mchat-bbcodes').find('#colour_palette');
$colourPalette.appendTo($colourPalette.parent()).wrap('<div id="mchat-colour"></div>').show();
$('#bbpalette,#abbc3_bbpalette,#color_wheel').prop('onclick', null).attr('data-mchat-toggle', 'colour');
$('#bbpalette,#abbc3_bbpalette,#color_wheel').prop('onclick', null).attr({
'data-mchat-action': 'toggle',
'data-mchat-element': 'colour'
});
$.each(['userlist', 'smilies', 'bbcodes', 'colour'], function(i, elem) {
if (mChat.storage.get('show_' + elem)) {
$('.mchat-button-' + elem).addClass('mchat-button-is-down');
mChat.cached(elem).toggle();
}
});
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();
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 (mChat.storage.get('color') === newColor) {
mChat.storage.remove('color');
} else {
mChat.storage.set('color', newColor);
mChat.cached('colour').find('.colour-palette a').removeClass('remember-color');
}
$this.toggleClass('remember-color');
}
});
if (mChat.pause) {
mChat.cached('form').on('input', function() {
if (mChat.refreshInterval !== false) {
var val = mChat.cached('input').val();
if (mChat.isPaused && val === '') {
mChat.pauseEnd();
} else if (!mChat.isPaused && val !== '') {
mChat.pauseStart();
}
}
var color = mChat.storage.get('color');
if (color) {
mChat.cached('colour').find('.colour-palette a[data-color="' + color + '"]').addClass('remember-color');
}
if (mChat.maxInputHeight) {
mChat.cached('input').one('focus', function() {
autosize(this);
});
}
if (mChat.showCharCount) {
mChat.cached('form').submit(function(e) {
e.preventDefault();
}).keypress(function(e) {
if ((e.which === 10 || e.which === 13) && mChat.cached('input').is(e.target)) {
var isCtrl = e.ctrlKey || e.metaKey;
if (!mChat.maxInputHeight || !isCtrl === !mChat.storage.get('no_enter')) {
e.preventDefault();
mChat.add();
} else if (mChat.maxInputHeight && isCtrl) {
mChat.appendText('\n');
}
}
});
if (mChat.showCharCount || mChat.mssgLngth) {
mChat.cached('form').on('input', mChat.updateCharCount);
mChat.cached('input').on('focus', function() {
setTimeout(function() {
mChat.updateCharCount();
}, 1);
setTimeout(mChat.updateCharCount, 1);
});
}
mChat.cached('input').autogrow({
vertical: false,
horizontal: true
});
}
mChat.startRelativeTimeUpdate(mChat.cached('messages'));
mChat.registerNavItem('sound', mChat.playSound);
if (mChat.maxInputHeight) {
mChat.registerNavItem('enter', true);
}
$(window).on('beforeunload', 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 (mChat.storage.get('color') === newColor) {
mChat.storage.remove('color');
} else {
mChat.storage.set('color', newColor);
mChat.cached('colour').find('.colour-palette a').removeClass('remember-color');
}
$this.toggleClass('remember-color');
}
});
var color = mChat.storage.get('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);
}).on('click', '[data-mchat-toggle]', function(e) {
e.preventDefault();
var elem = $(this).data('mchat-toggle');
mChat.toggle(elem);
mChat[action].call(this, e);
}).on('click', '.mchat-panel-buttons button', function() {
var $this = $(this).blur();
if ($this.hasClass('mchat-button-down')) {
$this.toggleClass('mchat-button-is-down');
}
});
});

View File

@@ -1,13 +1,13 @@
{% 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' %}
{% if MCHAT_MAX_INPUT_HEIGHT %}
{% INCLUDEJS '@dmzx_mchat/javascript/autosize.min.js' %}
{% endif %}
{% INCLUDEJS '@dmzx_mchat/javascript/jquery.titlealert.min.js' %}
{% INCLUDEJS '@dmzx_mchat/javascript/mchat.js' %}
<script type="text/javascript">
// <![CDATA[
<script>
var form_name = 'postform';
var text_name = 'message';
var mChat = {
@@ -19,7 +19,6 @@
},
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' }},
@@ -31,7 +30,8 @@
refreshTime : {{ MCHAT_REFRESH_JS }},
whoisRefresh : {{ MCHAT_WHOIS_REFRESH }},
timeout : {{ MCHAT_TIMEOUT }},
mssgLngth : {{ MCHAT_MESSAGE_LNGTH }},
mssgLngth : {{ MCHAT_MAX_MESSAGE_LENGTH }},
maxInputHeight : {{ MCHAT_MAX_INPUT_HEIGHT }},
editDeleteLimit : {{ MCHAT_EDIT_DELETE_LIMIT }},
logId : {{ MCHAT_LOG_ID }},
removeBBCodes : '{{ MCHAT_DISALLOWED_BBCODES | escape('js') }}',
@@ -48,18 +48,12 @@
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') }}',
charCount : '{{ lang(MCHAT_MAX_MESSAGE_LENGTH ? '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') }}'
}
};
// ]]>
</script>