App-Alice
view release on metacpan or search on metacpan
share/static/alice.js view on Meta::CPAN
);
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");
};
},
connectServer: function (alias) {
$(alias + "_status").className = "connected";
$(alias + "_status").innerHTML = "connected";
$(alias + "_connection").innerHTML = "disconnect";
$(alias + "_connection").onclick = function (e) {
e.stop();
serverConnection(alias, "disconnect");
};
},
showConnection: function (alias) {
$$("div#servers .active").invoke("removeClassName","active");
$("setting_" + alias).addClassName("active");
$("menu_" + alias).addClassName("active");
},
addChannel: function (alias) {
var channel = prompt("Please enter a channel name.");
if (channel)
$("channels_" + alias).insert("<option value=\""+channel+"\">"+channel+"</option>");
return false;
},
addCommand: function (alias) {
var command = prompt("Please enter a channel name.");
if (command)
$("on_connect_" + alias).insert("<option value=\""+command+"\">"+command+"</option>");
return false;
},
removeCommands: function (alias) {
$A($("on_connect_" + alias).options).each(function (option) {
if (option.selected) option.remove()});
return false;
},
removeChannels: function (alias) {
$A($("channels_" + alias).options).each(function (option) {
if (option.selected) option.remove()});
return false;
},
addServer: function () {
share/static/alice.js view on Meta::CPAN
}
else return;
this.len += (end + this.seperator.length) - start;
data = data.slice(start, end);
try {
data = data.evalJSON();
var queue = data.queue;
var length = queue.length;
for (var i=0; i<length; i++) {
if (queue[i].type == "action")
this.application.handleAction(queue[i]);
else if (queue[i].type == "message") {
if (queue[i].msgid) this.msgid = queue[i].msgid;
if (queue[i].timestamp)
queue[i].timestamp = Alice.epochToLocal(queue[i].timestamp);
this.application.displayMessage(queue[i]);
}
}
}
catch (e) {
console.log(e.toString());
}
var lag = time / 1000 - data.time;
if (lag > 5) {
console.log("lag is " + Math.round(lag) + "s, reconnecting.");
this.connect();
}
},
requestWindow: function(title, windowId, message) {
new Ajax.Request('/say', {
method: 'post',
parameters: {source: windowId, msg: "/create " + title},
onSuccess: function (transport) {
this.handleUpdate(transport);
if (message) {
setTimeout(function() {
this.application.displayMessage(message)
}.bind(this), 1000);
}
}.bind(this)
});
},
closeWindow: function(win) {
new Ajax.Request('/say', {
method: 'post',
parameters: {source: win.id, msg: "/close"}
});
},
getConfig: function(callback) {
new Ajax.Request('/config', {
method: 'get',
onSuccess: callback
});
},
getPrefs: function(callback) {
new Ajax.Request('/prefs', {
method: 'get',
onSuccess: callback
});
},
getLog: function(callback) {
new Ajax.Request('/logs', {
method: 'get',
onSuccess: callback
});
},
sendMessage: function(form) {
new Ajax.Request('/say', {
method: 'post',
parameters: form.serialize(),
onException: function (request, exception) {
alert("There was an error sending a message.");
}
});
},
sendTabOrder: function (windows) {
new Ajax.Request('/tabs', {
method: 'post',
parameters: {tabs: windows}
});
},
sendPing: function() {
new Ajax.Request('/ping');
}
});
Alice.Window = Class.create({
initialize: function(application, element, title, active, hashtag) {
this.application = application;
this.element = $(element);
this.title = title;
this.hashtag = hashtag;
this.id = this.element.identify();
this.active = active;
this.tab = $(this.id + "_tab");
this.input = new Alice.Input(this, this.id + "_msg");
this.tabButton = $(this.id + "_tab_button");
this.tabOverflowButton = $(this.id + "_tab_overflow_button");
this.form = $(this.id + "_form");
this.topic = $(this.id + "_topic");
if (this.topic) {
var orig_height = this.topic.getStyle("height");
this.topic.observe("click", function(e) {
if (this.topic.getStyle("height") == orig_height) {
this.topic.setStyle({height: "auto"});
} else {
this.topic.setStyle({height: orig_height});
}
}.bind(this));
}
( run in 0.839 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )