Completely rewrite Chat's JavaScript files

This commit is contained in:
Dmitriy Simushev 2012-12-27 14:07:11 +00:00
parent 1565458c26
commit 053837d069
251 changed files with 4340 additions and 6848 deletions

View File

@ -162,7 +162,7 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) {
$token = verifyparam( "token", "/^\d{1,8}$/");
$threadid = verifyparam( "thread", "/^\d{1,8}$/");
$level = verifyparam( "level", "/^(ajaxed|simple|old)$/");
$level = verifyparam( "level", "/^(ajaxed|old)$/");
$thread = Thread::load($threadid, $token);
if (! $thread) {
@ -178,11 +178,9 @@ if( $pparam == "mailthread" ) {
// Load JavaScript plugins and JavaScripts, CSS files required by them
$page['additional_css'] = get_additional_css('chatWindow');
$page['additional_js'] = get_additional_js('chatWindow');
$page['js_plugins'] = get_js_plugins('chatWindow');
$page['js_plugin_options'] = get_js_plugin_options('chatWindow');
// Expand page
expand("styles/dialogs", getchatstyle(), "chat.tpl");
} else if( $level == "simple" ) {
expand("styles/dialogs", getchatstyle(), "chatsimple.tpl");
} else if( $level == "old" ) {
expand("styles/dialogs", getchatstyle(), "nochat.tpl");
}

View File

@ -0,0 +1,12 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,j){var f=new j.Marionette.Application;f.addRegions({controlsRegion:"#controls-region",avatarRegion:"#avatar-region",messagesRegion:a.Regions.Messages,statusRegion:"#status-region",messageFormRegion:"#message-form-region",soundRegion:"#sound-region"});f.addInitializer(function(d){var g=a.Objects,c=a.Objects.Models,b=a.Objects.Models.Controls,h=a.Objects.Models.Status;g.server=new a.Server(d.server);g.thread=new a.Thread(d.thread);c.user=new a.Models.User(d.user);c.page=new a.Models.Page(d.page);
var e=new a.Collections.Controls;c.user.get("isAgent")||(b.userName=new a.Models.UserNameControl({weight:220}),e.push(b.userName),b.sendMail=new a.Models.SendMailControl({weight:200,link:d.links.mailLink}),e.push(b.sendMail));c.user.get("isAgent")&&(b.redirect=new a.Models.RedirectControl({weight:200,link:d.links.redirectLink}),e.push(b.redirect),b.history=new a.Models.HistoryControl({weight:180,link:d.links.historyLink}),e.push(b.history));b.sound=new a.Models.SoundControl({weight:160});e.push(b.sound);
b.refresh=new a.Models.RefreshControl({weight:140});e.push(b.refresh);d.links.sslLink&&(b.secureMode=new a.Models.SecureModeControl({weight:120,link:d.links.sslLink}),e.push(b.secureMode));b.close=new a.Models.CloseControl({weight:100});e.push(b.close);g.Collections.controls=e;f.controlsRegion.show(new a.Views.ControlsCollection({collection:e}));h.message=new a.Models.StatusMessage({hideTimeout:5E3});h.typing=new a.Models.StatusTyping({hideTimeout:5E3});g.Collections.status=new a.Collections.Status([h.message,
h.typing]);f.statusRegion.show(new a.Views.StatusCollection({collection:g.Collections.status}));c.user.get("isAgent")||(c.avatar=new a.Models.Avatar,f.avatarRegion.show(new a.Views.Avatar({model:c.avatar})));g.Collections.messages=new a.Collections.Messages;c.messageForm=new a.Models.MessageForm(d.messageForm);f.messageFormRegion.show(new a.Views.MessageForm({model:c.messageForm}));f.messagesRegion.show(new a.Views.MessagesCollection({collection:g.Collections.messages}));c.sound=new a.Models.Sound;
f.soundRegion.show(new a.Views.Sound({model:c.sound}));g.server.runUpdater()});a.Application=f})(Mibew,Backbone);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Collections.Controls=b.Collection.extend({comparator:function(a){return a.get("weight")}})})(Mibew,Backbone);

View File

@ -0,0 +1,10 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(b,d,c){b.Collections.Messages=d.Collection.extend({model:b.Models.Message,initialize:function(){b.Objects.server.callFunctionsPeriodically(c.bind(this.updateFunctionBuilder,this),c.bind(this.updateChatState,this));b.Objects.server.registerFunction("updateMessages",c.bind(this.apiUpdateMessages,this))},apiUpdateMessages:function(a){a.lastId&&(b.Objects.thread.lastId=a.lastId);for(var e=[],c=0,d=a.messages.length;c<d;c++)e.push(new b.Models.Message(a.messages[c]));0<e.length&&this.add(e)},
updateFunctionBuilder:function(){var a=b.Objects.thread,c=b.Objects.Models.user;return[{"function":"update",arguments:{"return":{typing:"typing",canPost:"canPost"},references:{},threadId:a.threadId,token:a.token,lastId:a.lastId,typed:c.get("typing"),user:!c.get("isAgent")}}]},updateChatState:function(a){a.errorCode?b.Objects.Models.Status.message.setMessage(a.errorMessage||"refresh failed"):(a.typing&&b.Objects.Models.Status.typing.show(),b.Objects.Models.user.set({canPost:a.canPost||!1}))},add:function(){var a=
Array.prototype.slice.apply(arguments),a=d.Collection.prototype.add.apply(this,a);this.trigger("multiple:add");return a}})})(Mibew,Backbone,_);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Collections.Status=b.Collection.extend({comparator:function(a){return a.get("weight")}})})(Mibew,Backbone);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(b){b.registerHelper("allowTags",function(a){a=a.replace(/&lt;(span|strong)&gt;(.*?)&lt;\/\1&gt;/g,"<$1>$2</$1>");a=a.replace(/&lt;span class=&quot;(.*?)&quot;&gt;(.*?)&lt;\/span&gt;/g,'<span class="$1">$2</span>');return new b.SafeString(a)})})(Handlebars);

View File

@ -5,4 +5,4 @@
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
var PluginManager=function(){var b={};this.addPlugin=function(a,c){b[a]=c};this.getPlugin=function(a){return b[a]?b[a]:!1}};
(function(a){a.Regions={};a.Objects.Models.Controls={};a.Objects.Models.Status={}})(Mibew);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Models.Avatar=a.Models.Base.extend({defaults:{imageLink:!1},initialize:function(){a.Objects.server.registerFunction("setupAvatar",b.bind(this.apiSetupAvatar,this))},apiSetupAvatar:function(a){a.imageLink&&this.set({imageLink:a.imageLink})}})})(Mibew,_);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a){a.Models.Control=a.Models.Base.extend({defaults:{title:"",weight:0}})})(Mibew);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a){a.Models.CloseControl=a.Models.Control.extend({getModelType:function(){return"CloseControl"},closeThread:function(){var b=a.Objects.thread;a.Objects.server.callFunctions([{"function":"close",arguments:{references:{},"return":{closed:"closed"},threadId:b.threadId,token:b.token,lastId:b.lastId,user:!a.Objects.Models.user.get("isAgent")}}],function(b){b.closed?window.close():a.Objects.Models.Status.message.setMessage(b.errorMessage||"Cannot close")},!0)}})})(Mibew);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Models.HistoryControl=a.Models.Control.extend({defaults:b.extend({},a.Models.Control.prototype.defaults,{link:!1}),getModelType:function(){return"HistoryControl"}})})(Mibew,_);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Models.RedirectControl=a.Models.Control.extend({defaults:b.extend({},a.Models.Control.prototype.defaults,{link:!1}),getModelType:function(){return"RedirectControl"}})})(Mibew,_);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a){a.Models.RefreshControl=a.Models.Control.extend({getModelType:function(){return"RefreshControl"},refresh:function(){a.Objects.server.restartUpdater()}})})(Mibew);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Models.SecureModeControl=a.Models.Control.extend({defaults:b.extend({},a.Models.Control.prototype.defaults,{link:!1}),getModelType:function(){return"SecureModeControl"}})})(Mibew,_);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Models.SendMailControl=a.Models.Control.extend({defaults:b.extend({},a.Models.Control.prototype.defaults,{link:!1}),getModelType:function(){return"SendMailControl"}})})(Mibew,_);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Models.SoundControl=a.Models.Control.extend({defaults:b.extend({},a.Models.Control.prototype.defaults,{enabled:!0}),getModelType:function(){return"SoundControl"}})})(Mibew,_);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(b){b.Models.UserNameControl=b.Models.Control.extend({getModelType:function(){return"UserNameControl"},changeName:function(a){var c=b.Objects.Models.user,d=b.Objects.thread,e=c.get("name");a&&e!=a&&(b.Objects.server.callFunctions([{"function":"rename",arguments:{references:{},"return":{},threadId:d.threadId,token:d.token,name:a}}],function(a){a.errorCode&&(b.Objects.Models.Status.message.setMessage(a.errorMessage||"Cannot rename"),c.set({name:e}))},!0),c.set({name:a}))}})})(Mibew);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a){a.Models.Message=a.Models.Base.extend({defaults:{message:""}})})(Mibew);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a){a.Models.MessageForm=a.Models.Base.extend({defaults:{predefinedAnswers:[],ignoreCtrl:!1},postMessage:function(e){var b=a.Objects.thread,c=a.Objects.Models.user;if(c.get("canPost")){this.trigger("before:post",this);var d=this;a.Objects.server.callFunctions([{"function":"post",arguments:{references:{},"return":{},message:e,threadId:b.threadId,token:b.token,user:!c.get("isAgent")}}],function(){d.trigger("after:post",d)},!0)}}})})(Mibew);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(b,c){b.Models.Status=b.Models.Base.extend({defaults:{visible:!0,weight:0,hideTimeout:4E3,title:""},initialize:function(){this.hideTimer=null},autoHide:function(a){a=a||this.get("hideTimeout");this.hideTimer&&clearTimeout(this.hideTimer);this.hideTimer=setTimeout(c.bind(function(){this.set({visible:!1})},this),a)}})})(Mibew,_);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Models.StatusMessage=a.Models.Status.extend({defaults:b.extend({},a.Models.Status.prototype.defaults,{message:"",visible:!1}),getModelType:function(){return"StatusMessage"},setMessage:function(a){this.set({message:a,visible:!0});this.autoHide()}})})(Mibew,_);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Models.StatusTyping=a.Models.Status.extend({defaults:b.extend({},a.Models.Status.prototype.defaults,{visible:!1,hideTimeout:2E3}),getModelType:function(){return"StatusTyping"},show:function(){this.set({visible:!0});this.autoHide()}})})(Mibew,_);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Regions.Messages=b.Marionette.Region.extend({el:"#messages-region",onShow:function(a){a.on("after:item:added",this.scrollToBottom,this)},scrollToBottom:function(){this.$el.scrollTop(this.$el.prop("scrollHeight"))}})})(Mibew,Backbone);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b,c){a.Views.Avatar=b.Marionette.ItemView.extend({template:c.templates.avatar,className:"avatar",modelEvents:{change:"render"}})})(Mibew,Backbone,Handlebars);

View File

@ -0,0 +1,9 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(b,c,d){b.Views.Control=c.Marionette.ItemView.extend({template:d.templates.control,modelEvents:{change:"render"},events:{mouseover:"mouseOver",mouseleave:"mouseLeave"},attributes:function(){var a=[];a.push("control");this.className&&(a.push(this.className),this.className="");var b=this.getDashedControlType();b&&a.push(b);return{"class":a.join(" ")}},mouseOver:function(){var a=this.getDashedControlType();this.$el.addClass("active"+(a?"-"+a:""))},mouseLeave:function(){var a=this.getDashedControlType();
this.$el.removeClass("active"+(a?"-"+a:""))},getDashedControlType:function(){"undefined"==typeof this.dashedControlType&&(this.dashedControlType=b.Utils.toDashFormat(this.model.getModelType())||"");return this.dashedControlType}})})(Mibew,Backbone,Handlebars);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,c,d){a.Views.CloseControl=a.Views.Control.extend({template:c.templates.close_control,events:d.extend({},a.Views.Control.prototype.events,{click:"close"}),close:function(){var b=a.Localization.get("chat.close.confirmation");(!1===b||confirm(b))&&this.model.closeThread()}})})(Mibew,Handlebars,_);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a){a.Views.ControlsCollection=a.Views.CollectionBase.extend({itemView:a.Views.Control,className:"controls-collection"})})(Mibew);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(b,d,e){b.Views.HistoryControl=b.Views.Control.extend({template:d.templates.history_control,events:e.extend({},b.Views.Control.prototype.events,{click:"showHistory"}),showHistory:function(){var c=b.Objects.Models.user,a=this.model.get("link");c.get("isAgent")&&a&&(c=this.$el.find(".control-config").eq(0).data("win-params"),a=a.replace("&amp;","&","g"),a=window.open(a,"UserHistory",c),null!==a&&(a.focus(),a.opener=window))}})})(Mibew,Handlebars,_);

View File

@ -0,0 +1,9 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,d,e){a.Views.RedirectControl=a.Views.Control.extend({template:d.templates.redirect_control,events:e.extend({},a.Views.Control.prototype.events,{click:"redirect"}),initialize:function(){a.Objects.Models.user.on("change",this.render,this)},serializeData:function(){var b=this.model.toJSON();b.user=a.Objects.Models.user.toJSON();return b},redirect:function(){var b=a.Objects.Models.user;if(b.get("isAgent")&&b.get("canPost")&&(b=this.model.get("link"))){var c=a.Objects.Models.page.get("style");
window.location.href=b.replace(/\&amp\;/g,"&")+(c?"&style="+c:"")}}})})(Mibew,Handlebars,_);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b,c){a.Views.RefreshControl=a.Views.Control.extend({template:b.templates.refresh_control,events:c.extend({},a.Views.Control.prototype.events,{click:"refresh"}),refresh:function(){this.model.refresh()}})})(Mibew,Handlebars,_);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,d,e){a.Views.SecureModeControl=a.Views.Control.extend({template:d.templates.secure_mode_control,events:e.extend({},a.Views.Control.prototype.events,{click:"secure"}),secure:function(){var b=this.model.get("link");if(b){var c=a.Objects.Models.page.get("style");window.location.href=b.replace(/\&amp\;/g,"&")+(c?"&style="+c:"")}}})})(Mibew,Handlebars,_);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(b,c,e){b.Views.SendMailControl=b.Views.Control.extend({template:c.templates.send_mail_control,events:e.extend({},b.Views.Control.prototype.events,{click:"sendMail"}),sendMail:function(){var a=this.model.get("link");if(a){var c=this.$el.find(".control-config").eq(0).data("win-params"),d=b.Objects.Models.page.get("style"),a=a.replace(/\&amp\;/g,"&")+(d?"&style="+d:""),a=window.open(a,"ForwardMail",c);null!==a&&(a.focus(),a.opener=window)}}})})(Mibew,Handlebars,_);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b,c){a.Views.SoundControl=a.Views.Control.extend({template:b.templates.sound_control,events:c.extend({},a.Views.Control.prototype.events,{click:"toggle"}),toggle:function(){this.model.set({enabled:!this.model.get("enabled")})}})})(Mibew,Handlebars,_);

View File

@ -0,0 +1,9 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(b,c,d){b.Views.UserNameControl=b.Views.Control.extend({template:c.templates.user_name_control,events:d.extend({},b.Views.Control.prototype.events,{"click .user-name-control-set":"changeName","click .user-name-control-change":"showNameInput","keydown #user-name-control-input":"inputKeyDown"}),ui:{nameInput:"#user-name-control-input"},initialize:function(){b.Objects.Models.user.on("change:name",this.hideNameInput,this);this.nameInput=b.Objects.Models.user.get("defaultName")},serializeData:function(){var a=
this.model.toJSON();a.user=b.Objects.Models.user.toJSON();a.nameInput=this.nameInput;return a},inputKeyDown:function(a){a=a.which;(13==a||10==a)&&this.changeName()},hideNameInput:function(){this.nameInput=!1;this.render()},showNameInput:function(){this.nameInput=!0;this.render()},changeName:function(){var a=this.ui.nameInput.val();this.model.changeName(a)}})})(Mibew,Handlebars,_);

View File

@ -0,0 +1,9 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(c,d,e){var f={"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},g=/[&<>'"`]/g;c.Views.Message=d.Marionette.ItemView.extend({template:e.templates.message,className:"message",modelEvents:{change:"render"},serializeData:function(){var a=this.model.toJSON(),b=this.model.get("kind");a.allowFormatting=b!=this.KIND_USER&&b!=this.KIND_AGENT;a.kindName=this.kindToString(b);a.message=this.escapeString(a.message);return a},kindToString:function(a){return a==this.KIND_USER?"user":
a==this.KIND_AGENT?"agent":a==this.KIND_FOR_AGENT?"hidden":a==this.KIND_INFO?"inf":a==this.KIND_CONN?"conn":a==this.KIND_EVENTS?"event":""},escapeString:function(a){return a.replace(g,function(a){return f[a]||"&amp;"})},KIND_USER:1,KIND_AGENT:2,KIND_FOR_AGENT:3,KIND_INFO:4,KIND_CONN:5,KIND_EVENTS:6,KIND_AVATAR:7})})(Mibew,Backbone,Handlebars);

View File

@ -0,0 +1,11 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(b,d,e){b.Views.MessageForm=d.Marionette.ItemView.extend({template:e.templates.message_form,events:{"click #send-message":"postMessage","keydown #message-input":"messageKeyDown","keyup #message-input":"checkUserTyping","change #message-input":"checkUserTyping","change #predefined":"selectPredefinedAnswer","focus #message-input":"setFocus","blur #message-input":"dropFocus"},modelEvents:{change:"render"},ui:{message:"#message-input",send:"#send-message",predefinedAnswer:"#predefined"},initialize:function(){b.Objects.Models.user.on("change:canPost",
this.render,this)},serializeData:function(){var a=this.model.toJSON();a.user=b.Objects.Models.user.toJSON();return a},postMessage:function(){var a=this.ui.message.val();""!=a&&(this.disableInput(),this.model.postMessage(a));b.Objects.Collections.messages.on("multiple:add",this.postMessageComplete,this)},messageKeyDown:function(a){var c=a.which;a=a.ctrlKey;(13==c&&(a||this.model.get("ignoreCtrl"))||10==c)&&this.postMessage()},enableInput:function(){this.ui.message.removeAttr("disabled")},disableInput:function(){this.ui.message.attr("disabled",
"disabled")},clearInput:function(){this.ui.message.val("").change()},postMessageComplete:function(){this.clearInput();this.enableInput();this.focused&&this.ui.focus();b.Objects.Collections.messages.off("multiple:add",this.postMessageComplete,this)},selectPredefinedAnswer:function(){var a=this.ui.message,c=this.ui.predefinedAnswer,b=c.get(0).selectedIndex;b&&(a.val(this.model.get("predefinedAnswers")[b-1].full).change(),a.focus(),c.get(0).selectedIndex=0)},checkUserTyping:function(){var a=b.Objects.Models.user,
c=""!=this.ui.message.val();c!=a.get("typing")&&a.set({typing:c})},setFocus:function(){this.focused=!0},dropFocus:function(){this.focused=!1}})})(Mibew,Backbone,Handlebars);

View File

@ -0,0 +1,9 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a){a.Views.MessagesCollection=a.Views.CollectionBase.extend({itemView:a.Views.Message,className:"messages-collection",initialize:function(){this.collection.on("multiple:add",this.messagesAdded,this);a.Objects.Models.messageForm.on("before:post",this.messagePost,this)},skipNextSound:!0,messagePost:function(){this.skipNextSound=!0},messagesAdded:function(){if(!this.skipNextSound&&a.Objects.Models.Controls.sound.get("enabled")){var b=a.Objects.Models.page.get("webimRoot");b&&a.Objects.Models.sound.play(b+
"/sounds/new_message.wav")}this.skipNextSound=!1}})})(Mibew);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b,c){a.Views.Status=b.Marionette.ItemView.extend({template:c.templates.status,className:"status",modelEvents:{change:"render"},onBeforeRender:function(){this.model.get("visible")?this.$el.show():this.$el.hide()}})})(Mibew,Backbone,Handlebars);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Views.StatusMessage=a.Views.Status.extend({template:b.templates.status_message})})(Mibew,Handlebars);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a){a.Views.StatusCollection=a.Views.CollectionBase.extend({itemView:a.Views.Status,className:"status-collection"})})(Mibew);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Views.StatusTyping=a.Views.Status.extend({template:b.templates.status_typing})})(Mibew,Handlebars);

View File

@ -0,0 +1,106 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a){a.Regions={};a.Objects.Models.Controls={};a.Objects.Models.Status={}})(Mibew);
(function(b){b.registerHelper("allowTags",function(a){a=a.replace(/&lt;(span|strong)&gt;(.*?)&lt;\/\1&gt;/g,"<$1>$2</$1>");a=a.replace(/&lt;span class=&quot;(.*?)&quot;&gt;(.*?)&lt;\/span&gt;/g,'<span class="$1">$2</span>');return new b.SafeString(a)})})(Handlebars);
(function(a){a.Models.Control=a.Models.Base.extend({defaults:{title:"",weight:0}})})(Mibew);
(function(b,c){b.Models.Status=b.Models.Base.extend({defaults:{visible:!0,weight:0,hideTimeout:4E3,title:""},initialize:function(){this.hideTimer=null},autoHide:function(a){a=a||this.get("hideTimeout");this.hideTimer&&clearTimeout(this.hideTimer);this.hideTimer=setTimeout(c.bind(function(){this.set({visible:!1})},this),a)}})})(Mibew,_);
(function(a,b){a.Models.Avatar=a.Models.Base.extend({defaults:{imageLink:!1},initialize:function(){a.Objects.server.registerFunction("setupAvatar",b.bind(this.apiSetupAvatar,this))},apiSetupAvatar:function(a){a.imageLink&&this.set({imageLink:a.imageLink})}})})(Mibew,_);
(function(a){a.Models.CloseControl=a.Models.Control.extend({getModelType:function(){return"CloseControl"},closeThread:function(){var b=a.Objects.thread;a.Objects.server.callFunctions([{"function":"close",arguments:{references:{},"return":{closed:"closed"},threadId:b.threadId,token:b.token,lastId:b.lastId,user:!a.Objects.Models.user.get("isAgent")}}],function(b){b.closed?window.close():a.Objects.Models.Status.message.setMessage(b.errorMessage||"Cannot close")},!0)}})})(Mibew);
(function(a,b){a.Models.HistoryControl=a.Models.Control.extend({defaults:b.extend({},a.Models.Control.prototype.defaults,{link:!1}),getModelType:function(){return"HistoryControl"}})})(Mibew,_);
(function(a,b){a.Models.RedirectControl=a.Models.Control.extend({defaults:b.extend({},a.Models.Control.prototype.defaults,{link:!1}),getModelType:function(){return"RedirectControl"}})})(Mibew,_);
(function(a){a.Models.RefreshControl=a.Models.Control.extend({getModelType:function(){return"RefreshControl"},refresh:function(){a.Objects.server.restartUpdater()}})})(Mibew);
(function(a,b){a.Models.SecureModeControl=a.Models.Control.extend({defaults:b.extend({},a.Models.Control.prototype.defaults,{link:!1}),getModelType:function(){return"SecureModeControl"}})})(Mibew,_);
(function(a,b){a.Models.SendMailControl=a.Models.Control.extend({defaults:b.extend({},a.Models.Control.prototype.defaults,{link:!1}),getModelType:function(){return"SendMailControl"}})})(Mibew,_);
(function(a,b){a.Models.SoundControl=a.Models.Control.extend({defaults:b.extend({},a.Models.Control.prototype.defaults,{enabled:!0}),getModelType:function(){return"SoundControl"}})})(Mibew,_);
(function(b){b.Models.UserNameControl=b.Models.Control.extend({getModelType:function(){return"UserNameControl"},changeName:function(a){var c=b.Objects.Models.user,d=b.Objects.thread,e=c.get("name");a&&e!=a&&(b.Objects.server.callFunctions([{"function":"rename",arguments:{references:{},"return":{},threadId:d.threadId,token:d.token,name:a}}],function(a){a.errorCode&&(b.Objects.Models.Status.message.setMessage(a.errorMessage||"Cannot rename"),c.set({name:e}))},!0),c.set({name:a}))}})})(Mibew);
(function(a){a.Models.Message=a.Models.Base.extend({defaults:{message:""}})})(Mibew);
(function(a){a.Models.MessageForm=a.Models.Base.extend({defaults:{predefinedAnswers:[],ignoreCtrl:!1},postMessage:function(e){var b=a.Objects.thread,c=a.Objects.Models.user;if(c.get("canPost")){this.trigger("before:post",this);var d=this;a.Objects.server.callFunctions([{"function":"post",arguments:{references:{},"return":{},message:e,threadId:b.threadId,token:b.token,user:!c.get("isAgent")}}],function(){d.trigger("after:post",d)},!0)}}})})(Mibew);
(function(a,b){a.Models.StatusMessage=a.Models.Status.extend({defaults:b.extend({},a.Models.Status.prototype.defaults,{message:"",visible:!1}),getModelType:function(){return"StatusMessage"},setMessage:function(a){this.set({message:a,visible:!0});this.autoHide()}})})(Mibew,_);
(function(a,b){a.Models.StatusTyping=a.Models.Status.extend({defaults:b.extend({},a.Models.Status.prototype.defaults,{visible:!1,hideTimeout:2E3}),getModelType:function(){return"StatusTyping"},show:function(){this.set({visible:!0});this.autoHide()}})})(Mibew,_);
(function(a,b){a.Collections.Controls=b.Collection.extend({comparator:function(a){return a.get("weight")}})})(Mibew,Backbone);
(function(b,d,c){b.Collections.Messages=d.Collection.extend({model:b.Models.Message,initialize:function(){b.Objects.server.callFunctionsPeriodically(c.bind(this.updateFunctionBuilder,this),c.bind(this.updateChatState,this));b.Objects.server.registerFunction("updateMessages",c.bind(this.apiUpdateMessages,this))},apiUpdateMessages:function(a){a.lastId&&(b.Objects.thread.lastId=a.lastId);for(var e=[],c=0,d=a.messages.length;c<d;c++)e.push(new b.Models.Message(a.messages[c]));0<e.length&&this.add(e)},
updateFunctionBuilder:function(){var a=b.Objects.thread,c=b.Objects.Models.user;return[{"function":"update",arguments:{"return":{typing:"typing",canPost:"canPost"},references:{},threadId:a.threadId,token:a.token,lastId:a.lastId,typed:c.get("typing"),user:!c.get("isAgent")}}]},updateChatState:function(a){a.errorCode?b.Objects.Models.Status.message.setMessage(a.errorMessage||"refresh failed"):(a.typing&&b.Objects.Models.Status.typing.show(),b.Objects.Models.user.set({canPost:a.canPost||!1}))},add:function(){var a=
Array.prototype.slice.apply(arguments),a=d.Collection.prototype.add.apply(this,a);this.trigger("multiple:add");return a}})})(Mibew,Backbone,_);
(function(a,b){a.Collections.Status=b.Collection.extend({comparator:function(a){return a.get("weight")}})})(Mibew,Backbone);
(function(b,c,d){b.Views.Control=c.Marionette.ItemView.extend({template:d.templates.control,modelEvents:{change:"render"},events:{mouseover:"mouseOver",mouseleave:"mouseLeave"},attributes:function(){var a=[];a.push("control");this.className&&(a.push(this.className),this.className="");var b=this.getDashedControlType();b&&a.push(b);return{"class":a.join(" ")}},mouseOver:function(){var a=this.getDashedControlType();this.$el.addClass("active"+(a?"-"+a:""))},mouseLeave:function(){var a=this.getDashedControlType();
this.$el.removeClass("active"+(a?"-"+a:""))},getDashedControlType:function(){"undefined"==typeof this.dashedControlType&&(this.dashedControlType=b.Utils.toDashFormat(this.model.getModelType())||"");return this.dashedControlType}})})(Mibew,Backbone,Handlebars);
(function(a,b,c){a.Views.Status=b.Marionette.ItemView.extend({template:c.templates.status,className:"status",modelEvents:{change:"render"},onBeforeRender:function(){this.model.get("visible")?this.$el.show():this.$el.hide()}})})(Mibew,Backbone,Handlebars);
(function(a,b,c){a.Views.Avatar=b.Marionette.ItemView.extend({template:c.templates.avatar,className:"avatar",modelEvents:{change:"render"}})})(Mibew,Backbone,Handlebars);
(function(a,c,d){a.Views.CloseControl=a.Views.Control.extend({template:c.templates.close_control,events:d.extend({},a.Views.Control.prototype.events,{click:"close"}),close:function(){var b=a.Localization.get("chat.close.confirmation");(!1===b||confirm(b))&&this.model.closeThread()}})})(Mibew,Handlebars,_);
(function(a){a.Views.ControlsCollection=a.Views.CollectionBase.extend({itemView:a.Views.Control,className:"controls-collection"})})(Mibew);
(function(b,d,e){b.Views.HistoryControl=b.Views.Control.extend({template:d.templates.history_control,events:e.extend({},b.Views.Control.prototype.events,{click:"showHistory"}),showHistory:function(){var c=b.Objects.Models.user,a=this.model.get("link");c.get("isAgent")&&a&&(c=this.$el.find(".control-config").eq(0).data("win-params"),a=a.replace("&amp;","&","g"),a=window.open(a,"UserHistory",c),null!==a&&(a.focus(),a.opener=window))}})})(Mibew,Handlebars,_);
(function(a,d,e){a.Views.RedirectControl=a.Views.Control.extend({template:d.templates.redirect_control,events:e.extend({},a.Views.Control.prototype.events,{click:"redirect"}),initialize:function(){a.Objects.Models.user.on("change",this.render,this)},serializeData:function(){var b=this.model.toJSON();b.user=a.Objects.Models.user.toJSON();return b},redirect:function(){var b=a.Objects.Models.user;if(b.get("isAgent")&&b.get("canPost")&&(b=this.model.get("link"))){var c=a.Objects.Models.page.get("style");
window.location.href=b.replace(/\&amp\;/g,"&")+(c?"&style="+c:"")}}})})(Mibew,Handlebars,_);
(function(a,b,c){a.Views.RefreshControl=a.Views.Control.extend({template:b.templates.refresh_control,events:c.extend({},a.Views.Control.prototype.events,{click:"refresh"}),refresh:function(){this.model.refresh()}})})(Mibew,Handlebars,_);
(function(a,d,e){a.Views.SecureModeControl=a.Views.Control.extend({template:d.templates.secure_mode_control,events:e.extend({},a.Views.Control.prototype.events,{click:"secure"}),secure:function(){var b=this.model.get("link");if(b){var c=a.Objects.Models.page.get("style");window.location.href=b.replace(/\&amp\;/g,"&")+(c?"&style="+c:"")}}})})(Mibew,Handlebars,_);
(function(b,c,e){b.Views.SendMailControl=b.Views.Control.extend({template:c.templates.send_mail_control,events:e.extend({},b.Views.Control.prototype.events,{click:"sendMail"}),sendMail:function(){var a=this.model.get("link");if(a){var c=this.$el.find(".control-config").eq(0).data("win-params"),d=b.Objects.Models.page.get("style"),a=a.replace(/\&amp\;/g,"&")+(d?"&style="+d:""),a=window.open(a,"ForwardMail",c);null!==a&&(a.focus(),a.opener=window)}}})})(Mibew,Handlebars,_);
(function(a,b,c){a.Views.SoundControl=a.Views.Control.extend({template:b.templates.sound_control,events:c.extend({},a.Views.Control.prototype.events,{click:"toggle"}),toggle:function(){this.model.set({enabled:!this.model.get("enabled")})}})})(Mibew,Handlebars,_);
(function(b,c,d){b.Views.UserNameControl=b.Views.Control.extend({template:c.templates.user_name_control,events:d.extend({},b.Views.Control.prototype.events,{"click .user-name-control-set":"changeName","click .user-name-control-change":"showNameInput","keydown #user-name-control-input":"inputKeyDown"}),ui:{nameInput:"#user-name-control-input"},initialize:function(){b.Objects.Models.user.on("change:name",this.hideNameInput,this);this.nameInput=b.Objects.Models.user.get("defaultName")},serializeData:function(){var a=
this.model.toJSON();a.user=b.Objects.Models.user.toJSON();a.nameInput=this.nameInput;return a},inputKeyDown:function(a){a=a.which;(13==a||10==a)&&this.changeName()},hideNameInput:function(){this.nameInput=!1;this.render()},showNameInput:function(){this.nameInput=!0;this.render()},changeName:function(){var a=this.ui.nameInput.val();this.model.changeName(a)}})})(Mibew,Handlebars,_);
(function(c,d,e){var f={"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},g=/[&<>'"`]/g;c.Views.Message=d.Marionette.ItemView.extend({template:e.templates.message,className:"message",modelEvents:{change:"render"},serializeData:function(){var a=this.model.toJSON(),b=this.model.get("kind");a.allowFormatting=b!=this.KIND_USER&&b!=this.KIND_AGENT;a.kindName=this.kindToString(b);a.message=this.escapeString(a.message);return a},kindToString:function(a){return a==this.KIND_USER?"user":
a==this.KIND_AGENT?"agent":a==this.KIND_FOR_AGENT?"hidden":a==this.KIND_INFO?"inf":a==this.KIND_CONN?"conn":a==this.KIND_EVENTS?"event":""},escapeString:function(a){return a.replace(g,function(a){return f[a]||"&amp;"})},KIND_USER:1,KIND_AGENT:2,KIND_FOR_AGENT:3,KIND_INFO:4,KIND_CONN:5,KIND_EVENTS:6,KIND_AVATAR:7})})(Mibew,Backbone,Handlebars);
(function(b,d,e){b.Views.MessageForm=d.Marionette.ItemView.extend({template:e.templates.message_form,events:{"click #send-message":"postMessage","keydown #message-input":"messageKeyDown","keyup #message-input":"checkUserTyping","change #message-input":"checkUserTyping","change #predefined":"selectPredefinedAnswer","focus #message-input":"setFocus","blur #message-input":"dropFocus"},modelEvents:{change:"render"},ui:{message:"#message-input",send:"#send-message",predefinedAnswer:"#predefined"},initialize:function(){b.Objects.Models.user.on("change:canPost",
this.render,this)},serializeData:function(){var a=this.model.toJSON();a.user=b.Objects.Models.user.toJSON();return a},postMessage:function(){var a=this.ui.message.val();""!=a&&(this.disableInput(),this.model.postMessage(a));b.Objects.Collections.messages.on("multiple:add",this.postMessageComplete,this)},messageKeyDown:function(a){var c=a.which;a=a.ctrlKey;(13==c&&(a||this.model.get("ignoreCtrl"))||10==c)&&this.postMessage()},enableInput:function(){this.ui.message.removeAttr("disabled")},disableInput:function(){this.ui.message.attr("disabled",
"disabled")},clearInput:function(){this.ui.message.val("").change()},postMessageComplete:function(){this.clearInput();this.enableInput();this.focused&&this.ui.focus();b.Objects.Collections.messages.off("multiple:add",this.postMessageComplete,this)},selectPredefinedAnswer:function(){var a=this.ui.message,c=this.ui.predefinedAnswer,b=c.get(0).selectedIndex;b&&(a.val(this.model.get("predefinedAnswers")[b-1].full).change(),a.focus(),c.get(0).selectedIndex=0)},checkUserTyping:function(){var a=b.Objects.Models.user,
c=""!=this.ui.message.val();c!=a.get("typing")&&a.set({typing:c})},setFocus:function(){this.focused=!0},dropFocus:function(){this.focused=!1}})})(Mibew,Backbone,Handlebars);
(function(a){a.Views.MessagesCollection=a.Views.CollectionBase.extend({itemView:a.Views.Message,className:"messages-collection",initialize:function(){this.collection.on("multiple:add",this.messagesAdded,this);a.Objects.Models.messageForm.on("before:post",this.messagePost,this)},skipNextSound:!0,messagePost:function(){this.skipNextSound=!0},messagesAdded:function(){if(!this.skipNextSound&&a.Objects.Models.Controls.sound.get("enabled")){var b=a.Objects.Models.page.get("webimRoot");b&&a.Objects.Models.sound.play(b+
"/sounds/new_message.wav")}this.skipNextSound=!1}})})(Mibew);
(function(a,b){a.Views.StatusMessage=a.Views.Status.extend({template:b.templates.status_message})})(Mibew,Handlebars);
(function(a){a.Views.StatusCollection=a.Views.CollectionBase.extend({itemView:a.Views.Status,className:"status-collection"})})(Mibew);
(function(a,b){a.Views.StatusTyping=a.Views.Status.extend({template:b.templates.status_typing})})(Mibew,Handlebars);
(function(a){a.Models.Control=a.Models.Base.extend({defaults:{title:"",weight:0}})})(Mibew);
(function(b,c){b.Models.Status=b.Models.Base.extend({defaults:{visible:!0,weight:0,hideTimeout:4E3,title:""},initialize:function(){this.hideTimer=null},autoHide:function(a){a=a||this.get("hideTimeout");this.hideTimer&&clearTimeout(this.hideTimer);this.hideTimer=setTimeout(c.bind(function(){this.set({visible:!1})},this),a)}})})(Mibew,_);
(function(b,c,d){b.Views.Control=c.Marionette.ItemView.extend({template:d.templates.control,modelEvents:{change:"render"},events:{mouseover:"mouseOver",mouseleave:"mouseLeave"},attributes:function(){var a=[];a.push("control");this.className&&(a.push(this.className),this.className="");var b=this.getDashedControlType();b&&a.push(b);return{"class":a.join(" ")}},mouseOver:function(){var a=this.getDashedControlType();this.$el.addClass("active"+(a?"-"+a:""))},mouseLeave:function(){var a=this.getDashedControlType();
this.$el.removeClass("active"+(a?"-"+a:""))},getDashedControlType:function(){"undefined"==typeof this.dashedControlType&&(this.dashedControlType=b.Utils.toDashFormat(this.model.getModelType())||"");return this.dashedControlType}})})(Mibew,Backbone,Handlebars);
(function(a,b,c){a.Views.Status=b.Marionette.ItemView.extend({template:c.templates.status,className:"status",modelEvents:{change:"render"},onBeforeRender:function(){this.model.get("visible")?this.$el.show():this.$el.hide()}})})(Mibew,Backbone,Handlebars);
(function(a,b){a.Collections.Controls=b.Collection.extend({comparator:function(a){return a.get("weight")}})})(Mibew,Backbone);
(function(b,d,c){b.Collections.Messages=d.Collection.extend({model:b.Models.Message,initialize:function(){b.Objects.server.callFunctionsPeriodically(c.bind(this.updateFunctionBuilder,this),c.bind(this.updateChatState,this));b.Objects.server.registerFunction("updateMessages",c.bind(this.apiUpdateMessages,this))},apiUpdateMessages:function(a){a.lastId&&(b.Objects.thread.lastId=a.lastId);for(var e=[],c=0,d=a.messages.length;c<d;c++)e.push(new b.Models.Message(a.messages[c]));0<e.length&&this.add(e)},
updateFunctionBuilder:function(){var a=b.Objects.thread,c=b.Objects.Models.user;return[{"function":"update",arguments:{"return":{typing:"typing",canPost:"canPost"},references:{},threadId:a.threadId,token:a.token,lastId:a.lastId,typed:c.get("typing"),user:!c.get("isAgent")}}]},updateChatState:function(a){a.errorCode?b.Objects.Models.Status.message.setMessage(a.errorMessage||"refresh failed"):(a.typing&&b.Objects.Models.Status.typing.show(),b.Objects.Models.user.set({canPost:a.canPost||!1}))},add:function(){var a=
Array.prototype.slice.apply(arguments),a=d.Collection.prototype.add.apply(this,a);this.trigger("multiple:add");return a}})})(Mibew,Backbone,_);
(function(a,b){a.Collections.Status=b.Collection.extend({comparator:function(a){return a.get("weight")}})})(Mibew,Backbone);
(function(a,b){a.Models.Avatar=a.Models.Base.extend({defaults:{imageLink:!1},initialize:function(){a.Objects.server.registerFunction("setupAvatar",b.bind(this.apiSetupAvatar,this))},apiSetupAvatar:function(a){a.imageLink&&this.set({imageLink:a.imageLink})}})})(Mibew,_);
(function(a){a.Models.CloseControl=a.Models.Control.extend({getModelType:function(){return"CloseControl"},closeThread:function(){var b=a.Objects.thread;a.Objects.server.callFunctions([{"function":"close",arguments:{references:{},"return":{closed:"closed"},threadId:b.threadId,token:b.token,lastId:b.lastId,user:!a.Objects.Models.user.get("isAgent")}}],function(b){b.closed?window.close():a.Objects.Models.Status.message.setMessage(b.errorMessage||"Cannot close")},!0)}})})(Mibew);
(function(a,b){a.Models.HistoryControl=a.Models.Control.extend({defaults:b.extend({},a.Models.Control.prototype.defaults,{link:!1}),getModelType:function(){return"HistoryControl"}})})(Mibew,_);
(function(a,b){a.Models.RedirectControl=a.Models.Control.extend({defaults:b.extend({},a.Models.Control.prototype.defaults,{link:!1}),getModelType:function(){return"RedirectControl"}})})(Mibew,_);
(function(a){a.Models.RefreshControl=a.Models.Control.extend({getModelType:function(){return"RefreshControl"},refresh:function(){a.Objects.server.restartUpdater()}})})(Mibew);
(function(a,b){a.Models.SecureModeControl=a.Models.Control.extend({defaults:b.extend({},a.Models.Control.prototype.defaults,{link:!1}),getModelType:function(){return"SecureModeControl"}})})(Mibew,_);
(function(a,b){a.Models.SendMailControl=a.Models.Control.extend({defaults:b.extend({},a.Models.Control.prototype.defaults,{link:!1}),getModelType:function(){return"SendMailControl"}})})(Mibew,_);
(function(a,b){a.Models.SoundControl=a.Models.Control.extend({defaults:b.extend({},a.Models.Control.prototype.defaults,{enabled:!0}),getModelType:function(){return"SoundControl"}})})(Mibew,_);
(function(b){b.Models.UserNameControl=b.Models.Control.extend({getModelType:function(){return"UserNameControl"},changeName:function(a){var c=b.Objects.Models.user,d=b.Objects.thread,e=c.get("name");a&&e!=a&&(b.Objects.server.callFunctions([{"function":"rename",arguments:{references:{},"return":{},threadId:d.threadId,token:d.token,name:a}}],function(a){a.errorCode&&(b.Objects.Models.Status.message.setMessage(a.errorMessage||"Cannot rename"),c.set({name:e}))},!0),c.set({name:a}))}})})(Mibew);
(function(a){a.Models.Message=a.Models.Base.extend({defaults:{message:""}})})(Mibew);
(function(a){a.Models.MessageForm=a.Models.Base.extend({defaults:{predefinedAnswers:[],ignoreCtrl:!1},postMessage:function(e){var b=a.Objects.thread,c=a.Objects.Models.user;if(c.get("canPost")){this.trigger("before:post",this);var d=this;a.Objects.server.callFunctions([{"function":"post",arguments:{references:{},"return":{},message:e,threadId:b.threadId,token:b.token,user:!c.get("isAgent")}}],function(){d.trigger("after:post",d)},!0)}}})})(Mibew);
(function(a,b){a.Models.StatusMessage=a.Models.Status.extend({defaults:b.extend({},a.Models.Status.prototype.defaults,{message:"",visible:!1}),getModelType:function(){return"StatusMessage"},setMessage:function(a){this.set({message:a,visible:!0});this.autoHide()}})})(Mibew,_);
(function(a,b){a.Models.StatusTyping=a.Models.Status.extend({defaults:b.extend({},a.Models.Status.prototype.defaults,{visible:!1,hideTimeout:2E3}),getModelType:function(){return"StatusTyping"},show:function(){this.set({visible:!0});this.autoHide()}})})(Mibew,_);
(function(a,b){a.Regions.Messages=b.Marionette.Region.extend({el:"#messages-region",onShow:function(a){a.on("after:item:added",this.scrollToBottom,this)},scrollToBottom:function(){this.$el.scrollTop(this.$el.prop("scrollHeight"))}})})(Mibew,Backbone);
(function(a,b,c){a.Views.Avatar=b.Marionette.ItemView.extend({template:c.templates.avatar,className:"avatar",modelEvents:{change:"render"}})})(Mibew,Backbone,Handlebars);
(function(a,c,d){a.Views.CloseControl=a.Views.Control.extend({template:c.templates.close_control,events:d.extend({},a.Views.Control.prototype.events,{click:"close"}),close:function(){var b=a.Localization.get("chat.close.confirmation");(!1===b||confirm(b))&&this.model.closeThread()}})})(Mibew,Handlebars,_);
(function(a){a.Views.ControlsCollection=a.Views.CollectionBase.extend({itemView:a.Views.Control,className:"controls-collection"})})(Mibew);
(function(b,d,e){b.Views.HistoryControl=b.Views.Control.extend({template:d.templates.history_control,events:e.extend({},b.Views.Control.prototype.events,{click:"showHistory"}),showHistory:function(){var c=b.Objects.Models.user,a=this.model.get("link");c.get("isAgent")&&a&&(c=this.$el.find(".control-config").eq(0).data("win-params"),a=a.replace("&amp;","&","g"),a=window.open(a,"UserHistory",c),null!==a&&(a.focus(),a.opener=window))}})})(Mibew,Handlebars,_);
(function(a,d,e){a.Views.RedirectControl=a.Views.Control.extend({template:d.templates.redirect_control,events:e.extend({},a.Views.Control.prototype.events,{click:"redirect"}),initialize:function(){a.Objects.Models.user.on("change",this.render,this)},serializeData:function(){var b=this.model.toJSON();b.user=a.Objects.Models.user.toJSON();return b},redirect:function(){var b=a.Objects.Models.user;if(b.get("isAgent")&&b.get("canPost")&&(b=this.model.get("link"))){var c=a.Objects.Models.page.get("style");
window.location.href=b.replace(/\&amp\;/g,"&")+(c?"&style="+c:"")}}})})(Mibew,Handlebars,_);
(function(a,b,c){a.Views.RefreshControl=a.Views.Control.extend({template:b.templates.refresh_control,events:c.extend({},a.Views.Control.prototype.events,{click:"refresh"}),refresh:function(){this.model.refresh()}})})(Mibew,Handlebars,_);
(function(a,d,e){a.Views.SecureModeControl=a.Views.Control.extend({template:d.templates.secure_mode_control,events:e.extend({},a.Views.Control.prototype.events,{click:"secure"}),secure:function(){var b=this.model.get("link");if(b){var c=a.Objects.Models.page.get("style");window.location.href=b.replace(/\&amp\;/g,"&")+(c?"&style="+c:"")}}})})(Mibew,Handlebars,_);
(function(b,c,e){b.Views.SendMailControl=b.Views.Control.extend({template:c.templates.send_mail_control,events:e.extend({},b.Views.Control.prototype.events,{click:"sendMail"}),sendMail:function(){var a=this.model.get("link");if(a){var c=this.$el.find(".control-config").eq(0).data("win-params"),d=b.Objects.Models.page.get("style"),a=a.replace(/\&amp\;/g,"&")+(d?"&style="+d:""),a=window.open(a,"ForwardMail",c);null!==a&&(a.focus(),a.opener=window)}}})})(Mibew,Handlebars,_);
(function(a,b,c){a.Views.SoundControl=a.Views.Control.extend({template:b.templates.sound_control,events:c.extend({},a.Views.Control.prototype.events,{click:"toggle"}),toggle:function(){this.model.set({enabled:!this.model.get("enabled")})}})})(Mibew,Handlebars,_);
(function(b,c,d){b.Views.UserNameControl=b.Views.Control.extend({template:c.templates.user_name_control,events:d.extend({},b.Views.Control.prototype.events,{"click .user-name-control-set":"changeName","click .user-name-control-change":"showNameInput","keydown #user-name-control-input":"inputKeyDown"}),ui:{nameInput:"#user-name-control-input"},initialize:function(){b.Objects.Models.user.on("change:name",this.hideNameInput,this);this.nameInput=b.Objects.Models.user.get("defaultName")},serializeData:function(){var a=
this.model.toJSON();a.user=b.Objects.Models.user.toJSON();a.nameInput=this.nameInput;return a},inputKeyDown:function(a){a=a.which;(13==a||10==a)&&this.changeName()},hideNameInput:function(){this.nameInput=!1;this.render()},showNameInput:function(){this.nameInput=!0;this.render()},changeName:function(){var a=this.ui.nameInput.val();this.model.changeName(a)}})})(Mibew,Handlebars,_);
(function(c,d,e){var f={"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},g=/[&<>'"`]/g;c.Views.Message=d.Marionette.ItemView.extend({template:e.templates.message,className:"message",modelEvents:{change:"render"},serializeData:function(){var a=this.model.toJSON(),b=this.model.get("kind");a.allowFormatting=b!=this.KIND_USER&&b!=this.KIND_AGENT;a.kindName=this.kindToString(b);a.message=this.escapeString(a.message);return a},kindToString:function(a){return a==this.KIND_USER?"user":
a==this.KIND_AGENT?"agent":a==this.KIND_FOR_AGENT?"hidden":a==this.KIND_INFO?"inf":a==this.KIND_CONN?"conn":a==this.KIND_EVENTS?"event":""},escapeString:function(a){return a.replace(g,function(a){return f[a]||"&amp;"})},KIND_USER:1,KIND_AGENT:2,KIND_FOR_AGENT:3,KIND_INFO:4,KIND_CONN:5,KIND_EVENTS:6,KIND_AVATAR:7})})(Mibew,Backbone,Handlebars);
(function(b,d,e){b.Views.MessageForm=d.Marionette.ItemView.extend({template:e.templates.message_form,events:{"click #send-message":"postMessage","keydown #message-input":"messageKeyDown","keyup #message-input":"checkUserTyping","change #message-input":"checkUserTyping","change #predefined":"selectPredefinedAnswer","focus #message-input":"setFocus","blur #message-input":"dropFocus"},modelEvents:{change:"render"},ui:{message:"#message-input",send:"#send-message",predefinedAnswer:"#predefined"},initialize:function(){b.Objects.Models.user.on("change:canPost",
this.render,this)},serializeData:function(){var a=this.model.toJSON();a.user=b.Objects.Models.user.toJSON();return a},postMessage:function(){var a=this.ui.message.val();""!=a&&(this.disableInput(),this.model.postMessage(a));b.Objects.Collections.messages.on("multiple:add",this.postMessageComplete,this)},messageKeyDown:function(a){var c=a.which;a=a.ctrlKey;(13==c&&(a||this.model.get("ignoreCtrl"))||10==c)&&this.postMessage()},enableInput:function(){this.ui.message.removeAttr("disabled")},disableInput:function(){this.ui.message.attr("disabled",
"disabled")},clearInput:function(){this.ui.message.val("").change()},postMessageComplete:function(){this.clearInput();this.enableInput();this.focused&&this.ui.focus();b.Objects.Collections.messages.off("multiple:add",this.postMessageComplete,this)},selectPredefinedAnswer:function(){var a=this.ui.message,c=this.ui.predefinedAnswer,b=c.get(0).selectedIndex;b&&(a.val(this.model.get("predefinedAnswers")[b-1].full).change(),a.focus(),c.get(0).selectedIndex=0)},checkUserTyping:function(){var a=b.Objects.Models.user,
c=""!=this.ui.message.val();c!=a.get("typing")&&a.set({typing:c})},setFocus:function(){this.focused=!0},dropFocus:function(){this.focused=!1}})})(Mibew,Backbone,Handlebars);
(function(a){a.Views.MessagesCollection=a.Views.CollectionBase.extend({itemView:a.Views.Message,className:"messages-collection",initialize:function(){this.collection.on("multiple:add",this.messagesAdded,this);a.Objects.Models.messageForm.on("before:post",this.messagePost,this)},skipNextSound:!0,messagePost:function(){this.skipNextSound=!0},messagesAdded:function(){if(!this.skipNextSound&&a.Objects.Models.Controls.sound.get("enabled")){var b=a.Objects.Models.page.get("webimRoot");b&&a.Objects.Models.sound.play(b+
"/sounds/new_message.wav")}this.skipNextSound=!1}})})(Mibew);
(function(a,b){a.Views.StatusMessage=a.Views.Status.extend({template:b.templates.status_message})})(Mibew,Handlebars);
(function(a){a.Views.StatusCollection=a.Views.CollectionBase.extend({itemView:a.Views.Status,className:"status-collection"})})(Mibew);
(function(a,b){a.Views.StatusTyping=a.Views.Status.extend({template:b.templates.status_typing})})(Mibew,Handlebars);
(function(a,j){var f=new j.Marionette.Application;f.addRegions({controlsRegion:"#controls-region",avatarRegion:"#avatar-region",messagesRegion:a.Regions.Messages,statusRegion:"#status-region",messageFormRegion:"#message-form-region",soundRegion:"#sound-region"});f.addInitializer(function(d){var g=a.Objects,c=a.Objects.Models,b=a.Objects.Models.Controls,h=a.Objects.Models.Status;g.server=new a.Server(d.server);g.thread=new a.Thread(d.thread);c.user=new a.Models.User(d.user);c.page=new a.Models.Page(d.page);
var e=new a.Collections.Controls;c.user.get("isAgent")||(b.userName=new a.Models.UserNameControl({weight:220}),e.push(b.userName),b.sendMail=new a.Models.SendMailControl({weight:200,link:d.links.mailLink}),e.push(b.sendMail));c.user.get("isAgent")&&(b.redirect=new a.Models.RedirectControl({weight:200,link:d.links.redirectLink}),e.push(b.redirect),b.history=new a.Models.HistoryControl({weight:180,link:d.links.historyLink}),e.push(b.history));b.sound=new a.Models.SoundControl({weight:160});e.push(b.sound);
b.refresh=new a.Models.RefreshControl({weight:140});e.push(b.refresh);d.links.sslLink&&(b.secureMode=new a.Models.SecureModeControl({weight:120,link:d.links.sslLink}),e.push(b.secureMode));b.close=new a.Models.CloseControl({weight:100});e.push(b.close);g.Collections.controls=e;f.controlsRegion.show(new a.Views.ControlsCollection({collection:e}));h.message=new a.Models.StatusMessage({hideTimeout:5E3});h.typing=new a.Models.StatusTyping({hideTimeout:5E3});g.Collections.status=new a.Collections.Status([h.message,
h.typing]);f.statusRegion.show(new a.Views.StatusCollection({collection:g.Collections.status}));c.user.get("isAgent")||(c.avatar=new a.Models.Avatar,f.avatarRegion.show(new a.Views.Avatar({model:c.avatar})));g.Collections.messages=new a.Collections.Messages;c.messageForm=new a.Models.MessageForm(d.messageForm);f.messageFormRegion.show(new a.Views.MessageForm({model:c.messageForm}));f.messagesRegion.show(new a.Views.MessagesCollection({collection:g.Collections.messages}));c.sound=new a.Models.Sound;
f.soundRegion.show(new a.Views.Sound({model:c.sound}));g.server.runUpdater()});a.Application=f})(Mibew,Backbone);

View File

@ -1,16 +0,0 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
ChatController=Class.create();
ChatController.prototype={options:{},thread:null,server:null,view:null,cansend:!0,skipNextSound:!0,focused:!0,message:null,ownThread:null,initialize:function(a,b,c,d){this.options=d;this.thread=c;this.server=a;this.view=b;this.message=$("msgwnd");this.ownThread=null!=this.message;this.message&&(this.message.onkeydown=this.handleKeyDown.bind(this),this.message.onfocus=function(){this.focused=!0}.bind(this),this.message.onblur=function(){this.focused=!1}.bind(this));this.server.callFunctionsPeriodically(this.updateFunctionBuilder.bind(this),this.updateChatState.bind(this));
this.server.registerFunction("updateMessages",this.updateMessages.bind(this));this.server.registerFunction("setupAvatar",this.setupAvatar.bind(this));this.server.runUpdater()},handleException:function(){this.view.setStatus("offline, reconnecting");this.view.enableInput(!0)},handleTimeout:function(){this.view.setStatus("timeout, reconnecting");this.view.enableInput(!0)},refresh:function(){this.server.restartUpdater()},postMessage:function(a){""!=a&&this.cansend&&(this.cansend=!1,this.skipNextSound=
!0,"opera"!=myRealAgent&&this.view.enableInput(!1),this.server.callFunctions([{"function":"post",arguments:{references:{},"return":{},message:a,threadId:this.thread.threadid,token:this.thread.token,user:this.thread.user}}],function(){this.view.enableInput(!0);this.cansend=!0;this.view.clearInput()}.bind(this),!0))},changeName:function(a){this.skipNextSound=!0;this.server.callFunctions([{"function":"rename",arguments:{references:{},"return":{},threadId:this.thread.threadid,token:this.thread.token,
name:a}}],function(a){a.errorCode&&this.handleError(a,"cannot rename")}.bind(this),!0)},closeThread:function(){(!this.view.getLocaleString("closeConfirmation")||confirm(this.view.getLocaleString("closeConfirmation")))&&this.server.callFunctions([{"function":"close",arguments:{references:{},"return":{closed:"closed"},threadId:this.thread.threadid,token:this.thread.token,lastId:this.thread.lastid,user:this.thread.user}}],this.onThreadClosed.bind(this),!0)},onThreadClosed:function(a){a.closed?window.close():
this.handleError(a,"cannot close")},setupAvatar:function(a){$("avatarwnd")&&this.thread.user&&this.view.updateAvatar(this.options.webimRoot,a.imageLink)},updateMessages:function(a){a.lastId&&(this.thread.lastid=a.lastId);this.view.displayMessages(a.messages);this.view.clearStatus();0<a.messages.length&&(this.skipNextSound||(a=$("soundimg"),(null==a||a.className.match(/\bisound\b/))&&playSound(this.options.webimRoot+"/sounds/new_message.wav")),this.focused||window.focus());this.skipNextSound=!1},updateFunctionBuilder:function(){return[{"function":"update",
arguments:{"return":{typing:"typing",canPost:"canPost"},references:{},threadId:this.thread.threadid,token:this.thread.token,lastId:this.thread.lastid,typed:this.message&&""!=this.message.value,user:this.thread.user}}]},updateChatState:function(a){if(a.errorCode)this.handleError(a,"refresh failed");else if("undefined"!=typeof a.typing&&this.view.showTyping(a.typing),"undefined"!=typeof a.canPost&&(a.canPost&&!this.ownThread||this.ownThread&&!a.canPost))window.location.href=window.location.href},isSendkey:function(a,
b){return 13==b&&(a||this.options.ignorectrl)||10==b},handleKeyDown:function(a){a?(ctrl=a.ctrlKey,a=a.which):(a=event.keyCode,ctrl=event.ctrlKey);return this.message&&this.isSendkey(ctrl,a)?(a=this.message.value,this.options.ignorectrl&&(a=a.replace(/[\r\n]+$/,"")),this.postMessage(a),!1):!0},handleError:function(a){a.errorCode?this.view.setStatus(a.errorMessage):this.view.setStatus("reconnecting")},applyName:function(){this.changeName($("uname").value);this.view.hideNameField();this.view.updateUserName($("uname").value)},
showNameField:function(){this.view.showNameField()},selectPredefinedAnswer:function(a){var b=a.selectedIndex;0!=b&&(this.view.displayPredefinedAnswer(b-1),this.view.resetSelectedIndex(a))},toggleSound:function(){var a=$("soundimg");a&&(a.className.match(/\bisound\b/)?this.view.changeSoundButtonState(!1):this.view.changeSoundButtonState(!0))}};

View File

@ -1,12 +0,0 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
var chatController={};
Behaviour.register({"#postmessage a":function(a){a.onclick=function(){var a=$("msgwnd");a&&chatController.postMessage(a.value)}},"select#predefined":function(a){a.onchange=function(){chatController.selectPredefinedAnswer(this)}},"div#changename2 a":function(a){a.onclick=function(){chatController.showNameField();return!1}},"div#changename1 a":function(a){a.onclick=function(){chatController.applyName();return!1}},"div#changename1 input#uname":function(a){a.onkeydown=function(a){13==(a||event).keyCode&&
chatController.applyName()}},"a#refresh":function(a){a.onclick=function(){chatController.refresh()}},"a#togglesound":function(a){a.onclick=function(){chatController.toggleSound()}},"a.closethread":function(a){a.onclick=function(){chatController.closeThread()}}});
EventHelper.register(window,"onload",function(){$LAB.setOptions({BasePath:chatParams.jsBasePath}).script("mibewapi.js").wait().script("chatserver.js").script("thread.js").script("messageview.js").script("pluginmanager.js").script("brws.js").wait().script("chatcontroller.js").script("chatview.js").wait(function(){FrameUtils.options.cssfile=chatParams.cssfile;var a=new ChatServer(chatParams.serverParams),c=new Thread(chatParams.threadParams),b=new PluginManager;chatParams.initPlugins(b,c,a);b=new ChatView(new MessageView,
chatParams.localizedStrings||{},chatParams.predefinedAnswers||[]);chatController=new ChatController(a,b,c,{ignorectrl:-1}.extend(chatParams.controllerParams||{}))})});

View File

@ -1,15 +0,0 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
ChatServer=Class.create();
ChatServer.prototype={initialize:function(a){this.updateTimer=null;this.options={servl:"",requestsFrequency:2,onTimeout:function(){},onTransportError:function(){},onCallError:function(){},onUpdateError:function(){},onResponseError:function(){}}.extend(a);this.callbacks={};this.callPeriodically=[];this.ajaxOptions={_method:"post",asynchronous:!0,timeout:5E3,onComplete:this.receiveResponse.bind(this),onException:this.onTransportError.bind(this),onTimeout:this.onTimeout.bind(this)};this.ajaxRequest=
null;this.buffer=[];this.functions={};this.mibewAPI=new MibewAPI(new MibewAPICoreInteraction)},callFunctions:function(a,b,d){try{if(!(a instanceof Array))throw Error("The first arguments must be an array");for(var c in a)a.hasOwnProperty(c)&&this.mibewAPI.checkFunction(a[c],!1);var e=this.generateToken();this.callbacks[e]=b;this.buffer.push({token:e,functions:a});d&&this.update()}catch(f){return this.options.onCallError(f),!1}return!0},callFunctionsPeriodically:function(a,b){this.callPeriodically.push({functionsListBuilder:a,
callbackFunction:b})},generateToken:function(){var a;do a="wnd"+(new Date).getTime().toString()+Math.round(50*Math.random()).toString();while(a in this.callbacks);return a},processRequest:function(a){var b=new MibewAPIExecutionContext,d=this.mibewAPI.getResultFunction(a.functions,this.callbacks.hasOwnProperty(a.token));if(null===d)for(var c in a.functions)a.functions.hasOwnProperty(c)&&(this.processFunction(a.functions[c],b),this.buffer.push(this.mibewAPI.buildResult(b.getResults(),a.token)));else this.callbacks.hasOwnProperty(a.token)&&
(this.callbacks[a.token](d.arguments),delete this.callbacks[a.token])},processFunction:function(a,b){if(this.functions.hasOwnProperty(a["function"])){var d=b.getArgumentsList(a),c={},e;for(e in this.functions[a["function"]])this.functions[a["function"]].hasOwnProperty(e)&&c.extend(this.functions[a["function"]][e](d));b.storeFunctionResults(a,c)}},sendRequests:function(a){this.ajaxRequest=new Ajax.Request(this.options.servl,this.ajaxOptions.extend({parameters:"data="+this.mibewAPI.encodePackage(a)}))},
runUpdater:function(){null==this.updateTimer&&this.update();this.updateTimer=setTimeout(this.update.bind(this),1E3*this.options.requestsFrequency)},restartUpdater:function(){this.updateTimer&&clearTimeout(this.updateTimer);this.ajaxRequest._options&&(this.ajaxRequest._options.onComplete=void 0);this.update();this.updateTimer=setTimeout(this.update.bind(this),1E3)},update:function(){this.updateTimer&&clearTimeout(this.updateTimer);for(var a=0;a<this.callPeriodically.length;a++)this.callFunctions(this.callPeriodically[a].functionsListBuilder(),
this.callPeriodically[a].callbackFunction);if(0==this.buffer.length)this.runUpdater();else try{this.sendRequests(this.buffer),this.buffer=[]}catch(b){this.options.onUpdateError(b)}},receiveResponse:function(a){""==a.response&&this.runUpdater();try{var b=this.mibewAPI.decodePackage(a.response),d;for(d in b.requests)this.processRequest(b.requests[d])}catch(c){this.options.onResponseError(c)}finally{this.runUpdater()}},registerFunction:function(a,b){a in this.functions||(this.functions[a]=[]);this.functions[a].push(b)},
onTransportError:function(a,b){this.restartUpdater();this.options.onTransportError(b)},onTimeout:function(){this.restartUpdater();this.options.onTimeout()}};

View File

@ -1,14 +0,0 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
var FrameUtils={options:{},getDocument:function(a){return a.contentDocument?a.contentDocument:a.contentWindow?a.contentWindow.document:a.document?a.document:null},initFrame:function(a){var b=this.getDocument(a);b.open();b.write("<html><head>");this.options.cssfile&&b.write('<link rel="stylesheet" type="text/css" media="all" href="'+this.options.cssfile+'">');b.write("</head><body bgcolor='#FFFFFF' text='#000000' link='#C28400' vlink='#C28400' alink='#C28400'>");b.write("<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td valign='top' class='message' id='content'></td></tr></table><a id='bottom' name='bottom'></a>");
b.write("</body></html>");b.close();a.onload=function(){a.myHtml&&(FrameUtils.getDocument(a).getElementById("content").innerHTML+=a.myHtml,FrameUtils.scrollDown(a))}},insertIntoFrame:function(a,b){var c=this.getDocument(a).getElementById("content");null==c?(a.myHtml||(a.myHtml=""),a.myHtml+=b):c.innerHTML+=b},scrollDown:function(a){var b=this.getDocument(a).getElementById("bottom");if("opera"==myAgent)try{a.contentWindow.scrollTo(0,this.getDocument(a).getElementById("content").clientHeight)}catch(c){}b&&
b.scrollIntoView(!1)}};ChatView=Class.create();
ChatView.prototype={statusTimeout:null,localizedStrings:{},predefinedAnswers:[],messageContainer:null,messageView:null,initialize:function(a,b,c){this.localizedStrings=b||{};this.predefinedAnswers=c||[];this.messageView=a;this.messageContainer="safari"==myRealAgent?self.frames[0]:$("chatwnd");FrameUtils.initFrame(this.messageContainer)},getLocaleString:function(a){return"undefined"==typeof this.localizedStrings[a]?!1:this.localizedStrings[a]},enableInput:function(a){var b=$("msgwnd");b&&(b.disabled=
!a)},clearInput:function(){var a=$("msgwnd");a&&(a.value="",a.focus())},showStatusDiv:function(a){$("engineinfo")&&($("engineinfo").style.display="inline",$("engineinfo").innerHTML=a)},setStatus:function(a){this.statusTimeout&&clearTimeout(this.statusTimeout);this.showStatusDiv(a);this.statusTimeout=setTimeout(this.clearStatus.bind(this),4E3)},clearStatus:function(){$("engineinfo").style.display="none"},showTyping:function(a){$("typingdiv")&&($("typingdiv").style.display=a?"inline":"none")},updateAvatar:function(a,
b){var c="";""!=b&&(c='<img src="'+a+'/images/free.gif" width="7" height="1" border="0" alt="" /><img src="'+b+'" border="0" alt=""/>');$("avatarwnd").innerHTML=c},displayMessages:function(a){for(var b=0;b<a.length;b++)this.outputMessage(a[b]);0<a.length&&FrameUtils.scrollDown(this.messageContainer)},outputMessage:function(a){a=this.messageView.themeMessage(a);FrameUtils.insertIntoFrame(this.messageContainer,a)},showNameField:function(){$("changename1").style.display="inline";$("changename2").style.display=
"none"},hideNameField:function(){$("changename1").style.display="none";$("changename2").style.display="inline"},updateUserName:function(a){$("unamelink").innerHTML=htmlescape(a)},changeSoundButtonState:function(a){$("soundimg").className=a?"tplimage isound":"tplimage inosound";(a=$("msgwnd"))&&a.focus()},displayPredefinedAnswer:function(a){var b=$("msgwnd");b.value=this.predefinedAnswers[a];b.focus()},resetSelectedIndex:function(a){a.selectedIndex=0}};

View File

@ -0,0 +1,9 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(e,a){a.registerHelper("apply",function(c,b){var f=c,e=/^[0-9A-z_]+$/;b=b.split(/\s*,\s*/);for(var d in b)if(b.hasOwnProperty(d)&&e.test(b[d])){if("function"!=typeof a.helpers[b[d]])throw Error("Unregistered helper '"+b[d]+"'!");f=a.helpers[b[d]](f).toString()}return new a.SafeString(f)});a.registerHelper("formatTime",function(c){var b=new Date(1E3*c);c=b.getHours().toString();var a=b.getMinutes().toString(),b=b.getSeconds().toString();return(10<c?c:"0"+c)+":"+(10<a?a:"0"+a)+":"+(10<b?b:
"0"+b)});a.registerHelper("urlReplace",function(c){return new a.SafeString(c.replace(/((?:https?|ftp):\/\/\S*)/g,'<a href="$1" target="_blank">$1</a>'))});a.registerHelper("nl2br",function(c){return new a.SafeString(c.replace(/\n/g,"<br/>"))});a.registerHelper("L10n",function(a){return e.Localization.get(a)||""})})(Mibew,Handlebars);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
var Mibew={};(function(a,b){b.Marionette.TemplateCache.prototype.compileTemplate=function(a){return Handlebars.compile(a)};a.Models={};a.Collections={};a.Views={};a.Objects={};a.Objects.Models={};a.Objects.Collections={}})(Mibew,Backbone);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(b,d){b.Localization={};var c={};b.Localization.get=function(a){return!c.hasOwnProperty(a)?!1:c[a]};b.Localization.set=function(a){d.extend(c,a)}})(Mibew,_);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Models.Base=b.Model.extend({getModelType:function(){return""}})})(Mibew,Backbone);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Models.Page=b.Model.extend()})(Mibew,Backbone);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Models.Sound=b.Model.extend({play:function(a){this.set({file:a});this.trigger("sound:play",this)}})})(Mibew,Backbone);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Models.User=b.Model.extend({defaults:{isAgent:!1,canPost:!0,typing:!1,name:"",canChangeName:!1,dafaultName:!0}})})(Mibew,Backbone);

View File

@ -0,0 +1,14 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(b,f,g,c){b.Server=function(a){this.updateTimer=null;this.options=c.extend({url:"",requestsFrequency:2,reconnectPause:1,onTimeout:function(){},onTransportError:function(){},onCallError:function(){},onUpdateError:function(){},onResponseError:function(){}},a);this.callbacks={};this.callPeriodically=[];this.ajaxRequest=null;this.buffer=[];this.functions={};this.mibewAPI=new f(new MibewAPICoreInteraction)};b.Server.prototype.callFunctions=function(a,e,b){try{if(!(a instanceof Array))throw Error("The first arguments must be an array");
for(var d in a)a.hasOwnProperty(d)&&this.mibewAPI.checkFunction(a[d],!1);var c=this.generateToken();this.callbacks[c]=e;this.buffer.push({token:c,functions:a});b&&this.update()}catch(f){return this.options.onCallError(f),!1}return!0};b.Server.prototype.callFunctionsPeriodically=function(a,e){this.callPeriodically.push({functionsListBuilder:a,callbackFunction:e})};b.Server.prototype.generateToken=function(){var a;do a="wnd"+(new Date).getTime().toString()+Math.round(50*Math.random()).toString();while(a in
this.callbacks);return a};b.Server.prototype.processRequest=function(a){var e=new MibewAPIExecutionContext,b=this.mibewAPI.getResultFunction(a.functions,this.callbacks.hasOwnProperty(a.token));if(null===b)for(var d in a.functions)a.functions.hasOwnProperty(d)&&(this.processFunction(a.functions[d],e),this.buffer.push(this.mibewAPI.buildResult(e.getResults(),a.token)));else this.callbacks.hasOwnProperty(a.token)&&(this.callbacks[a.token](b.arguments),delete this.callbacks[a.token])};b.Server.prototype.processFunction=
function(a,e){if(this.functions.hasOwnProperty(a["function"])){var b=e.getArgumentsList(a),d={},f;for(f in this.functions[a["function"]])this.functions[a["function"]].hasOwnProperty(f)&&(d=c.extend(d,this.functions[a["function"]][f](b)));e.storeFunctionResults(a,d)}};b.Server.prototype.sendRequests=function(a){this.ajaxRequest=g.ajax({url:this.options.url,timeout:5E3,async:!0,cache:!1,type:"POST",dataType:"text",data:{data:this.mibewAPI.encodePackage(a)},success:c.bind(this.receiveResponse,this),
error:c.bind(this.onError,this)})};b.Server.prototype.runUpdater=function(){null==this.updateTimer&&this.update();this.updateTimer=setTimeout(c.bind(this.update,this),1E3*this.options.requestsFrequency)};b.Server.prototype.restartUpdater=function(){this.updateTimer&&clearTimeout(this.updateTimer);this.ajaxRequest&&this.ajaxRequest.abort();this.update();this.updateTimer=setTimeout(c.bind(this.update,this),1E3*this.options.reconnectPause)};b.Server.prototype.update=function(){this.updateTimer&&clearTimeout(this.updateTimer);
for(var a=0;a<this.callPeriodically.length;a++)this.callFunctions(this.callPeriodically[a].functionsListBuilder(),this.callPeriodically[a].callbackFunction);if(0==this.buffer.length)this.runUpdater();else try{this.sendRequests(this.buffer),this.buffer=[]}catch(b){this.options.onUpdateError(b)}};b.Server.prototype.receiveResponse=function(a){""==a&&this.runUpdater();try{var b=this.mibewAPI.decodePackage(a),c;for(c in b.requests)this.processRequest(b.requests[c])}catch(d){this.options.onResponseError(d)}finally{this.runUpdater()}};
b.Server.prototype.registerFunction=function(a,b){a in this.functions||(this.functions[a]=[]);this.functions[a].push(b)};b.Server.prototype.onError=function(a,b){if("abort"!=b)if(this.restartUpdater(),"timeout"==b)this.options.onTimeout();else if("error"==b)this.options.onTransportError()}})(Mibew,MibewAPI,$,_);

View File

@ -5,4 +5,4 @@
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
var Thread=function(a){this.threadid=a.threadid||0;this.token=a.token||0;this.lastid=a.lastid||0;this.user=a.user||!1};
(function(b){b.Thread=function(a){this.threadId=a.threadId||0;this.token=a.token||0;this.lastId=a.lastId||0}})(Mibew);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(c){c.Utils={};c.Utils.toUpperCaseFirst=function(a){return"string"!=typeof a?!1:""===a?a:a.substring(0,1).toUpperCase()+a.substring(1)};c.Utils.toDashFormat=function(a){if("string"!=typeof a)return!1;a=a.match(/((?:[A-Z]?[a-z]+)|(?:[A-Z][a-z]*))/g);for(var b=0;b<a.length;b++)a[b]=a[b].toLowerCase();return a.join("-")}})(Mibew);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(d,b,e){d.Views.CollectionBase=b.Marionette.CollectionView.extend({itemView:b.Marionette.ItemView,buildItemView:function(a,b,c){c=e.extend({model:a},c);return(a=a.getModelType())&&d.Views[a]?new d.Views[a](c):new b(c)}})})(Mibew,Backbone,_);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b,c){a.Views.Sound=b.Marionette.ItemView.extend({template:c.templates.sound,className:"sound-player",modelEvents:{"sound:play":"render"}})})(Mibew,Backbone,Handlebars);

View File

@ -0,0 +1,29 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
var Mibew={};(function(a,b){b.Marionette.TemplateCache.prototype.compileTemplate=function(a){return Handlebars.compile(a)};a.Models={};a.Collections={};a.Views={};a.Objects={};a.Objects.Models={};a.Objects.Collections={}})(Mibew,Backbone);
(function(e,a){a.registerHelper("apply",function(c,b){var f=c,e=/^[0-9A-z_]+$/;b=b.split(/\s*,\s*/);for(var d in b)if(b.hasOwnProperty(d)&&e.test(b[d])){if("function"!=typeof a.helpers[b[d]])throw Error("Unregistered helper '"+b[d]+"'!");f=a.helpers[b[d]](f).toString()}return new a.SafeString(f)});a.registerHelper("formatTime",function(c){var b=new Date(1E3*c);c=b.getHours().toString();var a=b.getMinutes().toString(),b=b.getSeconds().toString();return(10<c?c:"0"+c)+":"+(10<a?a:"0"+a)+":"+(10<b?b:
"0"+b)});a.registerHelper("urlReplace",function(c){return new a.SafeString(c.replace(/((?:https?|ftp):\/\/\S*)/g,'<a href="$1" target="_blank">$1</a>'))});a.registerHelper("nl2br",function(c){return new a.SafeString(c.replace(/\n/g,"<br/>"))});a.registerHelper("L10n",function(a){return e.Localization.get(a)||""})})(Mibew,Handlebars);
(function(b,d){b.Localization={};var c={};b.Localization.get=function(a){return!c.hasOwnProperty(a)?!1:c[a]};b.Localization.set=function(a){d.extend(c,a)}})(Mibew,_);
(function(b,f,g,c){b.Server=function(a){this.updateTimer=null;this.options=c.extend({url:"",requestsFrequency:2,reconnectPause:1,onTimeout:function(){},onTransportError:function(){},onCallError:function(){},onUpdateError:function(){},onResponseError:function(){}},a);this.callbacks={};this.callPeriodically=[];this.ajaxRequest=null;this.buffer=[];this.functions={};this.mibewAPI=new f(new MibewAPICoreInteraction)};b.Server.prototype.callFunctions=function(a,e,b){try{if(!(a instanceof Array))throw Error("The first arguments must be an array");
for(var d in a)a.hasOwnProperty(d)&&this.mibewAPI.checkFunction(a[d],!1);var c=this.generateToken();this.callbacks[c]=e;this.buffer.push({token:c,functions:a});b&&this.update()}catch(f){return this.options.onCallError(f),!1}return!0};b.Server.prototype.callFunctionsPeriodically=function(a,e){this.callPeriodically.push({functionsListBuilder:a,callbackFunction:e})};b.Server.prototype.generateToken=function(){var a;do a="wnd"+(new Date).getTime().toString()+Math.round(50*Math.random()).toString();while(a in
this.callbacks);return a};b.Server.prototype.processRequest=function(a){var e=new MibewAPIExecutionContext,b=this.mibewAPI.getResultFunction(a.functions,this.callbacks.hasOwnProperty(a.token));if(null===b)for(var d in a.functions)a.functions.hasOwnProperty(d)&&(this.processFunction(a.functions[d],e),this.buffer.push(this.mibewAPI.buildResult(e.getResults(),a.token)));else this.callbacks.hasOwnProperty(a.token)&&(this.callbacks[a.token](b.arguments),delete this.callbacks[a.token])};b.Server.prototype.processFunction=
function(a,e){if(this.functions.hasOwnProperty(a["function"])){var b=e.getArgumentsList(a),d={},f;for(f in this.functions[a["function"]])this.functions[a["function"]].hasOwnProperty(f)&&(d=c.extend(d,this.functions[a["function"]][f](b)));e.storeFunctionResults(a,d)}};b.Server.prototype.sendRequests=function(a){this.ajaxRequest=g.ajax({url:this.options.url,timeout:5E3,async:!0,cache:!1,type:"POST",dataType:"text",data:{data:this.mibewAPI.encodePackage(a)},success:c.bind(this.receiveResponse,this),
error:c.bind(this.onError,this)})};b.Server.prototype.runUpdater=function(){null==this.updateTimer&&this.update();this.updateTimer=setTimeout(c.bind(this.update,this),1E3*this.options.requestsFrequency)};b.Server.prototype.restartUpdater=function(){this.updateTimer&&clearTimeout(this.updateTimer);this.ajaxRequest&&this.ajaxRequest.abort();this.update();this.updateTimer=setTimeout(c.bind(this.update,this),1E3*this.options.reconnectPause)};b.Server.prototype.update=function(){this.updateTimer&&clearTimeout(this.updateTimer);
for(var a=0;a<this.callPeriodically.length;a++)this.callFunctions(this.callPeriodically[a].functionsListBuilder(),this.callPeriodically[a].callbackFunction);if(0==this.buffer.length)this.runUpdater();else try{this.sendRequests(this.buffer),this.buffer=[]}catch(b){this.options.onUpdateError(b)}};b.Server.prototype.receiveResponse=function(a){""==a&&this.runUpdater();try{var b=this.mibewAPI.decodePackage(a),c;for(c in b.requests)this.processRequest(b.requests[c])}catch(d){this.options.onResponseError(d)}finally{this.runUpdater()}};
b.Server.prototype.registerFunction=function(a,b){a in this.functions||(this.functions[a]=[]);this.functions[a].push(b)};b.Server.prototype.onError=function(a,b){if("abort"!=b)if(this.restartUpdater(),"timeout"==b)this.options.onTimeout();else if("error"==b)this.options.onTransportError()}})(Mibew,MibewAPI,$,_);
(function(b){b.Thread=function(a){this.threadId=a.threadId||0;this.token=a.token||0;this.lastId=a.lastId||0}})(Mibew);
(function(c){c.Utils={};c.Utils.toUpperCaseFirst=function(a){return"string"!=typeof a?!1:""===a?a:a.substring(0,1).toUpperCase()+a.substring(1)};c.Utils.toDashFormat=function(a){if("string"!=typeof a)return!1;a=a.match(/((?:[A-Z]?[a-z]+)|(?:[A-Z][a-z]*))/g);for(var b=0;b<a.length;b++)a[b]=a[b].toLowerCase();return a.join("-")}})(Mibew);
(function(a,b){a.Models.Base=b.Model.extend({getModelType:function(){return""}})})(Mibew,Backbone);
(function(a,b){a.Models.Page=b.Model.extend()})(Mibew,Backbone);
(function(a,b){a.Models.Sound=b.Model.extend({play:function(a){this.set({file:a});this.trigger("sound:play",this)}})})(Mibew,Backbone);
(function(a,b){a.Models.User=b.Model.extend({defaults:{isAgent:!1,canPost:!0,typing:!1,name:"",canChangeName:!1,dafaultName:!0}})})(Mibew,Backbone);
(function(d,b,e){d.Views.CollectionBase=b.Marionette.CollectionView.extend({itemView:b.Marionette.ItemView,buildItemView:function(a,b,c){c=e.extend({model:a},c);return(a=a.getModelType())&&d.Views[a]?new d.Views[a](c):new b(c)}})})(Mibew,Backbone,_);
(function(a,b,c){a.Views.Sound=b.Marionette.ItemView.extend({template:c.templates.sound,className:"sound-player",modelEvents:{"sound:play":"render"}})})(Mibew,Backbone,Handlebars);
(function(a,b){a.Models.Page=b.Model.extend()})(Mibew,Backbone);
(function(a,b){a.Models.Sound=b.Model.extend({play:function(a){this.set({file:a});this.trigger("sound:play",this)}})})(Mibew,Backbone);
(function(a,b){a.Models.User=b.Model.extend({defaults:{isAgent:!1,canPost:!0,typing:!1,name:"",canChangeName:!1,dafaultName:!0}})})(Mibew,Backbone);
(function(a,b,c){a.Views.Sound=b.Marionette.ItemView.extend({template:c.templates.sound,className:"sound-player",modelEvents:{"sound:play":"render"}})})(Mibew,Backbone,Handlebars);

View File

@ -1,9 +0,0 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
Handlebars.registerHelper("apply",function(b,a){var c=b,e=/^[0-9A-z_]+$/,a=a.split(/\s*,\s*/),d;for(d in a)if(a.hasOwnProperty(d)&&e.test(a[d])){if("function"!=typeof Handlebars.helpers[a[d]])throw Error("Unregistered helper '"+a[d]+"'!");c=Handlebars.helpers[a[d]](c).toString()}return new Handlebars.SafeString(c)});
Handlebars.registerHelper("formatTime",function(b){var a=new Date(1E3*b),b=a.getHours().toString(),c=a.getMinutes().toString(),a=a.getSeconds().toString();return(10<b?b:"0"+b)+":"+(10<c?c:"0"+c)+":"+(10<a?a:"0"+a)});Handlebars.registerHelper("urlReplace",function(b){return new Handlebars.SafeString(b.replace(/((?:https?|ftp):\/\/\S*)/g,'<a href="$1" target="_blank">$1</a>'))});Handlebars.registerHelper("nl2br",function(b){return new Handlebars.SafeString(b.replace(/\n/g,"<br/>"))});

View File

@ -1,10 +0,0 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
var MessageView=function(){var b={"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},c=/[&<>'"`]/g;this.kindToString=function(a){return a==this.KIND_USER?"user":a==this.KIND_AGENT?"agent":a==this.KIND_FOR_AGENT?"hidden":a==this.KIND_INFO?"inf":a==this.KIND_CONN?"conn":a==this.KIND_EVENTS?"event":""};this.escapeString=function(a){return a.replace(c,function(a){return b[a]||"&amp;"})};this.themeMessage=function(a){if(!Handlebars.templates.message)throw Error("There is no template for message loaded!");
if(a.kind==this.KIND_AVATAR)throw Error("KIND_AVATAR message kind is deprecated at window!");a.allowFormating=a.kind!=this.KIND_USER&&a.kind!=this.KIND_AGENT;a.kindName=this.kindToString(a.kind);a.message=this.escapeString(a.message);return Handlebars.templates.message(a)}};MessageView.prototype.KIND_USER=1;MessageView.prototype.KIND_AGENT=2;MessageView.prototype.KIND_FOR_AGENT=3;MessageView.prototype.KIND_INFO=4;MessageView.prototype.KIND_CONN=5;MessageView.prototype.KIND_EVENTS=6;
MessageView.prototype.KIND_AVATAR=7;Handlebars.registerHelper("allowTags",function(b){b=b.replace(/&lt;(span|strong)&gt;(.*?)&lt;\/\1&gt;/g,"<$1>$2</$1>");b=b.replace(/&lt;span class=&quot;(.*?)&quot;&gt;(.*?)&lt;\/span&gt;/g,'<span class="$1">$2</span>');return new Handlebars.SafeString(b)});

View File

@ -0,0 +1,38 @@
// Backbone.js 0.9.2
// (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc.
// Backbone may be freely distributed under the MIT license.
// For all details and documentation:
// http://backbonejs.org
(function(){var l=this,y=l.Backbone,z=Array.prototype.slice,A=Array.prototype.splice,g;g="undefined"!==typeof exports?exports:l.Backbone={};g.VERSION="0.9.2";var f=l._;!f&&"undefined"!==typeof require&&(f=require("underscore"));var i=l.jQuery||l.Zepto||l.ender;g.setDomLibrary=function(a){i=a};g.noConflict=function(){l.Backbone=y;return this};g.emulateHTTP=!1;g.emulateJSON=!1;var p=/\s+/,k=g.Events={on:function(a,b,c){var d,e,f,g,j;if(!b)return this;a=a.split(p);for(d=this._callbacks||(this._callbacks=
{});e=a.shift();)f=(j=d[e])?j.tail:{},f.next=g={},f.context=c,f.callback=b,d[e]={tail:g,next:j?j.next:f};return this},off:function(a,b,c){var d,e,h,g,j,q;if(e=this._callbacks){if(!a&&!b&&!c)return delete this._callbacks,this;for(a=a?a.split(p):f.keys(e);d=a.shift();)if(h=e[d],delete e[d],h&&(b||c))for(g=h.tail;(h=h.next)!==g;)if(j=h.callback,q=h.context,b&&j!==b||c&&q!==c)this.on(d,j,q);return this}},trigger:function(a){var b,c,d,e,f,g;if(!(d=this._callbacks))return this;f=d.all;a=a.split(p);for(g=
z.call(arguments,1);b=a.shift();){if(c=d[b])for(e=c.tail;(c=c.next)!==e;)c.callback.apply(c.context||this,g);if(c=f){e=c.tail;for(b=[b].concat(g);(c=c.next)!==e;)c.callback.apply(c.context||this,b)}}return this}};k.bind=k.on;k.unbind=k.off;var o=g.Model=function(a,b){var c;a||(a={});b&&b.parse&&(a=this.parse(a));if(c=n(this,"defaults"))a=f.extend({},c,a);b&&b.collection&&(this.collection=b.collection);this.attributes={};this._escapedAttributes={};this.cid=f.uniqueId("c");this.changed={};this._silent=
{};this._pending={};this.set(a,{silent:!0});this.changed={};this._silent={};this._pending={};this._previousAttributes=f.clone(this.attributes);this.initialize.apply(this,arguments)};f.extend(o.prototype,k,{changed:null,_silent:null,_pending:null,idAttribute:"id",initialize:function(){},toJSON:function(){return f.clone(this.attributes)},get:function(a){return this.attributes[a]},escape:function(a){var b;if(b=this._escapedAttributes[a])return b;b=this.get(a);return this._escapedAttributes[a]=f.escape(null==
b?"":""+b)},has:function(a){return null!=this.get(a)},set:function(a,b,c){var d,e;f.isObject(a)||null==a?(d=a,c=b):(d={},d[a]=b);c||(c={});if(!d)return this;d instanceof o&&(d=d.attributes);if(c.unset)for(e in d)d[e]=void 0;if(!this._validate(d,c))return!1;this.idAttribute in d&&(this.id=d[this.idAttribute]);var b=c.changes={},h=this.attributes,g=this._escapedAttributes,j=this._previousAttributes||{};for(e in d){a=d[e];if(!f.isEqual(h[e],a)||c.unset&&f.has(h,e))delete g[e],(c.silent?this._silent:
b)[e]=!0;c.unset?delete h[e]:h[e]=a;!f.isEqual(j[e],a)||f.has(h,e)!=f.has(j,e)?(this.changed[e]=a,c.silent||(this._pending[e]=!0)):(delete this.changed[e],delete this._pending[e])}c.silent||this.change(c);return this},unset:function(a,b){(b||(b={})).unset=!0;return this.set(a,null,b)},clear:function(a){(a||(a={})).unset=!0;return this.set(f.clone(this.attributes),a)},fetch:function(a){var a=a?f.clone(a):{},b=this,c=a.success;a.success=function(d,e,f){if(!b.set(b.parse(d,f),a))return!1;c&&c(b,d)};
a.error=g.wrapError(a.error,b,a);return(this.sync||g.sync).call(this,"read",this,a)},save:function(a,b,c){var d,e;f.isObject(a)||null==a?(d=a,c=b):(d={},d[a]=b);c=c?f.clone(c):{};if(c.wait){if(!this._validate(d,c))return!1;e=f.clone(this.attributes)}a=f.extend({},c,{silent:!0});if(d&&!this.set(d,c.wait?a:c))return!1;var h=this,i=c.success;c.success=function(a,b,e){b=h.parse(a,e);if(c.wait){delete c.wait;b=f.extend(d||{},b)}if(!h.set(b,c))return false;i?i(h,a):h.trigger("sync",h,a,c)};c.error=g.wrapError(c.error,
h,c);b=this.isNew()?"create":"update";b=(this.sync||g.sync).call(this,b,this,c);c.wait&&this.set(e,a);return b},destroy:function(a){var a=a?f.clone(a):{},b=this,c=a.success,d=function(){b.trigger("destroy",b,b.collection,a)};if(this.isNew())return d(),!1;a.success=function(e){a.wait&&d();c?c(b,e):b.trigger("sync",b,e,a)};a.error=g.wrapError(a.error,b,a);var e=(this.sync||g.sync).call(this,"delete",this,a);a.wait||d();return e},url:function(){var a=n(this,"urlRoot")||n(this.collection,"url")||t();
return this.isNew()?a:a+("/"==a.charAt(a.length-1)?"":"/")+encodeURIComponent(this.id)},parse:function(a){return a},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return null==this.id},change:function(a){a||(a={});var b=this._changing;this._changing=!0;for(var c in this._silent)this._pending[c]=!0;var d=f.extend({},a.changes,this._silent);this._silent={};for(c in d)this.trigger("change:"+c,this,this.get(c),a);if(b)return this;for(;!f.isEmpty(this._pending);){this._pending=
{};this.trigger("change",this,a);for(c in this.changed)!this._pending[c]&&!this._silent[c]&&delete this.changed[c];this._previousAttributes=f.clone(this.attributes)}this._changing=!1;return this},hasChanged:function(a){return!arguments.length?!f.isEmpty(this.changed):f.has(this.changed,a)},changedAttributes:function(a){if(!a)return this.hasChanged()?f.clone(this.changed):!1;var b,c=!1,d=this._previousAttributes,e;for(e in a)if(!f.isEqual(d[e],b=a[e]))(c||(c={}))[e]=b;return c},previous:function(a){return!arguments.length||
!this._previousAttributes?null:this._previousAttributes[a]},previousAttributes:function(){return f.clone(this._previousAttributes)},isValid:function(){return!this.validate(this.attributes)},_validate:function(a,b){if(b.silent||!this.validate)return!0;var a=f.extend({},this.attributes,a),c=this.validate(a,b);if(!c)return!0;b&&b.error?b.error(this,c,b):this.trigger("error",this,c,b);return!1}});var r=g.Collection=function(a,b){b||(b={});b.model&&(this.model=b.model);b.comparator&&(this.comparator=b.comparator);
this._reset();this.initialize.apply(this,arguments);a&&this.reset(a,{silent:!0,parse:b.parse})};f.extend(r.prototype,k,{model:o,initialize:function(){},toJSON:function(a){return this.map(function(b){return b.toJSON(a)})},add:function(a,b){var c,d,e,g,i,j={},k={},l=[];b||(b={});a=f.isArray(a)?a.slice():[a];c=0;for(d=a.length;c<d;c++){if(!(e=a[c]=this._prepareModel(a[c],b)))throw Error("Can't add an invalid model to a collection");g=e.cid;i=e.id;j[g]||this._byCid[g]||null!=i&&(k[i]||this._byId[i])?
l.push(c):j[g]=k[i]=e}for(c=l.length;c--;)a.splice(l[c],1);c=0;for(d=a.length;c<d;c++)(e=a[c]).on("all",this._onModelEvent,this),this._byCid[e.cid]=e,null!=e.id&&(this._byId[e.id]=e);this.length+=d;A.apply(this.models,[null!=b.at?b.at:this.models.length,0].concat(a));this.comparator&&this.sort({silent:!0});if(b.silent)return this;c=0;for(d=this.models.length;c<d;c++)if(j[(e=this.models[c]).cid])b.index=c,e.trigger("add",e,this,b);return this},remove:function(a,b){var c,d,e,g;b||(b={});a=f.isArray(a)?
a.slice():[a];c=0;for(d=a.length;c<d;c++)if(g=this.getByCid(a[c])||this.get(a[c]))delete this._byId[g.id],delete this._byCid[g.cid],e=this.indexOf(g),this.models.splice(e,1),this.length--,b.silent||(b.index=e,g.trigger("remove",g,this,b)),this._removeReference(g);return this},push:function(a,b){a=this._prepareModel(a,b);this.add(a,b);return a},pop:function(a){var b=this.at(this.length-1);this.remove(b,a);return b},unshift:function(a,b){a=this._prepareModel(a,b);this.add(a,f.extend({at:0},b));return a},
shift:function(a){var b=this.at(0);this.remove(b,a);return b},get:function(a){return null==a?void 0:this._byId[null!=a.id?a.id:a]},getByCid:function(a){return a&&this._byCid[a.cid||a]},at:function(a){return this.models[a]},where:function(a){return f.isEmpty(a)?[]:this.filter(function(b){for(var c in a)if(a[c]!==b.get(c))return!1;return!0})},sort:function(a){a||(a={});if(!this.comparator)throw Error("Cannot sort a set without a comparator");var b=f.bind(this.comparator,this);1==this.comparator.length?
this.models=this.sortBy(b):this.models.sort(b);a.silent||this.trigger("reset",this,a);return this},pluck:function(a){return f.map(this.models,function(b){return b.get(a)})},reset:function(a,b){a||(a=[]);b||(b={});for(var c=0,d=this.models.length;c<d;c++)this._removeReference(this.models[c]);this._reset();this.add(a,f.extend({silent:!0},b));b.silent||this.trigger("reset",this,b);return this},fetch:function(a){a=a?f.clone(a):{};void 0===a.parse&&(a.parse=!0);var b=this,c=a.success;a.success=function(d,
e,f){b[a.add?"add":"reset"](b.parse(d,f),a);c&&c(b,d)};a.error=g.wrapError(a.error,b,a);return(this.sync||g.sync).call(this,"read",this,a)},create:function(a,b){var c=this,b=b?f.clone(b):{},a=this._prepareModel(a,b);if(!a)return!1;b.wait||c.add(a,b);var d=b.success;b.success=function(e,f){b.wait&&c.add(e,b);d?d(e,f):e.trigger("sync",a,f,b)};a.save(null,b);return a},parse:function(a){return a},chain:function(){return f(this.models).chain()},_reset:function(){this.length=0;this.models=[];this._byId=
{};this._byCid={}},_prepareModel:function(a,b){b||(b={});a instanceof o?a.collection||(a.collection=this):(b.collection=this,a=new this.model(a,b),a._validate(a.attributes,b)||(a=!1));return a},_removeReference:function(a){this==a.collection&&delete a.collection;a.off("all",this._onModelEvent,this)},_onModelEvent:function(a,b,c,d){("add"==a||"remove"==a)&&c!=this||("destroy"==a&&this.remove(b,d),b&&a==="change:"+b.idAttribute&&(delete this._byId[b.previous(b.idAttribute)],this._byId[b.id]=b),this.trigger.apply(this,
arguments))}});f.each("forEach,each,map,reduce,reduceRight,find,detect,filter,select,reject,every,all,some,any,include,contains,invoke,max,min,sortBy,sortedIndex,toArray,size,first,initial,rest,last,without,indexOf,shuffle,lastIndexOf,isEmpty,groupBy".split(","),function(a){r.prototype[a]=function(){return f[a].apply(f,[this.models].concat(f.toArray(arguments)))}});var u=g.Router=function(a){a||(a={});a.routes&&(this.routes=a.routes);this._bindRoutes();this.initialize.apply(this,arguments)},B=/:\w+/g,
C=/\*\w+/g,D=/[-[\]{}()+?.,\\^$|#\s]/g;f.extend(u.prototype,k,{initialize:function(){},route:function(a,b,c){g.history||(g.history=new m);f.isRegExp(a)||(a=this._routeToRegExp(a));c||(c=this[b]);g.history.route(a,f.bind(function(d){d=this._extractParameters(a,d);c&&c.apply(this,d);this.trigger.apply(this,["route:"+b].concat(d));g.history.trigger("route",this,b,d)},this));return this},navigate:function(a,b){g.history.navigate(a,b)},_bindRoutes:function(){if(this.routes){var a=[],b;for(b in this.routes)a.unshift([b,
this.routes[b]]);b=0;for(var c=a.length;b<c;b++)this.route(a[b][0],a[b][1],this[a[b][1]])}},_routeToRegExp:function(a){a=a.replace(D,"\\$&").replace(B,"([^/]+)").replace(C,"(.*?)");return RegExp("^"+a+"$")},_extractParameters:function(a,b){return a.exec(b).slice(1)}});var m=g.History=function(){this.handlers=[];f.bindAll(this,"checkUrl")},s=/^[#\/]/,E=/msie [\w.]+/;m.started=!1;f.extend(m.prototype,k,{interval:50,getHash:function(a){return(a=(a?a.location:window.location).href.match(/#(.*)$/))?a[1]:
""},getFragment:function(a,b){if(null==a)if(this._hasPushState||b){var a=window.location.pathname,c=window.location.search;c&&(a+=c)}else a=this.getHash();a.indexOf(this.options.root)||(a=a.substr(this.options.root.length));return a.replace(s,"")},start:function(a){if(m.started)throw Error("Backbone.history has already been started");m.started=!0;this.options=f.extend({},{root:"/"},this.options,a);this._wantsHashChange=!1!==this.options.hashChange;this._wantsPushState=!!this.options.pushState;this._hasPushState=
!(!this.options.pushState||!window.history||!window.history.pushState);var a=this.getFragment(),b=document.documentMode;if(b=E.exec(navigator.userAgent.toLowerCase())&&(!b||7>=b))this.iframe=i('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo("body")[0].contentWindow,this.navigate(a);this._hasPushState?i(window).bind("popstate",this.checkUrl):this._wantsHashChange&&"onhashchange"in window&&!b?i(window).bind("hashchange",this.checkUrl):this._wantsHashChange&&(this._checkUrlInterval=setInterval(this.checkUrl,
this.interval));this.fragment=a;a=window.location;b=a.pathname==this.options.root;if(this._wantsHashChange&&this._wantsPushState&&!this._hasPushState&&!b)return this.fragment=this.getFragment(null,!0),window.location.replace(this.options.root+"#"+this.fragment),!0;this._wantsPushState&&this._hasPushState&&b&&a.hash&&(this.fragment=this.getHash().replace(s,""),window.history.replaceState({},document.title,a.protocol+"//"+a.host+this.options.root+this.fragment));if(!this.options.silent)return this.loadUrl()},
stop:function(){i(window).unbind("popstate",this.checkUrl).unbind("hashchange",this.checkUrl);clearInterval(this._checkUrlInterval);m.started=!1},route:function(a,b){this.handlers.unshift({route:a,callback:b})},checkUrl:function(){var a=this.getFragment();a==this.fragment&&this.iframe&&(a=this.getFragment(this.getHash(this.iframe)));if(a==this.fragment)return!1;this.iframe&&this.navigate(a);this.loadUrl()||this.loadUrl(this.getHash())},loadUrl:function(a){var b=this.fragment=this.getFragment(a);return f.any(this.handlers,
function(a){if(a.route.test(b))return a.callback(b),!0})},navigate:function(a,b){if(!m.started)return!1;if(!b||!0===b)b={trigger:b};var c=(a||"").replace(s,"");this.fragment!=c&&(this._hasPushState?(0!=c.indexOf(this.options.root)&&(c=this.options.root+c),this.fragment=c,window.history[b.replace?"replaceState":"pushState"]({},document.title,c)):this._wantsHashChange?(this.fragment=c,this._updateHash(window.location,c,b.replace),this.iframe&&c!=this.getFragment(this.getHash(this.iframe))&&(b.replace||
this.iframe.document.open().close(),this._updateHash(this.iframe.location,c,b.replace))):window.location.assign(this.options.root+a),b.trigger&&this.loadUrl(a))},_updateHash:function(a,b,c){c?a.replace(a.toString().replace(/(javascript:|#).*$/,"")+"#"+b):a.hash=b}});var v=g.View=function(a){this.cid=f.uniqueId("view");this._configure(a||{});this._ensureElement();this.initialize.apply(this,arguments);this.delegateEvents()},F=/^(\S+)\s*(.*)$/,w="model,collection,el,id,attributes,className,tagName".split(",");
f.extend(v.prototype,k,{tagName:"div",$:function(a){return this.$el.find(a)},initialize:function(){},render:function(){return this},remove:function(){this.$el.remove();return this},make:function(a,b,c){a=document.createElement(a);b&&i(a).attr(b);c&&i(a).html(c);return a},setElement:function(a,b){this.$el&&this.undelegateEvents();this.$el=a instanceof i?a:i(a);this.el=this.$el[0];!1!==b&&this.delegateEvents();return this},delegateEvents:function(a){if(a||(a=n(this,"events"))){this.undelegateEvents();
for(var b in a){var c=a[b];f.isFunction(c)||(c=this[a[b]]);if(!c)throw Error('Method "'+a[b]+'" does not exist');var d=b.match(F),e=d[1],d=d[2],c=f.bind(c,this),e=e+(".delegateEvents"+this.cid);""===d?this.$el.bind(e,c):this.$el.delegate(d,e,c)}}},undelegateEvents:function(){this.$el.unbind(".delegateEvents"+this.cid)},_configure:function(a){this.options&&(a=f.extend({},this.options,a));for(var b=0,c=w.length;b<c;b++){var d=w[b];a[d]&&(this[d]=a[d])}this.options=a},_ensureElement:function(){if(this.el)this.setElement(this.el,
!1);else{var a=n(this,"attributes")||{};this.id&&(a.id=this.id);this.className&&(a["class"]=this.className);this.setElement(this.make(this.tagName,a),!1)}}});o.extend=r.extend=u.extend=v.extend=function(a,b){var c=G(this,a,b);c.extend=this.extend;return c};var H={create:"POST",update:"PUT","delete":"DELETE",read:"GET"};g.sync=function(a,b,c){var d=H[a];c||(c={});var e={type:d,dataType:"json"};c.url||(e.url=n(b,"url")||t());if(!c.data&&b&&("create"==a||"update"==a))e.contentType="application/json",
e.data=JSON.stringify(b.toJSON());g.emulateJSON&&(e.contentType="application/x-www-form-urlencoded",e.data=e.data?{model:e.data}:{});if(g.emulateHTTP&&("PUT"===d||"DELETE"===d))g.emulateJSON&&(e.data._method=d),e.type="POST",e.beforeSend=function(a){a.setRequestHeader("X-HTTP-Method-Override",d)};"GET"!==e.type&&!g.emulateJSON&&(e.processData=!1);return i.ajax(f.extend(e,c))};g.wrapError=function(a,b,c){return function(d,e){e=d===b?e:d;a?a(b,e,c):b.trigger("error",b,e,c)}};var x=function(){},G=function(a,
b,c){var d;d=b&&b.hasOwnProperty("constructor")?b.constructor:function(){a.apply(this,arguments)};f.extend(d,a);x.prototype=a.prototype;d.prototype=new x;b&&f.extend(d.prototype,b);c&&f.extend(d,c);d.prototype.constructor=d;d.__super__=a.prototype;return d},n=function(a,b){return!a||!a[b]?null:f.isFunction(a[b])?a[b]():a[b]},t=function(){throw Error('A "url" property or function must be specified');}}).call(this);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,172 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function (Mibew, Backbone) {
// Create application instance
var App = new Backbone.Marionette.Application();
// Define regions
App.addRegions({
controlsRegion: '#controls-region',
avatarRegion: '#avatar-region',
messagesRegion: Mibew.Regions.Messages,
statusRegion: '#status-region',
messageFormRegion: '#message-form-region',
soundRegion: '#sound-region'
});
// Initialize application
App.addInitializer(function(options){
// Create some shortcuts
var objs = Mibew.Objects;
var models = Mibew.Objects.Models;
var controls = Mibew.Objects.Models.Controls;
var status = Mibew.Objects.Models.Status;
// Initialize Server, Thread and User
objs.server = new Mibew.Server(options.server);
objs.thread = new Mibew.Thread(options.thread);
models.user = new Mibew.Models.User(options.user);
// Initialize Page
models.page = new Mibew.Models.Page(options.page);
// Initialize controls
// Create controls collection
var ctrlsCollection = new Mibew.Collections.Controls();
// Create controls only for user
if (! models.user.get('isAgent')) {
// Create user name control
controls.userName = new Mibew.Models.UserNameControl({
weight: 220
});
ctrlsCollection.push(controls.userName);
// Create mail control
controls.sendMail = new Mibew.Models.SendMailControl({
weight: 200,
link: options.links.mailLink
});
ctrlsCollection.push(controls.sendMail);
}
// Create controls only for agent
if (models.user.get('isAgent')) {
controls.redirect = new Mibew.Models.RedirectControl({
weight: 200,
link: options.links.redirectLink
});
ctrlsCollection.push(controls.redirect);
controls.history = new Mibew.Models.HistoryControl({
weight: 180,
link: options.links.historyLink
});
ctrlsCollection.push(controls.history);
}
// Create toggle sound button
controls.sound = new Mibew.Models.SoundControl({
weight: 160
});
ctrlsCollection.push(controls.sound);
// Create refresh button
controls.refresh = new Mibew.Models.RefreshControl({
weight: 140
});
ctrlsCollection.push(controls.refresh);
if (options.links.sslLink) {
controls.secureMode = new Mibew.Models.SecureModeControl({
weight: 120,
link: options.links.sslLink
});
ctrlsCollection.push(controls.secureMode);
}
// Create close button
controls.close = new Mibew.Models.CloseControl({
weight: 100
});
ctrlsCollection.push(controls.close);
objs.Collections.controls = ctrlsCollection;
// Display controls
App.controlsRegion.show(new Mibew.Views.ControlsCollection({
collection: ctrlsCollection
}));
// Iniitialize status bar
// Create status message model
status.message = new Mibew.Models.StatusMessage({hideTimeout: 5000});
// Create typing status model
status.typing = new Mibew.Models.StatusTyping({hideTimeout: 5000});
// Create status collection
objs.Collections.status = new Mibew.Collections.Status([
status.message,
status.typing
]);
// Display status bar
App.statusRegion.show(new Mibew.Views.StatusCollection({
collection: objs.Collections.status
}));
// Initialize avatar only for user
if (! models.user.get('isAgent')) {
models.avatar = new Mibew.Models.Avatar();
App.avatarRegion.show(new Mibew.Views.Avatar({
model: models.avatar
}));
}
// Initialize chat window
// Create messages collection and store it
objs.Collections.messages = new Mibew.Collections.Messages();
// Create message processor model
models.messageForm = new Mibew.Models.MessageForm(
options.messageForm
);
// Display message processor
App.messageFormRegion.show(new Mibew.Views.MessageForm({
model: models.messageForm
}));
// Display messages
App.messagesRegion.show(new Mibew.Views.MessagesCollection({
collection: objs.Collections.messages
}));
// Initialize sounds
models.sound = new Mibew.Models.Sound();
App.soundRegion.show(new Mibew.Views.Sound({
model: models.sound
}));
// Run server updater
objs.server.runUpdater();
});
Mibew.Application = App;
})(Mibew, Backbone);

View File

@ -0,0 +1,27 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Backbone){
/**
* @class Represents collection of chat controls
*/
Mibew.Collections.Controls = Backbone.Collection.extend(
/** @lends Mibew.Collections.Controls.prototype */
{
/**
* Use for sort controls in collection
* @param {Backbone.Model} model Control model
*/
comparator: function(model) {
return model.get('weight');
}
}
);
})(Mibew, Backbone);

View File

@ -0,0 +1,135 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Backbone, _){
/**
* @class Represents messages list
*/
Mibew.Collections.Messages = Backbone.Collection.extend(
/** @lends Mibew.Collections.Message.prototype */
{
/**
* Default contructor for model
* @type Function
*/
model: Mibew.Models.Message,
/**
* Collection initializer.
*/
initialize: function() {
// Add periodic functions
Mibew.Objects.server.callFunctionsPeriodically(
_.bind(this.updateFunctionBuilder, this),
_.bind(this.updateChatState, this)
);
// Register API functions
Mibew.Objects.server.registerFunction(
'updateMessages',
_.bind(this.apiUpdateMessages, this)
);
},
/**
* Update messages if they are exist.
* This is an API function.
* @param args {Object} An object of passed arguments
*/
apiUpdateMessages: function(args) {
// Update last message id
if (args.lastId) {
Mibew.Objects.thread.lastId = args.lastId;
}
// Get all new messages
var newMessages = [];
for(var i = 0, length = args.messages.length; i < length; i++) {
// Store message
newMessages.push(
new Mibew.Models.Message(args.messages[i])
);
}
// Add new messages to the message collection if there are any
// messages
if (newMessages.length > 0) {
this.add(newMessages);
}
},
/**
* Builds update function, that should be called periodically at
* the server side
* @returns {Object[]} Array of functions objects
*/
updateFunctionBuilder: function() {
// Get thread and user objects
var thread = Mibew.Objects.thread;
var user = Mibew.Objects.Models.user;
// Build functions list
return [
{
"function": "update",
"arguments": {
"return": {
'typing': 'typing',
'canPost': 'canPost'
},
"references": {},
"threadId": thread.threadId,
"token": thread.token,
"lastId": thread.lastId,
"typed": user.get('typing'),
"user": (! user.get('isAgent'))
}
}
];
},
/**
* Updates chat status
* @param {Object} args Arguments passed from the server
*/
updateChatState: function(args) {
// Check if there was an error
if (args.errorCode) {
Mibew.Objects.Models.Status.message.setMessage(
args.errorMessage || 'refresh failed'
);
return;
}
// Update typing status
if (args.typing) {
Mibew.Objects.Models.Status.typing.show();
}
// Update user
Mibew.Objects.Models.user.set({
canPost: args.canPost || false
});
},
/**
* Override Backbone.Collection.add method to call additional event
*/
add: function() {
// Get arguments list
var args = Array.prototype.slice.apply(arguments);
// Call method of the parent class
var res = Backbone.Collection.prototype.add.apply(this, args);
// Triggers additional event
this.trigger('multiple:add');
return res;
}
}
);
})(Mibew, Backbone, _);

View File

@ -0,0 +1,27 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Backbone){
/**
* @class Represents status bar
*/
Mibew.Collections.Status = Backbone.Collection.extend(
/** @lends Mibew.Collections.Status.prototype */
{
/**
* Use for sort controls in collection
* @param {Backbone.Model} model Control model
*/
comparator: function(model) {
return model.get('weight');
}
}
);
})(Mibew, Backbone);

View File

@ -0,0 +1,29 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Handlebars){
/**
* Register 'allowTags' Handlebars helper.
*
* This helper unescape HTML entities for allowed (span and strong) tags.
*/
Handlebars.registerHelper('allowTags', function(text) {
var result = text;
result = result.replace(
/&lt;(span|strong)&gt;(.*?)&lt;\/\1&gt;/g,
'<$1>$2</$1>'
);
result = result.replace(
/&lt;span class=&quot;(.*?)&quot;&gt;(.*?)&lt;\/span&gt;/g,
'<span class="$1">$2</span>'
);
return new Handlebars.SafeString(result);
});
})(Handlebars);

View File

@ -0,0 +1,26 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew){
/**
* @namespace Holds application region constructors
*/
Mibew.Regions = {};
/**
* @namespace Holds instances of control models
*/
Mibew.Objects.Models.Controls = {};
/**
* @namespace Holds instances of status models
*/
Mibew.Objects.Models.Status = {};
})(Mibew);

View File

@ -0,0 +1,53 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, _){
/**
* @class Represents agent's avatar
*/
Mibew.Models.Avatar = Mibew.Models.Base.extend(
/** @lends Mibew.Models.Avatar.prototype */
{
/**
* A list of default model values.
* @type Object
*/
defaults : {
/**
* An URL of the avatar image or false by default.
* @type String|Boolean
*/
imageLink: false
},
/**
* Model initializer.
*/
initialize: function() {
// Register API function
Mibew.Objects.server.registerFunction(
'setupAvatar',
_.bind(this.apiSetupAvatar, this)
);
},
/**
* Set avatar
* This is an API function.
* @param args {Object} An object of passed arguments
*/
apiSetupAvatar: function(args) {
if (args.imageLink) {
this.set({imageLink: args.imageLink});
}
}
}
);
})(Mibew, _);

View File

@ -0,0 +1,38 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew){
/**
* @class Base class for controls
*/
Mibew.Models.Control = Mibew.Models.Base.extend(
/** @lends Mibew.Models.Control.prototype */
{
/**
* A list of model default values.
*/
defaults : {
/**
* Control title
* @type String
*/
title: '',
/**
* Control weight. Used for ordering controls.
* @type Number
*/
weight: 0
}
}
);
})(Mibew);

View File

@ -0,0 +1,66 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew){
/**
* @class Close control model
*/
Mibew.Models.CloseControl = Mibew.Models.Control.extend(
/** @lends Mibew.Models.CloseControl.prototype */
{
/**
* Returns model type
* @returns {String} Model type
*/
getModelType: function() {
return 'CloseControl';
},
/**
* Close chat thread at the server
*
* If something went wrong update status message otherwise close
* chat window
*
* @todo May be move to Mibew.Thread class
*/
closeThread: function() {
// Get thread and user objects
var thread = Mibew.Objects.thread;
var user = Mibew.Objects.Models.user;
// Send request to the server
Mibew.Objects.server.callFunctions(
[{
"function": "close",
"arguments": {
"references": {},
"return": {"closed": "closed"},
"threadId": thread.threadId,
"token": thread.token,
"lastId": thread.lastId,
"user": (! user.get('isAgent'))
}
}],
function(args){
if (args.closed) {
window.close();
} else {
// Something went wrong. Display error message
Mibew.Objects.Models.Status.message.setMessage(
args.errorMessage || 'Cannot close'
);
}
},
true
);
}
}
);
})(Mibew);

View File

@ -0,0 +1,47 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, _){
/**
* @class History control model
*/
Mibew.Models.HistoryControl = Mibew.Models.Control.extend(
/** @lends Mibew.Models.HistoryControl.prototype */
{
/**
* A list of default model values.
*
* The model inherits defaults from
* {@link Mibew.Models.Control.prototype.defaults}.
* @type Object
*/
defaults: _.extend(
{},
Mibew.Models.Control.prototype.defaults,
{
/**
* An URL of the History page or false by default.
* @type String|Boolean
*/
link: false
}
),
/**
* Returns model type
* @returns {String} Model type
*/
getModelType: function() {
return 'HistoryControl';
}
}
);
})(Mibew, _);

View File

@ -0,0 +1,47 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, _){
/**
* @class Redirect control model
*/
Mibew.Models.RedirectControl = Mibew.Models.Control.extend(
/** @lends Mibew.Models.RedirectControl.prototype */
{
/**
* A list of default model values.
*
* The model inherits defaults from
* {@link Mibew.Models.Control.prototype.defaults}.
* @type Object
*/
defaults: _.extend(
{},
Mibew.Models.Control.prototype.defaults,
{
/**
* An URL of the Redirect page or false by default.
* @type String|Boolean
*/
link: false
}
),
/**
* Returns model type
* @returns {String} Model type
*/
getModelType: function() {
return 'RedirectControl';
}
}
);
})(Mibew, _);

View File

@ -0,0 +1,34 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew){
/**
* @class Represent Refresh control model
*/
Mibew.Models.RefreshControl = Mibew.Models.Control.extend(
/** @lends Mibew.Models.RefreshControl.prototype */
{
/**
* Returns model type
* @returns {String} Model type
*/
getModelType: function() {
return 'RefreshControl';
},
/**
* Refresh message window
*/
refresh: function() {
Mibew.Objects.server.restartUpdater();
}
}
);
})(Mibew);

View File

@ -0,0 +1,46 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, _){
/**
* @class Represent Secure mode control model
*/
Mibew.Models.SecureModeControl = Mibew.Models.Control.extend(
/** @lends Mibew.Models.SecureModeControl.prototype */
{
/**
* A list of default model values.
*
* The model inherits defaults from
* {@link Mibew.Models.Control.prototype.defaults}.
* @type Object
*/
defaults: _.extend(
{},
Mibew.Models.Control.prototype.defaults,
{
/**
* An URL of the secure chat or false by default.
* @type String|Boolean
*/
link: false
}
),
/**
* Returns model type
* @returns {String} Model type
*/
getModelType: function() {
return 'SecureModeControl';
}
}
);
})(Mibew, _);

View File

@ -0,0 +1,45 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, _){
/**
* @class Represent Send mail control model
*/
Mibew.Models.SendMailControl = Mibew.Models.Control.extend(
/** @lends Mibew.Models.SendMailControl.prototype */
{
/**
* A list of default model values.
*
* The model inherits defaults from
* {@link Mibew.Models.Control.prototype.defaults}.
* @type Object
*/
defaults: _.extend(
{},
Mibew.Models.Control.prototype.defaults,
{
/**
* An URL of the Mail page or false by default.
* @type String|Boolean
*/
link: false
}
),
/**
* Returns model type
* @returns {String} Model type
*/
getModelType: function() {
return 'SendMailControl';
}
}
);
})(Mibew, _);

View File

@ -0,0 +1,45 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, _){
/**
* @class Represents toggle sound control model
*/
Mibew.Models.SoundControl = Mibew.Models.Control.extend(
/** @lends Mibew.Models.SoundControl.prototype */
{
/**
* A list of default model values.
* The model inherits defaults from
* {@link Mibew.Models.Control.prototype.defaults}.
* @type Object
*/
defaults: _.extend(
{},
Mibew.Models.Control.prototype.defaults,
{
/**
* Indicates if sound enable.
* @type Boolean
*/
enabled: true
}
),
/**
* Returns model type
* @returns {String} Model type
*/
getModelType: function() {
return 'SoundControl'
}
}
);
})(Mibew, _);

View File

@ -0,0 +1,71 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew){
/**
* @class User name control model
*/
Mibew.Models.UserNameControl = Mibew.Models.Control.extend(
/** @lends Mibew.Models.UserNameControl.prototype */
{
/**
* Returns model type
* @returns {String} Model type
*/
getModelType: function() {
return 'UserNameControl';
},
/**
* Change user name at client and server sides
* @param {String} newName New user name
*/
changeName: function(newName) {
// Get thread and user objects
var user = Mibew.Objects.Models.user;
var thread = Mibew.Objects.thread;
// Store old name in closure
var oldName = user.get('name');
// Check if name should be changed
if (! newName || oldName == newName) {
return;
}
// Try to change user name at the server side
Mibew.Objects.server.callFunctions(
[{
"function": "rename",
"arguments": {
"references": {},
"return": {},
"threadId": thread.threadId,
"token": thread.token,
"name": newName
}
}],
function(args){
if (args.errorCode) {
// Something went wrong. Show error message and
// restore old name
Mibew.Objects.Models.Status.message.setMessage(
args.errorMessage || 'Cannot rename'
);
user.set({name: oldName});
}
},
true
);
// Change user name at the cient side
user.set({name: newName});
}
}
);
})(Mibew);

View File

@ -0,0 +1,30 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew){
/**
* @class Base class for message models
*/
Mibew.Models.Message = Mibew.Models.Base.extend(
/** @lends Mibew.Models.Message.prototype */
{
/**
* Default values of model
*/
defaults : {
/**
* Text of the message
* @type String
*/
message: ''
}
}
);
})(Mibew);

View File

@ -0,0 +1,79 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew){
/**
* @class Represents message form model
*/
Mibew.Models.MessageForm = Mibew.Models.Base.extend(
/** @lends Mibew.Models.MessageForm.prototype */
{
/**
* A list of default model values.
* @type Object
*/
defaults: {
/**
* Array of predifined answers
* @type Array
*/
predefinedAnswers: [],
/**
* Indicates if Enter or Ctrl+Enter should send message
* @type Boolean
*/
ignoreCtrl: false
},
/**
* Post message.
* Send message to the server and run callback function after that.
* @param {String} msg Message to send
*/
postMessage: function(msg) {
// Get thread and user objects
var thread = Mibew.Objects.thread;
var user = Mibew.Objects.Models.user;
// Check if user can post a message
if (! user.get('canPost')) {
return;
}
// Triggers before post event
this.trigger('before:post', this);
// Store link to the object
var self = this;
// Post message to the server
Mibew.Objects.server.callFunctions(
[{
"function": "post",
"arguments": {
"references": {},
"return": {},
"message": msg,
"threadId": thread.threadId,
"token": thread.token,
"user": (! user.get('isAgent'))
}
}],
function() {
self.trigger('after:post', self);
},
true
);
}
}
);
})(Mibew);

View File

@ -0,0 +1,83 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, _){
/**
* @class Represents base status model
*/
Mibew.Models.Status = Mibew.Models.Base.extend(
/** @lends Mibew.Models.Status */
{
/**
* A list of default model values.
* @type Object
*/
defaults: {
/**
* Indicates if status element is visible or not.
* @type Boolean
*/
visible: true,
/**
* Use for ordering status elements in status collection.
* @type Number
*/
weight: 0,
/**
* Time in milliseconds after that status message will be
* cleaned.
* @type Number
*/
hideTimeout: 4000,
/**
* Title of status element.
* @type String
*/
title: ''
},
/**
* Class initializer
*/
initialize: function () {
/**
* Timer for hiding status element
*/
this.hideTimer = null;
},
/**
* Automatically hide status element after timeout
* @param {Number} [timeout] Timeout in milliseconds before hide
* status element. Default value is this.get('hideTimeout').
*/
autoHide: function(timeout) {
var delay = timeout || this.get('hideTimeout');
// Clear timer if it runs
if (this.hideTimer) {
clearTimeout(this.hideTimer);
}
// Hide status element after a while
this.hideTimer = setTimeout(
_.bind(
function(){this.set({visible: false});},
this
),
delay
);
}
}
);
})(Mibew, _);

View File

@ -0,0 +1,66 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, _){
/**
* @class Represents status message model
*/
Mibew.Models.StatusMessage = Mibew.Models.Status.extend(
/** @lends Mibew.Models.StatusMessage.prototype */
{
/**
* A list of default model values.
* The model inherits defaults from
* {@link Mibew.Models.Status.prototype.defaults}.
* @type Object
*/
defaults: _.extend(
{},
Mibew.Models.Status.prototype.defaults,
{
/**
* Text of the status message.
* @type String
*/
message: '',
/**
* Indicates if status message is visible or not.
* @type Boolean
*/
visible: false
}
),
/**
* Returns model type
* @returns {String} Model type
*/
getModelType: function() {
return 'StatusMessage'
},
/**
* Update status message
* @param {String} msg New status message
*/
setMessage: function(msg) {
// Update status message
this.set({
message: msg,
visible: true
});
// Hide status message after a while
this.autoHide();
}
}
);
})(Mibew, _);

View File

@ -0,0 +1,65 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, _){
/**
* @class Represents typing status model
*/
Mibew.Models.StatusTyping = Mibew.Models.Status.extend(
/** @lends Mibew.Models.StatusTyping.prototype */
{
/**
* A list of default model values.
*
* The model inherits defaults from
* {@link Mibew.Models.Status.prototype.defaults}.
* @type Object
*/
defaults: _.extend(
{},
Mibew.Models.Status.prototype.defaults,
{
/**
* Indicates if status element is visible or not.
* @type Boolean
*/
visible: false,
/**
* Time in milliseconds after that status message will be
* cleaned.
* @type Number
*/
hideTimeout: 2000
}
),
/**
* Returns model type
* @returns {String} Model type
*/
getModelType: function() {
return 'StatusTyping'
},
/**
* Make the status element visible
* @todo May be move it to the view!?
*/
show: function() {
// Make typing status visible
this.set({visible: true});
// Hide it after a while
this.autoHide();
}
}
);
})(Mibew, _);

View File

@ -0,0 +1,42 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Backbone){
/**
* @class Represents Messages region
*/
Mibew.Regions.Messages = Backbone.Marionette.Region.extend(
/** @lends Mibew.Regions.Message */
{
/**
* DOM element for the region
* @type String
*/
el: '#messages-region',
/**
* Show view event handler. Register handler to view's
* 'after:item:added' event.
* @param {Backbone.Marionette.ItemView} view View to show in region
*/
onShow: function(view) {
view.on('after:item:added', this.scrollToBottom, this);
},
/**
* Scroll region to bottom.
*/
scrollToBottom: function() {
this.$el.scrollTop(this.$el.prop('scrollHeight'));
}
}
);
})(Mibew, Backbone);

View File

@ -0,0 +1,39 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Backbone, Handlebars) {
/**
* @class Represents user avatar view
*/
Mibew.Views.Avatar = Backbone.Marionette.ItemView.extend(
/** @lends Mibew.Views.Avatar.prototype */
{
/**
* Template function
* @type Function
*/
template: Handlebars.templates.avatar,
/**
* Class name for view's DOM element
* @type String
*/
className: 'avatar',
/**
* Map model events to the view methods
* @type Object
*/
modelEvents: {
'change': 'render'
}
}
);
})(Mibew, Backbone, Handlebars);

View File

@ -0,0 +1,110 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Backbone, Handlebars) {
/**
* @class Represents default control. Implement some basic functionality.
*/
Mibew.Views.Control = Backbone.Marionette.ItemView.extend(
/** @lends Mibew.Views.Control.prototype */
{
/**
* Template function
* @type Function
*/
template: Handlebars.templates.control,
/**
* Map model events to the view methods
* @type Object
*/
modelEvents: {
'change': 'render'
},
/**
* Map ui events to view methods. Use as default for all child
* views.
* @type Object
*/
events: {
'mouseover': 'mouseOver',
'mouseleave': 'mouseLeave'
},
/**
* Generate hash of view's DOM element attributes. Add default CSS
* classes whose names based on the result of model's 'getModelType'
* method.
*/
attributes: function() {
// Init classes list
var classes = [];
// Add default for all controls CSS class
classes.push('control');
// Add CSS class from className properti of the view
if (this.className) {
classes.push(this.className);
// Prevent using className property instead of result of
// this method
this.className = '';
}
// Add CSS class based on model type
var controlType = this.getDashedControlType();
if (controlType) {
classes.push(controlType);
}
return {
'class': classes.join(' ')
}
},
/**
* Handles mouse over event on the control. Add 'active' CSS class
* to the view's DOM element.
*/
mouseOver: function() {
var controlType = this.getDashedControlType();
this.$el.addClass(
'active' +
(controlType ? '-' + controlType : '' )
);
},
/**
* Handles mouse leave event on the control. Remove 'active' CSS
* class from the view's DOM element.
*/
mouseLeave: function() {
var controlType = this.getDashedControlType();
this.$el.removeClass(
'active' +
(controlType ? '-' + controlType : '' )
);
},
/**
* Create dasherized version of the model type or use cached one.
* @returns {Strring} Model type
*/
getDashedControlType: function() {
if (typeof this.dashedControlType == 'undefined') {
// There is no control type in the cache
this.dashedControlType = Mibew.Utils.toDashFormat(
this.model.getModelType()
) || '';
}
return this.dashedControlType;
}
}
);
})(Mibew, Backbone, Handlebars);

View File

@ -0,0 +1,53 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Handlebars, _) {
/**
* @class Represents Close control view
*/
Mibew.Views.CloseControl = Mibew.Views.Control.extend(
/** @lends Mibew.Views.CloseControl.prototype */
{
/**
* Template function
* @type Function
*/
template: Handlebars.templates.close_control,
/**
* Map ui events to view methods
* The view inherits events from
* {@link Mibew.Views.Control.prototype.events}.
* @type Object
*/
events: _.extend(
{},
Mibew.Views.Control.prototype.events,
{
'click': 'close'
}
),
/**
* Display confirmation dialog and close chat window
*/
close: function() {
// Show confirmation message if can
var confirmMessage = Mibew.Localization.get('chat.close.confirmation');
if (confirmMessage !== false) {
if (! confirm(confirmMessage)) {
return;
}
}
this.model.closeThread();
}
}
);
})(Mibew, Handlebars, _);

View File

@ -0,0 +1,31 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew) {
/**
* @class Represents controls bar
*/
Mibew.Views.ControlsCollection = Mibew.Views.CollectionBase.extend(
/** @lends Mibew.Views.ControlsCollection.prototype */
{
/**
* Default item view constructor.
* @type Function
*/
itemView: Mibew.Views.Control,
/**
* Class name for view's DOM element
* @type String
*/
className: 'controls-collection'
}
);
})(Mibew);

View File

@ -0,0 +1,63 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Handlebars, _) {
/**
* @class Represents History control view
*/
Mibew.Views.HistoryControl = Mibew.Views.Control.extend(
/** @lends Mibew.Views.HistoryControl.prototype */
{
/**
* Template function
* @type Function
*/
template: Handlebars.templates.history_control,
/**
* Map ui events to view methods
* The view inherits events from
* {@link Mibew.Views.Control.prototype.events}.
* @type Object
*/
events: _.extend(
{},
Mibew.Views.Control.prototype.events,
{
'click': 'showHistory'
}
),
/**
* Dispalay history window
*/
showHistory: function() {
var user = Mibew.Objects.Models.user;
var link = this.model.get('link');
if (user.get('isAgent') && link) {
// TODO: Create wiki docs for it
var winParams = this.$el
.find('.control-config')
.eq(0)
.data('win-params');
// TODO: Kill &amp; at the server side
link = link.replace('&amp;', '&', 'g');
var newWindow = window.open(link, 'UserHistory', winParams);
if (newWindow !== null) {
newWindow.focus();
newWindow.opener=window;
}
}
}
}
);
})(Mibew, Handlebars, _);

View File

@ -0,0 +1,73 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Handlebars, _) {
/**
* @class Represents Redirect control view
*/
Mibew.Views.RedirectControl = Mibew.Views.Control.extend(
/** @lends Mibew.Views.RedirectControl.prototype */
{
/**
* Template function
* @type Function
*/
template: Handlebars.templates.redirect_control,
/**
* Map ui events to view methods
* The view inherits events from
* {@link Mibew.Views.Control.prototype.events}.
* @type Object
*/
events: _.extend(
{},
Mibew.Views.Control.prototype.events,
{
'click': 'redirect'
}
),
/**
* View initializer.
*/
initialize: function() {
Mibew.Objects.Models.user.on('change', this.render, this);
},
/**
* Override Backbone.Marionette.ItemView.serializeData to pass some
* extra fields to template.
* @returns {Object} Template data
*/
serializeData: function() {
var data = this.model.toJSON();
data.user = Mibew.Objects.Models.user.toJSON();
return data;
},
/**
* Display user redirection window
*/
redirect: function() {
var user = Mibew.Objects.Models.user;
if (user.get('isAgent') && user.get('canPost')) {
var link = this.model.get('link');
if (link) {
// Redirect browser to user redirection page
var style = Mibew.Objects.Models.page.get('style');
window.location.href = link.replace(/\&amp\;/g, '&')
+ (style ? ('&style=' + style) : '');
}
}
}
}
);
})(Mibew, Handlebars, _);

View File

@ -0,0 +1,46 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Handlebars, _) {
/**
* @class Represents Refresh control View
*/
Mibew.Views.RefreshControl = Mibew.Views.Control.extend(
/** @lends Mibew.Views.RefreshControl.prototype */
{
/**
* Template function
* @type Function
*/
template: Handlebars.templates.refresh_control,
/**
* Map ui events to view methods
* The view inherits events from
* {@link Mibew.Views.Control.prototype.events}.
* @type Object
*/
events: _.extend(
{},
Mibew.Views.Control.prototype.events,
{
'click': 'refresh'
}
),
/**
* Refresh chat window via model's refresh method
*/
refresh: function() {
this.model.refresh();
}
}
);
})(Mibew, Handlebars, _);

View File

@ -0,0 +1,51 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Handlebars, _) {
/**
* @class Represents Secure mode control View
*/
Mibew.Views.SecureModeControl = Mibew.Views.Control.extend(
/** @lends Mibew.Views.SecureModeControl.prototype */
{
/**
* Template function
* @type Function
*/
template: Handlebars.templates.secure_mode_control,
/**
* Map ui events to view methods
* The view inherits events from
* {@link Mibew.Views.Control.prototype.events}.
* @type Object
*/
events: _.extend(
{},
Mibew.Views.Control.prototype.events,
{
'click': 'secure'
}
),
/**
* Move to secure chat
*/
secure: function() {
var link = this.model.get('link')
if (link) {
var style = Mibew.Objects.Models.page.get('style');
window.location.href = link.replace(/\&amp\;/g, '&')
+ (style ? ('&style=' + style) : '');
}
}
}
);
})(Mibew, Handlebars, _);

View File

@ -0,0 +1,65 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Handlebars, _) {
/**
* @class Represents Send mail control View
*/
Mibew.Views.SendMailControl = Mibew.Views.Control.extend(
/** @lends Mibew.Views.SendMailControl.prototype */
{
/**
* Template function
* @type Function
*/
template: Handlebars.templates.send_mail_control,
/**
* Map ui events to view methods
* The view inherits events from
* {@link Mibew.Views.Control.prototype.events}.
* @type Object
*/
events: _.extend(
{},
Mibew.Views.Control.prototype.events,
{
'click': 'sendMail'
}
),
/**
* Load and display send mail window
*/
sendMail: function() {
var link = this.model.get('link')
if (link) {
// TODO: Create wiki docs for it
var winParams = this.$el
.find('.control-config')
.eq(0)
.data('win-params');
var style = Mibew.Objects.Models.page.get('style');
// TODO: Kill &amp; at the server side
link = link.replace(/\&amp\;/g, '&')
+ (style ? ('&style=' + style) : '');
var newWindow = window.open(link, 'ForwardMail', winParams);
if (newWindow !== null) {
newWindow.focus();
newWindow.opener=window;
}
}
}
}
);
})(Mibew, Handlebars, _);

View File

@ -0,0 +1,48 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Handlebars, _) {
/**
* @class Represents cound control view
*/
Mibew.Views.SoundControl = Mibew.Views.Control.extend(
/** @lends Mibew.Views.SoundControl.prototype */
{
/**
* Template function
* @type Function
*/
template: Handlebars.templates.sound_control,
/**
* Map ui events to view methods
* The view inherits events from
* {@link Mibew.Views.Control.prototype.events}.
* @type Object
*/
events: _.extend(
{},
Mibew.Views.Control.prototype.events,
{
'click': 'toggle'
}
),
/**
* Toggle sound state
*/
toggle: function() {
this.model.set({
enabled: !this.model.get('enabled')
});
}
}
);
})(Mibew, Handlebars, _);

View File

@ -0,0 +1,109 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Handlebars, _) {
Mibew.Views.UserNameControl = Mibew.Views.Control.extend(
/** @lends Mibew.Views.UserNameControl.prototype */
{
/**
* Template function
* @type Function
*/
template: Handlebars.templates.user_name_control,
/**
* Map ui events to view methods
* The view inherits events from
* {@link Mibew.Views.Control.prototype.events}.
* @type Object
*/
events: _.extend(
{},
Mibew.Views.Control.prototype.events,
{
'click .user-name-control-set': 'changeName',
'click .user-name-control-change': 'showNameInput',
'keydown #user-name-control-input': 'inputKeyDown'
}
),
/**
* Define shortcuts for ui elements
* @type Object
*/
ui: {
'nameInput': '#user-name-control-input'
},
/**
* View initializer
*/
initialize: function() {
// Hide name input on every user name change
Mibew.Objects.Models.user.on(
'change:name',
this.hideNameInput,
this
);
// Show or hide name input by default
this.nameInput = Mibew.Objects.Models.user.get('defaultName');
},
/**
* Override Backbone.Marionette.ItemView.serializeData to pass some
* extra fields to template.
* @returns {Object} Template data
*/
serializeData: function() {
var data = this.model.toJSON();
data.user = Mibew.Objects.Models.user.toJSON();
data.nameInput = this.nameInput;
return data;
},
/**
* Handles key down event on the name input
* @param {Event} e Event object
*/
inputKeyDown: function(e) {
var key = e.which;
if (key == 13 || key == 10) {
// Change name after Enter key pressed
this.changeName();
}
},
/**
* Hide name input and rerender the view
*/
hideNameInput: function() {
this.nameInput = false;
this.render();
},
/**
* Show name input and rerender the view
*/
showNameInput: function() {
this.nameInput = true;
this.render();
},
/**
* Change user name
*/
changeName: function () {
var newName = this.ui.nameInput.val();
this.model.changeName(newName);
}
}
);
})(Mibew, Handlebars, _);

View File

@ -0,0 +1,150 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Backbone, Handlebars) {
/**
* List of replacements pairs
* @type Object
* @private
*/
var badCharList = {
"<": "&lt;",
">": "&gt;",
"&": "&amp;",
'"': "&quot;",
"'": "&#x27;",
"`": "&#x60;"
}
/**
* Regular expression for characters that must be replaced by HTML entities
* @type RegExp
* @private
*/
var badCharRegEx = /[&<>'"`]/g;
/**
* @class Represents default message view
*/
Mibew.Views.Message = Backbone.Marionette.ItemView.extend(
/** @lends Mibew.Views.Message.prototype */
{
/**
* Template function
* @type Function
*/
template: Handlebars.templates.message,
/**
* Class name for view's DOM element
* @type String
*/
className: 'message',
/**
* Map model events to the view methods
* @type Object
*/
modelEvents: {
'change': 'render'
},
/**
* Override Backbone.Marionette.ItemView.serializeData to pass some
* extra fields to template.
* @returns {Object} Template data
*/
serializeData: function() {
var msg = this.model.toJSON();
var messageKind = this.model.get('kind');
// Add message fields
msg.allowFormatting = (messageKind != this.KIND_USER
&& messageKind != this.KIND_AGENT);
msg.kindName = this.kindToString(messageKind);
msg.message = this.escapeString(msg.message);
return msg;
},
/**
* Map message kide code to kind name
* @param {Number} kind Kind code
* @returns {String} Kind name
*/
kindToString: function(kind) {
if (kind == this.KIND_USER) {
return "user";
}
if (kind == this.KIND_AGENT) {
return "agent";
}
if (kind == this.KIND_FOR_AGENT) {
return "hidden";
}
if (kind == this.KIND_INFO) {
return "inf";
}
if (kind == this.KIND_CONN) {
return "conn";
}
if (kind == this.KIND_EVENTS) {
return "event";
}
return "";
},
/**
* Replace HTML special characters('<', '>', '&', "'", '"', '`') by
* corresponding HTML entities.
*
* @param {String} str Unescaped string
* @returns {String} Escaped string
*/
escapeString: function(str) {
return str.replace(
badCharRegEx,
function(chr) {
return badCharList[chr] || "&amp;";
}
);
},
/** Message kind constants */
/** Message sent by user. */
KIND_USER: 1,
/** Message sent by operator */
KIND_AGENT: 2,
/** Hidden system message to operator */
KIND_FOR_AGENT: 3,
/** System messages for user and operator */
KIND_INFO: 4,
/** Message for user if operator have connection problems */
KIND_CONN: 5,
/** System message about some events (like rename). */
KIND_EVENTS: 6,
/**
* Message with operators avatar
*
* This kind of message leaved only for compatibility with core
*/
KIND_AVATAR: 7
/** End of message kind constants */
}
);
})(Mibew, Backbone, Handlebars);

View File

@ -0,0 +1,199 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Backbone, Handlebars) {
/**
* @class Represents Message Processor View
*/
Mibew.Views.MessageForm = Backbone.Marionette.ItemView.extend(
/** @lends Mibew.Views.MessageForm.prototype */
{
/**
* Template function
* @type Function
*/
template: Handlebars.templates.message_form,
/**
* UI events hash.
* Map UI events on the view methods.
* @type Object
*/
events: {
'click #send-message': 'postMessage',
'keydown #message-input': 'messageKeyDown',
'keyup #message-input': 'checkUserTyping',
'change #message-input': 'checkUserTyping',
'change #predefined': 'selectPredefinedAnswer',
'focus #message-input': 'setFocus',
'blur #message-input': 'dropFocus'
},
/**
* Map model events to the view methods
* @type Object
*/
modelEvents: {
'change': 'render'
},
/**
* Shortcuts for ui elements
* @type Object
*/
ui: {
message: '#message-input',
send: '#send-message',
predefinedAnswer: '#predefined'
},
/**
* View initializer.
*/
initialize: function() {
Mibew.Objects.Models.user.on('change:canPost', this.render, this);
},
/**
* Override Backbone.Marionette.ItemView.serializeData to pass some
* extra fields to template.
* @returns {Object} Template data
*/
serializeData: function() {
var data = this.model.toJSON();
data.user = Mibew.Objects.Models.user.toJSON();
return data;
},
/**
* Get, check and post message
*/
postMessage: function() {
var msg = this.ui.message.val();
// TODO: Think about it
// Cut multiple line breaks
//msg = msg.replace(/(\r\n|\n|\r)+$/,"\n");
if (msg != '') {
this.disableInput();
this.model.postMessage(msg);
}
Mibew.Objects.Collections.messages.on(
'multiple:add',
this.postMessageComplete,
this
);
},
/**
* Handler of key down event on the message input. Send message if
* Enter/Ctrl+Enter pressed.
*/
messageKeyDown: function(e) {
var key = e.which;
var ctrl = e.ctrlKey;
// Keycode of Enter key is '10' for Mac and '13' for other
// systems.
// There is no traditional Ctrl key on Mac.
if ((key == 13 && (ctrl || this.model.get('ignoreCtrl'))) || key == 10) {
this.postMessage();
}
},
/**
* Enable message input area
*/
enableInput: function() {
this.ui.message.removeAttr('disabled');
},
/**
* Disable message input area
*/
disableInput: function() {
this.ui.message.attr('disabled', 'disabled');
},
/**
* Clear message input area
*/
clearInput: function() {
this.ui.message
// Set empty value
.val('')
// And manually trigger change event
.change();
},
/**
* Callback function for message post.
* Clear input area and enable it.
*/
postMessageComplete: function() {
this.clearInput();
this.enableInput();
if (this.focused) {
this.ui.focus();
}
Mibew.Objects.Collections.messages.off(
'multiple:add',
this.postMessageComplete,
this
);
},
/**
* Set message to selected predefined answer and reset predefined
* answer selectbox.
*/
selectPredefinedAnswer: function() {
var message = this.ui.message;
var answer = this.ui.predefinedAnswer;
var index = answer.get(0).selectedIndex;
// Index should be set and not equals to zero
if (index) {
// Set message
message
// Set new value
.val(this.model.get('predefinedAnswers')[index-1].full)
// And manually trigger change event
.change();
message.focus();
// Reset predefined answer selector
answer.get(0).selectedIndex = 0;
}
},
/**
* Check if user typing and update user info
*/
checkUserTyping: function() {
var user = Mibew.Objects.Models.user;
var isTyping = (this.ui.message.val() != '');
if (isTyping != user.get('typing')) {
user.set({typing: isTyping});
}
},
/**
* Set focus indicator
*/
setFocus: function() {
this.focused = true
},
/**
* Unset focus indicator
*/
dropFocus: function() {
this.focused = false;
}
}
);
})(Mibew, Backbone, Handlebars);

View File

@ -0,0 +1,76 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew) {
/**
* @class Represents messages list view
*/
Mibew.Views.MessagesCollection = Mibew.Views.CollectionBase.extend(
/** @lends Mibew.Views.MessagesCollection.prototype */
{
/**
* Default item view constructor.
* @type Function
*/
itemView: Mibew.Views.Message,
/**
* Class name for view's DOM element
* @type String
*/
className: 'messages-collection',
/**
* View initializer.
*/
initialize: function() {
this.collection.on('multiple:add', this.messagesAdded, this);
Mibew.Objects.Models.messageForm.on(
'before:post',
this.messagePost,
this
);
},
/**
* Indicates if next sound should be skipped
* @type Boolean
*/
skipNextSound: true,
/**
* Messages form 'after:post' event handler. Disable next sound.
*/
messagePost: function() {
this.skipNextSound = true;
},
/**
* Messages collection 'add:all' event handler. Try to play sound
* about new message
*/
messagesAdded: function() {
if (! this.skipNextSound) {
// Check if sound disabled by user via sound control
if (Mibew.Objects.Models.Controls.sound.get('enabled')) {
// Build sound path
var path = Mibew.Objects.Models.page.get('webimRoot');
if (path) {
path += '/sounds/new_message.wav';
// Play sound
Mibew.Objects.Models.sound.play(path);
}
}
}
this.skipNextSound = false;
}
}
);
})(Mibew);

Some files were not shown because too many files have changed in this diff Show More