Commit 58241cbb authored by JC Brand's avatar JC Brand

Make converse.js more modular

- Removed the $(document).ready handler. Instead, converse.initialize must be
  called manually together with settings data.
- As a result the Plone specific event listeners are now also gone.
- Update tests and index.html to deal wit these changes
parent 7a062006
......@@ -1652,8 +1652,7 @@
crit = {order:'asc'};
$my_contacts.after($my_contacts.siblings('dd.current-xmpp-contact.offline').tsort('a', crit));
$my_contacts.after($my_contacts.siblings('dd.current-xmpp-contact.unavailable').tsort('a', crit));
},
}
});
converse.XMPPStatus = Backbone.Model.extend({
......@@ -1936,22 +1935,6 @@
$('.conn-feedback').text(message);
}
converse.initialize = function (data) {
this.prebind = data.attr('prebind');
this.fullname = data.attr('fullname');
this.xhr_user_search = data.attr('xhr_user_search');
this.auto_subscribe = data.attr('auto_subscribe') === "True" || false;
this.chatboxes = new this.ChatBoxes();
this.chatboxesview = new this.ChatBoxesView({model: this.chatboxes});
$('a.toggle-online-users').bind(
'click',
$.proxy(function (e) {
e.preventDefault(); this.toggleControlBox();
}, this)
);
},
converse.onConnected = function (connection) {
this.animate = true; // Use animations
this.connection = connection;
......@@ -2002,24 +1985,22 @@
this.giveFeedback('Online Contacts');
};
// Event handlers
// --------------
$(document).ready($.proxy(function () {
// TODO: This code is Plone specific and needs to be factored out
var data = $('div#collective-xmpp-chat-data');
this.initialize(data);
$(document).bind('jarnxmpp.connecting', $.proxy(function (ev, conn) {
this.giveFeedback('Connecting to chat...');
}, this));
$(document).bind('jarnxmpp.disconnected', $.proxy(function (ev, conn) {
this.giveFeedback('Unable to communicate with chat server').css('background-image', "url(images/error_icon.png)");
console.log("Connection Failed :(");
}, this));
$(document).unbind('jarnxmpp.connected');
$(document).bind('jarnxmpp.connected', $.proxy(function (ev, connection) {
this.onConnected(connection);
}, this));
}, converse));
converse.initialize = function (settings) {
this.prebind = settings.prebind;
this.fullname = settings.fullname;
this.xhr_user_search = settings.xhr_user_search;
this.auto_subscribe = settings.auto_subscribe;
this.animate = settings.animate;
this.chatboxes = new this.ChatBoxes();
this.chatboxesview = new this.ChatBoxesView({model: this.chatboxes});
$('a.toggle-online-users').bind(
'click',
$.proxy(function (e) {
e.preventDefault(); this.toggleControlBox();
}, this)
);
};
return converse;
}));
......@@ -131,10 +131,20 @@
</div>
</div>
<script type="text/javascript">
<script type="text/javascript">
$(document).ready(function {
converse.initialize({
prebind: false,
xhr_user_search: false,
auto_subscribe: false
});
});
</script>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">try { var pageTracker = _gat._getTracker("UA-2128260-8"); pageTracker._trackPageview(); } catch(err) {}</script>
</body>
</script>
<script type="text/javascript">try { var pageTracker = _gat._getTracker("UA-2128260-8"); pageTracker._trackPageview(); } catch(err) {}</script>
</body>
</html>
......@@ -21,13 +21,12 @@
'Lena Grunewald', 'Laura Grunewald', 'Mandy Seiler', 'Sven Bosch', 'Nuriye Cuypers'
];
var num_contacts = req_names.length + pend_names.length + cur_names.length;
this.bare_jid = 'dummy@localhost';
mock_connection = {
'muc': {
'listRooms': function () {},
'join': function () {}
},
'jid': this.bare_jid,
'jid': 'dummy@localhost',
'addHandler': function (handler, ns, name, type, id, from, options) {
return function () {};
},
......@@ -54,9 +53,13 @@
// Clear localStorage
window.localStorage.clear();
this.prebind = true;
this.initialize({
prebind: false,
xhr_user_search: false,
auto_subscribe: false,
animate: false
});
this.onConnected(mock_connection);
this.animate = false; // don't use animations
// Variable declarations for specs
var open_controlbox;
......@@ -485,7 +488,7 @@
var sender_jid = cur_names[0].replace(' ','.').toLowerCase() + '@localhost';
msg = $msg({
from: sender_jid,
to: this.bare_jid,
to: this.connection.jid,
type: 'chat',
id: (new Date()).getTime()
}).c('body').t(message).up()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment