Enable require.js support. Use burry.js instead of store.js

This commit is contained in:
JC Brand 2012-09-21 16:04:57 +02:00
parent bd4dfa9c36
commit 6d9ab59349

View File

@ -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,24 +99,15 @@ 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);
},
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({
@ -580,7 +588,7 @@ 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});
}
});
@ -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');
}
@ -1503,3 +1511,5 @@ $(document).ready($.proxy(function () {
}, this));
}, this));
}, xmppchat));
}));