Commit 1b97fbac authored by JC Brand's avatar JC Brand

Added a src directory and updated setup.py

parents
// TODO: Make this a module (with variable closure)
var babblexmpp = {
chats: [], // Records new chat windows being opened.
chat_focus: [],
sanitizePath: function (call) {
return babblexmpp.base_url + call;
},
hash: function (str) {
// FIXME: This is ugly...
if (str == 'online-users-container') {
return str;
}
var shaobj = new jsSHA(str);
return shaobj.getHash("HEX");
},
oc: function (a) {
// Thanks to Jonathan Snook: http://snook.ca
var o = {};
for(var i=0; i<a.length; i++) {
o[a[i]]='';
}
return o;
},
getMinimizedChats: function () {
var cookie = jQuery.cookie('chats_minimized_'+babblexmpp.username);
if (cookie) {
return cookie.split(/\|/);
}
return [];
},
positionNewChat: function (chatbox) {
var open_chats = 0;
for (var i=0; i<babblexmpp.chats.length; i++) {
if (jQuery("#"+babblexmpp.hash(babblexmpp.chats[i])).css('display') != 'none') {
open_chats++;
}
}
if (open_chats === 0) {
chatbox.css('right', '20px');
}
else {
width = (open_chats)*(225+7)+20;
chatbox.css('right', width+'px');
}
},
handleChatEvents: function (chat_id) {
var chat_type = chat_id.split('_')[0];
babblexmpp.chat_focus[chat_id] = false;
var chat_area = jQuery("#"+babblexmpp.hash(chat_id)+" .chat-textarea");
chat_area.blur(function(){
babblexmpp.chat_focus[chat_id] = false;
chat_area.removeClass('chat-textarea-'+chat_type+'-selected');
}).focus(function(){
babblexmpp.chat_focus[chat_id] = true;
chat_area.addClass('chat-textarea-'+chat_type+'-selected');
});
var chatbox = jQuery("#"+babblexmpp.hash(chat_id));
chatbox.click(function() {
if (chatbox.find('.chat-content').css('display') != 'none') {
chatbox.find('.chat-textarea').focus();
}
});
},
createChatBox: function (chat_id, jid) {
var path = babblexmpp.sanitizePath('/@@render_chat_box');
jQuery.ajax({
url: path,
cache: false,
async: false,
data: {
chat_id: chat_id,
box_id: babblexmpp.hash(chat_id),
jid: jid,
tzoffset: -(new Date().getTimezoneOffset())
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log(textStatus);
console.log(errorThrown);
return;
},
success: function(data) {
jQuery('body').append(data).find('.chat-message .time').each(function (){
jthis = jQuery(this);
var time = jthis.text().split(':');
var hour = time[0];
var minutes = time[1];
var date = new Date();
date.setHours(hour - date.getTimezoneOffset() / 60);
date.setMinutes(minutes);
jthis.replaceWith(date.toLocaleTimeString().substring(0,5));
});
var last_msg_date = jQuery('div#'+chat_id).attr('last_msg_date');
if ((last_msg_date !== undefined)&&(last_msg_date > global_received_date)) {
global_received_date = last_msg_date;
sent_since_date = [];
}
}
});
return jQuery('#'+babblexmpp.hash(chat_id));
},
createChat: function (chat_id, minimize, jid) {
console.log('createChat: chat_id is ' + chat_id);
var cookie = jQuery.cookie('chats-open-'+this.username);
console.log('createChat: cookie is ' + cookie);
var open_chats = [];
var chat_content;
if (cookie) {
open_chats = cookie.split('|');
}
if (!(chat_id in this.oc(open_chats))) {
// Update the cookie if this new chat is not yet in it.
open_chats.push(chat_id);
var new_cookie = open_chats.join('|');
jQuery.cookie('chats-open-'+this.username, new_cookie, {path: '/'});
console.log('createChat: updated cookie = ' + new_cookie + '\n');
}
var chatbox = jQuery("#"+this.hash(chat_id));
if (chatbox.length > 0) {
// The chatbox exists, merely hidden
if (chatbox.css('display') == 'none') {
chatbox.css('display','block');
this.reorderChats();
}
chatbox.find(".chat-textarea").focus();
chat_content = chatbox.find('.chat-content');
chat_content.scrollTop(chat_content[0].scrollHeight);
return;
}
chatbox = this.createChatBox(chat_id, jid);
if (chatbox.length === 0) {
console.log('Could not create chatbox with id: ' + chat_id);
return;
}
this.positionNewChat(chatbox);
this.chats.push(chat_id);
if (minimize == 1) {
// Minimize the chat if it's in the minimized_chats cookie
var minimized_chats = this.getMinimizedChats();
if (chat_id in this.oc(minimized_chats)) {
chatbox.find('.chat-content').css('display','none');
chatbox.find('.chat-input').css('display','none');
}
}
this.handleChatEvents(chat_id);
chatbox.show();
chat_content = chatbox.find('.chat-content');
if (chat_content.length) {
chat_content.scrollTop(chat_content[0].scrollHeight);
}
else {
console.log('createChat: could not get .chat-content');
}
return chatbox;
},
startChat: function (chat_id, jid) {
this.createChat(chat_id, 0, jid);
jQuery("#"+this.hash(chat_id)+" .chat-textarea").focus();
},
reorderChats: function () {
var index = 0;
for (var i=0; i < this.chats.length; i++) {
var chatbox = jQuery("#"+this.hash(this.chats[i]));
if (chatbox.css('display') != 'none') {
if (index === 0) {
chatbox.css('right', '20px');
}
else {
width = (index)*(225+7)+20;
chatbox.css('right', width+'px');
}
index++;
}
}
},
receiveMessage: function (event) {
var user_id = Strophe.getNodeFromJid(event.from),
jid = Strophe.getBareJidFromJid(event.from),
text = event.body.replace(/<br \/>/g, ""),
that = this;
jarnxmpp.Presence.getUserInfo(user_id, function (data) {
var chat_id = 'chatbox_'+user_id;
var chat = jQuery('#'+that.hash(chat_id));
if (chat.length <= 0) {
chat = that.createChat(chat_id, 0, jid);
}
if (chat.css('display') == 'none') {
chat.css('display','block');
that.reorderChats();
}
var chat_content = chat.find(".chat-content");
if (user_id == that.username) {
message_html = '<div class="chat-message">' +
'<span class="chat-message-me">me:&nbsp;&nbsp;</span>' +
'<span class="chat-message-content">'+text+'</span>' +
'</div>';
}
else {
message_html = '<div class="chat-message">' +
'<span class="chat-message-them">'+data.fullname+':&nbsp;&nbsp;</span>' +
'<span class="chat-message-content">'+text+'</span>' +
'</div>';
}
chat_content.append(message_html);
if (chat_content.css('display') == 'none') {
// The chatbox is minimized, so we change it's header color to alert
// the user.
chat.find('.chat-head').addClass('chat-head-minimized-with-messages');
}
chat_content.scrollTop(chat_content[0].scrollHeight);
jarnxmpp.UI.msg_counter += 1;
jarnxmpp.UI.updateMsgCounter();
});
}
};
function keypressed(event, textarea, audience, hashed_id, chat_type) {
if(event.keyCode == 13 && !event.shiftKey) {
var textbox = jQuery(textarea);
var message = textbox.val();
var form = textbox.parent();
form.submit();
message = message.replace(/^\s+|\s+jQuery/g,"");
textbox.val('').focus().css('height','44px');
if (message !== '') {
message = message.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;");
list = message.match(/\b(http:\/\/www\.\S+\.\w+|www\.\S+\.\w+|http:\/\/(?=[^w]){3}\S+[\.:]\S+)[^ ]+\b/g);
if (list) {
for (i = 0; i < list.length; i++) {
message = message.replace( list[i], "<a target='_blank' href='" + escape( list[i] ) + "'>"+ list[i] + "</a>" );
}
}
var now = new Date();
var minutes = now.getMinutes().toString();
if (minutes.length==1) {minutes = '0'+minutes;}
var time = now.toLocaleTimeString().substring(0,5);
var chat_content = jQuery('#'+hashed_id+' .chat-content');
chat_content.append(
'<div class="chat-message">' +
'<span class="chat-message-me">'+time+' me:&nbsp;&nbsp;</span>' +
'<span class="chat-message-content">'+message+'</span>' +
'</div>');
chat_content.scrollTop(chat_content[0].scrollHeight);
}
}
var adjustedHeight = textarea.clientHeight;
var maxHeight = 94;
if (maxHeight > adjustedHeight) {
adjustedHeight = Math.max(textarea.scrollHeight, adjustedHeight);
if (maxHeight) {
adjustedHeight = Math.min(maxHeight, adjustedHeight);
}
if (adjustedHeight > textarea.clientHeight) {
jQuery(textarea).css('height',adjustedHeight+8 +'px');
}
}
else {
jQuery(textarea).css('overflow','auto');
}
}
function closeChat(chat_id, audience) {
jQuery('#'+babblexmpp.hash(chat_id)).css('display','none');
babblexmpp.reorderChats();
var cookie = jQuery.cookie('chats-open-'+babblexmpp.username);
var open_chats = [];
if (cookie) {
open_chats = cookie.split('|');
}
new_chats = [];
for (var i=0; i < open_chats.length; i++) {
if (open_chats[i] != chat_id) {
new_chats.push(open_chats[i]);
}
}
if (new_chats.length) {
jQuery.cookie('chats-open-'+babblexmpp.username, new_chats.join('|'), {path: '/'});
}
else {
jQuery.cookie('chats-open-'+babblexmpp.username, null, {path: '/'});
}
}
function toggleChat(chat_id) {
var minimized_chats = babblexmpp.getMinimizedChats();
var hashed_id = babblexmpp.hash(chat_id);
var new_cookie;
if (jQuery('#'+hashed_id+' .chat-content').css('display') == 'none') {
// Chat will be maximized
new_cookie = [];
for (var i=0; i < minimized_chats.length; i++) {
if (minimized_chats[i] != chat_id) {
new_cookie.push(minimized_chats[i]);
}
}
jQuery.cookie('chats_minimized_'+babblexmpp.username, new_cookie.join('|'));
var chat_content = jQuery('#'+hashed_id+' .chat-content');
chat_content.css('display','block');
chat_content.scrollTop(chat_content[0].scrollHeight);
jQuery('#'+hashed_id+' .chat-head').removeClass('chat-head-minimized-with-messages');
jQuery('#'+hashed_id+' .chat-input').css('display','block');
}
else {
// Chat will be minimized
if (!(chat_id in babblexmpp.oc(minimized_chats))) {
new_cookie = chat_id;
new_cookie += '|'+minimized_chats.join('|');
jQuery.cookie('chats_minimized_'+babblexmpp.username, new_cookie);
}
jQuery('#'+hashed_id+' .chat-content').css('display','none');
jQuery('#'+hashed_id+' .chat-input').css('display','none');
}
}
$(document).unbind('jarnxmpp.message');
$(document).bind('jarnxmpp.message', function (event) {
babblexmpp.receiveMessage(event);
});
$(document).ready(function () {
var chatdata = jQuery('span#babble-client-chatdata');
babblexmpp.username = chatdata.attr('username');
babblexmpp.base_url = chatdata.attr('base_url');
$.hook(['show', 'hide']);
chat_id = 'online-users-container';
$("div#"+chat_id)
.bind('onbeforeshow', function (e) { })
.bind('onshow', function (e) { })
.bind('onaftershow', function (e) {
var cookie = jQuery.cookie('chats-open-'+babblexmpp.username);
var open_chats = [];
if (cookie) {
open_chats = cookie.split('|');
}
if (!(chat_id in babblexmpp.oc(open_chats))) {
// Update the cookie if this new chat is not yet in it.
open_chats.push(chat_id);
var new_cookie = open_chats.join('|');
jQuery.cookie('chats-open-'+babblexmpp.username, new_cookie, {path: '/'});
console.log('updated cookie = ' + new_cookie + '\n');
}
babblexmpp.chats.push(chat_id);
})
.bind('onafterhide', function (e) {
var cookie = jQuery.cookie('chats-open-'+babblexmpp.username);
if (cookie) {
open_chats = cookie.split('|');
}
new_chats = [];
for (var i=0; i < open_chats.length; i++) {
if (open_chats[i] != chat_id) {
new_chats.push(open_chats[i]);
}
}
if (new_chats.length) {
jQuery.cookie('chats-open-'+babblexmpp.username, new_chats.join('|'), {path: '/'});
}
else {
jQuery.cookie('chats-open-'+babblexmpp.username, null, {path: '/'});
}
});
$('a.user-details-toggle').live('click', function (e) {
var userid = $(this).parent().attr('data-userid'),
$field = $('[name="message"]:input', $(this).parent()[0]),
recipient = $field.attr('data-recipient');
babblexmpp.startChat('chatbox_'+userid, recipient);
e.preventDefault();
});
});
/* Copyright (c) 2006 Klaus Hartl (stilbuero.de) */
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
// CAUTION: Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
}
else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
/*!
* jQuery.hook v1.0
*
* Copyright (c) 2009 Aaron Heckmann
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
/**
* Provides the ability to hook into any jQuery.fn[method]
* with onbeforeMETHOD, onMETHOD, and onafterMETHOD.
*
* Pass in a string or array of method names you want
* to hook with onbefore, on, or onafter.
*
* Example:
* jQuery.hook('show');
* jQuery(selector).bind('onbeforeshow', function (e) { alert(e.type);});
* jQuery(selector).show() -> alerts 'onbeforeshow'
*
* jQuery.hook(['show','hide']);
* jQuery(selector)
* .bind('onbeforeshow', function (e) { alert(e.type);})
* .bind('onshow', function (e) { alert(e.type);})
* .bind('onaftershow', function (e) { alert(e.type);})
* .bind('onafterhide', function (e) { alert("The element is now hidden.");});
* jQuery(selector).show().hide()
* -> alerts 'onbeforeshow' then alerts 'onshow', then alerts 'onaftershow',
* then after the element is hidden alerts 'The element is now hidden.'
*
*
* You can also unhook what you've hooked into by calling jQuery.unhook() passing
* in your string or array of method names to unhook.
*
*/
(function($){
$.hook = function (fns) {
fns = typeof fns === 'string' ?
fns.split(' ') :
$.makeArray(fns)
;
jQuery.each( fns, function (i, method) {
var old = $.fn[ method ];
if ( old && !old.__hookold ) {
$.fn[ method ] = function () {
this.triggerHandler('onbefore'+method);
this.triggerHandler('on'+method);
var ret = old.apply(this, arguments);
this.triggerHandler('onafter'+method);
return ret;
};
$.fn[ method ].__hookold = old;
}
});
};
$.unhook = function (fns) {
fns = typeof fns === 'string' ?
fns.split(' ') :
$.makeArray(fns)
;
jQuery.each( $.makeArray(fns), function (i, method) {
var cur = $.fn[ method ];
if ( cur && cur.__hookold ) {
$.fn[ method ] = cur.__hookold;
}
});
};
})(jQuery);
/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS
* PUB 180-2 as well as the corresponding HMAC implementation as defined in
* FIPS PUB 198a
*
* Version 1.3 Copyright Brian Turek 2008-2010
* Distributed under the BSD License
* See http://jssha.sourceforge.net/ for more information
*
* Several functions taken from Paul Johnson
*/
(function(){var charSize=8,b64pad="",hexCase=0,str2binb=function(a){var b=[],mask=(1<<charSize)-1,length=a.length*charSize,i;for(i=0;i<length;i+=charSize){b[i>>5]|=(a.charCodeAt(i/charSize)&mask)<<(32-charSize-(i%32))}return b},hex2binb=function(a){var b=[],length=a.length,i,num;for(i=0;i<length;i+=2){num=parseInt(a.substr(i,2),16);if(!isNaN(num)){b[i>>3]|=num<<(24-(4*(i%8)))}else{return"INVALID HEX STRING"}}return b},binb2hex=function(a){var b=(hexCase)?"0123456789ABCDEF":"0123456789abcdef",str="",length=a.length*4,i,srcByte;for(i=0;i<length;i+=1){srcByte=a[i>>2]>>((3-(i%4))*8);str+=b.charAt((srcByte>>4)&0xF)+b.charAt(srcByte&0xF)}return str},binb2b64=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"+"0123456789+/",str="",length=a.length*4,i,j,triplet;for(i=0;i<length;i+=3){triplet=(((a[i>>2]>>8*(3-i%4))&0xFF)<<16)|(((a[i+1>>2]>>8*(3-(i+1)%4))&0xFF)<<8)|((a[i+2>>2]>>8*(3-(i+2)%4))&0xFF);for(j=0;j<4;j+=1){if(i*8+j*6<=a.length*32){str+=b.charAt((triplet>>6*(3-j))&0x3F)}else{str+=b64pad}}}return str},rotl=function(x,n){return(x<<n)|(x>>>(32-n))},parity=function(x,y,z){return x^y^z},ch=function(x,y,z){return(x&y)^(~x&z)},maj=function(x,y,z){return(x&y)^(x&z)^(y&z)},safeAdd_2=function(x,y){var a=(x&0xFFFF)+(y&0xFFFF),msw=(x>>>16)+(y>>>16)+(a>>>16);return((msw&0xFFFF)<<16)|(a&0xFFFF)},safeAdd_5=function(a,b,c,d,e){var f=(a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF)+(e&0xFFFF),msw=(a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16)+(f>>>16);return((msw&0xFFFF)<<16)|(f&0xFFFF)},coreSHA1=function(f,g){var W=[],a,b,c,d,e,T,i,t,appendedMessageLength,H=[0x67452301,0xefcdab89,0x98badcfe,0x10325476,0xc3d2e1f0],K=[0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6];f[g>>5]|=0x80<<(24-(g%32));f[(((g+65)>>9)<<4)+15]=g;appendedMessageLength=f.length;for(i=0;i<appendedMessageLength;i+=16){a=H[0];b=H[1];c=H[2];d=H[3];e=H[4];for(t=0;t<80;t+=1){if(t<16){W[t]=f[t+i]}else{W[t]=rotl(W[t-3]^W[t-8]^W[t-14]^W[t-16],1)}if(t<20){T=safeAdd_5(rotl(a,5),ch(b,c,d),e,K[t],W[t])}else if(t<40){T=safeAdd_5(rotl(a,5),parity(b,c,d),e,K[t],W[t])}else if(t<60){T=safeAdd_5(rotl(a,5),maj(b,c,d),e,K[t],W[t])}else{T=safeAdd_5(rotl(a,5),parity(b,c,d),e,K[t],W[t])}e=d;d=c;c=rotl(b,30);b=a;a=T}H[0]=safeAdd_2(a,H[0]);H[1]=safeAdd_2(b,H[1]);H[2]=safeAdd_2(c,H[2]);H[3]=safeAdd_2(d,H[3]);H[4]=safeAdd_2(e,H[4])}return H},jsSHA=function(a,b){this.sha1=null;this.strBinLen=null;this.strToHash=null;if("HEX"===b){if(0!==(a.length%2)){return"TEXT MUST BE IN BYTE INCREMENTS"}this.strBinLen=a.length*4;this.strToHash=hex2binb(a)}else if(("ASCII"===b)||('undefined'===typeof(b))){this.strBinLen=a.length*charSize;this.strToHash=str2binb(a)}else{return"UNKNOWN TEXT INPUT TYPE"}};jsSHA.prototype={getHash:function(a){var b=null,message=this.strToHash.slice();switch(a){case"HEX":b=binb2hex;break;case"B64":b=binb2b64;break;default:return"FORMAT NOT RECOGNIZED"}if(null===this.sha1){this.sha1=coreSHA1(message,this.strBinLen)}return b(this.sha1)},getHMAC:function(a,b,c){var d,keyToUse,i,retVal,keyBinLen,keyWithIPad=[],keyWithOPad=[];switch(c){case"HEX":d=binb2hex;break;case"B64":d=binb2b64;break;default:return"FORMAT NOT RECOGNIZED"}if("HEX"===b){if(0!==(a.length%2)){return"KEY MUST BE IN BYTE INCREMENTS"}keyToUse=hex2binb(a);keyBinLen=a.length*4}else if("ASCII"===b){keyToUse=str2binb(a);keyBinLen=a.length*charSize}else{return"UNKNOWN KEY INPUT TYPE"}if(64<(keyBinLen/8)){keyToUse=coreSHA1(keyToUse,keyBinLen);keyToUse[15]&=0xFFFFFF00}else if(64>(keyBinLen/8)){keyToUse[15]&=0xFFFFFF00}for(i=0;i<=15;i+=1){keyWithIPad[i]=keyToUse[i]^0x36363636;keyWithOPad[i]=keyToUse[i]^0x5C5C5C5C}retVal=coreSHA1(keyWithIPad.concat(this.strToHash),512+this.strBinLen);retVal=coreSHA1(keyWithOPad.concat(retVal),672);return(d(retVal))}};window.jsSHA=jsSHA}());
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