Isto é uma pré-visualização de um tema em Hitskin.com
Instalar o tema • Voltar para a ficha do tema
Chat em abas incompatível com comandos
3 participantes
Fórum dos Fóruns :: Ajuda e atendimento ao utilizador :: Questões sobre códigos :: Questões resolvidas sobre códigos Javascript e jQuery
Página 1 de 1
Chat em abas incompatível com comandos
Detalhes da questão
Endereço do fórum: http://www.brasilplayultimate.forumeiros.com
Versão do fórum: ModernBB
Descrição
Olá a todos, recentemente tive problemas com este script:
- Código:
- Código:
/*globals jQuery, _userdata*/
/**
* Adds tabs to the chat in which people can choose to talk separately.
*
* @author Kyo Panda
* @see <a href="https://ajuda.forumeiros.com">Fórum dos Fóruns</a>
* @license MIT
*/
(function($) {
'use strict';
/**
* Configuration
*/
var config = {
/**
* Settings for the 'all' tab
*/
all: {
enable: false, // If it is active or not
label: 'General', // Its label
},
/**
* List of tabs labels
*/
tabs: [
'General',
'Suporte',
'Animes',
],
/**
* The default active tab
*/
default: 'General',
/**
* Choose the types of messages you want to disable.
*/
hide: {
connect: true, // Member connect
disconnect: true, // Member disconnect
timeout: true, // Member disconnect by timeout
},
};
/**
* Internationalization settings
*/
var i18n = {
/**
* English
*/
en: {
'All': 'All',
'General': 'General',
'Suporte': 'Suport',
'Animes': 'Animes',
},
/**
* Spanish
*/
es: {
'All': 'Todos',
'General': 'General',
'Suporte': 'Suporte',
'Animes': 'Animes',
},
/**
* Portuguese
*/
pt: {
'All': 'Todos',
'General': 'Bate-papo',
'Suporte': 'Dúvidas',
'Animes': 'Animes',
},
};
var lang = {};
var t = function(text, reverse) {
if (reverse) {
for (var key in lang) {
if (lang[key] === text) {
return key;
}
}
return text;
}
return lang[text] ? lang[text] : text;
};
/**
* Style
*/
config.style = [
'#chatbox_tabs li:hover {',
'opacity: 0.7;',
'}',
'#chatbox_header {',
' position: relative;',
'}',
'',
'#chatbox_tabs {',
' position: absolute;',
' bottom: 0;',
' left: 80px;',
' list-style: none;',
' padding: 0 0 0 10px;',
' margin: 0;',
' overflow: hidden;',
'}',
'',
'#chatbox_tabs li {',
' float: left;',
' height: 24px;',
' line-height: 24px;',
' margin-right: 10px;',
' padding: 0 5px;',
' border: 1px #fff solid;',
' border-radius: 3px 3px 0 0;',
' cursor: pointer;',
' font-family: Arial, sans-serif;',
' color: #000;',
' border-bottom: none;',
'}',
'',
'#chatbox_tabs li.active {',
' background-color: #f5f5f5;',
' color: #333;',
'}',
].join('\n');
/**
* Chatbox override
*/
var insertChatBoxNew = window.insertChatBoxNew;
window.insertChatBox = window.insertChatBoxNew = function() {
insertChatBoxNew.apply(this, arguments);
var chatbox = $('#frame_chatbox').get(0);
if (chatbox.readyState === 'complete') {
return run(event.target.contentWindow);
}
var onload = chatbox.onload;
chatbox.onload = function(event) {
if (onload) {
onload.apply(this, arguments);
}
run(event.target.contentWindow);
};
};
/**
* Script initialization
*/
var run = function(context) {
/**
* Initial variables
*/
lang = window._userdata && i18n[_userdata.user_lang] ?
i18n[_userdata.user_lang] : {}
;
if (
config.all.enable
&& config.tabs.indexOf(config.all.label) === -1
) {
config.tabs.unshift(config.all.label);
}
var tabs = {
html: [],
stored: [],
visible: config.tabs.indexOf(config.default),
regex: new RegExp(
'\\[(' + config.tabs.join('|') + ')\\]', 'gi'
),
tregex: (function() {
var values = [];
values = $.map(config.tabs, function(text) {
return t(text);
});
return new RegExp(
'\\[(' + values.join('|') + ')\\]\\s?', 'gi'
);
}()),
all: function(label) {
return config.all.enable && label === config.all.label;
},
};
if (tabs.visible === -1) {
tabs.visible = 0;
}
$.each(config.tabs, function() {
tabs.html.push('<li>' + t(this) + '</li>');
});
var $message = null;
/**
* Tabs creation
*/
$('<style>', { text: config.style }).appendTo(context.document.head);
var $tabs = $('<ul>', { id: 'chatbox_tabs' })
.html(tabs.html.join(''))
.find('li:nth-child(' + (tabs.visible + 1) + ')')
.addClass('active')
.end()
.on('click', 'li', function() {
var $this = $(this);
if ($this.index() === tabs.visible) {
return;
}
tabs.visible = $this.index();
$tabs.find('.active').removeClass('active');
$this.addClass('active');
context.chatbox.refresh({ messages: tabs.stored });
})
.appendTo($('#chatbox_header', context.document))
;
/**
* Chatbox refresh
*/
var refresh = context.Chatbox.prototype.refresh;
context.Chatbox.prototype.refresh = function(data) {
if (!data.messages || !data.messages.length) {
return refresh.call(this, data);
}
tabs.stored = data.messages;
data = JSON.parse(JSON.stringify(data));
data.messages = $.grep(data.messages, function(message) {
if (config.hide[message.action]) {
return false;
}
return true;
});
var label = config.tabs[tabs.visible];
if (tabs.all(label)) {
$.each(data.messages, function() {
this.msg = this.msg.replace(tabs.regex, function(text, match) {
return '[' + t(match) + ']';
});
});
return refresh.call(this, data);
}
data.messages = $.grep(data.messages, function(message) {
if (
message.action === 'msg'
&& message.msg.indexOf('[' + label + ']') === -1
) {
return false;
}
message.msg = message.msg.replace(tabs.regex, '');
return true;
});
refresh.call(this, data);
};
/**
* Chatbox send
*/
var send = context.Chatbox.prototype.send;
context.Chatbox.prototype.send = function() {
if (!$message) {
$message = $('#message', context.document);
}
var label = config.tabs[tabs.visible];
var value = $message
.val()
.replace(tabs.tregex, function(text, match) {
console.log(match, t(match, true));
return '[' + t(match, true) + ']';
})
;
if (!tabs.all(label)) {
value = '[' + label + '] ' + value;
}
$message.val(value);
send.apply(this, arguments);
};
/**
* Chatbox initial refresh
*/
context.chatbox.refresh(context.chatbox);
}
}(jQuery));
Vejam: http://prntscr.com/lztt9u
Há como proceder ?
Re: Chat em abas incompatível com comandos
Olá @iScroll,
Tente trocar por este código:
Até mais.
PS: Já atualizei o tutorial com este novo código, obrigado.
Tente trocar por este código:
- Código:
/*globals jQuery, _userdata*/
/**
* Adds tabs to the chat in which people can choose to talk separately.
*
* @author Kyo Panda
* @see <a href="http://ajuda.forumeiros.com">Fórum dos Fóruns</a>
* @license MIT
*/
FA = window.FA || {};
FA.Chatbox = FA.Chatbox || {};
FA.Chatbox.Tabs = (function($, config, i18n, style) {
/**
* Object initialization
*/
function Tabs() {
/**
* Language variable
*/
this.lang = {};
/**
* Regex for translating tab tags in messages
*/
this.regex = new RegExp('\\[(' + $.map(config.tabs, function(tab) {
return tab.label;
}).join('|') + ')\\]');
/**
* Tabs initialization
*/
$.each(config.tabs, function() {
/**
* Regex for removing the tags on messages
*/
this.regex = new RegExp('\\[' + this.label + '\\](\s?)', 'gi');
/**
* Last message tab, for new messages notification
*/
this.lastMessage = 0;
});
/**
* Override chatbox
*/
this.overrideChatbox();
};
/**
* Translation function
*/
Tabs.prototype.t = function(text) {
return this.lang[text] ? this.lang[text] : text;
};
/**
* Initialization function
*/
Tabs.prototype.init = function() {
/**
* User language definition
*/
this.lang = window._userdata && i18n[_userdata.user_lang] ?
i18n[_userdata.user_lang] : {}
;
/**
* Tabs creation
*/
this.build();
/**
* Override chatbox refresh
*/
this.overrideChatboxRefresh();
/**
* Override chatbox send
*/
this.overrideChatboxSend();
/**
* Initial refresh
*/
this.refresh();
};
/**
* Refresh data
*/
Tabs.prototype.refresh = function() {
if (!this.source) {
return this.context.chatbox.refresh(this.context.chatbox);
}
return this.context.chatbox.refresh(this.source);
};
/**
* Tabs creation
*/
Tabs.prototype.build = function() {
var self = this;
/**
* Style creation
*/
$('head', this.context.document)
.append($('<style>', { text: style }))
;
/**
* Parent HTML creation
*/
this.$tabs = $('<ul>', { id: 'chatbox_tabs' })
/**
* Tab change function
*/
.on('click', 'li', function() {
self.change($(this));
})
.appendTo($('#chatbox_header', this.context.document))
;
/**
* Tabs HTML creation
*/
$.each(config.tabs, function(index, item) {
/**
* Don't create hidden tabs
*/
if (item.hidden) {
return;
}
/**
* Tab creation
*/
var $elem = $('<li>', {
'text': self.t(item.label),
'data-index': index,
});
/**
* Make tab active
*/
if (item.active) {
self.active = item;
$elem.addClass('active');
}
/**
* Hide properties of "all" tab
*/
if (item.all) {
$elem.addClass('all');
}
self.$tabs.append($elem);
});
};
/**
* Tab change function
*/
Tabs.prototype.change = function($elem) {
/**
* Set the active tab
*/
this.active = config.tabs[~~$elem.data('index')];
/**
* Display the active tab
*/
this.$tabs.children('.active').removeClass('active');
$elem.addClass('active').removeClass('new-message');
this.refresh();
};
/**
* Notification
*/
Tabs.prototype.notify = function(message) {
var date = new Date();
this.source.messages.push({
userId: -10,
action: 'msg',
msgColor: 'green',
date: date.toLocaleDateString(),
datetime: date.toLocaleTimeString(),
time: date.getTime(),
msg: (this.active.all ? '' : '[' + this.active.label + '] ')
+ message.replace(/^\/sm\s/i, '')
,
});
};
/**
* Mark tab with new messages
*/
Tabs.prototype.setNewMessageStatus = function(tab) {
var self = this;
this.$tabs.children().each(function() {
var $this = $(this);
var text = $this.text();
if (
tab.label === text
|| self.t(tab.label) === text
) {
$this.addClass('new-message');
return false;
}
});
};
/**
* Chatbox override
*/
Tabs.prototype.overrideChatbox = function() {
var self = this;
var insertChatBoxNew = window.insertChatBoxNew;
window.insertChatBox = window.insertChatBoxNew = function() {
insertChatBoxNew.apply(this, arguments);
var chatbox = $('#frame_chatbox').get(0);
if (chatbox.readyState === 'complete') {
self.context = chatbox.contentWindow;
return self.init();
}
var onload = chatbox.onload;
chatbox.onload = function(event) {
if (onload) {
onload.apply(this, arguments);
}
self.context = event.target.contentWindow;
self.init();
};
};
};
/**
* Override chatbox refresh
*/
Tabs.prototype.overrideChatboxRefresh = function() {
var self = this;
var refresh = this.context.Chatbox.prototype.refresh;
this.context.Chatbox.prototype.refresh = function(data) {
/**
* Return if no new messages
*/
if (!data || !data.messages) {
return refresh.call(this, data);
}
/**
* Store the source data
*/
self.source = JSON.parse(JSON.stringify(data));
/**
* Remove hidden messages
*/
data.messages = $.grep(data.messages, function(message) {
return !config.hidden[message.action];
});
/**
* Capture new messages from other tabs
*/
var hasNewMessages = [];
var notifyNewMessages = true;
$.each(data.messages, function() {
var message = this;
$.each(config.tabs, function() {
if (message.msg.indexOf('[' + this.label + ']') === -1) {
return;
}
if (this.lastMessage < message.time) {
if (this.lastMessage === 0) {
notifyNewMessages = false;
}
if (notifyNewMessages) {
hasNewMessages.push(this);
}
this.lastMessage = message.time;
}
});
});
/**
* Display the all tab
*/
if (self.active.all) {
$.each(data.messages, function(index, message) {
message.msg = message.msg.replace(self.regex, function(text, match) {
return '[' + self.t(match) + ']';
});
});
return refresh.call(this, data);
}
/**
* Display the tab messages
*/
data.messages = $.grep(data.messages, function(message) {
if (message.action !== 'msg') {
return true;
}
if (message.msg.indexOf('[' + self.active.label + ']') !== -1) {
/**
* Remove tag from active and translate others
*/
message.msg = message.msg
.replace(self.active.regex, '$1')
.replace(self.regex, function(text, match) {
return '[' + self.t(match) + ']';
})
;
self.active.lastMessage = message.time;
return true;
}
return false;
});
/**
* Notify new messages from other tabs
*/
$.each($.unique(hasNewMessages), function() {
if (this.label === self.active.label) {
return;
}
self.setNewMessageStatus(this);
});
refresh.call(this, data);
};
};
/**
* Override chatbox send
*/
Tabs.prototype.overrideChatboxSend = function() {
var self = this;
var send = this.context.Chatbox.prototype.send;
this.context.Chatbox.prototype.send = function() {
/**
* Store the send input
*/
if (!self.$message) {
self.$message = $('#message', self.context.document);
}
var value = self.$message.val();
/**
* Change tab
*/
if (value.indexOf('/ct ') === 0) {
value = $.trim(value.replace(/^\/ct\s/i, ''));
var tabFound = false;
$.each(config.tabs, function(index) {
if (
this.label.toLowerCase() === value.toLowerCase()
|| self.t(this.label).toLowerCase() === value.toLowerCase()
) {
tabFound = true;
var $elem = self.$tabs
.children('[data-index="' + index + '"]')
;
if ($elem.length) {
self.change($elem);
return false;
}
self.$tabs.children('.active').removeClass('active');
self.active = this;
self.refresh();
return false;
}
});
if (!tabFound) {
self.notify(self.t('The tab "%s" doesn\'t exists.').replace('%s', value));
}
return self.refresh();
}
/**
* Notification command
*/
if (value.indexOf('/sm ') === 0) {
self.notify(value);
return self.refresh();
}
/**
* Add the tab tag to the input
*/
if (!self.active.all && value.indexOf('/') !== 0) {
value = '[' + self.active.label + '] ' + value;
}
self.$message.val(value);
send.apply(this, arguments);
};
};
return new Tabs();
} (jQuery,
/**
* Configuration
*/
{
/**
* Tabs configuration
* label : the tab label
* all : if the tab should show all the messages
* active : if the tab is active when first opening the chat
* hidden : if the tab is hidden
*/
tabs: [{
label: 'All',
all: true,
}, {
label: 'General',
active: true,
}, {
label: 'Animes',
}, {
label: 'Games',
}, {
label: 'Illuminati',
hidden: true,
}],
/**
* Hidden system messages
* connect : hide connection messages
* disconnect : hide disconnect messages
* timeout : hide timeout messages
*/
hidden: {
connect: true,
disconnect: true,
timeout: true,
},
},
/**
* Internationalization settings
*/
{
/**
* Portuguese
*/
pt: {
'All': 'Todos',
'General': 'Geral',
'Animes': 'Animes',
'Games': 'Jogos',
'Illuminati': 'Illuminati',
'The tab "%s" doesn\'t exists.': 'A aba "%s" não existe.',
},
},
/**
* Style
*/
[
'#chatbox_header {',
' position: relative;',
'}',
'',
'#chatbox_tabs {',
' position: absolute;',
' bottom: 0;',
' left: 180px;',
' list-style: none;',
' padding: 0 0 0 10px;',
' margin: 0;',
' overflow: hidden;',
'}',
'',
'#chatbox_tabs li {',
' float: left;',
' height: 24px;',
' line-height: 24px;',
' margin-right: 10px;',
' padding: 0 5px 0 20px;',
' border: 1px #fff solid;',
' border-radius: 3px 3px 0 0;',
' cursor: pointer;',
' font-family: Arial, sans-serif;',
' color: #fff;',
' border-bottom: none;',
' position: relative;',
'}',
'',
'#chatbox_tabs li:before {',
' content: " ";',
' position: absolute;',
' top: 50%;',
' left: 5px;',
' transform: translate(0, -50%);',
' background-color: #999;',
' width: 10px;',
' height: 10px;',
' border-radius: 50%;',
'}',
'',
'#chatbox_tabs li.new-message:before {',
' background-color: green;',
'}',
'',
'#chatbox_tabs li.all {',
' padding-left: 5px;',
'}',
'#chatbox_tabs li.all:before {',
' display: none;',
'}',
'',
'#chatbox_tabs li.active {',
' background-color: #fff;',
' color: #333;',
'}',
].join('\n')
));
Até mais.
PS: Já atualizei o tutorial com este novo código, obrigado.
Re: Chat em abas incompatível com comandos
Muito bom @RafaelS., mas há possibilidade do /clear limpar apenas o chat em que o comando for executado ?
Se não, podes fechar o tópico.
Se não, podes fechar o tópico.
Re: Chat em abas incompatível com comandos
@iScroll,
Infelizmente não tenho a possibilidade de realizar o que pediu.
A sua dúvida encontra-se resolvida?
Até mais.
Infelizmente não tenho a possibilidade de realizar o que pediu.
A sua dúvida encontra-se resolvida?
Até mais.
Re: Chat em abas incompatível com comandos
Tópico resolvidoMovido para "Questões resolvidas". |
tikky- Admineiro
- Membro desde : 13/01/2017
Mensagens : 7964
Pontos : 9219
Tópicos semelhantes
» Comandos do chatbox com abas
» [Resolvido] Comandos do chat
» Quais são os comandos de chat?
» Abas no chat
» Abas no Chat
» [Resolvido] Comandos do chat
» Quais são os comandos de chat?
» Abas no chat
» Abas no Chat
Fórum dos Fóruns :: Ajuda e atendimento ao utilizador :: Questões sobre códigos :: Questões resolvidas sobre códigos Javascript e jQuery
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos