diff options
Diffstat (limited to 'build/js/jsxc/jsxc.lib.js')
-rw-r--r-- | build/js/jsxc/jsxc.lib.js | 162 |
1 files changed, 120 insertions, 42 deletions
diff --git a/build/js/jsxc/jsxc.lib.js b/build/js/jsxc/jsxc.lib.js index 0b8185a..ad9b6af 100644 --- a/build/js/jsxc/jsxc.lib.js +++ b/build/js/jsxc/jsxc.lib.js @@ -1,5 +1,5 @@ /** - * jsxc v0.5.1 - 2014-01-27 + * jsxc v0.5.2 - 2014-01-28 * * Copyright (c) 2014 Klaus Herberth <klaus@jsxc.org> <br> * Released under the MIT license @@ -7,7 +7,7 @@ * Please see http://jsxc.org/ * * @author Klaus Herberth <klaus@jsxc.org> - * @version 0.5.1 + * @version 0.5.2 */ var jsxc; @@ -22,7 +22,7 @@ var jsxc; */ jsxc = { /** Version of jsxc */ - version: '0.5.1', + version: '0.5.2', /** True if i'm the chief */ chief: false, @@ -81,9 +81,6 @@ var jsxc; /** My css id */ cid: null, - /** Shortcut for jsxc.options.debug */ - debug: null, - /** Some constants */ CONST: { NOTIFICATION_DEFAULT: 'default', @@ -93,6 +90,53 @@ var jsxc; }, /** + * Write debug message to console and to log. + * + * @memberOf jsxc + * @param {String} msg Debug message + * @param {Object} data + * @param {String} Could be warn|error|null + */ + debug: function(msg, data, level) { + if (level) { + msg = '[' + level + '] ' + msg; + } + + if (data) { + console.log(msg, data); + jsxc.log = jsxc.log + msg + ': ' + $("<span>").prepend($(data).clone()).html() + '\n'; + } else { + console.log(msg); + jsxc.log = jsxc.log + msg + '\n'; + } + }, + + /** + * Write warn message. + * + * @memberOf jsxc + * @param {String} msg Warn message + * @param {Object} data + */ + warn: function(msg, data) { + jsxc.debug(msg, data, 'WARN'); + }, + + /** + * Write error message. + * + * @memberOf jsxc + * @param {String} msg Error message + * @param {Object} data + */ + error: function(msg, data) { + jsxc.debug(msg, data, 'ERROR'); + }, + + /** debug log */ + log: '', + + /** * Starts the action * * @memberOf jsxc @@ -114,9 +158,6 @@ var jsxc; jsxc.storage.updateUserItem('options', key, value); }; - // Shortcut - jsxc.debug = jsxc.options.debug; - jsxc.storageNotConform = jsxc.storage.getItem('storageNotConform') || 2; // detect language @@ -174,7 +215,9 @@ var jsxc; // create jquery object var form = jsxc.options.loginForm.form = $(jsxc.options.loginForm.form); - var events = form.data('events') || {submit: []}; + var events = form.data('events') || { + submit: [] + }; var submits = []; // save attached submit events and remove them. Will be reattached @@ -182,7 +225,7 @@ var jsxc; $.each(events.submit, function(index, val) { submits.push(val.handler); }); - + form.data('submits', submits); form.off('submit'); @@ -455,12 +498,12 @@ var jsxc; submitLoginForm: function() { var form = jsxc.options.loginForm.form.off('submit'); - //Attach original events + // Attach original events var submits = form.data('submits') || []; $.each(submits, function(index, val) { form.submit(val); - }); - + }); + if (form.find('#submit')) { form.find('#submit').click(); } else { @@ -526,7 +569,7 @@ var jsxc; var k = key.replace(/ /gi, '_'); if (!jsxc.l[k]) { - jsxc.debug('[WARN] No translation for: ' + k); + jsxc.warn('No translation for: ' + k); } return jsxc.l[k] || key.replace(/_/gi, ' '); @@ -672,6 +715,7 @@ var jsxc; var ri = $('#' + cid); // roster item from user var we = jsxc.gui.getWindow(cid); // window element from user var ue = $('#' + cid + ', #jsxc_window_' + cid + ', .jsxc_buddy_' + cid); // both + var bullet = $('.jsxc_buddy_' + cid); // Attach data to corresponding roster item ri.data(data); @@ -681,6 +725,7 @@ var jsxc; // Change name and add title ue.find('.jsxc_name').text(data.name).attr('title', 'is ' + jsxc.CONST.STATUS[data.status]); + bullet.attr('title', 'is ' + jsxc.CONST.STATUS[data.status]); // Update gui according to encryption state switch (data.msgstate) { @@ -738,7 +783,7 @@ var jsxc; jsxc.storage.setUserItem('avatar_' + data.avatar, src); setAvatar(src); }, Strophe.getBareJidFromJid(data.jid), function(msg) { - jsxc.debug('Error', msg); + jsxc.error('Could not load vcard.', msg); }); } } @@ -1083,6 +1128,37 @@ var jsxc; */ showAboutDialog: function() { jsxc.gui.dialog.open(jsxc.gui.template.get('aboutDialog')); + + $('#jsxc_dialog .jsxc_debuglog').click(function() { + jsxc.gui.showDebugLog(); + }); + }, + + /** + * Show debug log. + * + * @memberOf jsxc.gui + */ + showDebugLog: function() { + var userInfo = '<h3>User information</h3>'; + + if (navigator) { + var key; + for (key in navigator) { + if (navigator.hasOwnProperty(key) && typeof navigator[key] === 'string') { + userInfo += '<b>' + key + ':</b> ' + navigator[key] + '<br />'; + } + } + } + + if (window.screen) { + userInfo += '<b>Height:</b> ' + window.screen.height + '<br />'; + userInfo += '<b>Width:</b> ' + window.screen.width + '<br />'; + } + + userInfo += '<b>jsxc version:</b> ' + jsxc.version + '<br />'; + + jsxc.gui.dialog.open('<div class="jsxc_log">'+userInfo+'<h3>Log</h3><pre>' + jsxc.escapeHTML(jsxc.log) + '</pre></div>'); } }; @@ -1156,7 +1232,7 @@ var jsxc; * * @param {String} cid CSS compatible jid */ - add: function(cid) { + add: function(cid) { var data = jsxc.storage.getUserItem('buddy_' + cid); var bud = jsxc.gui.buddyTemplate.clone().attr('id', cid).attr('data-type', data.type || 'chat'); @@ -1577,9 +1653,9 @@ var jsxc; * @param {String} cid CSS compatible jid */ close: function(cid) { - + if (!jsxc.el_exists('#jsxc_window_' + cid)) { - jsxc.debug('[Warning] Want to close a window, that is not open.'); + jsxc.warn('Want to close a window, that is not open.'); return; } @@ -1653,7 +1729,7 @@ var jsxc; * * @param {String} cid */ - hide: function(cid) { + hide: function(cid) { jsxc.storage.updateUserItem('window_' + cid, 'minimize', true); jsxc.gui.window._hide(cid); @@ -1664,7 +1740,7 @@ var jsxc; * * @param {String} cid */ - _hide: function(cid) { + _hide: function(cid) { $('#jsxc_window_' + cid + ' .jsxc_window').slideUp(); jsxc.gui.getWindow(cid).trigger('hidden.window.jsxc'); }, @@ -2019,7 +2095,8 @@ var jsxc; <br />\ Real-time chat app for OwnCloud. This app requires external<br /> XMPP server (openfire, ejabberd etc.).<br />\ <br />\ - <i>Released under the MIT license</i></p>' + <i>Released under the MIT license</i></p>\ + <p class="jsxc_right"><a class="button jsxc_debuglog" href="#">Show debug log</a></p>' }; /** @@ -2051,16 +2128,16 @@ var jsxc; // Create new connection (no login) jsxc.xmpp.conn = new Strophe.Connection(url); - // jsxc.xmpp.conn.xmlInput = function(data) { - // jsxc.debug('<', data); - // }; - // jsxc.xmpp.conn.xmlOutput = function(data) { - // jsxc.debug('>', data); - // }; - // - // Strophe.log = function (level, msg) { - // jsxc.debug(level + " " + msg); - // }; +// jsxc.xmpp.conn.xmlInput = function(data) { +// console.log('<', data); +// }; +// jsxc.xmpp.conn.xmlOutput = function(data) { +// console.log('>', data); +// }; + +// Strophe.log = function (level, msg) { +// console.log(level + " " + msg); +// }; var callback = function(status, condition) { @@ -2071,7 +2148,7 @@ var jsxc; jsxc.cid = jsxc.jidToCid(jsxc.xmpp.conn.jid.toLowerCase()); $(document).trigger('connected.jsxc'); break; - case Strophe.Status.ATTACHED: + case Strophe.Status.ATTACHED: $(document).trigger('attached.jsxc'); break; case Strophe.Status.DISCONNECTED: @@ -2142,7 +2219,7 @@ var jsxc; jsxc.xmpp.conn.pause(); // Save sid and jid - jsxc.storage.setItem('sid', jsxc.xmpp.conn.sid); + jsxc.storage.setItem('sid', jsxc.xmpp.conn._proto.sid); jsxc.storage.setItem('jid', jsxc.xmpp.conn.jid.toLowerCase()); jsxc.storage.setItem('lastActivity', (new Date()).getTime()); @@ -2191,7 +2268,7 @@ var jsxc; }).c('query', { xmlns: 'jabber:iq:roster' }); - + jsxc.xmpp.conn.sendIQ(iq, jsxc.xmpp.onRoster); } else { jsxc.xmpp.sendPres(); @@ -2226,6 +2303,7 @@ var jsxc; pres.c('c', jsxc.xmpp.conn.caps.generateCapsAttrs()); } + jsxc.debug('Send presence', pres.toString()); jsxc.xmpp.conn.send(pres); }, @@ -2392,7 +2470,7 @@ var jsxc; * @param {dom} presence * @private */ - onPresence: function(presence) { + onPresence: function(presence) { /* * <presence xmlns='jabber:client' type='unavailable' from='' to=''/> * @@ -2407,6 +2485,8 @@ var jsxc; * node='http://psi-im.org/caps' ver='caps-b75d8d2b25' ext='ca cs * ep-notify-2 html'/> </presence> */ + jsxc.debug('onPresence', presence); + var ptype = $(presence).attr('type'); var from = $(presence).attr('from'); var jid = Strophe.getBareJidFromJid(from).toLowerCase(); @@ -2418,14 +2498,12 @@ var jsxc; var status = null; var xVCard = $(presence).find('x[xmlns="vcard-temp:x:update"]'); - jsxc.debug('onPresence', presence); - if (jid === to) { return true; } if (ptype === 'error') { - jsxc.debug('[XMPP ERROR] ' + $(presence).attr('code')); + jsxc.error('[XMPP] ' + $(presence).attr('code')); return true; } @@ -2456,7 +2534,7 @@ var jsxc; } var maxVal = []; - var max = 0, prop; + var max = 0, prop = null; for (prop in res) { if (res.hasOwnProperty(prop)) { if (max <= res[prop]) { @@ -2515,7 +2593,7 @@ var jsxc; * <body>...</body> <active * xmlns='http://jabber.org/protocol/chatstates'/> </message> */ - + jsxc.debug('Incoming message', message); var type = $(message).attr('type'); @@ -3205,7 +3283,7 @@ var jsxc; }); jsxc.buddyList[cid].on('error', function(err) { - jsxc.debug('[OTR] ' + err); + jsxc.error('[OTR] ', err); jsxc.gui.window.postMessage(cid, 'sys', '[OTR] ' + err); }); |