Enable require.js support. Use burry.js instead of store.js
This commit is contained in:
parent
bd4dfa9c36
commit
6d9ab59349
130
converse.js
130
converse.js
|
@ -9,13 +9,30 @@
|
|||
/* The following line defines global variables defined elsewhere. */
|
||||
/*globals jQuery, portal_url*/
|
||||
|
||||
var xmppchat = (function (jarnxmpp, $, console) {
|
||||
var ob = jarnxmpp;
|
||||
ob.messages = {};
|
||||
ob.messages.ClientStorage = (function () {
|
||||
|
||||
// AMD/global registrations
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define([
|
||||
'burry.js/burry'
|
||||
], function (Burry) {
|
||||
var store = new Burry.Store('collective.xmpp.chat');
|
||||
_.str = require('underscore.string');
|
||||
return factory(jarnxmpp, jQuery, store, _, console);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
// Browser globals
|
||||
var store = new Burry.Store('collective.xmpp.chat');
|
||||
root.xmppchat = factory(jarnxmpp, jQuery, store, _, console || {log: function(){}});
|
||||
}
|
||||
}(this, function (jarnxmpp, $, store, _, console) {
|
||||
|
||||
var xmppchat = jarnxmpp;
|
||||
xmppchat.messages = {};
|
||||
xmppchat.messages.ClientStorage = (function () {
|
||||
// TODO: Messages must be encrypted with a key and salt
|
||||
methods = {};
|
||||
|
||||
methods.addMessage = function (jid, msg, direction) {
|
||||
var bare_jid = Strophe.getBareJidFromJid(jid),
|
||||
now = new Date().toISOString(),
|
||||
|
@ -33,20 +50,20 @@ var xmppchat = (function (jarnxmpp, $, console) {
|
|||
return methods;
|
||||
})();
|
||||
|
||||
ob.messages.getMessages = function (jid, callback) {
|
||||
xmppchat.messages.getMessages = function (jid, callback) {
|
||||
var bare_jid = Strophe.getBareJidFromJid(jid),
|
||||
msgs = this.ClientStorage.getMessages(bare_jid);
|
||||
callback(msgs);
|
||||
};
|
||||
|
||||
ob.collections = {
|
||||
xmppchat.collections = {
|
||||
/* FIXME: XEP-0136 specifies 'urn:xmpp:archive' but the mod_archive_odbc
|
||||
* add-on for ejabberd wants the URL below. This might break for other
|
||||
* Jabber servers.
|
||||
*/
|
||||
'URI': 'http://www.xmpp.org/extensions/xep-0136.html#ns'
|
||||
};
|
||||
ob.collections.getLastCollection = function (jid, callback) {
|
||||
xmppchat.collections.getLastCollection = function (jid, callback) {
|
||||
var bare_jid = Strophe.getBareJidFromJid(jid),
|
||||
iq = $iq({'type':'get'})
|
||||
.c('list', {'xmlns': this.URI,
|
||||
|
@ -64,7 +81,7 @@ var xmppchat = (function (jarnxmpp, $, console) {
|
|||
});
|
||||
};
|
||||
|
||||
ob.collections.getLastMessages = function (jid, callback) {
|
||||
xmppchat.collections.getLastMessages = function (jid, callback) {
|
||||
var that = this;
|
||||
this.getLastCollection(jid, function (result) {
|
||||
// Retrieve the last page of a collection (max 30 elements).
|
||||
|
@ -82,27 +99,18 @@ var xmppchat = (function (jarnxmpp, $, console) {
|
|||
xmppchat.connection.sendIQ(iq, callback);
|
||||
});
|
||||
};
|
||||
return ob;
|
||||
})(jarnxmpp || {}, jQuery, console || {log: function(){}});
|
||||
|
||||
|
||||
xmppchat.ChatBox = Backbone.Model.extend({
|
||||
|
||||
hash: function (str) {
|
||||
return hex_sha1(str);
|
||||
},
|
||||
|
||||
xmppchat.ChatBox = Backbone.Model.extend({
|
||||
initialize: function () {
|
||||
this.set({
|
||||
'user_id' : Strophe.getNodeFromJid(this.get('jid')),
|
||||
'box_id' : this.hash(this.get('jid')),
|
||||
'box_id' : hex_sha1(this.get('jid')),
|
||||
'fullname' : this.get('fullname')
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
xmppchat.ChatBoxView = Backbone.View.extend({
|
||||
xmppchat.ChatBoxView = Backbone.View.extend({
|
||||
length: 200,
|
||||
tagName: 'div',
|
||||
className: 'chatbox',
|
||||
|
@ -437,9 +445,9 @@ xmppchat.ChatBoxView = Backbone.View.extend({
|
|||
var $content = this.$el.find('.chat-content');
|
||||
$content.scrollTop($content[0].scrollHeight);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
xmppchat.ContactsPanel = Backbone.View.extend({
|
||||
xmppchat.ContactsPanel = Backbone.View.extend({
|
||||
el: '#users',
|
||||
events: {
|
||||
'click a.add-xmpp-contact': 'toggleContactForm',
|
||||
|
@ -484,9 +492,9 @@ xmppchat.ContactsPanel = Backbone.View.extend({
|
|||
$('form.search-xmpp-contact').hide();
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
xmppchat.RoomsPanel = Backbone.View.extend({
|
||||
xmppchat.RoomsPanel = Backbone.View.extend({
|
||||
el: '#chatrooms',
|
||||
events: {
|
||||
'submit form.add-chatroom': 'createChatRoom',
|
||||
|
@ -538,22 +546,22 @@ xmppchat.RoomsPanel = Backbone.View.extend({
|
|||
}
|
||||
xmppchat.chatboxesview.openChat(jid);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
xmppchat.SettingsPanel = Backbone.View.extend({
|
||||
xmppchat.SettingsPanel = Backbone.View.extend({
|
||||
el: '#settings'
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
xmppchat.ControlBox = xmppchat.ChatBox.extend({
|
||||
xmppchat.ControlBox = xmppchat.ChatBox.extend({
|
||||
initialize: function () {
|
||||
this.set({
|
||||
'box_id' : 'controlbox'
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
xmppchat.ControlBoxView = xmppchat.ChatBoxView.extend({
|
||||
xmppchat.ControlBoxView = xmppchat.ChatBoxView.extend({
|
||||
el: '#controlbox',
|
||||
events: {
|
||||
'click a.close-controlbox-button': 'closeChat'
|
||||
|
@ -570,9 +578,9 @@ xmppchat.ControlBoxView = xmppchat.ChatBoxView.extend({
|
|||
render: function () {
|
||||
return this;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
xmppchat.ChatRoom = xmppchat.ChatBox.extend({
|
||||
xmppchat.ChatRoom = xmppchat.ChatBox.extend({
|
||||
initialize: function (jid) {
|
||||
var nick = Strophe.getNodeFromJid(xmppchat.connection.jid);
|
||||
this.set({
|
||||
|
@ -580,13 +588,13 @@ xmppchat.ChatRoom = xmppchat.ChatBox.extend({
|
|||
'name': Strophe.unescapeNode(Strophe.getNodeFromJid(jid)),
|
||||
'nick': Strophe.unescapeNode(Strophe.getNodeFromJid(xmppchat.connection.jid)),
|
||||
'jid': jid,
|
||||
'box_id' : this.hash(jid)
|
||||
'box_id' : hex_sha1(jid)
|
||||
}, {'silent': true});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
xmppchat.ChatRoomView = xmppchat.ChatBoxView.extend({
|
||||
xmppchat.ChatRoomView = xmppchat.ChatBoxView.extend({
|
||||
length: 300,
|
||||
tagName: 'div',
|
||||
className: 'chatroom',
|
||||
|
@ -683,7 +691,7 @@ xmppchat.ChatRoomView = xmppchat.ChatBoxView.extend({
|
|||
},
|
||||
|
||||
onLeave: function () {
|
||||
var controlboxview = xmppchat.chatboxesview.views.controlbox;
|
||||
var controlboxview = xmppchat.chatboxesview.views['controlbox'];
|
||||
if (controlboxview) {
|
||||
controlboxview.roomspanel.trigger('update-rooms-list');
|
||||
}
|
||||
|
@ -754,7 +762,7 @@ xmppchat.ChatRoomView = xmppchat.ChatBoxView.extend({
|
|||
},
|
||||
|
||||
onRoster: function (roster, room) {
|
||||
var controlboxview = xmppchat.chatboxesview.views['controlbox'];
|
||||
var controlboxview = xmppchat.chatboxesview.views.controlbox;
|
||||
if (controlboxview) {
|
||||
controlboxview.roomspanel.trigger('update-rooms-list');
|
||||
}
|
||||
|
@ -779,11 +787,11 @@ xmppchat.ChatRoomView = xmppchat.ChatBoxView.extend({
|
|||
$(this.el).html(this.template(this.model.toJSON()));
|
||||
return this;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
xmppchat.ChatBoxes = Backbone.Collection.extend();
|
||||
xmppchat.ChatBoxes = Backbone.Collection.extend();
|
||||
|
||||
xmppchat.ChatBoxesView = Backbone.View.extend({
|
||||
xmppchat.ChatBoxesView = Backbone.View.extend({
|
||||
el: '#collective-xmpp-chat-data',
|
||||
|
||||
restoreOpenChats: function () {
|
||||
|
@ -906,10 +914,10 @@ xmppchat.ChatBoxesView = Backbone.View.extend({
|
|||
this.views = {};
|
||||
this.restoreOpenChats();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
xmppchat.RosterItem = Backbone.Model.extend({
|
||||
xmppchat.RosterItem = Backbone.Model.extend({
|
||||
|
||||
initialize: function (jid, subscription, ask, name) {
|
||||
var user_id = Strophe.getNodeFromJid(jid);
|
||||
|
@ -929,10 +937,10 @@ xmppchat.RosterItem = Backbone.Model.extend({
|
|||
'status': 'offline'
|
||||
}, {'silent': true});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
xmppchat.RosterItemView = Backbone.View.extend({
|
||||
xmppchat.RosterItemView = Backbone.View.extend({
|
||||
tagName: 'dd',
|
||||
|
||||
openChat: function () {
|
||||
|
@ -1043,10 +1051,10 @@ xmppchat.RosterItemView = Backbone.View.extend({
|
|||
}
|
||||
}, this);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
xmppchat.Roster = (function (_, $, console) {
|
||||
xmppchat.Roster = (function (_, $, console) {
|
||||
var ob = {},
|
||||
Collection = Backbone.Collection.extend({
|
||||
model: xmppchat.RosterItem,
|
||||
|
@ -1244,10 +1252,10 @@ xmppchat.Roster = (function (_, $, console) {
|
|||
return true;
|
||||
};
|
||||
return ob;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
xmppchat.RosterView= (function (roster, _, $, console) {
|
||||
xmppchat.RosterView= (function (roster, _, $, console) {
|
||||
var View = Backbone.View.extend({
|
||||
el: $('#xmppchat-roster'),
|
||||
model: roster,
|
||||
|
@ -1313,9 +1321,9 @@ xmppchat.RosterView= (function (roster, _, $, console) {
|
|||
});
|
||||
var view = new View();
|
||||
return view;
|
||||
});
|
||||
});
|
||||
|
||||
xmppchat.XMPPStatus = Backbone.Model.extend({
|
||||
xmppchat.XMPPStatus = Backbone.Model.extend({
|
||||
|
||||
sendPresence: function (type) {
|
||||
if (type === undefined) {
|
||||
|
@ -1337,9 +1345,9 @@ xmppchat.XMPPStatus = Backbone.Model.extend({
|
|||
xmppchat.connection.send($pres({'type':presence_type}).c('status').t(custom_status));
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
xmppchat.XMPPStatusView = Backbone.View.extend({
|
||||
xmppchat.XMPPStatusView = Backbone.View.extend({
|
||||
el: "span#xmpp-status-holder",
|
||||
|
||||
events: {
|
||||
|
@ -1362,7 +1370,7 @@ xmppchat.XMPPStatusView = Backbone.View.extend({
|
|||
|
||||
status_template: _.template(
|
||||
'<div class="xmpp-status">' +
|
||||
'<a class="choose-xmpp-status <%= presence_type%>" href="#" title="Click to change your chat status">' +
|
||||
'<a class="choose-xmpp-status <%= presence_type %>" href="#" title="Click to change your chat status">' +
|
||||
'<%= chat_status %> <span class="value"><%= chat_status %></span>' +
|
||||
'</a>' +
|
||||
'<a class="change-xmpp-status-message" href="#" Title="Click here to write a custom status message"></a>' +
|
||||
|
@ -1440,11 +1448,11 @@ xmppchat.XMPPStatusView = Backbone.View.extend({
|
|||
});
|
||||
$select.remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Event handlers
|
||||
// --------------
|
||||
$(document).ready($.proxy(function () {
|
||||
// Event handlers
|
||||
// --------------
|
||||
$(document).ready($.proxy(function () {
|
||||
var chatdata = jQuery('div#collective-xmpp-chat-data'),
|
||||
$toggle = $('a#toggle-online-users');
|
||||
$toggle.unbind('click');
|
||||
|
@ -1502,4 +1510,6 @@ $(document).ready($.proxy(function () {
|
|||
}
|
||||
}, this));
|
||||
}, this));
|
||||
}, xmppchat));
|
||||
}, xmppchat));
|
||||
}));
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user