javaeye3/public/javascripts/app/chat.js

75 lines
2.1 KiB
JavaScript

function reply_twitter(name, id) {
if($('twitter_body')) {
$('twitter_reply_to_id').value = id;
$('twitter_body').value = "@" + name + " " + $('twitter_body').value;
$('twitter_body').focus();
}else{
$('t_' + id).appendChild($('twitter_form'));
var inputs = $$('#twitter_form input');
inputs[0].value = "@" + name + " ";
inputs[1].value = id;
$('twitter_spinner').hide();
$('twitter_update').show();
$('twitter_form').show();
inputs[0].focus();
}
}
var WordCounter = Class.create({
initialize : function() {
this.textarea = $('twitter_body');
this.tooltip = $('word_counter');
this.submit = $('btn_submit');
},
update : function() {
if(this.last == this.textarea.value) return;
this.last = this.textarea.value;
var length = this.textarea.value.strip().length;
if(length <= 140) {
this.tooltip.innerHTML = "可以填写 <span>" + (140 - length) + "</span> 字";
}else{
this.tooltip.innerHTML = "已经超出 <span class='error'>" + (length - 140) + "</span> 字";
}
if(length > 0 && length <= 140) {
this.submit.removeClassName("disabled").removeAttribute("disabled");
}else{
this.submit.addClassName("disabled").setAttribute("disabled", "true");
}
}
});
document.observe("dom:loaded", function() {
if($('twitter_body')) {
var wc = new WordCounter();
new PeriodicalExecuter(function() {
wc.update();
}, 0.5);
if(!(window.parent && window.parent != window)) {
$('twitter_body').focus();
}
}
});
function update_twitter() {
if($('twitter_body') && $F('twitter_body').length > 0 && !$('btn_submit').getAttribute("disabled")) {
$('btn_submit').addClassName("disabled").setAttribute("disabled", "true");
$('twitter_form').submit();
}
}
new HotKey("s",function() {
update_twitter();
},{
altKey: true,
ctrlKey: false
});
new HotKey(new Number(13),function() {
update_twitter();
},{
altKey: false,
ctrlKey: true
});