Alice
view release on metacpan or search on metacpan
share/static/alice.js view on Meta::CPAN
var events = WebSocket.__flash.receiveEvents();
for (var i = 0; i < events.length; ++i) {
WebSocket.__instances[events[i].webSocketId].__handleEvent(events[i]);
}
} catch (e) {
logger.error(e);
}
}, 0);
return true;
};
WebSocket.__log = function(message) {
logger.log(decodeURIComponent(message));
};
WebSocket.__error = function(message) {
logger.error(decodeURIComponent(message));
};
WebSocket.__addTask = function(task) {
if (WebSocket.__flash) {
task();
} else {
WebSocket.__tasks.push(task);
}
};
/**
* Test if the browser is running flash lite.
* @return {boolean} True if flash lite is running, false otherwise.
*/
WebSocket.__isFlashLite = function() {
if (!window.navigator || !window.navigator.mimeTypes) {
return false;
}
var mimeType = window.navigator.mimeTypes["application/x-shockwave-flash"];
if (!mimeType || !mimeType.enabledPlugin || !mimeType.enabledPlugin.filename) {
return false;
}
return mimeType.enabledPlugin.filename.match(/flashlite/i) ? true : false;
};
if (!window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION) {
if (window.addEventListener) {
window.addEventListener("load", function(){
WebSocket.__initialize();
}, false);
} else {
window.attachEvent("onload", function(){
WebSocket.__initialize();
});
}
}
})();
var Alice = { };
Object.extend(Alice, {
RE: {
img: /^http[^\s]*\.(?:jpe?g|gif|png|bmp|svg)[^\/]*$/i,
audio: /^http[^\s]*\.(?:wav|mp3|ogg|aiff?|m4[ar])[^\/]*$/i,
url: /(https?:\/\/[^\s<"]*)/ig
},
cleanupCopy: function(node) {
if (!node.select("li.message").length) return;
var lines = [];
node.select("li.message").each(function(line) {
var left = line.down("div.left span.nick");
var message = line.down("div.msg");
var clean = [];
if (left) {
var nick = left.innerHTML.stripTags();
nick = nick.replace(/^\s+/, "");
nick = nick.replace(/\s+$/, "");
clean.push("<"+nick+">");
}
if (message) {
var body = message.innerHTML.stripTags();
body = body.replace(/^\s+/, "");
body = body.replace(/\s+$/, "");
clean.push(body);
}
if (clean.length) lines.push(
clean.join(" ").replace(/\n/g, "").escapeHTML());
});
node.update(lines.join("<br>"));
node.cleanWhitespace();
},
epochToLocal: function(epoch, format) {
var date = new Date(parseInt(epoch) * 1000);
if (!date) return epoch;
var hours = date.getHours();
if (format == "12") {
var ap;
if (hours >= 12) {
if (hours > 12) hours -= 12;
ap = "p";
} else {
ap = "a"
}
return sprintf("%d:%02d%s", hours, date.getMinutes(), ap);
}
return sprintf("%02d:%02d", hours, date.getMinutes());
},
makeLinksClickable: function(elem) {
var children = elem.childNodes;
var length = children.length;
for (var i=0; i < length; i++) {
var node = children[i];
if (node.nodeName != "#text") {
Alice.makeLinksClickable(node);
}
else if (node.nodeValue.match(Alice.RE.url)) {
var span = new Element("SPAN");
span.innerHTML = node.nodeValue.escapeHTML().replace(
Alice.RE.url, '<a href="$1" target="_blank" rel="noreferrer">$1</a>');
node.parentNode.replaceChild(span, node);
}
}
},
growlNotify: function(message) {
if (window.fluid) {
window.fluid.showGrowlNotification({
title: message.subject,
description: message.body,
priority: 1,
sticky: false,
identifier: message.msgid
});
}
else if (window.webkitNotifications) {
if (window.webkitNotifications.checkPermission() == 0) {
var popup = window.webkitNotifications.createNotification(
"http://static.usealice.org/image/alice.png",
message.subject,
message.body
);
popup.ondisplay = function() {
setTimeout(function () {popup.cancel();}, 5000);
};
popup.show();
}
}
},
isSpecialKey: function(keyCode) {
var special_keys = [
16,27,9,32,13,8,145,20,144,19,45,36,46,35,33,34,37,38,39,
40,17,18,91,112,113,114,115,116,117,118,119,120,121,122,123,
224
];
return special_keys.indexOf(keyCode) > -1;
},
playAudio: function(image, audio) {
image.src = '/static/image/pause.png';
if (! audio) {
var url = image.nextSibling.href;
audio = new Audio(url);
audio.addEventListener('ended', function () {
image.src = '/static/image/play.png';
image.onclick = function () { Alice.playAudio(image, audio) };
});
}
audio.play();
image.onclick = function() {
audio.pause();
this.src = '/static/image/play.png';
this.onclick = function () { Alice.playAudio(this, audio) };
};
},
joinChannel: function() {
var network = $('join_network').value;
var channel = $('join_channel').value;
if (!network || !channel) {
alert("Must select a channel and network!");
return;
}
var win = alice.activeWindow();
alice.connection.sendMessage({
source: win.id,
msg: "/join -"+network+" "+channel
});
alice.input.disabled = false;
$('join').remove();
},
tabsets: {
addSet: function () {
var name = prompt("Please enter a name for this tab set.");
if (name && !Alice.tabsets.hasTabset(name)) {
Alice.tabsets.clearActive();
$('sets').insert('<li class="active">'+name.escapeHTML()+'</li>');
var list = $('empty_tabset').clone(true).addClassName('active').show();
list.id = null;
$('tabset_data').insert(list);
}
else {
alert("Invalid tab set name.");
}
},
hasTabset: function (name) {
var sets = $$('#sets li');
for (var i=0; i < sets.length; i++) {
if (sets[i].innerHTML == name) {
return true;
}
}
return false;
},
submit: function (params) {
new Ajax.Request("/savetabsets", {
method: "post",
parameters: Object.toQueryString(params),
onSuccess: function(transport){
$('tabset_menu').replace(transport.responseText);
Alice.tabsets.remove()
}
});
return false;
},
params: function () {
var values = Alice.tabsets.values();
return Alice.tabsets.sets().inject({}, function(acc, set, index) {
share/static/alice.js view on Meta::CPAN
window.onfocus = function () {
alice.input.focus();
alice.freeze();
alice.tabs_width = $('tabs_container').getWidth();
alice.updateOverflowMenus();
alice.isFocused = true
alice.clearMissed();
};
window.status = " ";
window.onblur = function () {
alice.isFocused = false
};
}
window.onhashchange = function (e) {alice.focusHash()};
window.onorientationchange = function() {
var active = alice.activeWindow();
active.scrollToPosition(0);
alice.freeze();
active.shiftTab();
};
document.observe("copy", function(e) {
if (!e.findElement("ul.messages")) return;
if(!Prototype.Browser.IE && typeof window.getSelection !== 'undefined') {
var buffer = new Element("DIV", {"class": "copybuffer"});
document.getElementsByTagName("body")[0].appendChild(buffer);
var sel = window.getSelection();
var range = sel.getRangeAt(0);
buffer.appendChild(range.cloneContents());
Alice.cleanupCopy(buffer);
sel.selectAllChildren(buffer);
setTimeout(function() {
if(typeof window.getSelection().setBaseAndExtent !== 'undefined') {
sel.setBaseAndExtent(
range.startContainer,
range.startOffset,
range.endContainer,
range.endOffset
);
}
}, 0);
}
});
if (alice.isMobile) return;
alice.addFilters([
function(msg, win) {
msg.select("a").filter(function(a) {
return Alice.RE.audio.match(a.href);
}).each(function(a) {
var img = new Element("IMG", {"class": "audio", src: "/static/image/play.png"});
img.onclick = function(){ Alice.playAudio(img) };
a.insert({before: img})
});
},
function (msg, win) {
if (alice.options.images == "show") {
var matches = msg.select("a").inject(0, function(acc, a) {
var oembed = alice.oembeds.find(function(service) {
return service.match(a.href);
});
if (oembed) {
alice.embed(a, win);
acc++;
}
return acc;
});
return matches > 0;
}
},
function (msg, win) {
msg.select("a").filter(function(a) {
var img = a.readAttribute("img") || a.innerHTML;
return img.match(Alice.RE.img);
}).each(function(a) {
var image = a.readAttribute("img") || a.href;
if (alice.options.images == "show" && !image.match(/#(nsfw|hide)$/))
win.inlineImage(a);
else
a.observe("click", function(e){e.stop();win.inlineImage(a)});
});
}
]);
if (window.navigator.userAgent.match(/chrome/i)) {
alice.addFilters([
function(msg, win) {
msg.setStyle({borderWidthTop: "1px"});
}
]);
}
});
setInterval(function(){new Ajax.Request("/say")}, 1000 * 60 * 5);
}
( run in 1.070 second using v1.01-cache-2.11-cpan-df04353d9ac )