changeset 20:7fcccf59e6ec

Always use two-spaces indent.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 26 Jan 2012 15:04:53 +0100
parents b7bd814333eb
children b7d52bf259e0
files lightstring.js plugins.js
diffstat 2 files changed, 186 insertions(+), 186 deletions(-) [+]
line wrap: on
line diff
--- a/lightstring.js
+++ b/lightstring.js
@@ -24,14 +24,14 @@ var Lightstring = {
   /**
    * @namespace Holds XMPP namespaces.
    */
-	NS: {
+  NS: {
     stream: 'http://etherx.jabber.org/streams',
     jabberClient: 'jabber:client'
   },
   /**
    * @namespace Holds XMPP stanza builders.
    */
-	stanza: {
+  stanza: {
     stream: {
       open: function(aService) {
         //FIXME no ending "/" - node-xmpp-bosh bug
@@ -262,7 +262,7 @@ Lightstring.Connection.prototype = {
       console.log(e.data);
     });
     this.socket.addEventListener('close', function(e) {
-			that.emit('disconnected', e.data);
+      that.emit('disconnected', e.data);
     });
     this.socket.addEventListener('message', function(e) {
       that.emit('XMLInput', e.data);
@@ -270,8 +270,8 @@ Lightstring.Connection.prototype = {
       that.emit('DOMInput', elm);
       that.emit(elm.tagName, elm);
 
-			if (elm.tagName === 'iq')
-				that.emit(elm.getAttribute('id'), elm);
+      if (elm.tagName === 'iq')
+        that.emit(elm.getAttribute('id'), elm);
     });
   },
   /**
@@ -295,7 +295,7 @@ Lightstring.Connection.prototype = {
 
 
     if (elm.tagName === 'iq') {
-			var id = elm.getAttribute('id');
+      var id = elm.getAttribute('id');
       if (!id) {
         elm.setAttribute('id', this.getNewId());
         str = Lightstring.dom2xml(elm);
@@ -316,12 +316,12 @@ Lightstring.Connection.prototype = {
    * @function Closes the XMPP stream and the socket.
    */
   disconnect: function() {
-		this.emit('disconnecting');
+    this.emit('disconnecting');
     var stream = Lightstring.stanza.stream.close();
-		this.send(stream);
+    this.send(stream);
     this.emit('XMLOutput', stream);
-		this.socket.close();
-	},
+    this.socket.close();
+  },
   /**
    * @function Emits an event.
    * @param {String} aName The event name.
--- a/plugins.js
+++ b/plugins.js
@@ -34,26 +34,26 @@ Lightstring.presence = function(aConnect
 //////////
 Lightstring.NS.roster = 'jabber:iq:roster';
 Lightstring.stanza.roster = {
-	'get': function() {
-		return "<iq type='get'><query xmlns='"+Lightstring.NS.roster+"'/></iq>";
-	},
-	add: function(aAddress, aGroups, aCustomName) {
-		var iq = $iq({type: 'set'}).c('query', {xmlns: Lightstring.NS.roster}).c('item', {jid: aAddress}).tree();
-		if(aCustomName) iq.querySelector('item').setAttribute(aCustomName);
-		for (var i=0; i<aGroups.length; i++) {
-			if(i === 0) iq.querySelector('item').appendChild(document.createElement('group'));
-			iq.querySelector('group').appendChild(document.createElement(aGroups[i]));
-		}
-		return iq;
-	},
-	remove: function(aAddress) {
-		return $iq({type: 'set'}).c('query', {xmlns: Lightstring.NS.roster}).c('item', {jid: aAddress, subscription: 'remove'}).tree();
-	}
+  'get': function() {
+    return "<iq type='get'><query xmlns='"+Lightstring.NS.roster+"'/></iq>";
+  },
+  add: function(aAddress, aGroups, aCustomName) {
+    var iq = $iq({type: 'set'}).c('query', {xmlns: Lightstring.NS.roster}).c('item', {jid: aAddress}).tree();
+    if(aCustomName) iq.querySelector('item').setAttribute(aCustomName);
+    for (var i=0; i<aGroups.length; i++) {
+      if(i === 0) iq.querySelector('item').appendChild(document.createElement('group'));
+      iq.querySelector('group').appendChild(document.createElement(aGroups[i]));
+    }
+    return iq;
+  },
+  remove: function(aAddress) {
+    return $iq({type: 'set'}).c('query', {xmlns: Lightstring.NS.roster}).c('item', {jid: aAddress, subscription: 'remove'}).tree();
+  }
 };
 Lightstring.getRoster = function(connection, aCallback) {
-	connection.send(this.stanza.roster.get(), function(answer){
-		var contacts = [];
-		var elems = answer.querySelectorAll('item');
+  connection.send(this.stanza.roster.get(), function(answer){
+    var contacts = [];
+    var elems = answer.querySelectorAll('item');
     for(var i = 0; i<elms.length; i++) {
       var item = elms[i];
       var jid = item.getAttribute('jid');
@@ -75,33 +75,33 @@ Lightstring.getRoster = function(connect
       }
 
       contacts.push(contact);
-		};
-		aCallback(contacts);
-	});
+    };
+    aCallback(contacts);
+  });
 }
 /////////
 //vCard//
 /////////
 Lightstring.NS.vcard = 'vcard-temp';
 Lightstring.stanza.vcard = {
-	'get': function(aTo) {
-		if(aTo)
-			return "<iq type='get' to='"+aTo+"'><vCard xmlns='"+Lightstring.NS.vcard+"'/></iq>";
-		else
-			return "<iq type='get'><vCard xmlns='"+Lightstring.NS.vcard+"'/></iq>";
-	}
+  'get': function(aTo) {
+    if(aTo)
+      return "<iq type='get' to='"+aTo+"'><vCard xmlns='"+Lightstring.NS.vcard+"'/></iq>";
+    else
+      return "<iq type='get'><vCard xmlns='"+Lightstring.NS.vcard+"'/></iq>";
+  }
 };
 //FIXME we should return a proper vcard, not an XMPP one
 Lightstring.getVcard = function(aConnection, aTo, aCallback) {
-	aConnection.send(Lightstring.stanza.vcard.get(aTo), function(answer, err){
-		if(answer) {
-			var vcard = answer.querySelector('vCard');
-			if(vcard)
-				aCallback(vcard);
-		}		
-		else
-			aCallback(null);
-	});
+  aConnection.send(Lightstring.stanza.vcard.get(aTo), function(answer, err){
+    if(answer) {
+      var vcard = answer.querySelector('vCard');
+      if(vcard)
+        aCallback(vcard);
+    }    
+    else
+      aCallback(null);
+  });
 }
 /////////
 //Disco//
@@ -109,56 +109,56 @@ Lightstring.getVcard = function(aConnect
 Lightstring.NS['disco#info'] = "http://jabber.org/protocol/disco#info";
 Lightstring.NS['disco#items'] = "http://jabber.org/protocol/disco#items";
 Lightstring.stanza.disco = {
-	items: function(aTo, aNode) {
-		if(aTo)
-			var iq = "<iq type='get' to='"+aTo+"'>";
-		else
-			var iq = "<iq type='get'>";
-		
-		if(aNode)
-			var query = "<query xmlns='"+Lightstring.NS['disco#items']+"' node='"+aNode+"'/>";
-		else
-			var query = "<query xmlns='"+Lightstring.NS['disco#items']+"'/>";
-			
-		return iq+query+"</iq>";
-	},
-	info: function(aTo, aNode) {
-		if(aTo)
-			var iq = "<iq type='get' to='"+aTo+"'>";
-		else
-			var iq = "<iq type='get'>";
-		if(aNode)
-			var query = "<query xmlns='"+Lightstring.NS['disco#info']+"' node='"+aNode+"'/>";
-		else
-			var query = "<query xmlns='"+Lightstring.NS['disco#info']+"'/>";
-			
-		return iq+query+"</iq>";
-	}
+  items: function(aTo, aNode) {
+    if(aTo)
+      var iq = "<iq type='get' to='"+aTo+"'>";
+    else
+      var iq = "<iq type='get'>";
+    
+    if(aNode)
+      var query = "<query xmlns='"+Lightstring.NS['disco#items']+"' node='"+aNode+"'/>";
+    else
+      var query = "<query xmlns='"+Lightstring.NS['disco#items']+"'/>";
+      
+    return iq+query+"</iq>";
+  },
+  info: function(aTo, aNode) {
+    if(aTo)
+      var iq = "<iq type='get' to='"+aTo+"'>";
+    else
+      var iq = "<iq type='get'>";
+    if(aNode)
+      var query = "<query xmlns='"+Lightstring.NS['disco#info']+"' node='"+aNode+"'/>";
+    else
+      var query = "<query xmlns='"+Lightstring.NS['disco#info']+"'/>";
+      
+    return iq+query+"</iq>";
+  }
 };
 Lightstring.discoItems = function(aConnection, aTo, aCallback) {
-	aConnection.send(Lightstring.stanza.disco.items(aTo), function(answer){
-		var items = [];
+  aConnection.send(Lightstring.stanza.disco.items(aTo), function(answer){
+    var items = [];
     var elms = answer.querySelectorAll('item');
     for(var i = 0; i < elms.length; i++) {
       var node = elms[i];
-			var item = {
-				jid: node.getAttribute('jid'),
-				name: node.getAttribute('name'),
-				node: node.getAttribute('node')
-			}
-			items.push(item);
-		};
-		if(aCallback)
-			aCallback(items);
-	});
+      var item = {
+        jid: node.getAttribute('jid'),
+        name: node.getAttribute('name'),
+        node: node.getAttribute('node')
+      }
+      items.push(item);
+    };
+    if(aCallback)
+      aCallback(items);
+  });
 };
 Lightstring.discoInfo = function(aConnection, aTo, aNode, aCallback) {
-	aConnection.send(Lightstring.stanza.disco.info(aTo, aNode), function(answer){
-		var field = answer.querySelector('field[var="pubsub#creator"] > value');
-		var creator = field ? field.textContent : '';
-		//FIXME callback the entire data
-		aCallback(creator);
-	});
+  aConnection.send(Lightstring.stanza.disco.info(aTo, aNode), function(answer){
+    var field = answer.querySelector('field[var="pubsub#creator"] > value');
+    var creator = field ? field.textContent : '';
+    //FIXME callback the entire data
+    aCallback(creator);
+  });
 };
 //////////
 //PubSub//
@@ -167,126 +167,126 @@ Lightstring.NS.x = "jabber:x:data";
 Lightstring.NS.pubsub = "http://jabber.org/protocol/pubsub";
 Lightstring.NS.pubsub_owner = "http://jabber.org/protocol/pubsub#owner";
 Lightstring.stanza.pubsub = {
-	getConfig: function(aTo, aNode) {
-		return  "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><configure node='"+aNode+"'/></pubsub></iq>";
-	},
-	items: function(aTo, aNode) {
-		return  "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><items node='"+aNode+"'/></pubsub></iq>";
-	},
-	affiliations: function(aTo, aNode) {
-		return "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><affiliations node='"+aNode+"'/></pubsub></iq>";
-	},
-	publish: function(aTo, aNode, aItem, aId) {
-		return  "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><publish node='"+aNode+"'><item id='"+aId+"'>"+aItem+"</item></publish></pubsub></iq>";
-	},
-	retract: function(aTo, aNode, aItem) {
-		return  "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><retract node='"+aNode+"'><item id='"+aItem+"'/></retract></pubsub></iq>";
-	},
-	'delete': function(aTo, aNode, aURI) {
-		return  "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><delete node='"+aNode+"'/></pubsub></iq>";
-	},
-	create: function(aTo, aNode, aFields) {
-		var iq = "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><create node='"+aNode+"'/>";
-		if(aFields) {
-			iq += "<configure><x xmlns='"+Lightstring.NS.x+"' type='submit'>"
-			aFields.forEach(function(field) {
-				iq += field;
-			});
-			iq += "</x></configure>";
-		}
-		iq += "</pubsub></iq>";
-		return iq;
-	},
-	setAffiliations: function(aTo, aNode, aAffiliations) {
-		var iq = "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><affiliations node='"+aNode+"'>";
-		for(var i = 0; i < aAffiliations.length; i++) {
-			iq += "<affiliation jid='"+aAffiliations[i][0]+"' affiliation='"+aAffiliations[i][1]+"'/>"
-		}
-		iq += "</affiliations></pubsub></iq>";
-		return iq;
-	},
+  getConfig: function(aTo, aNode) {
+    return  "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><configure node='"+aNode+"'/></pubsub></iq>";
+  },
+  items: function(aTo, aNode) {
+    return  "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><items node='"+aNode+"'/></pubsub></iq>";
+  },
+  affiliations: function(aTo, aNode) {
+    return "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><affiliations node='"+aNode+"'/></pubsub></iq>";
+  },
+  publish: function(aTo, aNode, aItem, aId) {
+    return  "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><publish node='"+aNode+"'><item id='"+aId+"'>"+aItem+"</item></publish></pubsub></iq>";
+  },
+  retract: function(aTo, aNode, aItem) {
+    return  "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><retract node='"+aNode+"'><item id='"+aItem+"'/></retract></pubsub></iq>";
+  },
+  'delete': function(aTo, aNode, aURI) {
+    return  "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><delete node='"+aNode+"'/></pubsub></iq>";
+  },
+  create: function(aTo, aNode, aFields) {
+    var iq = "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><create node='"+aNode+"'/>";
+    if(aFields) {
+      iq += "<configure><x xmlns='"+Lightstring.NS.x+"' type='submit'>"
+      aFields.forEach(function(field) {
+        iq += field;
+      });
+      iq += "</x></configure>";
+    }
+    iq += "</pubsub></iq>";
+    return iq;
+  },
+  setAffiliations: function(aTo, aNode, aAffiliations) {
+    var iq = "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><affiliations node='"+aNode+"'>";
+    for(var i = 0; i < aAffiliations.length; i++) {
+      iq += "<affiliation jid='"+aAffiliations[i][0]+"' affiliation='"+aAffiliations[i][1]+"'/>"
+    }
+    iq += "</affiliations></pubsub></iq>";
+    return iq;
+  },
 };
 Lightstring.pubsubItems = function(aConnection, aTo, aNode, aCallback) {
-	aConnection.send(Lightstring.stanza.pubsub.items(aTo, aNode), function(answer){
-		var items = [];
+  aConnection.send(Lightstring.stanza.pubsub.items(aTo, aNode), function(answer){
+    var items = [];
     var elms = answer.querySelectorAll('item');
     for(var i = 0; i < elms.length; i++) {
       var node = elms[i];
-			var item = {
-				id: node.getAttribute('id'),
-				name: node.querySelector('title').textContent,
-				src: node.querySelector('content').getAttribute('src'),
-				type: node.querySelector('content').getAttribute('type'),
-			}
-			var miniature = node.querySelector('link');
-			if(miniature)
-				item.miniature = miniature.getAttribute('href');
-			items.push(item);
-		};
-		if(aCallback)
-			aCallback(items);
-	});
+      var item = {
+        id: node.getAttribute('id'),
+        name: node.querySelector('title').textContent,
+        src: node.querySelector('content').getAttribute('src'),
+        type: node.querySelector('content').getAttribute('type'),
+      }
+      var miniature = node.querySelector('link');
+      if(miniature)
+        item.miniature = miniature.getAttribute('href');
+      items.push(item);
+    };
+    if(aCallback)
+      aCallback(items);
+  });
 }
 Lightstring.pubsubCreate = function(aConnection, aTo, aNode, aFields, aCallback) {
-	aConnection.send(Lightstring.stanza.pubsub.create(aTo, aNode, aFields), function(answer) {
-		if(answer.getAttribute('type') === 'result')
-			aCallback(null, answer);
-		else
-			aCallback(answer, null);
-	});
+  aConnection.send(Lightstring.stanza.pubsub.create(aTo, aNode, aFields), function(answer) {
+    if(answer.getAttribute('type') === 'result')
+      aCallback(null, answer);
+    else
+      aCallback(answer, null);
+  });
 };
 Lightstring.pubsubConfig = function(aConnection, aTo, aNode, aCallback) {
-	aConnection.send(Lightstring.stanza.pubsub.getConfig(aTo, aNode), function(answer){
-		var accessmodel = answer.querySelector('field[var="pubsub#access_model"]').lastChild.textContent;
-		if(accessmodel)
-			aCallback(accessmodel);
-		else
-			aCallback(null);
-	});
+  aConnection.send(Lightstring.stanza.pubsub.getConfig(aTo, aNode), function(answer){
+    var accessmodel = answer.querySelector('field[var="pubsub#access_model"]').lastChild.textContent;
+    if(accessmodel)
+      aCallback(accessmodel);
+    else
+      aCallback(null);
+  });
 }
 Lightstring.pubsubRetract = function(aConnection, aTo, aNode, aItem, aCallback) {
-	aConnection.send(Lightstring.stanza.pubsub.retract(aTo, aNode, aItem), function(answer){
-		if(aCallback)
-			aCallback(answer);
-	});
+  aConnection.send(Lightstring.stanza.pubsub.retract(aTo, aNode, aItem), function(answer){
+    if(aCallback)
+      aCallback(answer);
+  });
 }
 Lightstring.pubsubPublish = function(aConnection, aTo, aNode, aItem, aId, aCallback) {
-	aConnection.send(Lightstring.stanza.pubsub.publish(aTo, aNode, aItem, aId), function(answer){
-		if(answer.getAttribute('type') === 'result')
-			aCallback(null, answer);
-		else
-			aCallback(answer, null);
-	});
+  aConnection.send(Lightstring.stanza.pubsub.publish(aTo, aNode, aItem, aId), function(answer){
+    if(answer.getAttribute('type') === 'result')
+      aCallback(null, answer);
+    else
+      aCallback(answer, null);
+  });
 }
 Lightstring.pubsubDelete = function(aConnection, aTo, aNode, aCallback) {
-	aConnection.send(Lightstring.stanza.pubsub.delete(aTo, aNode), function(answer){
-		if(aCallback)
-			aCallback(answer);
-	});
+  aConnection.send(Lightstring.stanza.pubsub.delete(aTo, aNode), function(answer){
+    if(aCallback)
+      aCallback(answer);
+  });
 }
 Lightstring.pubsubGetAffiliations = function(aConnection, aTo, aNode, aCallback) {
-	aConnection.send(Lightstring.stanza.pubsub.affiliations(aTo, aNode), function(answer) {
-		if((answer.getAttribute('type') === 'result') && aCallback) {
-			var affiliations = {};
-			answer.querySelectorAll('affiliation').forEach(function(affiliation) {
-				affiliations[affiliation.getAttribute("jid")] = affiliation.getAttribute("affiliation");
-			})
-			aCallback(affiliations);
-		}
-	});
+  aConnection.send(Lightstring.stanza.pubsub.affiliations(aTo, aNode), function(answer) {
+    if((answer.getAttribute('type') === 'result') && aCallback) {
+      var affiliations = {};
+      answer.querySelectorAll('affiliation').forEach(function(affiliation) {
+        affiliations[affiliation.getAttribute("jid")] = affiliation.getAttribute("affiliation");
+      })
+      aCallback(affiliations);
+    }
+  });
 };
 Lightstring.pubsubSetAffiliations = function(aConnection, aTo, aNode, aAffiliations, aCallback) {
-	aConnection.send(Lightstring.stanza.pubsub.setAffiliations(aTo, aNode, aAffiliations));
+  aConnection.send(Lightstring.stanza.pubsub.setAffiliations(aTo, aNode, aAffiliations));
 };
 //////
 //IM//
 //////
 Lightstring.stanza.message = {
-	normal: function(aTo, aSubject, aText) {
-		return "<message type='normal' to='"+aTo+"'><subject>"+aSubject+"</subject><body>"+aText+"</body></message>";
-	},
-	chat: function(aTo, aText) {
-		return "<message type='chat' to='"+aTo+"'><body>"+aText+"</body></message>";
-	}
+  normal: function(aTo, aSubject, aText) {
+    return "<message type='normal' to='"+aTo+"'><subject>"+aSubject+"</subject><body>"+aText+"</body></message>";
+  },
+  chat: function(aTo, aText) {
+    return "<message type='chat' to='"+aTo+"'><body>"+aText+"</body></message>";
+  }
 };