noticeaction improvements
[statusnet:freesocial.git] / theme / FreesocTheme / js / interaction-basics.js
1 $(document).ready(function() {
2         $(".notice_data-text").live('input', function(e) {
3                 $(this).next(".count").html($(this).val().length);
4         });
5         $(".notice_data-text").live('keyup', function(e) {
6                 $(this).next(".count").html($(this).val().length);
7         });
8         
9         $("nav .compose > a").click(function(e) {
10                 e.preventDefault();
11                 $("#post").slideToggle(600);
12                 if ($("#post").is(":visible")) {
13                         $("#newnotice").focus();
14                 }
15         });
16
17         $("form").live('submit', function(e) {
18                 e.preventDefault();
19                 submits = $(this).find('input[type="submit"]');
20                 if (submits.length == 1) {
21                         submits.click();
22                 }
23         });
24         $('form input[type="submit"]').live('click', function(e) {
25                 form = $(this).closest('form');
26                 notice = form.parent();
27                 data = { "ajax": "true" };
28                 data[$(this).attr("name")] = $(this).attr("value");
29
30                 form.ajaxSubmit({
31                         data: $.merge( data, form.serializeArray() ),
32                         success: function(html) {
33                                 if (!html) {
34                                         notice.replaceWith(html);
35                                 } else {
36                                         notice.html(html);
37                                 }
38                         }
39                 });
40
41                 form.find("input").attr("disabled", "true");
42         });
43
44         $(".hide-replies").live('click', function(e) {
45                 e.preventDefault();
46                 notice = $(this).closest('.notice')
47                 notice.load('/ajax/' + notice.attr("id"));
48         });
49
50         $('.notice_data-text').live('keydown', function (e) {
51                 if (e.ctrlKey && e.keyCode == 13) {
52                         $('#' + $(this).attr("id") + '-submit').click();
53                 }
54         });
55         $('.notice .action').live('click', function (e) {
56                 e.preventDefault();
57
58                 var element = $(this);
59 // fuck you webkit              [action, id] = $(element).attr('id').split('-');
60                 var action = $(element).attr("id").split('-')[0];
61                 var id = $(element).attr("id").split('-')[1];
62
63                 var notice = $('#notice-' + id);
64                 var footer = notice.children('footer');
65                 var form = footer.next('form');
66                 if (form) {
67                         if (form.hasClass(action)) {
68                                 form.find('textarea').focus();
69                                 return;
70                         }
71                         form.remove();
72                 }
73
74                 var form = $(loadingIcon());
75                 footer.after(form);
76                 var r = $.ajax('/ajax/' + $(element).attr("id"))
77                         .done(function(html) {
78                                 form.replaceWith(html);
79                                 footer.next('form').find('textarea').focus();
80                         });
81         });
82
83         $(".show-more").live('click', function(e) {
84                 e.preventDefault();
85
86                 var section = $(this).parent();
87                 section.html(loadingIcon());
88                 var r = $.ajax('/ajax/' + section.attr('id'))
89                         .done(function(html) {
90                                 section.replaceWith(html);
91                         });
92 //              $(this).parent().load('/ajax/' + $(this).parent().attr('id') +  ' article');
93         });
94
95         function loadingIcon() {
96                 return '<img src="/theme/FreesocTheme/img/loading.gif" />';
97         }
98 });