]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - js/util.js
Refactored NoticeLocationAttach(). It works better in UAs that don't
[quix0rs-gnu-social.git] / js / util.js
1 /*
2  * StatusNet - a distributed open-source microblogging tool
3  * Copyright (C) 2008, StatusNet, Inc.
4  *
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.
9  *
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.
14  *
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/>.
17  *
18  * @category  UI interaction
19  * @package   StatusNet
20  * @author    Sarven Capadisli <csarven@status.net>
21  * @author    Evan Prodromou <evan@status.net>
22  * @copyright 2009 StatusNet, Inc.
23  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
24  * @link      http://status.net/
25  */
26
27 var SN = { // StatusNet
28     C: { // Config
29         I: { // Init
30             CounterBlackout: false,
31             MaxLength: 140,
32             PatternUsername: /^[0-9a-zA-Z\-_.]*$/,
33             HTTP20x30x: [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307]
34         },
35
36         S: { // Selector
37             Disabled: 'disabled',
38             Warning: 'warning',
39             Error: 'error',
40             Success: 'success',
41             Processing: 'processing',
42             CommandResult: 'command_result',
43             FormNotice: 'form_notice',
44             NoticeDataText: 'notice_data-text',
45             NoticeTextCount: 'notice_text-count',
46             NoticeInReplyTo: 'notice_in-reply-to',
47             NoticeDataAttach: 'notice_data-attach',
48             NoticeDataAttachSelected: 'notice_data-attach_selected',
49             NoticeActionSubmit: 'notice_action-submit',
50             NoticeLat: 'notice_data-lat',
51             NoticeLon: 'notice_data-lon',
52             NoticeLocationId: 'notice_data-location_id',
53             NoticeLocationNs: 'notice_data-location_ns',
54             NoticeLocationName: 'notice_data-location_name',
55             NoticeLocationCookieName: 'location_enabled',
56             NoticeDataGeo: 'notice_data-geo',
57             NoticeDataGeoSelected: 'notice_data-geo_selected'
58         }
59     },
60
61     U: { // Utils
62         FormNoticeEnhancements: function(form) {
63             form_id = form.attr('id');
64
65             if (jQuery.data(form[0], 'ElementData') === undefined) {
66                 MaxLength = $('#'+form_id+' #'+SN.C.S.NoticeTextCount).text();
67                 if (typeof(MaxLength) == 'undefined') {
68                      MaxLength = SN.C.I.MaxLength;
69                 }
70                 jQuery.data(form[0], 'ElementData', {MaxLength:MaxLength});
71
72                 SN.U.Counter(form);
73
74                 NDT = $('#'+form_id+' #'+SN.C.S.NoticeDataText);
75
76                 NDT.bind('keyup', function(e) {
77                     SN.U.Counter(form);
78                 });
79
80                 NDT.bind('keydown', function(e) {
81                     SN.U.SubmitOnReturn(e, form);
82                 });
83             }
84             else {
85                 $('#'+form_id+' #'+SN.C.S.NoticeTextCount).text(jQuery.data(form[0], 'ElementData').MaxLength);
86             }
87
88             if ($('body')[0].id != 'conversation') {
89                 $('#'+form_id+' textarea').focus();
90             }
91         },
92
93         SubmitOnReturn: function(event, el) {
94             if (event.keyCode == 13 || event.keyCode == 10) {
95                 el.submit();
96                 event.preventDefault();
97                 event.stopPropagation();
98                 $('#'+el[0].id+' #'+SN.C.S.NoticeDataText).blur();
99                 $('body').focus();
100                 return false;
101             }
102             return true;
103         },
104
105         Counter: function(form) {
106             SN.C.I.FormNoticeCurrent = form;
107             form_id = form.attr('id');
108
109             var MaxLength = jQuery.data(form[0], 'ElementData').MaxLength;
110
111             if (MaxLength <= 0) {
112                 return;
113             }
114
115             var remaining = MaxLength - $('#'+form_id+' #'+SN.C.S.NoticeDataText).val().length;
116             var counter = $('#'+form_id+' #'+SN.C.S.NoticeTextCount);
117
118             if (remaining.toString() != counter.text()) {
119                 if (!SN.C.I.CounterBlackout || remaining === 0) {
120                     if (counter.text() != String(remaining)) {
121                         counter.text(remaining);
122                     }
123                     if (remaining < 0) {
124                         form.addClass(SN.C.S.Warning);
125                     } else {
126                         form.removeClass(SN.C.S.Warning);
127                     }
128                     // Skip updates for the next 500ms.
129                     // On slower hardware, updating on every keypress is unpleasant.
130                     if (!SN.C.I.CounterBlackout) {
131                         SN.C.I.CounterBlackout = true;
132                         SN.C.I.FormNoticeCurrent = form;
133                         window.setTimeout("SN.U.ClearCounterBlackout(SN.C.I.FormNoticeCurrent);", 500);
134                     }
135                 }
136             }
137         },
138
139         ClearCounterBlackout: function(form) {
140             // Allow keyup events to poke the counter again
141             SN.C.I.CounterBlackout = false;
142             // Check if the string changed since we last looked
143             SN.U.Counter(form);
144         },
145
146         FormXHR: function(f) {
147             if (jQuery.data(f[0], "ElementData") === undefined) {
148                 jQuery.data(f[0], "ElementData", {Bind:'submit'});
149                 f.bind('submit', function(e) {
150                     form_id = $(this)[0].id;
151                     $.ajax({
152                         type: 'POST',
153                         dataType: 'xml',
154                         url: $(this)[0].action,
155                         data: $(this).serialize() + '&ajax=1',
156                         beforeSend: function(xhr) {
157                             $('#'+form_id).addClass(SN.C.S.Processing);
158                             $('#'+form_id+' .submit').addClass(SN.C.S.Disabled);
159                             $('#'+form_id+' .submit').attr(SN.C.S.Disabled, SN.C.S.Disabled);
160                         },
161                         error: function (xhr, textStatus, errorThrown) {
162                             alert(errorThrown || textStatus);
163                         },
164                         success: function(data, textStatus) {
165                             if (typeof($('form', data)[0]) != 'undefined') {
166                                 form_new = document._importNode($('form', data)[0], true);
167                                 $('#'+form_id).replaceWith(form_new);
168                                 $('#'+form_new.id).each(function() { SN.U.FormXHR($(this)); });
169                             }
170                             else {
171                                 $('#'+form_id).replaceWith(document._importNode($('p', data)[0], true));
172                             }
173                         }
174                     });
175                     return false;
176                 });
177             }
178         },
179
180         FormNoticeXHR: function(form) {
181             form_id = form.attr('id');
182             form.append('<input type="hidden" name="ajax" value="1"/>');
183             form.ajaxForm({
184                 dataType: 'xml',
185                 timeout: '60000',
186                 beforeSend: function(xhr) {
187                     if ($('#'+form_id+' #'+SN.C.S.NoticeDataText)[0].value.length === 0) {
188                         form.addClass(SN.C.S.Warning);
189                         return false;
190                     }
191                     form.addClass(SN.C.S.Processing);
192                     $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).addClass(SN.C.S.Disabled);
193                     $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).attr(SN.C.S.Disabled, SN.C.S.Disabled);
194                     return true;
195                 },
196                 error: function (xhr, textStatus, errorThrown) {
197                     form.removeClass(SN.C.S.Processing);
198                     $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled);
199                     $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).removeAttr(SN.C.S.Disabled, SN.C.S.Disabled);
200                     $('#'+form_id+' .form_response').remove();
201                     if (textStatus == 'timeout') {
202                         form.append('<p class="form_response error">Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists.</p>');
203                     }
204                     else {
205                         if ($('.'+SN.C.S.Error, xhr.responseXML).length > 0) {
206                             form.append(document._importNode($('.'+SN.C.S.Error, xhr.responseXML)[0], true));
207                         }
208                         else {
209                             if (parseInt(xhr.status) === 0 || jQuery.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) >= 0) {
210                                 $('#'+form_id).resetForm();
211                                 $('#'+form_id+' #'+SN.C.S.NoticeDataAttachSelected).remove();
212                                 SN.U.FormNoticeEnhancements($('#'+form_id));
213                             }
214                             else {
215                                 form.append('<p class="form_response error">(Sorry! We had trouble sending your notice ('+xhr.status+' '+xhr.statusText+'). Please report the problem to the site administrator if this happens again.</p>');
216                             }
217                         }
218                     }
219                 },
220                 success: function(data, textStatus) {
221                     $('#'+form_id+' .form_response').remove();
222                     var result;
223                     if ($('#'+SN.C.S.Error, data).length > 0) {
224                         result = document._importNode($('p', data)[0], true);
225                         result = result.textContent || result.innerHTML;
226                         form.append('<p class="form_response error">'+result+'</p>');
227                     }
228                     else {
229                         if($('body')[0].id == 'bookmarklet') {
230                             self.close();
231                         }
232
233                         if ($('#'+SN.C.S.CommandResult, data).length > 0) {
234                             result = document._importNode($('p', data)[0], true);
235                             result = result.textContent || result.innerHTML;
236                             form.append('<p class="form_response success">'+result+'</p>');
237                         }
238                         else {
239                             var notices = $('#notices_primary .notices');
240                             if (notices.length > 0) {
241                                 var notice = document._importNode($('li', data)[0], true);
242                                 if ($('#'+notice.id).length === 0) {
243                                     var notice_irt_value = $('#'+SN.C.S.NoticeInReplyTo).val();
244                                     var notice_irt = '#notices_primary #notice-'+notice_irt_value;
245                                     if($('body')[0].id == 'conversation') {
246                                         if(notice_irt_value.length > 0 && $(notice_irt+' .notices').length < 1) {
247                                             $(notice_irt).append('<ul class="notices"></ul>');
248                                         }
249                                         $($(notice_irt+' .notices')[0]).append(notice);
250                                     }
251                                     else {
252                                         notices.prepend(notice);
253                                     }
254                                     $('#'+notice.id).css({display:'none'});
255                                     $('#'+notice.id).fadeIn(2500);
256                                     SN.U.NoticeWithAttachment($('#'+notice.id));
257                                     SN.U.NoticeReplyTo($('#'+notice.id));
258                                     SN.U.FormXHR($('#'+notice.id+' .form_favor'));
259                                 }
260                             }
261                             else {
262                                 result = document._importNode($('title', data)[0], true);
263                                 result_title = result.textContent || result.innerHTML;
264                                 form.append('<p class="form_response success">'+result_title+'</p>');
265                             }
266                         }
267                         $('#'+form_id).resetForm();
268                         $('#'+form_id+' #'+SN.C.S.NoticeDataAttachSelected).remove();
269                         SN.U.FormNoticeEnhancements($('#'+form_id));
270                     }
271                 },
272                 complete: function(xhr, textStatus) {
273                     form.removeClass(SN.C.S.Processing);
274                     $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).removeAttr(SN.C.S.Disabled);
275                     $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled);
276                 }
277             });
278         },
279
280         NoticeReply: function() {
281             if ($('#'+SN.C.S.NoticeDataText).length > 0 && $('#content .notice_reply').length > 0) {
282                 $('#content .notice').each(function() { SN.U.NoticeReplyTo($(this)); });
283             }
284         },
285
286         NoticeReplyTo: function(notice_item) {
287             var notice = notice_item[0];
288             var notice_reply = $('.notice_reply', notice)[0];
289
290             if (jQuery.data(notice_reply, "ElementData") === undefined) {
291                 jQuery.data(notice_reply, "ElementData", {Bind:'submit'});
292                 $(notice_reply).bind('click', function() {
293                     var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname.uid');
294                     SN.U.NoticeReplySet(nickname.text(), $($('.notice_id', notice)[0]).text());
295                     return false;
296                 });
297             }
298         },
299
300         NoticeReplySet: function(nick,id) {
301             if (nick.match(SN.C.I.PatternUsername)) {
302                 var text = $('#'+SN.C.S.NoticeDataText);
303                 if (text.length > 0) {
304                     replyto = '@' + nick + ' ';
305                     text.val(replyto + text.val().replace(RegExp(replyto, 'i'), ''));
306                     $('#'+SN.C.S.FormNotice+' #'+SN.C.S.NoticeInReplyTo).val(id);
307
308                     text[0].focus();
309                     if (text[0].setSelectionRange) {
310                         var len = text.val().length;
311                         text[0].setSelectionRange(len,len);
312                     }
313                 }
314             }
315         },
316
317         NoticeFavor: function() {
318             $('.form_favor').each(function() { SN.U.FormXHR($(this)); });
319             $('.form_disfavor').each(function() { SN.U.FormXHR($(this)); });
320         },
321
322         NoticeRepeat: function() {
323             $('.form_repeat').each(function() {
324                 SN.U.FormXHR($(this));
325                 SN.U.NoticeRepeatConfirmation($(this));
326             });
327         },
328
329         NoticeRepeatConfirmation: function(form) {
330             function NRC() {
331                 form.closest('.notice-options').addClass('opaque');
332                 form.addClass('dialogbox');
333
334                 form.append('<button class="close">&#215;</button>');
335                 form.find('button.close').click(function(){
336                     $(this).remove();
337
338                     form.closest('.notice-options').removeClass('opaque');
339                     form.removeClass('dialogbox');
340                     form.find('.submit_dialogbox').remove();
341                     form.find('.submit').show();
342
343                     return false;
344                 });
345             };
346
347             form.find('.submit').bind('click', function(e) {
348                 e.preventDefault();
349
350                 var submit = form.find('.submit').clone();
351                 submit.addClass('submit_dialogbox');
352                 submit.removeClass('submit');
353                 form.append(submit);
354
355                 $(this).hide();
356
357                 NRC();
358             });
359         },
360
361         NoticeAttachments: function() {
362             $('.notice a.attachment').each(function() {
363                 SN.U.NoticeWithAttachment($(this).closest('.notice'));
364             });
365         },
366
367         NoticeWithAttachment: function(notice) {
368             if ($('.attachment', notice).length === 0) {
369                 return;
370             }
371
372             var notice_id = notice.attr('id');
373
374             $.fn.jOverlay.options = {
375                 method : 'GET',
376                 data : '',
377                 url : '',
378                 color : '#000',
379                 opacity : '0.6',
380                 zIndex : 9999,
381                 center : false,
382                 imgLoading : $('address .url')[0].href+'theme/base/images/illustrations/illu_progress_loading-01.gif',
383                 bgClickToClose : true,
384                 success : function() {
385                     $('#jOverlayContent').append('<button class="close">&#215;</button>');
386                     $('#jOverlayContent button').click($.closeOverlay);
387                 },
388                 timeout : 0,
389                 autoHide : true,
390                 css : {'max-width':'542px', 'top':'5%', 'left':'32.5%'}
391             };
392
393             $('#'+notice_id+' a.attachment').click(function() {
394                 $().jOverlay({url: $('address .url')[0].href+'attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'});
395                 return false;
396             });
397
398             var t;
399             $("body:not(#shownotice) #"+notice_id+" a.thumbnail").hover(
400                 function() {
401                     var anchor = $(this);
402                     $("a.thumbnail").children('img').hide();
403                     anchor.closest(".entry-title").addClass('ov');
404
405                     if (anchor.children('img').length === 0) {
406                         t = setTimeout(function() {
407                             $.get($('address .url')[0].href+'attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) {
408                                 anchor.append(data);
409                             });
410                         }, 500);
411                     }
412                     else {
413                         anchor.children('img').show();
414                     }
415                 },
416                 function() {
417                     clearTimeout(t);
418                     $("a.thumbnail").children('img').hide();
419                     $(this).closest(".entry-title").removeClass('ov');
420                 }
421             );
422         },
423
424         NoticeDataAttach: function() {
425             NDA = $('#'+SN.C.S.NoticeDataAttach);
426             NDA.change(function() {
427                 S = '<div id="'+SN.C.S.NoticeDataAttachSelected+'" class="'+SN.C.S.Success+'"><code>'+$(this).val()+'</code> <button class="close">&#215;</button></div>';
428                 NDAS = $('#'+SN.C.S.NoticeDataAttachSelected);
429                 if (NDAS.length > 0) {
430                     NDAS.replaceWith(S);
431                 }
432                 else {
433                     $('#'+SN.C.S.FormNotice).append(S);
434                 }
435                 $('#'+SN.C.S.NoticeDataAttachSelected+' button').click(function(){
436                     $('#'+SN.C.S.NoticeDataAttachSelected).remove();
437                     NDA.val('');
438
439                     return false;
440                 });
441             });
442         },
443
444         NoticeLocationAttach: function() {
445             var NLat = $('#'+SN.C.S.NoticeLat).val();
446             var NLon = $('#'+SN.C.S.NoticeLon).val();
447
448             function removeNoticeDataGeo() {
449                 $('label[for='+SN.C.S.NoticeDataGeo+']').removeClass('checked');
450                 $('#'+SN.C.S.NoticeDataGeoSelected).hide();
451                 $('#'+SN.C.S.NoticeLat).val('');
452                 $('#'+SN.C.S.NoticeLon).val('');
453                 $('#'+SN.C.S.NoticeLocationNs).val('');
454                 $('#'+SN.C.S.NoticeLocationId).val('');
455             }
456
457             function getJSONgeocodeURL(geocodeURL, data) {
458                 $.getJSON(geocodeURL, data, function(location) {
459                     NLN = $('#'+SN.C.S.NoticeLocationName);
460                     NLN.replaceWith('<a id="notice_data-location_name"/>');
461                     NLN = $('#'+SN.C.S.NoticeLocationName);
462
463                     if (typeof(location.location_ns) != 'undefined') {
464                         $('#'+SN.C.S.NoticeLocationNs).val(location.location_ns);
465                     }
466
467                     if (typeof(location.location_id) != 'undefined') {
468                         $('#'+SN.C.S.NoticeLocationId).val(location.location_id);
469                     }
470
471                     if (typeof(location.name) == 'undefined') {
472                         NLN_text = position.coords.latitude + ';' + position.coords.longitude;
473                     }
474                     else {
475                         NLN_text = location.name;
476                     }
477
478                     NLN.attr('href', location.url);
479                     NLN.text(NLN_text);
480                     NLN.click(function() {
481                         window.open(location.url);
482
483                         return false;
484                     });
485                 });
486             }
487             var NDG = $('#'+SN.C.S.NoticeDataGeo);
488             if (NDG.length > 0) {
489                 var NLE = $('#notice_data-location_wrap');
490                 var geocodeURL = NLE.attr('title');
491                 NLE.removeAttr('title');
492
493                 $('label[for='+SN.C.S.NoticeDataGeo+']').attr('title', jQuery.trim($('label[for='+SN.C.S.NoticeDataGeo+']').text()));
494
495                 NDG.change(function() {
496                     $.cookie(SN.C.S.NoticeLocationCookieName, $('#'+SN.C.S.NoticeDataGeo).attr('checked'));
497
498                     var NLN = $('#'+SN.C.S.NoticeLocationName);
499                     if (NLN.length > 0) {
500                         NLN.remove();
501                     }
502
503                     if ($('#'+SN.C.S.NoticeDataGeo).attr('checked') === true) {
504                         $('label[for='+SN.C.S.NoticeDataGeo+']').addClass('checked');
505
506                         var S = '<div id="'+SN.C.S.NoticeDataGeoSelected+'" class="'+SN.C.S.Success+'"/>';
507                         var NDGS = $('#'+SN.C.S.NoticeDataGeoSelected);
508
509                         if (NDGS.length > 0) {
510                             NDGS.replaceWith(S);
511                         }
512                         else {
513                             $('#'+SN.C.S.FormNotice).append(S);
514                         }
515
516                         NDGS = $('#'+SN.C.S.NoticeDataGeoSelected);
517                         NDGS.prepend('<span id="'+SN.C.S.NoticeLocationName+'">Geo</span> <button class="minimize">&#95;</button> <button class="close">&#215;</button>');
518
519                         var NLN = $('#'+SN.C.S.NoticeLocationName);
520                         NLN.addClass('processing');
521
522                         $('#'+SN.C.S.NoticeDataGeoSelected+' button.close').click(function(){
523                             $('#'+SN.C.S.NoticeDataGeoSelected).remove();
524                             $('#'+SN.C.S.NoticeDataGeo).attr('checked', false);
525                             $('label[for='+SN.C.S.NoticeDataGeo+']').removeClass('checked');
526
527                             return false;
528                         });
529
530                         $('#'+SN.C.S.NoticeDataGeoSelected+' button.minimize').click(function(){
531                             $('#'+SN.C.S.NoticeDataGeoSelected).hide();
532
533                             return false;
534                         });
535
536                         if (navigator.geolocation) {
537                             navigator.geolocation.getCurrentPosition(
538                                 function(position) {
539                                     $('#'+SN.C.S.NoticeLat).val(position.coords.latitude);
540                                     $('#'+SN.C.S.NoticeLon).val(position.coords.longitude);
541
542                                     var data = {
543                                         'lat': position.coords.latitude,
544                                         'lon': position.coords.longitude,
545                                         'token': $('#token').val()
546                                     };
547
548                                     getJSONgeocodeURL(geocodeURL, data);
549                                 },
550
551                                 function(error) {
552                                     if (error.PERMISSION_DENIED == 1) {
553                                         removeNoticeDataGeo();
554                                     }
555                                 }
556                             );
557                         }
558                         else {
559                             if (NLat.length > 0 && NLon.length > 0) {
560                                 var data = {
561                                     'lat': NLat,
562                                     'lon': NLon,
563                                     'token': $('#token').val()
564                                 };
565
566                                 getJSONgeocodeURL(geocodeURL, data);
567                             }
568                         }
569                     }
570                     else {
571                         $('label[for='+SN.C.S.NoticeDataGeo+']').removeClass('checked');
572
573                         removeNoticeDataGeo();
574                     }
575                 }).change();
576
577                 var cookieVal = $.cookie(SN.C.S.NoticeLocationCookieName);
578                 NDG.attr('checked', (cookieVal === null || cookieVal == 'true'));
579             }
580         },
581
582         NewDirectMessage: function() {
583             NDM = $('.entity_send-a-message a');
584             NDM.attr({'href':NDM.attr('href')+'&ajax=1'});
585             NDM.bind('click', function() {
586                 var NDMF = $('.entity_send-a-message form');
587                 if (NDMF.length === 0) {
588                     $(this).addClass('processing');
589                     $.get(NDM.attr('href'), null, function(data) {
590                         $('.entity_send-a-message').append(document._importNode($('form', data)[0], true));
591                         NDMF = $('.entity_send-a-message .form_notice');
592                         SN.U.FormNoticeXHR(NDMF);
593                         SN.U.FormNoticeEnhancements(NDMF);
594                         NDMF.append('<button class="close">&#215;</button>');
595                         $('.entity_send-a-message button').click(function(){
596                             NDMF.hide();
597                             return false;
598                         });
599                         NDM.removeClass('processing');
600                     });
601                 }
602                 else {
603                     NDMF.show();
604                     $('.entity_send-a-message textarea').focus();
605                 }
606                 return false;
607             });
608         }
609     },
610
611     Init: {
612         NoticeForm: function() {
613             if ($('body.user_in').length > 0) {
614                 $('.'+SN.C.S.FormNotice).each(function() {
615                     SN.U.FormNoticeXHR($(this));
616                     SN.U.FormNoticeEnhancements($(this));
617                 });
618
619                 SN.U.NoticeDataAttach();
620                 SN.U.NoticeLocationAttach();
621             }
622         },
623
624         Notices: function() {
625             if ($('body.user_in').length > 0) {
626                 SN.U.NoticeFavor();
627                 SN.U.NoticeRepeat();
628                 SN.U.NoticeReply();
629             }
630
631             SN.U.NoticeAttachments();
632         },
633
634         EntityActions: function() {
635             if ($('body.user_in').length > 0) {
636                 $('.form_user_subscribe').each(function() { SN.U.FormXHR($(this)); });
637                 $('.form_user_unsubscribe').each(function() { SN.U.FormXHR($(this)); });
638                 $('.form_group_join').each(function() { SN.U.FormXHR($(this)); });
639                 $('.form_group_leave').each(function() { SN.U.FormXHR($(this)); });
640                 $('.form_user_nudge').each(function() { SN.U.FormXHR($(this)); });
641
642                 SN.U.NewDirectMessage();
643             }
644         }
645     }
646 };
647
648 $(document).ready(function(){
649     if ($('.'+SN.C.S.FormNotice).length > 0) {
650         SN.Init.NoticeForm();
651     }
652     if ($('#content .notices').length > 0) {
653         SN.Init.Notices();
654     }
655     if ($('#content .entity_actions').length > 0) {
656         SN.Init.EntityActions();
657     }
658 });
659