App-Alice
view release on metacpan or search on metacpan
share/static/alice.js view on Meta::CPAN
WysiHat.Toolbar.ButtonSets = {};
WysiHat.Toolbar.ButtonSets.Basic = $A([
{ label: "Bold" },
{ label: "Underline" },
{ label: "Italic" }
]);
var Alice = { };
Object.extend(Alice, {
uncacheGravatar: function(content) {
if (!this.timestamp) {
var date = new Date();
this.timestamp = date.getTime();
}
return content.replace(
/(src=".*?gravatar.com\/avatar\/[^?]*\?)/gi,
"$1time=" + this.timestamp + "&"
);
},
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) {
hours -= 12;
ap = "p";
} else {
ap = "a"
}
return sprintf("%d:%02d%s", hours, date.getMinutes(), ap);
}
return sprintf("%02d:%02d", hours, date.getMinutes());
},
stripNick: function(html) {
return html.replace(/<div class="left">.*<\/div>/, '');
},
growlNotify: function(message) {
if (window.fluid) {
window.fluid.showGrowlNotification({
title: message.window.title + ": " + message.nick,
description: message.body.unescapeHTML(),
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.window.title + ": " + message.nick,
message.body.unescapeHTML()
);
popup.ondisplay = function() {
setTimeout(function () {popup.cancel();}, 3000);
};
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
];
return special_keys.indexOf(keyCode) > -1;
},
loadInlineImage: function(image) {
var maxWidth = arguments.callee.maxWidth || 300;
var maxHeight = arguments.callee.maxHeight || 300;
image.style.visibility = 'hidden';
if (image.height > image.width && image.height > maxHeight) {
image.style.width = 'auto';
image.style.height = maxHeight + 'px';
}
else if (image.width > maxWidth) {
image.style.height = 'auto';
image.style.width = maxWidth + 'px';
}
else {
image.style.height = 'auto';
}
image.style.display = 'block';
image.style.visibility = 'visible';
setTimeout(function () {
var messagelist = image.up(".message_wrap");
messagelist.scrollTop = messagelist.scrollHeight;
}, 50);
},
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) };
};
},
prefs: {
addHighlight: function (alias) {
var channel = prompt("Enter a word to highlight.");
if (channel)
$('highlights').insert("<option value=\""+channel+"\">"+channel+"</option>");
return false;
},
removeHighlights: function (alias) {
$A($('highlights').options).each(function (option) {
if (option.selected) option.remove()});
return false;
},
remove: function() {
alice.windows().each(function(win) {
win.input.disabled = false;
});
$('prefs').remove();
},
submit: function(form) {
var options = {highlights: []};
["images", "avatars", "alerts"].each(function (pref) {
options[pref] = $(pref).checked ? "show" : "hide";
});
$A($("highlights").options).each(function(option) {
options.highlights.push(option.value);
});
["style", "timeformat"].each(function(pref) {
options[pref] = $(pref).value;
});
alice.options = options;
new Ajax.Request('/save', {
method: 'get',
parameters: options,
onSuccess: function(){Alice.prefs.remove()}
});
return false;
}
},
connections: {
disconnectServer: function (alias) {
$(alias + "_status").className = "disconnected";
$(alias + "_status").innerHTML = "disconnected";
$(alias + "_connection").innerHTML = "connect";
$(alias + "_connection").onclick = function (e) {
e.stop();
serverConnection(alias, "connect");
share/static/alice.js view on Meta::CPAN
break;
case "Connections":
alice.toggleConfig(e);
break;
case "Preferences":
alice.togglePrefs(e);
break;
case "Logout":
if (confirm("Logout?")) window.location = "/logout";
break;
case "Help":
alice.toggleHelp();
break;
}
$$('#config_overlay option').each(function(opt){opt.selected = false});
});
window.onkeydown = function (e) {
var win = alice.activeWindow();
if (win && !$('config') && !Alice.isSpecialKey(e.which))
win.input.focus();
};
window.onresize = function () {
if (alice.activeWindow()) {
if (Prototype.Browser.Gecko) alice.activeWindow().resizeMessagearea();
alice.activeWindow().scrollToBottom();
}
};
window.onfocus = function () {
if (!alice.isMobile)
window.document.body.removeClassName("blurred");
if (alice.activeWindow())
alice.activeWindow().input.focus();
alice.isFocused = true
alice.clearMissed();
};
window.status = " ";
window.onblur = function () {
if (!alice.isMobile)
window.document.body.addClassName("blurred");
alice.isFocused = false
};
window.onhashchange = alice.focusHash.bind(alice);
window.onorientationchange = function() {
alice.activeWindow().scrollToBottom(true);
};
alice.addFilters([
function(content) {
var filtered = content;
filtered = filtered.replace(
/(<a href=\"(:?.*?\.(:?wav|mp3|ogg|aiff|m4a))")/gi,
"<img src=\"/static/image/play.png\" " +
"onclick=\"Alice.playAudio(this)\" class=\"audio\"/>$1");
return filtered;
},
function (content) {
var filtered = content;
if (alice.options.images == "show") {
filtered = filtered.replace(
/(<a[^>]*>)([^<]*\.(:?jpe?g|gif|png|bmp|svg)(:?\?v=0)?)</gi,
"$1<img src=\"http://i.usealice.org/$2\" onload=\"Alice.loadInlineImage(this)\" " +
"alt=\"Loading Image...\" title=\"$2\" style=\"display:none\"/><");
}
return filtered;
}
]);
});
}
( run in 1.031 second using v1.01-cache-2.11-cpan-df04353d9ac )