2008-08-27 02:38:35 +01: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-24 18:46:13 +01:00
|
|
|
$(document).ready(function(){
|
|
|
|
// count character on keyup
|
2008-09-05 05:54:15 +01:00
|
|
|
function counter(event){
|
2008-07-01 19:30:16 +01:00
|
|
|
var maxLength = 140;
|
2008-08-17 16:31:43 +01:00
|
|
|
var currentLength = $("#status_textarea").val().length;
|
2008-07-08 10:04:18 +01:00
|
|
|
var remaining = maxLength - currentLength;
|
|
|
|
var counter = $("#counter");
|
2008-06-25 13:58:47 +01:00
|
|
|
counter.text(remaining);
|
2008-06-24 18:46:13 +01:00
|
|
|
|
2008-07-08 10:04:18 +01:00
|
|
|
if (remaining <= 0) {
|
2008-06-25 13:58:47 +01:00
|
|
|
counter.attr("class", "toomuch");
|
2008-07-08 10:04:18 +01:00
|
|
|
} else {
|
2008-06-25 13:58:47 +01:00
|
|
|
counter.attr("class", "");
|
2008-07-08 10:04:18 +01:00
|
|
|
}
|
2008-06-24 18:46:13 +01:00
|
|
|
}
|
2008-09-18 16:04:38 +01:00
|
|
|
|
2008-09-05 05:57:36 +01:00
|
|
|
function submitonreturn(event) {
|
|
|
|
if (event.keyCode == 13) {
|
|
|
|
$("#status_form").submit();
|
2008-09-05 06:03:56 +01:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
return false;
|
2008-09-05 05:57:36 +01:00
|
|
|
}
|
2008-09-05 06:03:56 +01:00
|
|
|
return true;
|
2008-09-05 05:57:36 +01:00
|
|
|
}
|
2008-09-18 16:04:38 +01:00
|
|
|
|
2008-06-24 18:46:13 +01:00
|
|
|
if ($("#status_textarea").length) {
|
2008-09-05 05:57:36 +01:00
|
|
|
$("#status_textarea").bind("keyup", counter);
|
|
|
|
$("#status_textarea").bind("keydown", submitonreturn);
|
2008-09-18 16:04:38 +01:00
|
|
|
|
2008-07-01 19:30:16 +01:00
|
|
|
// run once in case there's something in there
|
2008-07-08 10:04:18 +01:00
|
|
|
counter();
|
2008-09-18 16:04:38 +01:00
|
|
|
|
2008-09-05 06:08:24 +01:00
|
|
|
// set the focus
|
|
|
|
$("#status_textarea").focus();
|
2008-06-24 18:46:13 +01:00
|
|
|
}
|
2008-09-18 04:20:48 +01:00
|
|
|
|
|
|
|
// XXX: refactor this code
|
|
|
|
|
|
|
|
var favoptions = {dataType: 'xml',
|
|
|
|
success: function(xml) {
|
2008-09-18 15:55:45 +01:00
|
|
|
var new_form = $('form.disfavor', xml).get(0);
|
2008-09-18 16:04:38 +01:00
|
|
|
var dis = new_form.id;
|
|
|
|
var fav = dis.replace('disfavor', 'favor');
|
|
|
|
$('form#'+fav).replaceWith(new_form);
|
2008-09-18 16:07:53 +01:00
|
|
|
$('form#'+dis).ajaxForm(disoptions).each(addAjaxHidden);
|
2008-09-18 04:20:48 +01:00
|
|
|
}};
|
2008-09-18 16:04:38 +01:00
|
|
|
|
2008-09-18 04:20:48 +01:00
|
|
|
var disoptions = {dataType: 'xml',
|
2008-09-08 22:16:10 +01:00
|
|
|
success: function(xml) {
|
2008-09-18 15:55:45 +01:00
|
|
|
var new_form = $('form.favor', xml).get(0);
|
2008-09-18 16:04:38 +01:00
|
|
|
var fav = new_form.id;
|
2008-09-18 16:16:42 +01:00
|
|
|
var dis = fav.replace('favor', 'disfavor');
|
2008-09-18 16:04:38 +01:00
|
|
|
$('form#'+dis).replaceWith(new_form);
|
2008-09-18 16:07:53 +01:00
|
|
|
$('form#'+fav).ajaxForm(favoptions).each(addAjaxHidden); ;
|
2008-09-08 22:16:56 +01:00
|
|
|
}};
|
2008-09-18 14:56:08 +01:00
|
|
|
|
2008-09-18 15:07:56 +01:00
|
|
|
function addAjaxHidden() {
|
|
|
|
var ajax = document.createElement('input');
|
2008-09-18 15:05:33 +01:00
|
|
|
ajax.setAttribute('type', 'hidden');
|
|
|
|
ajax.setAttribute('name', 'ajax');
|
|
|
|
ajax.setAttribute('value', 1);
|
2008-09-18 15:07:56 +01:00
|
|
|
this.appendChild(ajax);
|
2008-09-18 14:56:08 +01:00
|
|
|
}
|
2008-09-18 16:04:38 +01:00
|
|
|
|
2008-09-18 04:20:48 +01:00
|
|
|
$("form.favor").ajaxForm(favoptions);
|
2008-09-18 14:56:08 +01:00
|
|
|
$("form.disfavor").ajaxForm(disoptions);
|
2008-09-18 16:04:38 +01:00
|
|
|
|
2008-09-18 14:56:08 +01:00
|
|
|
$("form.favor").each(addAjaxHidden);
|
2008-09-18 16:04:38 +01:00
|
|
|
$("form.disfavor").each(addAjaxHidden);
|
2008-06-24 18:46:13 +01:00
|
|
|
});
|
|
|
|
|
2008-10-20 18:02:45 +01:00
|
|
|
function doreply(nick,id) {
|
2008-07-09 08:14:39 +01:00
|
|
|
rgx_username = /^[0-9a-zA-Z\-_.]*$/;
|
|
|
|
if (nick.match(rgx_username)) {
|
|
|
|
replyto = "@" + nick + " ";
|
2008-09-05 10:08:48 +01:00
|
|
|
if ($("#status_textarea").length) {
|
2008-07-09 08:24:29 +01:00
|
|
|
$("#status_textarea").val(replyto);
|
2008-10-20 18:25:49 +01:00
|
|
|
$("form#status_form input#inreplyto").val(id);
|
2008-07-09 08:14:39 +01:00
|
|
|
$("#status_textarea").focus();
|
2008-08-27 02:50:10 +01:00
|
|
|
return false;
|
|
|
|
}
|
2008-07-09 08:14:39 +01:00
|
|
|
}
|
2008-08-27 02:50:10 +01:00
|
|
|
return true;
|
2008-07-09 08:14:39 +01:00
|
|
|
}
|
|
|
|
|