Jump to content
  • 0

Конфликтуют js скрипты в Opera


Slunyavchik
 Share

Question

Всем привет! Прошу помощи, так как совсем отчаялся.

Проблема проявляется в браузере Opera(9.80 возможно и другие версии).

Суть проблемы:

Есть js редактор текста http://ckeditor.com/ проблема в том что именно в опере, не устанавливается курсор в поле ввода. Причём курсор начинает периодический появляться если несколько раз обновить страницу. Ошибка скорей всего не в редакторе а в js скрипте чата который видимо как то конфликтует со скриптом чата.

При отключении js скрипта чата, всё работает исправно.Чат так же написан на js. В остальных браузерах всё работает нормально.

После долгих мучений с js скриптом чата, решил попробовать установить другой редактор(http://imperavi.com/), не помгло.Так же глюки, так же в опере, только глюки чуть другие, не работает панель инструментов.

Исходник чата:


var Chat = {
user_id : null,
chat : null,
form : null,
tabs : null,
usercache : null,
server : null,
items : {},
base_url : null,
user_session : null,
user_name : null,
Event : null,
messages : null,
create : function(link) {
$.get(link, function(data) {
$('body').append(data);
})
},
init : function() {
this.chat = $('#chat_container');
if(!this.chat.length)
return false;

this.initGroups();
this.initTabs();
this.initForm();

this.chat.find('#chat_create_conference a').bind('click.chat', function() {
Chat.openConferenceForm();
});

this.chat.find('#chat_add_user_to_conference').bind('click.chat', function() {
Chat.openUsersList();
});
this.chat.find('#chat_remove_conference').bind('click.chat', function() {
Chat.liveConference();
});
this.chat.find('.chat_users_combo').chosen({no_results_text: "No results matched"});

this.chat.find('#chat_close_button').bind('click.chat', function() {
Chat.chat.hide();
});

$('body').append($('<div id="chat_open_link"><span>'+Chat.messages['Chat link']+'</span></a>').bind('click.chat', function() {
Chat.chat.toggle();
ChatScroll.init(Chat.chat.find('.chat_tabs'));
var pane = Chat.chat.find('.jspContainer').parent().jScrollPane({showArrows: true}).data('jsp');
if(pane) pane.reinitialise();
}));

this.chat.find('#chat_conference_log').bind('click.chat', function() {ChatMessage.getLogs();});

this.chat.draggable({cancel : ".chat_container_wrapper"});

this.usercache = Chat.user_session;
ChatServer.usercache = this.usercache;
ChatServer.init();
Chat.initCorners();
Chat.updateOnlines();
ChatScroll.init(this.chat.find('.chat_tabs'));
},
initCorners : function() {
this.chat.corner('5px');
this.chat.find('.chat_rooms .chat_header input').corner('3px');
this.chat.find('.chat_header').corner('top 5px');
this.tabs.find('li').corner('top 5px');
this.chat.find('.chat_content').corner('bl 5px');
this.chat.find('.chat_submit').corner('bottom 5px');
this.chat.find('.chat_form textarea').corner('5px');
this.chat.find('.chat_themes li, .chat_users li, .chat_users dt').corner('3px');

},
initGroups : function() {
this.chat.find('.chat_users dt').bind('click.chat', function() {Chat.openGroup(this);});

$('.chat_users', this.chat).delegate('li', 'dblclick', function() {
if($(this).find('input').val().split('_')[1] == Chat.user_id)
return false;
Chat.openRoom($(this).find('input').val(), $(this).text(), true);

if (window.getSelection)
window.getSelection().removeAllRanges();
else if (document.selection)
document.selection.empty();

});
$('.chat_themes', this.chat).delegate('li', 'dblclick', function() {
Chat.openRoom($(this).find('input').val(), $(this).find('.chat_conference_title').text(), true);

if (window.getSelection)
window.getSelection().removeAllRanges();
else if (document.selection)
document.selection.empty();

});

},
initTabs : function() {
this.tabs = this.chat.find('.chat_tabs ul');
//var c = this.tabs.parent().jcarousel();
this.tabs.find('li').bind('click.chat', function() {Chat.openTab($(this));});
},
initForm : function() {
this.chat.find('.chat_form form').bind('submit.chat', function() {ChatMessage.send(this);return false;});
this.chat.find('#chat_enter_send_input').bind('change.chat', function() {ChatMessage.enterSend(this);})
this.chat.find('.chat_form form textarea').bind('keyup.chat', function(e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
if(Chat.chat.find('#chat_enter_send_input').is(':checked') && keycode == 13) {
$(this).parents('form').trigger('submit');
return false;
}
})
},
openGroup : function(elem) {
dt = $(elem);
var dd = dt.siblings('dd');
var pane = dt.parents('.chat_all_users').jScrollPane({showArrows: true}).data('jsp');
if(dt.hasClass('chat_opened')) {
dd.slideUp('fast', function() {
dt.removeClass('chat_opened');
if(pane) pane.reinitialise();
});
} else {
dd.slideDown('fast', function() {
dt.addClass('chat_opened');
if(pane) pane.reinitialise();
});
}
},
openConferenceForm : function() {
var div = $('#chat_create_conference');
div.find('a').hide();
var form = $('<form method="post" action="">' +
'<input type="text" name="" value="" maxlength="50" placeholder="'+Chat.messages['Conference name']+'" />' +
'<input type="submit" value="'+Chat.messages['Create']+'" />' +
'<input type="button" value="'+Chat.messages['Cancel']+'" />' +
'</form>');
form.find('input[type=button]').click(function() {
div.find('form').remove();
div.find('a').show();
});
form.bind('submit.chat', function() {
if(form.find('input[type=text]').val() == '')
return false;
Chat.createConference(form.find('input[type=text]').val());
div.find('form').remove();
div.find('a').show();
return false;
});
div.append(form);
},
// Создает новую конференцию при тыке на "New conference"
createConference : function(text) {
$.post(
Chat.base_url + '/room/open',
{text : text},
function(data) {
var id = data.html_id.split('chat_')[1];
var li = $('<li><span class="chat_count">1</span><input type="hidden" value="'+id+'"><span class="chat_conference_title">'+data.title+'</span></li>');
Chat.chat.find('.chat_themes ul').append(li);
var pane = Chat.chat.find('.chat_themes').jScrollPane({showArrows: true}).data('jsp');
if(pane) pane.reinitialise();
Chat.createRoom(data.title, data, true);
},
'json'
);
},
/*
* Открывает комнату.
* Проверяет, существует ли в списке.
* Если существует - открывает вкладку.
* Если нет - создает комнату и открывает вкладку.
*/
openRoom : function(html_id, text, opened) {
var html_id = 'chat_' + html_id;
if(typeof(this.items[html_id]) != 'undefined') {
this.openTab(this.items[html_id]);
} else {
$.get(
Chat.base_url + '/room/open',
{'channel' : html_id},
function(data) {
Chat.createRoom(text, data, opened);
},
'json'
);
}
},
// Создает комнату, если ее не существует
createRoom : function(title, data, opened) {
var html_id = data.html_id;
this.items[html_id] = $('<li onclick="Chat.openTab($(this));" id="'+html_id+'_tab">'+title+'<a href="javascript:void(0);" class="tab_close" onclick="Chat.closeTabClick(this, event);"></a></li>')
this.tabs.append(this.items[html_id]);
var messages = $('<div class="chat_messages" id="chat_'+data.channel+'"><div class="content"></div></div>');
messages.appendTo(this.chat.find('.chat_messages_container'));
if(/^chat_conference/.test(html_id)) {
this.createUsersToConference(data.users, html_id);
}
for(var n in data.messages)
ChatMessage.insertMessage(data.messages[n], true);
Chat.initCorners();
if(opened)
this.openTab(this.items[html_id]);
else {
ChatScroll.init(this.chat.find('.chat_tabs'));
}

},
/*
* Создает список пользователей для конференции
*/
createUsersToConference : function(users, html_id) {
var ul = $('<ul id="'+html_id+'_users"></ul>');
for(var n in users) {
var li = $('<li class="chat_'+users[n].status+(users[n].id == this.user_id ? ' chat_disabled' : '')+'"><span></span><input type="hidden" value="private_'+users[n].id+'" />'+users[n].name+'</li>');
li.appendTo(ul);
}
Chat.chat.find('.chat_conference_users .jspPane').append(ul);
},
openTab : function(tab) {
if(tab.hasClass('chat_new_message'))
tab.removeClass('chat_new_message');
this.chat.find('.chat_tabs li').removeClass('active');
tab.addClass('active');
if(tab.index() == 0) {
this.chat.find('.chat_content .chat_conferences').hide();
this.chat.find('.chat_content .chat_themes').show();
this.chat.find('#chat_conference_log').hide();
} else {
this.chat.find('.chat_content .chat_themes').hide();
this.chat.find('.chat_content .chat_conferences').show();
this.chat.find('.chat_content .chat_messages_container > div').hide();
this.chat.find('#chat_conference_log').show();
var messages = this.chat.find('.chat_content .chat_messages_container > div.chat_messages:eq('+(tab.index() - 1)+')');
messages.show();
var pane = messages.jScrollPane({showArrows: true}).data('jsp');
pane.reinitialise();
pane.scrollToBottom();
}
if(/^chat_conference/.test(tab.attr('id'))) {
this.chat.find('.chat_conference_menu').show();
this.chat.find('.chat_conference_users').show();
var html_id = tab.attr('id').split('_tab')[0];
this.chat.find('.chat_conference_users ul').hide();
var cc = this.chat.find('.chat_conference_users #'+html_id+'_users').show();
this.chat.find('.chat_all_users').hide();
this.chat.find('.chat_conference_users').show();
var pane = $('.chat_conference_users').jScrollPane({showArrows: true}).data('jsp');
pane.reinitialise();
pane.scrollToBottom();
} else {
this.chat.find('.chat_conference_menu').hide();
this.chat.find('.chat_conference_users > ul').hide();
this.chat.find('.chat_all_users').show();
this.chat.find('.chat_conference_users').hide();
var pane = $('.chat_themes').jScrollPane({showArrows: true}).data('jsp');
pane.reinitialise();
}
if(this.tabs.find('.chat_new_message').size() == 0)
$('#chat_open_link').removeClass('chat_blink');
Chat.chat.find('.chat_form textarea').focus();
ChatScroll.init(this.chat.find('.chat_tabs'));
ChatScroll.goTo(tab);
},
closeTabClick : function(link, e) {
e = e || window.event;
e.cancelBubble = true
if (e.stopPropagation) e.stopPropagation();
this.closeTab($(link).parent());
},
closeTab : function(tab, remove_from_conferences) {
var html_id = tab.attr('id').split('_tab')[0];
var id = html_id.split('chat_')[1];
delete this.items[html_id];
var messages = this.chat.find('.chat_content .chat_messages_container > div.chat_messages:eq('+(tab.index() - 1)+')');
var cache = messages.attr('id').split('_')[1];
messages.remove();
if(remove_from_conferences) {
this.chat.find('.chat_themes').find('input[value='+id+']').parent().remove();
var pane = this.chat.find('.chat_themes').jScrollPane({showArrows: true}).data('jsp');
pane.reinitialise();
}
if(/^chat_conference/.test(html_id)) {
this.chat.find('.chat_conference_users #'+html_id+'_users').remove();
}
this.openTab(this.tabs.find('li:eq('+(tab.index() - 1)+')'));
tab.remove();
$.post(Chat.base_url + '/room/close', {cache : cache});
ChatScroll.init(this.chat.find('.chat_tabs'));
},
openUsersList : function() {
var conference_id = this.tabs.find('li.active').attr('id').split('_')[2];
$.get(
Chat.base_url + '/room/getConferenceUsers',
{conference_id : conference_id},
function(data) {
select = Chat.chat.find('.chat_users_combo');
select.empty();
var isset = false;
for(var n in data) {
isset = true;
if(typeof(data[n]) == 'object') {
var optgroup = $('<optgroup></optgroup>').attr('label', n);
for(var j in data[n]) {
optgroup.append('<option value="'+j+'">'+data[n][j]+'</option>');
}
select.append(optgroup);
} else {
select.append('<option value="'+n+'">'+data[n]+'</option>');
}
}
if(isset === false) {
select.append('<optgroup label="No results"><option></option></optgroup>')
}
select.trigger("liszt:updated");
$('#'+select.attr('id')+'_chzn').trigger('mousedown');
},
'json'
);
},
appendConferenceUser : function(select) {
var conference_id = this.tabs.find('li.active').attr('id').split('_')[2];
$.get(
Chat.base_url + '/room/addConferenceUser',
{user_id : $(select).val(), conference_id : conference_id}
);
},
/*
* Тык на кнопку "Покинуть обсуждение"
*/
liveConference : function() {
var tab = this.tabs.find('li.active');
var conference_id = tab.attr('id').split('_')[2];
$.get(
Chat.base_url + '/room/removeUserFromConference',
{conference_id : conference_id},
function() {
Chat.closeTab(tab, true);
}
);
},
changeConferenceUserCount : function(data, difference) {
var room_id = data.html_id.split('chat_')[1];
var count = this.chat.find('.chat_themes input[value='+room_id+']').siblings('span.chat_count').text();
var newCount = parseInt(count) + difference;
var ul = this.chat.find('#'+data.html_id+'_users');
var pane = $('.chat_conference_users').jScrollPane({showArrows: true}).data('jsp');
if(count > newCount) {
ul.find('input[value=private_'+data.user.id+']').parent().remove();
} else {
var items = {};
var params = {};
ul.find('li').each(function(i) {
var id = $(this).find('input').val().split('_')[1];
items[id] = $(this).text();
params[id] = {status : ($(this).hasClass('chat_online') ? 'online' : 'offline')};
});
items[data.user.id] = data.user.name;
params[data.user.id] = {status : data.user.status};
ul.empty();
asort(items);
for(var n in items) {
var li = $('<li class="chat_'+params[n].status+(n == this.user_id ? ' chat_disabled' : '')+'"><span></span><input type="hidden" value="private_'+n+'" />'+items[n]+'</li>');
li.appendTo(ul);
}
}
Chat.initCorners();
if(pane) pane.reinitialise();
this.chat.find('.chat_themes input[value='+room_id+']').siblings('span.chat_count').text(newCount);
},
updateOnlines : function() {
var size = this.chat.find('.chat_all_users li.chat_online').size();
this.chat.find('.chat_users .chat_header span').text(parseInt(size));
}
}

var ChatServer = {
server : null,
host : null,
namespace : null,
usercache : null,
init : function(usercache) {
this.updateStatus();
this.server = new Dklab_Realplexor(this.host, this.namespace);
this.server.subscribe(this.usercache, function(result, id, cursor) {
ChatServer.appendServerData(result, id);
});
this.server.execute();
},
updateStatus : function() {
$.get(Chat.base_url + '/room/updateStatus', {}, function() {
setTimeout(function() {ChatServer.updateStatus();}, 20000);
});
},
appendServerData : function(data, id) {
if(data.action == 'message') {
ChatMessage.appendMessage(data, id);
} else if(data.action == 'notification') {
if(data.event == 'remove_from_conference') {
var text = data.user.name + ' '+Chat.messages['has left']+'.';
Chat.changeConferenceUserCount(data, -1);
} else if(data.event == 'join_to_conference') {
var text = data.user.name + ' '+Chat.messages['has join']+'.';
Chat.changeConferenceUserCount(data, 1);
} else if(data.event == 'invite_to_conference') {
Chat.createRoom(data.title, data);
var id = data.html_id.split('chat_')[1];
var li = $('<li><span class="chat_count">'+this.objectSize(data.users)+'</span><input type="hidden" value="'+id+'"><span class="chat_conference_title">'+data.title+'</span></li>');
Chat.chat.find('.chat_themes ul').append(li);
var pane = Chat.chat.find('.chat_themes').jScrollPane({showArrows: true}).data('jsp');
if(pane) pane.reinitialise();
var text = 'You have been invited to the conference';
}
ChatMessage.insertNotification(data.channel, text, data.time);
} else if(data.action == 'users_status') {
for(var n in data.users) {
var user = data.users[n];
if(user.status == 1)
Chat.chat.find('input[value=private_'+user.id+']').parent().removeClass('chat_offline').addClass('chat_online');
else
Chat.chat.find('input[value=private_'+user.id+']').parent().addClass('chat_offline').removeClass('chat_online');
Chat.updateOnlines();
}
}
},
objectSize : function(o) {
var c = 0;
for (var k in o)
if (o.hasOwnProperty(k)) ++c;
return c;
}
}

var ChatMessage = {
appendMessage : function(data) {
if(Chat.chat.find('#chat_'+data.channel).size() == 0) {
Chat.createRoom(data.title, data);
}
this.insertMessage(data);
},
insertMessage : function(data, no_blink, begin) {
var time = this.getDateString(data.time);
var html = '<div class="chat_message_head"><span class="chat_message_time">'+time+'</span><span class="chat_message_user">'+data.user.name+'</span><span class="chat_message_company">'+data.user.company+'</span></div>';
html += '<p>'+data.text+'</p>';
var div = Chat.chat.find('#chat_'+data.channel);
if(!begin)
div.find('.content').append('<div class="chat_message">'+html+'</div>');
else
div.find('.content').prepend('<div class="chat_message">'+html+'</div>');
if(!no_blink)
this.blinkTab(data.html_id);
var pane = div.jScrollPane({showArrows: true}).data('jsp');
if(pane)
pane.reinitialise();
pane.scrollToBottom();
},
insertNotification : function(channel, text, time) {
var time = this.getDateString(time);
var html = '<div class="chat_message_head"><span class="chat_message_time">'+time+'</span> '+text+'</div>';
Chat.chat.find('#chat_'+channel).find('.content').append('<div class="chat_message">'+html+'</div>');
},
getLogs : function() {
var tab = Chat.tabs.find('li.active');
var channel = tab.attr('id').split('_tab')[0];
var div = Chat.chat.find('.chat_content .chat_messages_container > div.chat_messages:eq('+(tab.index() - 1)+')');
var count = div.find('.chat_message').size();
$.get(
Chat.base_url + '/room/getLogs',
{channel : channel, count : count},
function(data) {
for(var n in data)
ChatMessage.insertMessage(data[n], true, true);
},
'json'
);
},
getDateString : function(time) {
var date = new Date(time * 1000);
var str = date.getDate() + '.' + date.getMonth() + '.' + date.getFullYear() + ' ' + date.getHours()+':'+(date.getMinutes().toString().length == 1 ? '0' + date.getMinutes().toString() : date.getMinutes());
return str;
},
send : function(form) {
this.form = $(form);
var textarea = $('textarea', form);
var text = textarea.val();
if(text == '')
return false;

var channel = Chat.chat.find('.chat_messages_container > div.chat_messages:eq('+(Chat.tabs.find('li.active').index() - 1)+')').attr('id').split('_')[1];
$.get(form.action, {channel : channel, data : text});
textarea.val('');
},
blinkTab : function(html_id) {
var tab = Chat.chat.find('#'+html_id+'_tab');
if(tab.hasClass('active')) {
return false;
} else {
if(tab.size() > 0)
$('#chat_open_link').addClass('chat_blink');
tab.addClass('chat_new_message');
}
},
enterSend : function(elem) {
$.get(
Chat.base_url + '/room/enterSend',
{value : $(elem).is(':checked') ? 1 : 0}
);
}
}

function asort(arr, sort_function) {
if (sort_function == undefined)
sort_function = function(a, { return a - b }

var b = [];
for (var i in arr)
b.push([i, arr[i]]);
b.sort(function(a, { return sort_function(a[1], b[1]) });

c = {};
for (var i in
c[b[i][0]] = b[i][1];
return c;
}

var ChatScroll = {
wrapper : null,
ul : null,
items : null,
arrows : {
prev : null,
next : null,
},
init : function(elem) {
this.ul = elem.find('ul');
this.wrapper = $(elem.children('div'));
var width = 0;
this.initArrows();
this.ul.width('auto');
this.ul.find('li').each(function() {
width += parseInt(this.offsetWidth) + parseInt($(this).css('marginLeft')) + parseInt($(this).css('marginRight'));
});
this.ul.css('width', width);
this.checkTabs();
},
initArrows : function() {
if(this.arrows.prev)
return false;
var $this = this;
this.wrapper.siblings('a').each(function() {
if($(this).hasClass('chat_prev'))
$this.arrows.prev = $(this);
else
$this.arrows.next = $(this);
});
this.arrows.prev.bind('click.chat', function() {$this.move(1, $(this));return false;});
this.arrows.next.bind('click.chat', function() {$this.move(-1, $(this));return false;});
},
setArrowsState : function(arrows) {
for(var n in arrows) {
if(arrows[n] == false){
this.arrows[n].addClass('chat_disabled');
} else {
this.arrows[n].removeClass('chat_disabled');
}
}
},
move : function(direction, arrow) {
var $this = this;
if(arrow && arrow.hasClass('chat_disabled'))
return false;
var wrapper_width = this.wrapper.get(0).offsetWidth;
var diff = parseInt($this.ul.css('marginLeft')) + (this.wrapper.get(0).offsetWidth / 2 * direction);

if(diff * direction > this.ul.width() - this.wrapper.get(0).offsetWidth)
diff = (this.ul.width() - this.wrapper.get(0).offsetWidth) * direction;
if(diff > 0)
diff = 0;
this.ul.css('marginLeft', diff);
this.checkTabs();
},
checkTabs : function()
{
var states = {prev : false, next : false};
if(this.ul.width() > this.wrapper.get(0).offsetWidth)
states.next = true;
if(parseInt(this.ul.css('marginLeft')) < 0)
states.prev = true;
if(parseInt(this.ul.css('marginLeft')) == (this.ul.width() - this.wrapper.get(0).offsetWidth) * -1)
states.next = false;
this.setArrowsState(states);
},
goTo : function(tab) {
var left = 0;
this.ul.children('li').each(function() {
left += parseInt(this.offsetWidth);
if(this == tab.get(0))
return false;
});
var diff = (left - (this.wrapper.get(0).offsetWidth / 2)) * -1;
if(diff < this.wrapper.get(0).offsetWidth - this.ul.width())
diff = this.wrapper.get(0).offsetWidth - this.ul.width();
if(diff > this.ul.width() - this.wrapper.get(0).offsetWidth || this.ul.width() < this.wrapper.get(0).offsetWidth)
diff = 0;
if(diff > 0)
diff = 0;
this.ul.css('marginLeft', diff);
this.checkTabs();
}
}

Спасибо заранее!

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy