// http://whatsock.com/modules/accessible_chat_dialog_module/js/fb_chat.js /*! The Facebook Chat Bookmarklet - v1.0 For use on Facebook.com when a chat dialog is open. Bryan Garaventa, WhatSock */ window.enableWSFBChat = function(){ var getEl = function(e){ if (document.getElementById) return document.getElementById(e); else if (document.all) return document.all[e]; else return null; }, getElsByTag = function(tag, root){ var l = [], t = tag || '*', r = root || document; if (r.getElementsByTagName) l = r.getElementsByTagName(t); if (!l || !l.length){ if (t === '*' && r.all) l = r.all; else if (r.all && r.all.tags) l = r.all.tags(t); } return l; }, createEl = function(t){ var o = document.createElement(t); if (arguments.length === 1) return o; if (arguments[1]) setAttr(o, arguments[1]); if (arguments[2]) css(o, arguments[2]); return o; }, createAttr = function(a){ return document.createAttribute(a); }, css = function(obj, p, v){ if (!obj) return null; var o = isArray(obj) ? obj : [obj], check = 'top left bottom right width height'; for (var i = 0; i < o.length; i++){ if (typeof p === 'string'){ try { o[i].style[xCamelize(p)] = check.indexOf(p) !== -1 && typeof v === 'number' ? v + 'px' : v; } catch (ex) { } } else if (typeof p === 'object'){ for (var a = 1; a < arguments.length; a++){ for (var n in arguments[a]){ try { o[i].style[xCamelize(n)] = check.indexOf(n) !== -1 && typeof arguments[a][n] === 'number' ? arguments[a][n] + 'px' : arguments[a][n]; } catch (ex) { } } } } } return obj; }, trim = function(str){ return str.replace(/^\s+|\s+$/g, ''); }, setAttr = function(obj, name, value){ if (!obj) return null; if (typeof name === 'string'){ var a = createAttr(name); a.nodeValue = value; obj.setAttributeNode(a); } else if (typeof name === 'object'){ for (n in name){ var a = createAttr(n); a.nodeValue = name[n]; obj.setAttributeNode(a); } } return obj; }, isArray = function(v){ return v && typeof v === 'object' && typeof v.length === 'number' && typeof v.splice === 'function' && !(v.propertyIsEnumerable('length')); }, hasClass = function(obj, cn){ if (!obj || !obj.className) return false; var names = cn.split(' '), i = 0; for (var n = 0; n < names.length; n++){ if (obj.className.indexOf(names[n]) !== -1) i += 1; } if (i === names.length) return true; return false; }, getElsByClass = function(cn, tag, root){ var tag = tag || '*', root = root || document; if (root.getElementsByClassName && tag === '*') return root.getElementsByClassName(cn); var a = getElsByTag(tag, root), r = [], names = cn.split(' '); for (var i = 0; i < a.length; i++){ var c = 0; for (var n = 0; n < names.length; n++){ if (hasClass(a[i], names[n])) c += 1; } if (c === names.length) r.push(a[i]); } return r; }, firstChild = function(e, t){ var e = e ? e.firstChild : null; while(e){ if (e.nodeType === 1 && (!t || t.toLowerCase() === e.nodeName.toLowerCase())) break; e = e.nextSibling; } return e; }, lastChild = function(e, t){ var e = e ? e.lastChild : null; while(e){ if (e.nodeType === 1 && (!t || t.toLowerCase() === e.nodeName.toLowerCase())) break; e = e.previousSibling; } return e; }, prevSib = function(e, t){ var e = e ? e.previousSibling : null; while(e){ if (e.nodeType === 1 && (!t || t.toLowerCase() === e.nodeName.toLowerCase())) break; e = e.previousSibling; } return e; }, xCamelize = function(cssPropStr){ var i, c, a, s; a = cssPropStr.split('-'); s = a[0]; for (i=1; i= 1) announce(String.announce.alertMsgs[0], true); }, timeLength); } return obj; }; String.announce = { alertMsgs: [], clear: function(){ if (this.alertTO) clearTimeout(this.alertTO); this.alertMsgs.length = 0; }, baseDelay: 1000, charMultiplier: 10, lastMsg: '', iterate: function(str, regExp){ var iCount = 0; str.replace(regExp, function(){ iCount++; }); return iCount; } }; if (!String.announce.placeHolder){ String.announce.placeHolder = createEl('span', { role: 'status', 'aria-live': 'assertive', 'aria-relevant': 'all' }, sraCSS); document.body.appendChild(String.announce.placeHolder); } setAttr(prevSib(conv), { role: 'heading', 'aria-level': 3 }); setAttr(edit, 'accesskey', 'm'); setAttr(edit.parentNode, 'role', 'dialog'); addEv(edit, 'keydown', function(ev){ var e = ev ? ev : window.event; changePressed(e); }); addEv(edit, 'keyup', function(ev){ var e = ev ? ev : window.event, k = e.which || e.keyCode; if (k == key.val && pressed.ctrl == key.ctrl && pressed.alt == key.alt && pressed.shift == key.shift){ var r = track.conv; r.reverse(); for (var x = 4; x >= 0; x--){ if (r[x]) announce(r[x]); } if (e.preventDefault) e.preventDefault(); else e.returnValue = false; } changePressed(e); }); announce('The Facebook Chat Bookmarklet is activated. Press Control+Shift+1 to hear the last 5 messages announced.'); check(); track.timer = setInterval(check, 1000); }; window.enableWSFBChat();