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
This commit is contained in:
parent
7a0620060f
commit
58241cbb74
53
converse.js
53
converse.js
|
@ -1652,8 +1652,7 @@
|
||||||
crit = {order:'asc'};
|
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.offline').tsort('a', crit));
|
||||||
$my_contacts.after($my_contacts.siblings('dd.current-xmpp-contact.unavailable').tsort('a', crit));
|
$my_contacts.after($my_contacts.siblings('dd.current-xmpp-contact.unavailable').tsort('a', crit));
|
||||||
},
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
converse.XMPPStatus = Backbone.Model.extend({
|
converse.XMPPStatus = Backbone.Model.extend({
|
||||||
|
@ -1936,22 +1935,6 @@
|
||||||
$('.conn-feedback').text(message);
|
$('.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) {
|
converse.onConnected = function (connection) {
|
||||||
this.animate = true; // Use animations
|
this.animate = true; // Use animations
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
|
@ -2002,24 +1985,22 @@
|
||||||
this.giveFeedback('Online Contacts');
|
this.giveFeedback('Online Contacts');
|
||||||
};
|
};
|
||||||
|
|
||||||
// Event handlers
|
converse.initialize = function (settings) {
|
||||||
// --------------
|
this.prebind = settings.prebind;
|
||||||
$(document).ready($.proxy(function () {
|
this.fullname = settings.fullname;
|
||||||
// TODO: This code is Plone specific and needs to be factored out
|
this.xhr_user_search = settings.xhr_user_search;
|
||||||
var data = $('div#collective-xmpp-chat-data');
|
this.auto_subscribe = settings.auto_subscribe;
|
||||||
this.initialize(data);
|
this.animate = settings.animate;
|
||||||
$(document).bind('jarnxmpp.connecting', $.proxy(function (ev, conn) {
|
|
||||||
this.giveFeedback('Connecting to chat...');
|
this.chatboxes = new this.ChatBoxes();
|
||||||
}, this));
|
this.chatboxesview = new this.ChatBoxesView({model: this.chatboxes});
|
||||||
$(document).bind('jarnxmpp.disconnected', $.proxy(function (ev, conn) {
|
$('a.toggle-online-users').bind(
|
||||||
this.giveFeedback('Unable to communicate with chat server').css('background-image', "url(images/error_icon.png)");
|
'click',
|
||||||
console.log("Connection Failed :(");
|
$.proxy(function (e) {
|
||||||
}, this));
|
e.preventDefault(); this.toggleControlBox();
|
||||||
$(document).unbind('jarnxmpp.connected');
|
}, this)
|
||||||
$(document).bind('jarnxmpp.connected', $.proxy(function (ev, connection) {
|
);
|
||||||
this.onConnected(connection);
|
};
|
||||||
}, this));
|
|
||||||
}, converse));
|
|
||||||
|
|
||||||
return converse;
|
return converse;
|
||||||
}));
|
}));
|
||||||
|
|
18
index.html
18
index.html
|
@ -131,10 +131,20 @@
|
||||||
</div>
|
</div>
|
||||||
</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.");
|
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"));
|
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript">try { var pageTracker = _gat._getTracker("UA-2128260-8"); pageTracker._trackPageview(); } catch(err) {}</script>
|
<script type="text/javascript">try { var pageTracker = _gat._getTracker("UA-2128260-8"); pageTracker._trackPageview(); } catch(err) {}</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -21,13 +21,12 @@
|
||||||
'Lena Grunewald', 'Laura Grunewald', 'Mandy Seiler', 'Sven Bosch', 'Nuriye Cuypers'
|
'Lena Grunewald', 'Laura Grunewald', 'Mandy Seiler', 'Sven Bosch', 'Nuriye Cuypers'
|
||||||
];
|
];
|
||||||
var num_contacts = req_names.length + pend_names.length + cur_names.length;
|
var num_contacts = req_names.length + pend_names.length + cur_names.length;
|
||||||
this.bare_jid = 'dummy@localhost';
|
|
||||||
mock_connection = {
|
mock_connection = {
|
||||||
'muc': {
|
'muc': {
|
||||||
'listRooms': function () {},
|
'listRooms': function () {},
|
||||||
'join': function () {}
|
'join': function () {}
|
||||||
},
|
},
|
||||||
'jid': this.bare_jid,
|
'jid': 'dummy@localhost',
|
||||||
'addHandler': function (handler, ns, name, type, id, from, options) {
|
'addHandler': function (handler, ns, name, type, id, from, options) {
|
||||||
return function () {};
|
return function () {};
|
||||||
},
|
},
|
||||||
|
@ -54,9 +53,13 @@
|
||||||
|
|
||||||
// Clear localStorage
|
// Clear localStorage
|
||||||
window.localStorage.clear();
|
window.localStorage.clear();
|
||||||
this.prebind = true;
|
this.initialize({
|
||||||
|
prebind: false,
|
||||||
|
xhr_user_search: false,
|
||||||
|
auto_subscribe: false,
|
||||||
|
animate: false
|
||||||
|
});
|
||||||
this.onConnected(mock_connection);
|
this.onConnected(mock_connection);
|
||||||
this.animate = false; // don't use animations
|
|
||||||
|
|
||||||
// Variable declarations for specs
|
// Variable declarations for specs
|
||||||
var open_controlbox;
|
var open_controlbox;
|
||||||
|
@ -485,7 +488,7 @@
|
||||||
var sender_jid = cur_names[0].replace(' ','.').toLowerCase() + '@localhost';
|
var sender_jid = cur_names[0].replace(' ','.').toLowerCase() + '@localhost';
|
||||||
msg = $msg({
|
msg = $msg({
|
||||||
from: sender_jid,
|
from: sender_jid,
|
||||||
to: this.bare_jid,
|
to: this.connection.jid,
|
||||||
type: 'chat',
|
type: 'chat',
|
||||||
id: (new Date()).getTime()
|
id: (new Date()).getTime()
|
||||||
}).c('body').t(message).up()
|
}).c('body').t(message).up()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user