2 * Laconica - a distributed open-source microblogging tool
3 * Copyright (C) 2008, Controlez-Vous, Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 $(document).ready(function(){
20 $('.attachments').click(function() {$().jOverlay({zIndex:999, success:function(html) {$('.attachment').click(function() {$().jOverlay({url:$(this).attr('href') + '/ajax'}); return false; });
21 }, url:$(this).attr('href') + '/ajax'}); return false; });
22 $('.attachment').click(function() {$().jOverlay({url:$(this).attr('href') + '/ajax'}); return false; });
24 // count character on keyup
25 function counter(event){
27 var currentLength = $("#notice_data-text").val().length;
28 var remaining = maxLength - currentLength;
29 var counter = $("#notice_text-count");
30 counter.text(remaining);
33 $("#form_notice").addClass("warning");
35 $("#form_notice").removeClass("warning");
39 function submitonreturn(event) {
40 if (event.keyCode == 13) {
41 $("#form_notice").submit();
42 event.preventDefault();
43 event.stopPropagation();
49 if ($("#notice_data-text").length) {
50 $("#notice_data-text").bind("keyup", counter);
51 $("#notice_data-text").bind("keydown", submitonreturn);
53 // run once in case there's something in there
57 $("#notice_data-text").focus();
60 // XXX: refactor this code
62 var favoptions = { dataType: 'xml',
63 success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
64 var dis = new_form.id;
65 var fav = dis.replace('disfavor', 'favor');
66 $('form#'+fav).replaceWith(new_form);
67 $('form#'+dis).ajaxForm(disoptions).each(addAjaxHidden);
71 var disoptions = { dataType: 'xml',
72 success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
73 var fav = new_form.id;
74 var dis = fav.replace('favor', 'disfavor');
75 $('form#'+dis).replaceWith(new_form);
76 $('form#'+fav).ajaxForm(favoptions).each(addAjaxHidden);
80 var joinoptions = { dataType: 'xml',
81 success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
82 var leave = new_form.id;
83 var join = leave.replace('leave', 'join');
84 $('form#'+join).replaceWith(new_form);
85 $('form#'+leave).ajaxForm(leaveoptions).each(addAjaxHidden);
89 var leaveoptions = { dataType: 'xml',
90 success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
91 var join = new_form.id;
92 var leave = join.replace('join', 'leave');
93 $('form#'+leave).replaceWith(new_form);
94 $('form#'+join).ajaxForm(joinoptions).each(addAjaxHidden);
98 function addAjaxHidden() {
99 var ajax = document.createElement('input');
100 ajax.setAttribute('type', 'hidden');
101 ajax.setAttribute('name', 'ajax');
102 ajax.setAttribute('value', 1);
103 this.appendChild(ajax);
106 $("form.form_favor").ajaxForm(favoptions);
107 $("form.form_disfavor").ajaxForm(disoptions);
108 $("form.form_group_join").ajaxForm(joinoptions);
109 $("form.form_group_leave").ajaxForm(leaveoptions);
110 $("form.form_favor").each(addAjaxHidden);
111 $("form.form_disfavor").each(addAjaxHidden);
112 $("form.form_group_join").each(addAjaxHidden);
113 $("form.form_group_leave").each(addAjaxHidden);
115 $("#form_user_nudge").ajaxForm ({ dataType: 'xml',
116 beforeSubmit: function(xml) { $("#form_user_nudge input[type=submit]").attr("disabled", "disabled");
117 $("#form_user_nudge input[type=submit]").addClass("disabled");
119 success: function(xml) { $("#form_user_nudge").replaceWith(document._importNode($("#nudge_response", xml).get(0),true));
120 $("#form_user_nudge input[type=submit]").removeAttr("disabled");
121 $("#form_user_nudge input[type=submit]").removeClass("disabled");
124 $("#form_user_nudge").each(addAjaxHidden);
126 var Subscribe = { dataType: 'xml',
127 beforeSubmit: function(formData, jqForm, options) { $(".form_user_subscribe input[type=submit]").attr("disabled", "disabled");
128 $(".form_user_subscribe input[type=submit]").addClass("disabled");
130 success: function(xml) { var form_unsubscribe = document._importNode($('form', xml).get(0), true);
131 var form_unsubscribe_id = form_unsubscribe.id;
132 var form_subscribe_id = form_unsubscribe_id.replace('unsubscribe', 'subscribe');
133 $("form#"+form_subscribe_id).replaceWith(form_unsubscribe);
134 $("form#"+form_unsubscribe_id).ajaxForm(UnSubscribe).each(addAjaxHidden);
135 $("dd.subscribers").text(parseInt($("dd.subscribers").text())+1);
136 $(".form_user_subscribe input[type=submit]").removeAttr("disabled");
137 $(".form_user_subscribe input[type=submit]").removeClass("disabled");
141 var UnSubscribe = { dataType: 'xml',
142 beforeSubmit: function(formData, jqForm, options) { $(".form_user_unsubscribe input[type=submit]").attr("disabled", "disabled");
143 $(".form_user_unsubscribe input[type=submit]").addClass("disabled");
145 success: function(xml) { var form_subscribe = document._importNode($('form', xml).get(0), true);
146 var form_subscribe_id = form_subscribe.id;
147 var form_unsubscribe_id = form_subscribe_id.replace('subscribe', 'unsubscribe');
148 $("form#"+form_unsubscribe_id).replaceWith(form_subscribe);
149 $("form#"+form_subscribe_id).ajaxForm(Subscribe).each(addAjaxHidden);
150 $("#profile_send_a_new_message").remove();
151 $("#profile_nudge").remove();
152 $("dd.subscribers").text(parseInt($("dd.subscribers").text())-1);
153 $(".form_user_unsubscribe input[type=submit]").removeAttr("disabled");
154 $(".form_user_unsubscribe input[type=submit]").removeClass("disabled");
158 $(".form_user_subscribe").ajaxForm(Subscribe);
159 $(".form_user_unsubscribe").ajaxForm(UnSubscribe);
160 $(".form_user_subscribe").each(addAjaxHidden);
161 $(".form_user_unsubscribe").each(addAjaxHidden);
163 var PostNotice = { dataType: 'xml',
164 beforeSubmit: function(formData, jqForm, options) { if ($("#notice_data-text").get(0).value.length == 0) {
165 $("#form_notice").addClass("warning");
168 $("#form_notice").addClass("processing");
169 $("#notice_action-submit").attr("disabled", "disabled");
170 $("#notice_action-submit").addClass("disabled");
174 error: function (xhr, textStatus, errorThrown) { $("#form_notice").removeClass("processing");
175 $("#notice_action-submit").removeAttr("disabled");
176 $("#notice_action-submit").removeClass("disabled");
177 if (textStatus == "timeout") {
178 alert ("Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists");
181 if ($(".error", xhr.responseXML).length > 0) {
182 $('#form_notice').append(document._importNode($(".error", xhr.responseXML).get(0), true));
185 alert("Sorry! We had trouble sending your notice ("+xhr.status+" "+xhr.statusText+"). Please report the problem to the site administrator if this happens again.");
189 success: function(xml) { if ($("#error", xml).length > 0) {
190 var result = document._importNode($("p", xml).get(0), true);
191 result = result.textContent || result.innerHTML;
195 if ($("#command_result", xml).length > 0) {
196 var result = document._importNode($("p", xml).get(0), true);
197 result = result.textContent || result.innerHTML;
201 li = $("li", xml).get(0);
202 if ($("#"+li.id).length == 0) {
203 $("#notices_primary .notices").prepend(document._importNode(li, true));
204 $("#notices_primary .notice:first").css({display:"none"});
205 $("#notices_primary .notice:first").fadeIn(2500);
210 $("#notice_data-text").val("");
213 $("#form_notice").removeClass("processing");
214 $("#notice_action-submit").removeAttr("disabled");
215 $("#notice_action-submit").removeClass("disabled");
218 $("#form_notice").ajaxForm(PostNotice);
219 $("#form_notice").each(addAjaxHidden);
224 function NoticeHover() {
225 $("#content .notice").hover(
227 $(this).addClass('hover');
230 $(this).removeClass('hover');
235 function NoticeReply() {
236 if ($('#notice_data-text').length > 0) {
237 $('#content .notice').each(function() {
238 var notice = $(this);
239 $('.notice_reply', $(this)).click(function() {
240 var nickname = ($('.author .nickname', notice).length > 0) ? $('.author .nickname', notice) : $('.author .nickname');
241 NoticeReplySet(nickname.text(), $('.notice_id', notice).text());
248 function NoticeReplySet(nick,id) {
249 rgx_username = /^[0-9a-zA-Z\-_.]*$/;
250 if (nick.match(rgx_username)) {
251 replyto = "@" + nick + " ";
252 if ($("#notice_data-text").length) {
253 $("#notice_data-text").val(replyto);
254 $("#form_notice input#notice_in-reply-to").val(id);
255 $("#notice_data-text").focus();