2008-08-27 10:38:35 +09:00
|
|
|
/*
|
|
|
|
* Laconica - a distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2008, Controlez-Vous, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-06-25 02:46:13 +09:00
|
|
|
$(document).ready(function(){
|
|
|
|
// count character on keyup
|
2008-09-05 13:54:15 +09:00
|
|
|
function counter(event){
|
2008-07-02 03:30:16 +09:00
|
|
|
var maxLength = 140;
|
2008-08-18 00:31:43 +09:00
|
|
|
var currentLength = $("#status_textarea").val().length;
|
2008-07-08 18:04:18 +09:00
|
|
|
var remaining = maxLength - currentLength;
|
|
|
|
var counter = $("#counter");
|
2008-06-25 21:58:47 +09:00
|
|
|
counter.text(remaining);
|
2008-06-25 02:46:13 +09:00
|
|
|
|
2008-07-08 18:04:18 +09:00
|
|
|
if (remaining <= 0) {
|
2008-06-25 21:58:47 +09:00
|
|
|
counter.attr("class", "toomuch");
|
2008-07-08 18:04:18 +09:00
|
|
|
} else {
|
2008-06-25 21:58:47 +09:00
|
|
|
counter.attr("class", "");
|
2008-07-08 18:04:18 +09:00
|
|
|
}
|
2008-06-25 02:46:13 +09:00
|
|
|
}
|
2008-07-09 16:14:39 +09:00
|
|
|
|
2008-09-05 13:57:36 +09:00
|
|
|
function submitonreturn(event) {
|
|
|
|
if (event.keyCode == 13) {
|
|
|
|
$("#status_form").submit();
|
2008-09-05 14:03:56 +09:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
return false;
|
2008-09-05 13:57:36 +09:00
|
|
|
}
|
2008-09-05 14:03:56 +09:00
|
|
|
return true;
|
2008-09-05 13:57:36 +09:00
|
|
|
}
|
2008-09-05 13:54:15 +09:00
|
|
|
|
2008-06-25 02:46:13 +09:00
|
|
|
if ($("#status_textarea").length) {
|
2008-09-05 13:57:36 +09:00
|
|
|
$("#status_textarea").bind("keyup", counter);
|
|
|
|
$("#status_textarea").bind("keydown", submitonreturn);
|
|
|
|
|
2008-07-02 03:30:16 +09:00
|
|
|
// run once in case there's something in there
|
2008-07-08 18:04:18 +09:00
|
|
|
counter();
|
2008-09-05 14:08:24 +09:00
|
|
|
|
|
|
|
// set the focus
|
|
|
|
$("#status_textarea").focus();
|
2008-06-25 02:46:13 +09:00
|
|
|
}
|
2008-09-18 12:20:48 +09:00
|
|
|
|
|
|
|
// XXX: refactor this code
|
|
|
|
|
|
|
|
var favoptions = {dataType: 'xml',
|
|
|
|
success: function(xml) {
|
|
|
|
var new_form = $('form.disfavor', xml);
|
|
|
|
var id = new_form.id.replace('disfavor', 'favor');
|
|
|
|
$('form#'+id).replace(new_form);
|
|
|
|
}};
|
2008-09-09 06:16:10 +09:00
|
|
|
|
2008-09-18 12:20:48 +09:00
|
|
|
var disoptions = {dataType: 'xml',
|
2008-09-09 06:16:10 +09:00
|
|
|
success: function(xml) {
|
2008-09-18 12:20:48 +09:00
|
|
|
var new_form = $('form.favor', xml);
|
|
|
|
var id = new_form.id.replace('favor', 'disfavor');
|
|
|
|
$('form#'+id).replace(new_form);
|
2008-09-09 06:16:56 +09:00
|
|
|
}};
|
2008-09-09 06:16:10 +09:00
|
|
|
|
2008-09-18 12:20:48 +09:00
|
|
|
$("form.favor").ajaxForm(favoptions);
|
|
|
|
$("form.disfavor").ajaxForm(disoptions);
|
2008-06-25 02:46:13 +09:00
|
|
|
});
|
|
|
|
|
2008-07-09 16:14:39 +09:00
|
|
|
function doreply(nick) {
|
|
|
|
rgx_username = /^[0-9a-zA-Z\-_.]*$/;
|
|
|
|
if (nick.match(rgx_username)) {
|
|
|
|
replyto = "@" + nick + " ";
|
2008-09-05 18:08:48 +09:00
|
|
|
if ($("#status_textarea").length) {
|
2008-07-09 16:24:29 +09:00
|
|
|
$("#status_textarea").val(replyto);
|
2008-07-09 16:14:39 +09:00
|
|
|
$("#status_textarea").focus();
|
2008-08-27 10:50:10 +09:00
|
|
|
return false;
|
|
|
|
}
|
2008-07-09 16:14:39 +09:00
|
|
|
}
|
2008-08-27 10:50:10 +09:00
|
|
|
return true;
|
2008-07-09 16:14:39 +09:00
|
|
|
}
|
|
|
|
|