Add underscore as a dependency and use it and jQuery

This has fixed some IE8 errors while parsing the presence stanza
This commit is contained in:
JC Brand 2012-12-11 16:31:39 +02:00
parent aad263868a
commit 3224a8c522

View File

@ -17,7 +17,8 @@
} }
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define([ define([
"Libraries/strophe" "Libraries/strophe",
"Libraries/underscore"
], function () { ], function () {
if (console===undefined || console.log===undefined) { if (console===undefined || console.log===undefined) {
console = { log: function () {}, error: function () {} }; console = { log: function () {}, error: function () {} };
@ -59,8 +60,8 @@
* (Function) pres_handler_cb - The function call back to handle presence in the chat room. * (Function) pres_handler_cb - The function call back to handle presence in the chat room.
* (String) password - The optional password to use. (password protected rooms only) * (String) password - The optional password to use. (password protected rooms only)
*/ */
var msg, room_nick, _base, var msg, room_nick, _this = this;
_this = this;
room_nick = this.test_append_nick(room, nick); room_nick = this.test_append_nick(room, nick);
msg = $pres({ msg = $pres({
from: this._connection.jid, from: this._connection.jid,
@ -94,15 +95,14 @@
} }
} }
} }
for (id in handlers) { _.each(handlers, function (handler, id, handlers) {
handler = handlers[id];
if (!handler(stanza, room)) { delete handlers[id]; } if (!handler(stanza, room)) { delete handlers[id]; }
} });
return true; return true;
}); });
} }
if ((_base = this.rooms)[room] === null) { if (!_.has(this.rooms, room)) {
_base[room] = new XmppRoom(this, room, nick, password); this.rooms[room] = new XmppRoom(this, room, nick, password);
} }
if (pres_handler_cb) { if (pres_handler_cb) {
this.rooms[room].addHandler('presence', pres_handler_cb); this.rooms[room].addHandler('presence', pres_handler_cb);
@ -734,26 +734,26 @@
newnick = data.newnick || null; newnick = data.newnick || null;
switch (data.type) { switch (data.type) {
case 'error': case 'error':
return; return;
case 'unavailable': case 'unavailable':
if (newnick) { if (newnick) {
data.nick = newnick; data.nick = newnick;
if (this.roster[nick] && this.roster[newnick]) { if (this.roster[nick] && this.roster[newnick]) {
this.roster[nick].update(this.roster[newnick]); this.roster[nick].update(this.roster[newnick]);
this.roster[newnick] = this.roster[nick]; this.roster[newnick] = this.roster[nick];
}
if (this.roster[nick] && !this.roster[newnick]) {
this.roster[newnick] = this.roster[nick].update(data);
}
} }
if (this.roster[nick] && !this.roster[newnick]) { delete this.roster[nick];
this.roster[newnick] = this.roster[nick].update(data); break;
}
}
delete this.roster[nick];
break;
default: default:
if (this.roster[nick]) { if (this.roster[nick]) {
this.roster[nick].update(data); this.roster[nick].update(data);
} else { } else {
this._addOccupant(data); this._addOccupant(data);
} }
} }
_ref = this._roster_handlers; _ref = this._roster_handlers;
for (id in _ref) { for (id in _ref) {
@ -764,47 +764,49 @@
}; };
XmppRoom._parsePresence = function(pres) { XmppRoom._parsePresence = function(pres) {
/* Parses a presence stanza /* Parses a presence stanza into a map
* Parameters: * Parameters:
* (Object) pres - the presence stanza
* Returns:
* (Object) data - the data extracted from the presence stanza * (Object) data - the data extracted from the presence stanza
*/ */
var a, c, c2, data, _i, _j, _len, _len2, _ref, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8; var $pres, data, i, j, children, item;
$pres = $(pres);
data = {}; data = {};
a = pres.attributes; data.nick = Strophe.getResourceFromJid($pres.attr('from'));
data.nick = Strophe.getResourceFromJid(a.from.textContent); data.type = $pres.attr('type');
data.type = ((_ref = a.type) != null ? _ref.textContent : void 0) || null;
data.states = []; data.states = [];
_ref2 = pres.childNodes; for (i=0; i < $pres.children().length; i++) {
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { child = $pres.children()[0];
c = _ref2[_i]; switch (child.nodeName) {
switch (c.nodeName) { case 'status':
case "status": data.status = child.textContent || null;
data.status = c.textContent || null; break;
break; case 'show':
case "show": data.show = child.textContent || null;
data.show = c.textContent || null; break;
break; case 'x':
case "x": if ($(child).attr('xmlns') === Strophe.NS.MUC_USER) {
a = c.attributes; children = $(child).children();
if (((_ref3 = a.xmlns) != null ? _ref3.textContent : void 0) === Strophe.NS.MUC_USER) { for (j=0; j < children.length; j++) {
_ref4 = c.childNodes; item = children[0];
for (_j = 0, _len2 = _ref4.length; _j < _len2; _j++) { switch (item.nodeName) {
c2 = _ref4[_j]; case "item":
switch (c2.nodeName) { a = item.attributes;
case "item": data.affiliation = $(item).attr('affiliation') || null;
a = c2.attributes; data.role = $(item).attr('role') || null;
data.affiliation = ((_ref5 = a.affiliation) != null ? _ref5.textContent : void 0) || null; data.jid = $(item).attr('jid') || null;
data.role = ((_ref6 = a.role) != null ? _ref6.textContent : void 0) || null; data.newnick = $(item).attr('nick') || null;
data.jid = ((_ref7 = a.jid) != null ? _ref7.textContent : void 0) || null; break;
data.newnick = ((_ref8 = a.nick) != null ? _ref8.textContent : void 0) || null; case "status":
break; if ($(item).attr('code')) {
case "status": data.states.push($(item).attr('code'));
if (c2.attributes.code) { }
data.states.push(c2.attributes.code.textContent); break;
}
} }
} }
} break;
}
} }
} }
return data; return data;
@ -817,7 +819,8 @@
RoomConfig = (function() { RoomConfig = (function() {
function RoomConfig(info) { function RoomConfig(info) {
this.parse = __bind(this.parse, this); if (info != null) this.parse(info); this.parse = __bind(this.parse, this);
if (info !== null) { this.parse(info); }
} }
RoomConfig.prototype.parse = function(result) { RoomConfig.prototype.parse = function(result) {