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