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 and attachment pages not used at the moment except for attachment_ajax version
21 // $('.attachments').click(function() {$().jOverlay({zIndex:999, success:function(html) {$('.attachment').click(function() {$().jOverlay({url:$(this).attr('href') + '/ajax'}); return false; });
22 // }, url:$(this).attr('href') + '/ajax'}); return false; });
23 $('.attachment').click(function() {$().jOverlay({url:'http://laptop.waglo.com/attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); return false; });
25 // count character on keyup
26 function counter(event){
28 var currentLength = $("#notice_data-text").val().length;
29 var remaining = maxLength - currentLength;
30 var counter = $("#notice_text-count");
31 counter.text(remaining);
34 $("#form_notice").addClass("warning");
36 $("#form_notice").removeClass("warning");
40 function submitonreturn(event) {
41 if (event.keyCode == 13) {
42 $("#form_notice").submit();
43 event.preventDefault();
44 event.stopPropagation();
50 if ($("#notice_data-text").length) {
51 $("#notice_data-text").bind("keyup", counter);
52 $("#notice_data-text").bind("keydown", submitonreturn);
54 // run once in case there's something in there
58 $("#notice_data-text").focus();
61 // XXX: refactor this code
63 var favoptions = { dataType: 'xml',
64 success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
65 var dis = new_form.id;
66 var fav = dis.replace('disfavor', 'favor');
67 $('form#'+fav).replaceWith(new_form);
68 $('form#'+dis).ajaxForm(disoptions).each(addAjaxHidden);
72 var disoptions = { dataType: 'xml',
73 success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
74 var fav = new_form.id;
75 var dis = fav.replace('favor', 'disfavor');
76 $('form#'+dis).replaceWith(new_form);
77 $('form#'+fav).ajaxForm(favoptions).each(addAjaxHidden);
81 var joinoptions = { dataType: 'xml',
82 success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
83 var leave = new_form.id;
84 var join = leave.replace('leave', 'join');
85 $('form#'+join).replaceWith(new_form);
86 $('form#'+leave).ajaxForm(leaveoptions).each(addAjaxHidden);
90 var leaveoptions = { dataType: 'xml',
91 success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
92 var join = new_form.id;
93 var leave = join.replace('join', 'leave');
94 $('form#'+leave).replaceWith(new_form);
95 $('form#'+join).ajaxForm(joinoptions).each(addAjaxHidden);
99 function addAjaxHidden() {
100 var ajax = document.createElement('input');
101 ajax.setAttribute('type', 'hidden');
102 ajax.setAttribute('name', 'ajax');
103 ajax.setAttribute('value', 1);
104 this.appendChild(ajax);
107 $("form.form_favor").ajaxForm(favoptions);
108 $("form.form_disfavor").ajaxForm(disoptions);
109 $("form.form_group_join").ajaxForm(joinoptions);
110 $("form.form_group_leave").ajaxForm(leaveoptions);
111 $("form.form_favor").each(addAjaxHidden);
112 $("form.form_disfavor").each(addAjaxHidden);
113 $("form.form_group_join").each(addAjaxHidden);
114 $("form.form_group_leave").each(addAjaxHidden);
116 $("#form_user_nudge").ajaxForm ({ dataType: 'xml',
117 beforeSubmit: function(xml) { $("#form_user_nudge input[type=submit]").attr("disabled", "disabled");
118 $("#form_user_nudge input[type=submit]").addClass("disabled");
120 success: function(xml) { $("#form_user_nudge").replaceWith(document._importNode($("#nudge_response", xml).get(0),true));
121 $("#form_user_nudge input[type=submit]").removeAttr("disabled");
122 $("#form_user_nudge input[type=submit]").removeClass("disabled");
125 $("#form_user_nudge").each(addAjaxHidden);
127 var Subscribe = { dataType: 'xml',
128 beforeSubmit: function(formData, jqForm, options) { $(".form_user_subscribe input[type=submit]").attr("disabled", "disabled");
129 $(".form_user_subscribe input[type=submit]").addClass("disabled");
131 success: function(xml) { var form_unsubscribe = document._importNode($('form', xml).get(0), true);
132 var form_unsubscribe_id = form_unsubscribe.id;
133 var form_subscribe_id = form_unsubscribe_id.replace('unsubscribe', 'subscribe');
134 $("form#"+form_subscribe_id).replaceWith(form_unsubscribe);
135 $("form#"+form_unsubscribe_id).ajaxForm(UnSubscribe).each(addAjaxHidden);
136 $("dd.subscribers").text(parseInt($("dd.subscribers").text())+1);
137 $(".form_user_subscribe input[type=submit]").removeAttr("disabled");
138 $(".form_user_subscribe input[type=submit]").removeClass("disabled");
142 var UnSubscribe = { dataType: 'xml',
143 beforeSubmit: function(formData, jqForm, options) { $(".form_user_unsubscribe input[type=submit]").attr("disabled", "disabled");
144 $(".form_user_unsubscribe input[type=submit]").addClass("disabled");
146 success: function(xml) { var form_subscribe = document._importNode($('form', xml).get(0), true);
147 var form_subscribe_id = form_subscribe.id;
148 var form_unsubscribe_id = form_subscribe_id.replace('subscribe', 'unsubscribe');
149 $("form#"+form_unsubscribe_id).replaceWith(form_subscribe);
150 $("form#"+form_subscribe_id).ajaxForm(Subscribe).each(addAjaxHidden);
151 $("#profile_send_a_new_message").remove();
152 $("#profile_nudge").remove();
153 $("dd.subscribers").text(parseInt($("dd.subscribers").text())-1);
154 $(".form_user_unsubscribe input[type=submit]").removeAttr("disabled");
155 $(".form_user_unsubscribe input[type=submit]").removeClass("disabled");
159 $(".form_user_subscribe").ajaxForm(Subscribe);
160 $(".form_user_unsubscribe").ajaxForm(UnSubscribe);
161 $(".form_user_subscribe").each(addAjaxHidden);
162 $(".form_user_unsubscribe").each(addAjaxHidden);
164 var PostNotice = { dataType: 'xml',
165 beforeSubmit: function(formData, jqForm, options) { if ($("#notice_data-text").get(0).value.length == 0) {
166 $("#form_notice").addClass("warning");
169 $("#form_notice").addClass("processing");
170 $("#notice_action-submit").attr("disabled", "disabled");
171 $("#notice_action-submit").addClass("disabled");
175 error: function (xhr, textStatus, errorThrown) { $("#form_notice").removeClass("processing");
176 $("#notice_action-submit").removeAttr("disabled");
177 $("#notice_action-submit").removeClass("disabled");
178 if (textStatus == "timeout") {
179 alert ("Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists");
182 if ($(".error", xhr.responseXML).length > 0) {
183 $('#form_notice').append(document._importNode($(".error", xhr.responseXML).get(0), true));
186 alert("Sorry! We had trouble sending your notice ("+xhr.status+" "+xhr.statusText+"). Please report the problem to the site administrator if this happens again.");
190 success: function(xml) { if ($("#error", xml).length > 0) {
191 var result = document._importNode($("p", xml).get(0), true);
192 result = result.textContent || result.innerHTML;
196 if ($("#command_result", xml).length > 0) {
197 var result = document._importNode($("p", xml).get(0), true);
198 result = result.textContent || result.innerHTML;
202 li = $("li", xml).get(0);
203 if ($("#"+li.id).length == 0) {
204 $("#notices_primary .notices").prepend(document._importNode(li, true));
205 $("#notices_primary .notice:first").css({display:"none"});
206 $("#notices_primary .notice:first").fadeIn(2500);
211 $("#notice_data-text").val("");
214 $("#form_notice").removeClass("processing");
215 $("#notice_action-submit").removeAttr("disabled");
216 $("#notice_action-submit").removeClass("disabled");
219 $("#form_notice").ajaxForm(PostNotice);
220 $("#form_notice").each(addAjaxHidden);
225 function NoticeHover() {
226 $("#content .notice").hover(
228 $(this).addClass('hover');
231 $(this).removeClass('hover');
236 function NoticeReply() {
237 if ($('#notice_data-text').length > 0) {
238 $('#content .notice').each(function() {
239 var notice = $(this)[0];
240 $($('.notice_reply', notice)[0]).click(function() {
241 var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname');
242 NoticeReplySet(nickname.text(), $($('.notice_id', notice)[0]).text());
249 function NoticeReplySet(nick,id) {
250 rgx_username = /^[0-9a-zA-Z\-_.]*$/;
251 if (nick.match(rgx_username)) {
252 replyto = "@" + nick + " ";
253 if ($("#notice_data-text").length) {
254 $("#notice_data-text").val(replyto);
255 $("#form_notice input#notice_in-reply-to").val(id);
256 $("#notice_data-text").focus();