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 $('input#notice_data-attach').toggle();
21 $('label[for=notice_data-attach]').text('Upload a file as an attachment?');
22 $('label[for=notice_data-attach]').click(function () {
23 if ('Upload a file as an attachment?' == $(this).text()) {
24 $(this).text('Upload: ');
25 $('input#notice_data-attach').slideDown('fast');
27 $('input#notice_data-attach').slideUp('fast', function() {$('label[for=notice_data-attach]').text('Upload a file as an attachment?');});
31 $('a.attachment').click(function() {$().jOverlay({url: $('address .url')[0].href+'/attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); return false; });
32 $("a.thumbnail").hover(
35 $("a.thumbnail").children('img').remove();
37 setTimeout(function() {
38 anchor.closest(".entry-title").addClass('ov');
39 $.get($('address .url')[0].href+'/attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) {
44 setTimeout(function() {
45 anchor.children('img').remove();
46 anchor.closest(".entry-title").removeClass('ov');
50 $(this).children('img').remove();
51 $(this).closest(".entry-title").removeClass('ov');
55 // count character on keyup
56 function counter(event){
58 var currentLength = $("#notice_data-text").val().length;
59 var remaining = maxLength - currentLength;
60 var counter = $("#notice_text-count");
61 counter.text(remaining);
64 $("#form_notice").addClass("warning");
66 $("#form_notice").removeClass("warning");
70 function submitonreturn(event) {
71 if (event.keyCode == 13) {
72 $("#form_notice").submit();
73 event.preventDefault();
74 event.stopPropagation();
80 if ($("#notice_data-text").length) {
81 $("#notice_data-text").bind("keyup", counter);
82 $("#notice_data-text").bind("keydown", submitonreturn);
84 // run once in case there's something in there
88 $("#notice_data-text").focus();
91 // XXX: refactor this code
93 var favoptions = { dataType: 'xml',
94 success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
95 var dis = new_form.id;
96 var fav = dis.replace('disfavor', 'favor');
97 $('form#'+fav).replaceWith(new_form);
98 $('form#'+dis).ajaxForm(disoptions).each(addAjaxHidden);
102 var disoptions = { dataType: 'xml',
103 success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
104 var fav = new_form.id;
105 var dis = fav.replace('favor', 'disfavor');
106 $('form#'+dis).replaceWith(new_form);
107 $('form#'+fav).ajaxForm(favoptions).each(addAjaxHidden);
111 var joinoptions = { dataType: 'xml',
112 success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
113 var leave = new_form.id;
114 var join = leave.replace('leave', 'join');
115 $('form#'+join).replaceWith(new_form);
116 $('form#'+leave).ajaxForm(leaveoptions).each(addAjaxHidden);
120 var leaveoptions = { dataType: 'xml',
121 success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
122 var join = new_form.id;
123 var leave = join.replace('join', 'leave');
124 $('form#'+leave).replaceWith(new_form);
125 $('form#'+join).ajaxForm(joinoptions).each(addAjaxHidden);
129 function addAjaxHidden() {
130 var ajax = document.createElement('input');
131 ajax.setAttribute('type', 'hidden');
132 ajax.setAttribute('name', 'ajax');
133 ajax.setAttribute('value', 1);
134 this.appendChild(ajax);
137 $("form.form_favor").ajaxForm(favoptions);
138 $("form.form_disfavor").ajaxForm(disoptions);
139 $("form.form_group_join").ajaxForm(joinoptions);
140 $("form.form_group_leave").ajaxForm(leaveoptions);
141 $("form.form_favor").each(addAjaxHidden);
142 $("form.form_disfavor").each(addAjaxHidden);
143 $("form.form_group_join").each(addAjaxHidden);
144 $("form.form_group_leave").each(addAjaxHidden);
146 $("#form_user_nudge").ajaxForm ({ dataType: 'xml',
147 beforeSubmit: function(xml) { $("#form_user_nudge input[type=submit]").attr("disabled", "disabled");
148 $("#form_user_nudge input[type=submit]").addClass("disabled");
150 success: function(xml) { $("#form_user_nudge").replaceWith(document._importNode($("#nudge_response", xml).get(0),true));
151 $("#form_user_nudge input[type=submit]").removeAttr("disabled");
152 $("#form_user_nudge input[type=submit]").removeClass("disabled");
155 $("#form_user_nudge").each(addAjaxHidden);
157 var Subscribe = { dataType: 'xml',
158 beforeSubmit: function(formData, jqForm, options) { $(".form_user_subscribe input[type=submit]").attr("disabled", "disabled");
159 $(".form_user_subscribe input[type=submit]").addClass("disabled");
161 success: function(xml) { var form_unsubscribe = document._importNode($('form', xml).get(0), true);
162 var form_unsubscribe_id = form_unsubscribe.id;
163 var form_subscribe_id = form_unsubscribe_id.replace('unsubscribe', 'subscribe');
164 $("form#"+form_subscribe_id).replaceWith(form_unsubscribe);
165 $("form#"+form_unsubscribe_id).ajaxForm(UnSubscribe).each(addAjaxHidden);
166 $("dd.subscribers").text(parseInt($("dd.subscribers").text())+1);
167 $(".form_user_subscribe input[type=submit]").removeAttr("disabled");
168 $(".form_user_subscribe input[type=submit]").removeClass("disabled");
172 var UnSubscribe = { dataType: 'xml',
173 beforeSubmit: function(formData, jqForm, options) { $(".form_user_unsubscribe input[type=submit]").attr("disabled", "disabled");
174 $(".form_user_unsubscribe input[type=submit]").addClass("disabled");
176 success: function(xml) { var form_subscribe = document._importNode($('form', xml).get(0), true);
177 var form_subscribe_id = form_subscribe.id;
178 var form_unsubscribe_id = form_subscribe_id.replace('subscribe', 'unsubscribe');
179 $("form#"+form_unsubscribe_id).replaceWith(form_subscribe);
180 $("form#"+form_subscribe_id).ajaxForm(Subscribe).each(addAjaxHidden);
181 $("#profile_send_a_new_message").remove();
182 $("#profile_nudge").remove();
183 $("dd.subscribers").text(parseInt($("dd.subscribers").text())-1);
184 $(".form_user_unsubscribe input[type=submit]").removeAttr("disabled");
185 $(".form_user_unsubscribe input[type=submit]").removeClass("disabled");
189 $(".form_user_subscribe").ajaxForm(Subscribe);
190 $(".form_user_unsubscribe").ajaxForm(UnSubscribe);
191 $(".form_user_subscribe").each(addAjaxHidden);
192 $(".form_user_unsubscribe").each(addAjaxHidden);
194 var PostNotice = { dataType: 'xml',
195 beforeSubmit: function(formData, jqForm, options) { if ($("#notice_data-text").get(0).value.length == 0) {
196 $("#form_notice").addClass("warning");
199 $("#form_notice").addClass("processing");
200 $("#notice_action-submit").attr("disabled", "disabled");
201 $("#notice_action-submit").addClass("disabled");
205 error: function (xhr, textStatus, errorThrown) { $("#form_notice").removeClass("processing");
206 $("#notice_action-submit").removeAttr("disabled");
207 $("#notice_action-submit").removeClass("disabled");
208 if (textStatus == "timeout") {
209 alert ("Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists");
212 if ($(".error", xhr.responseXML).length > 0) {
213 $('#form_notice').append(document._importNode($(".error", xhr.responseXML).get(0), true));
216 alert("Sorry! We had trouble sending your notice ("+xhr.status+" "+xhr.statusText+"). Please report the problem to the site administrator if this happens again.");
220 success: function(xml) { if ($("#error", xml).length > 0) {
221 var result = document._importNode($("p", xml).get(0), true);
222 result = result.textContent || result.innerHTML;
226 if ($("#command_result", xml).length > 0) {
227 var result = document._importNode($("p", xml).get(0), true);
228 result = result.textContent || result.innerHTML;
232 li = $("li", xml).get(0);
233 if ($("#"+li.id).length == 0) {
234 $("#notices_primary .notices").prepend(document._importNode(li, true));
235 $("#notices_primary .notice:first").css({display:"none"});
236 $("#notices_primary .notice:first").fadeIn(2500);
240 $("#notice_data-text").val("");
241 $("#notice_data-attach").val("");
244 $("#form_notice").removeClass("processing");
245 $("#notice_action-submit").removeAttr("disabled");
246 $("#notice_action-submit").removeClass("disabled");
249 $("#form_notice").ajaxForm(PostNotice);
250 $("#form_notice").each(addAjaxHidden);
257 function NoticeHover() {
258 function mouseHandler(e) {
259 $(e.target).closest('li.hentry')[(e.type === 'mouseover') ? 'addClass' : 'removeClass']('hover');
261 $('#content .notices').mouseover(mouseHandler);
262 $('#content .notices').mouseout(mouseHandler);
266 function NoticeReply() {
267 if ($('#notice_data-text').length > 0) {
268 $('#content .notice').each(function() {
269 var notice = $(this)[0];
270 $($('.notice_reply', notice)[0]).click(function() {
271 var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname');
272 NoticeReplySet(nickname.text(), $($('.notice_id', notice)[0]).text());
279 function NoticeReplySet(nick,id) {
280 rgx_username = /^[0-9a-zA-Z\-_.]*$/;
281 if (nick.match(rgx_username)) {
282 replyto = "@" + nick + " ";
283 if ($("#notice_data-text").length) {
284 $("#notice_data-text").val(replyto);
285 $("#form_notice input#notice_in-reply-to").val(id);
286 $("#notice_data-text").focus();
293 function NoticeAttachments() {
294 $.fn.jOverlay.options = {
302 imgLoading : $('address .url')[0].href+'theme/base/images/illustrations/illu_progress_loading-01.gif',
303 bgClickToClose : true,
304 success : function() {
305 $('#jOverlayContent').append('<button>×</button>');
306 $('#jOverlayContent button').click($.closeOverlay);
311 $('a.attachment').click(function() {
312 $().jOverlay({url: $('address .url')[0].href+'/attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'});
317 $("body:not(#shownotice) a.thumbnail").hover(
319 var anchor = $(this);
320 $("a.thumbnail").children('img').hide();
321 anchor.closest(".entry-title").addClass('ov');
323 if (anchor.children('img').length == 0) {
324 t = setTimeout(function() {
325 $.get($('address .url')[0].href+'/attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) {
331 anchor.children('img').show();
336 $("a.thumbnail").children('img').hide();
337 $(this).closest(".entry-title").removeClass('ov');