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:
parent
aad263868a
commit
3224a8c522
@ -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);
|
||||||
@ -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 = c.textContent || null;
|
data.show = child.textContent || null;
|
||||||
break;
|
break;
|
||||||
case "x":
|
case 'x':
|
||||||
a = c.attributes;
|
if ($(child).attr('xmlns') === Strophe.NS.MUC_USER) {
|
||||||
if (((_ref3 = a.xmlns) != null ? _ref3.textContent : void 0) === Strophe.NS.MUC_USER) {
|
children = $(child).children();
|
||||||
_ref4 = c.childNodes;
|
for (j=0; j < children.length; j++) {
|
||||||
for (_j = 0, _len2 = _ref4.length; _j < _len2; _j++) {
|
item = children[0];
|
||||||
c2 = _ref4[_j];
|
switch (item.nodeName) {
|
||||||
switch (c2.nodeName) {
|
|
||||||
case "item":
|
case "item":
|
||||||
a = c2.attributes;
|
a = item.attributes;
|
||||||
data.affiliation = ((_ref5 = a.affiliation) != null ? _ref5.textContent : void 0) || null;
|
data.affiliation = $(item).attr('affiliation') || null;
|
||||||
data.role = ((_ref6 = a.role) != null ? _ref6.textContent : void 0) || null;
|
data.role = $(item).attr('role') || null;
|
||||||
data.jid = ((_ref7 = a.jid) != null ? _ref7.textContent : void 0) || null;
|
data.jid = $(item).attr('jid') || null;
|
||||||
data.newnick = ((_ref8 = a.nick) != null ? _ref8.textContent : void 0) || null;
|
data.newnick = $(item).attr('nick') || null;
|
||||||
break;
|
break;
|
||||||
case "status":
|
case "status":
|
||||||
if (c2.attributes.code) {
|
if ($(item).attr('code')) {
|
||||||
data.states.push(c2.attributes.code.textContent);
|
data.states.push($(item).attr('code'));
|
||||||
}
|
}
|
||||||
|
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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user