]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - js/util.js
use the new maxNoticeLength and maxUrlLength functionality introduced in commit 14adb...
[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             NoticeGeoName: 'notice_data-geo_name',
55             NoticeDataGeo: 'notice_data-geo',
56             NoticeDataGeoCookie: 'NoticeDataGeo',
57             NoticeDataGeoSelected: 'notice_data-geo_selected',
58             StatusNetInstance:'StatusNetInstance'
59         }
60     },
61
62     U: { // Utils
63         FormNoticeEnhancements: function(form) {
64             if (jQuery.data(form[0], 'ElementData') === undefined) {
65                 MaxLength = form.find('#'+SN.C.S.NoticeTextCount).text();
66                 if (typeof(MaxLength) == 'undefined') {
67                      MaxLength = SN.C.I.MaxLength;
68                 }
69                 jQuery.data(form[0], 'ElementData', {MaxLength:MaxLength});
70
71                 SN.U.Counter(form);
72
73                 NDT = form.find('#'+SN.C.S.NoticeDataText);
74
75                 NDT.bind('keyup', function(e) {
76                     SN.U.Counter(form);
77                 });
78
79                 NDT.bind('keydown', function(e) {
80                     SN.U.SubmitOnReturn(e, form);
81                 });
82             }
83             else {
84                 form.find('#'+SN.C.S.NoticeTextCount).text(jQuery.data(form[0], 'ElementData').MaxLength);
85             }
86
87             if ($('body')[0].id != 'conversation' && window.location.hash.length === 0) {
88                 form.find('textarea').focus();
89             }
90         },
91
92         SubmitOnReturn: function(event, el) {
93             if (event.keyCode == 13 || event.keyCode == 10) {
94                 el.submit();
95                 event.preventDefault();
96                 event.stopPropagation();
97                 $('#'+el[0].id+' #'+SN.C.S.NoticeDataText).blur();
98                 $('body').focus();
99                 return false;
100             }
101             return true;
102         },
103
104         Counter: function(form) {
105             SN.C.I.FormNoticeCurrent = form;
106
107             var MaxLength = jQuery.data(form[0], 'ElementData').MaxLength;
108
109             if (MaxLength <= 0) {
110                 return;
111             }
112
113             var remaining = MaxLength - form.find('#'+SN.C.S.NoticeDataText).val().length;
114             var counter = form.find('#'+SN.C.S.NoticeTextCount);
115
116             if (remaining.toString() != counter.text()) {
117                 if (!SN.C.I.CounterBlackout || remaining === 0) {
118                     if (counter.text() != String(remaining)) {
119                         counter.text(remaining);
120                     }
121                     if (remaining < 0) {
122                         form.addClass(SN.C.S.Warning);
123                     } else {
124                         form.removeClass(SN.C.S.Warning);
125                     }
126                     // Skip updates for the next 500ms.
127                     // On slower hardware, updating on every keypress is unpleasant.
128                     if (!SN.C.I.CounterBlackout) {
129                         SN.C.I.CounterBlackout = true;
130                         SN.C.I.FormNoticeCurrent = form;
131                         window.setTimeout("SN.U.ClearCounterBlackout(SN.C.I.FormNoticeCurrent);", 500);
132                     }
133                 }
134             }
135         },
136
137         ClearCounterBlackout: function(form) {
138             // Allow keyup events to poke the counter again
139             SN.C.I.CounterBlackout = false;
140             // Check if the string changed since we last looked
141             SN.U.Counter(form);
142         },
143
144         FormXHR: function(form) {
145             $.ajax({
146                 type: 'POST',
147                 dataType: 'xml',
148                 url: form.attr('action'),
149                 data: form.serialize() + '&ajax=1',
150                 beforeSend: function(xhr) {
151                     form
152                         .addClass(SN.C.S.Processing)
153                         .find('.submit')
154                             .addClass(SN.C.S.Disabled)
155                             .attr(SN.C.S.Disabled, SN.C.S.Disabled);
156                 },
157                 error: function (xhr, textStatus, errorThrown) {
158                     alert(errorThrown || textStatus);
159                 },
160                 success: function(data, textStatus) {
161                     if (typeof($('form', data)[0]) != 'undefined') {
162                         form_new = document._importNode($('form', data)[0], true);
163                         form.replaceWith(form_new);
164                     }
165                     else {
166                         form.replaceWith(document._importNode($('p', data)[0], true));
167                     }
168                 }
169             });
170         },
171
172         FormNoticeXHR: function(form) {
173             SN.C.I.NoticeDataGeo = {};
174             form.append('<input type="hidden" name="ajax" value="1"/>');
175             form.ajaxForm({
176                 dataType: 'xml',
177                 timeout: '60000',
178                 beforeSend: function(formData) {
179                     if (form.find('#'+SN.C.S.NoticeDataText)[0].value.length === 0) {
180                         form.addClass(SN.C.S.Warning);
181                         return false;
182                     }
183                     form
184                         .addClass(SN.C.S.Processing)
185                         .find('#'+SN.C.S.NoticeActionSubmit)
186                             .addClass(SN.C.S.Disabled)
187                             .attr(SN.C.S.Disabled, SN.C.S.Disabled);
188
189                     SN.C.I.NoticeDataGeo.NLat = $('#'+SN.C.S.NoticeLat).val();
190                     SN.C.I.NoticeDataGeo.NLon = $('#'+SN.C.S.NoticeLon).val();
191                     SN.C.I.NoticeDataGeo.NLNS = $('#'+SN.C.S.NoticeLocationNs).val();
192                     SN.C.I.NoticeDataGeo.NLID = $('#'+SN.C.S.NoticeLocationId).val();
193                     SN.C.I.NoticeDataGeo.NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked');
194
195                     cookieValue = $.cookie(SN.C.S.NoticeDataGeoCookie);
196
197                     if (cookieValue !== null && cookieValue != 'disabled') {
198                         cookieValue = JSON.parse(cookieValue);
199                         SN.C.I.NoticeDataGeo.NLat = $('#'+SN.C.S.NoticeLat).val(cookieValue.NLat).val();
200                         SN.C.I.NoticeDataGeo.NLon = $('#'+SN.C.S.NoticeLon).val(cookieValue.NLon).val();
201                         if ($('#'+SN.C.S.NoticeLocationNs).val(cookieValue.NLNS)) {
202                             SN.C.I.NoticeDataGeo.NLNS = $('#'+SN.C.S.NoticeLocationNs).val(cookieValue.NLNS).val();
203                             SN.C.I.NoticeDataGeo.NLID = $('#'+SN.C.S.NoticeLocationId).val(cookieValue.NLID).val();
204                         }
205                     }
206                     if (cookieValue == 'disabled') {
207                         SN.C.I.NoticeDataGeo.NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked', false).attr('checked');
208                     }
209                     else {
210                         SN.C.I.NoticeDataGeo.NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked', true).attr('checked');
211                     }
212
213                     return true;
214                 },
215                 error: function (xhr, textStatus, errorThrown) {
216                     form
217                         .removeClass(SN.C.S.Processing)
218                         .find('#'+SN.C.S.NoticeActionSubmit)
219                             .removeClass(SN.C.S.Disabled)
220                             .removeAttr(SN.C.S.Disabled, SN.C.S.Disabled);
221                     form.find('.form_response').remove();
222                     if (textStatus == 'timeout') {
223                         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>');
224                     }
225                     else {
226                         if ($('.'+SN.C.S.Error, xhr.responseXML).length > 0) {
227                             form.append(document._importNode($('.'+SN.C.S.Error, xhr.responseXML)[0], true));
228                         }
229                         else {
230                             if (parseInt(xhr.status) === 0 || jQuery.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) >= 0) {
231                                 form
232                                     .resetForm()
233                                     .find('#'+SN.C.S.NoticeDataAttachSelected).remove();
234                                 SN.U.FormNoticeEnhancements(form);
235                             }
236                             else {
237                                 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>');
238                             }
239                         }
240                     }
241                 },
242                 success: function(data, textStatus) {
243                     form.find('.form_response').remove();
244                     var result;
245                     if ($('#'+SN.C.S.Error, data).length > 0) {
246                         result = document._importNode($('p', data)[0], true);
247                         result = result.textContent || result.innerHTML;
248                         form.append('<p class="form_response error">'+result+'</p>');
249                     }
250                     else {
251                         if($('body')[0].id == 'bookmarklet') {
252                             self.close();
253                         }
254
255                         if ($('#'+SN.C.S.CommandResult, data).length > 0) {
256                             result = document._importNode($('p', data)[0], true);
257                             result = result.textContent || result.innerHTML;
258                             form.append('<p class="form_response success">'+result+'</p>');
259                         }
260                         else {
261                             var notices = $('#notices_primary .notices');
262                             if (notices.length > 0) {
263                                 var notice = document._importNode($('li', data)[0], true);
264                                 if ($('#'+notice.id).length === 0) {
265                                     var notice_irt_value = $('#'+SN.C.S.NoticeInReplyTo).val();
266                                     var notice_irt = '#notices_primary #notice-'+notice_irt_value;
267                                     if($('body')[0].id == 'conversation') {
268                                         if(notice_irt_value.length > 0 && $(notice_irt+' .notices').length < 1) {
269                                             $(notice_irt).append('<ul class="notices"></ul>');
270                                         }
271                                         $($(notice_irt+' .notices')[0]).append(notice);
272                                     }
273                                     else {
274                                         notices.prepend(notice);
275                                     }
276                                     $('#'+notice.id)
277                                         .css({display:'none'})
278                                         .fadeIn(2500);
279                                     SN.U.NoticeWithAttachment($('#'+notice.id));
280                                     SN.U.NoticeReplyTo($('#'+notice.id));
281                                 }
282                             }
283                             else {
284                                 result = document._importNode($('title', data)[0], true);
285                                 result_title = result.textContent || result.innerHTML;
286                                 form.append('<p class="form_response success">'+result_title+'</p>');
287                             }
288                         }
289                         form.resetForm();
290                         form.find('#'+SN.C.S.NoticeInReplyTo).val('');
291                         form.find('#'+SN.C.S.NoticeDataAttachSelected).remove();
292                         SN.U.FormNoticeEnhancements(form);
293                     }
294                 },
295                 complete: function(xhr, textStatus) {
296                     form
297                         .removeClass(SN.C.S.Processing)
298                         .find('#'+SN.C.S.NoticeActionSubmit)
299                             .removeAttr(SN.C.S.Disabled)
300                             .removeClass(SN.C.S.Disabled);
301
302                     $('#'+SN.C.S.NoticeLat).val(SN.C.I.NoticeDataGeo.NLat);
303                     $('#'+SN.C.S.NoticeLon).val(SN.C.I.NoticeDataGeo.NLon);
304                     if ($('#'+SN.C.S.NoticeLocationNs)) {
305                         $('#'+SN.C.S.NoticeLocationNs).val(SN.C.I.NoticeDataGeo.NLNS);
306                         $('#'+SN.C.S.NoticeLocationId).val(SN.C.I.NoticeDataGeo.NLID);
307                     }
308                     $('#'+SN.C.S.NoticeDataGeo).attr('checked', SN.C.I.NoticeDataGeo.NDG);
309                 }
310             });
311         },
312
313         NoticeReply: function() {
314             if ($('#'+SN.C.S.NoticeDataText).length > 0 && $('#content .notice_reply').length > 0) {
315                 $('#content .notice').each(function() { SN.U.NoticeReplyTo($(this)); });
316             }
317         },
318
319         NoticeReplyTo: function(notice) {
320             notice.find('.notice_reply').live('click', function() {
321                 var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname.uid');
322                 SN.U.NoticeReplySet(nickname.text(), $($('.notice_id', notice)[0]).text());
323                 return false;
324             });
325         },
326
327         NoticeReplySet: function(nick,id) {
328             if (nick.match(SN.C.I.PatternUsername)) {
329                 var text = $('#'+SN.C.S.NoticeDataText);
330                 if (text.length > 0) {
331                     replyto = '@' + nick + ' ';
332                     text.val(replyto + text.val().replace(RegExp(replyto, 'i'), ''));
333                     $('#'+SN.C.S.FormNotice+' #'+SN.C.S.NoticeInReplyTo).val(id);
334
335                     text[0].focus();
336                     if (text[0].setSelectionRange) {
337                         var len = text.val().length;
338                         text[0].setSelectionRange(len,len);
339                     }
340                 }
341             }
342         },
343
344         NoticeFavor: function() {
345             $('.form_favor').live('click', function() { SN.U.FormXHR($(this)); return false; });
346             $('.form_disfavor').live('click', function() { SN.U.FormXHR($(this)); return false; });
347         },
348
349         NoticeRepeat: function() {
350             $('.form_repeat').live('click', function(e) {
351                 e.preventDefault();
352
353                 SN.U.NoticeRepeatConfirmation($(this));
354                 return false;
355             });
356         },
357
358         NoticeRepeatConfirmation: function(form) {
359             var submit_i = form.find('.submit');
360
361             var submit = submit_i.clone();
362             submit
363                 .addClass('submit_dialogbox')
364                 .removeClass('submit');
365             form.append(submit);
366             submit.bind('click', function() { SN.U.FormXHR(form); return false; });
367
368             submit_i.hide();
369
370             form
371                 .addClass('dialogbox')
372                 .append('<button class="close">&#215;</button>')
373                 .closest('.notice-options')
374                     .addClass('opaque');
375
376             form.find('button.close').click(function(){
377                 $(this).remove();
378
379                 form
380                     .removeClass('dialogbox')
381                     .closest('.notice-options')
382                         .removeClass('opaque');
383
384                 form.find('.submit_dialogbox').remove();
385                 form.find('.submit').show();
386
387                 return false;
388             });
389         },
390
391         NoticeAttachments: function() {
392             $('.notice a.attachment').each(function() {
393                 SN.U.NoticeWithAttachment($(this).closest('.notice'));
394             });
395         },
396
397         NoticeWithAttachment: function(notice) {
398             if (notice.find('.attachment').length === 0) {
399                 return;
400             }
401
402             var attachment_more = notice.find('.attachment.more');
403             if (attachment_more.length > 0) {
404                 $(attachment_more[0]).click(function() {
405                     var m = $(this);
406                     m.addClass(SN.C.S.Processing);
407                     $.get(m.attr('href')+'/ajax', null, function(data) {
408                         m.parent('.entry-content').html($(data).find('#attachment_view .entry-content').html());
409                     });
410
411                     return false;
412                 });
413             }
414             else {
415                 $.fn.jOverlay.options = {
416                     method : 'GET',
417                     data : '',
418                     url : '',
419                     color : '#000',
420                     opacity : '0.6',
421                     zIndex : 9999,
422                     center : false,
423                     imgLoading : $('address .url')[0].href+'theme/base/images/illustrations/illu_progress_loading-01.gif',
424                     bgClickToClose : true,
425                     success : function() {
426                         $('#jOverlayContent').append('<button class="close">&#215;</button>');
427                         $('#jOverlayContent button').click($.closeOverlay);
428                     },
429                     timeout : 0,
430                     autoHide : true,
431                     css : {'max-width':'542px', 'top':'5%', 'left':'32.5%'}
432                 };
433
434                 notice.find('a.attachment').click(function() {
435                     var attachId = ($(this).attr('id').substring('attachment'.length + 1));
436                     if (attachId) {
437                         $().jOverlay({url: $('address .url')[0].href+'attachment/' + attachId + '/ajax'});
438                         return false;
439                     }
440                 });
441
442                 if ($('#shownotice').length == 0) {
443                     var t;
444                     notice.find('a.thumbnail').hover(
445                         function() {
446                             var anchor = $(this);
447                             $('a.thumbnail').children('img').hide();
448                             anchor.closest(".entry-title").addClass('ov');
449
450                             if (anchor.children('img').length === 0) {
451                                 t = setTimeout(function() {
452                                     $.get($('address .url')[0].href+'attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) {
453                                         anchor.append(data);
454                                     });
455                                 }, 500);
456                             }
457                             else {
458                                 anchor.children('img').show();
459                             }
460                         },
461                         function() {
462                             clearTimeout(t);
463                             $('a.thumbnail').children('img').hide();
464                             $(this).closest('.entry-title').removeClass('ov');
465                         }
466                     );
467                 }
468             }
469         },
470
471         NoticeDataAttach: function() {
472             NDA = $('#'+SN.C.S.NoticeDataAttach);
473             NDA.change(function() {
474                 S = '<div id="'+SN.C.S.NoticeDataAttachSelected+'" class="'+SN.C.S.Success+'"><code>'+$(this).val()+'</code> <button class="close">&#215;</button></div>';
475                 NDAS = $('#'+SN.C.S.NoticeDataAttachSelected);
476                 if (NDAS.length > 0) {
477                     NDAS.replaceWith(S);
478                 }
479                 else {
480                     $('#'+SN.C.S.FormNotice).append(S);
481                 }
482                 $('#'+SN.C.S.NoticeDataAttachSelected+' button').click(function(){
483                     $('#'+SN.C.S.NoticeDataAttachSelected).remove();
484                     NDA.val('');
485
486                     return false;
487                 });
488             });
489         },
490
491         NoticeLocationAttach: function() {
492             var NLat = $('#'+SN.C.S.NoticeLat).val();
493             var NLon = $('#'+SN.C.S.NoticeLon).val();
494             var NLNS = $('#'+SN.C.S.NoticeLocationNs).val();
495             var NLID = $('#'+SN.C.S.NoticeLocationId).val();
496             var NLN = $('#'+SN.C.S.NoticeGeoName).text();
497             var NDGe = $('#'+SN.C.S.NoticeDataGeo);
498
499             function removeNoticeDataGeo() {
500                 $('label[for='+SN.C.S.NoticeDataGeo+']')
501                     .attr('title', jQuery.trim($('label[for='+SN.C.S.NoticeDataGeo+']').text()))
502                     .removeClass('checked');
503
504                 $('#'+SN.C.S.NoticeLat).val('');
505                 $('#'+SN.C.S.NoticeLon).val('');
506                 $('#'+SN.C.S.NoticeLocationNs).val('');
507                 $('#'+SN.C.S.NoticeLocationId).val('');
508                 $('#'+SN.C.S.NoticeDataGeo).attr('checked', false);
509
510                 $.cookie(SN.C.S.NoticeDataGeoCookie, 'disabled', { path: '/' });
511             }
512
513             function getJSONgeocodeURL(geocodeURL, data) {
514                 $.getJSON(geocodeURL, data, function(location) {
515                     var lns, lid;
516
517                     if (typeof(location.location_ns) != 'undefined') {
518                         $('#'+SN.C.S.NoticeLocationNs).val(location.location_ns);
519                         lns = location.location_ns;
520                     }
521
522                     if (typeof(location.location_id) != 'undefined') {
523                         $('#'+SN.C.S.NoticeLocationId).val(location.location_id);
524                         lid = location.location_id;
525                     }
526
527                     if (typeof(location.name) == 'undefined') {
528                         NLN_text = data.lat + ';' + data.lon;
529                     }
530                     else {
531                         NLN_text = location.name;
532                     }
533
534                     $('label[for='+SN.C.S.NoticeDataGeo+']')
535                         .attr('title', NoticeDataGeo_text.ShareDisable + ' (' + NLN_text + ')');
536
537                     $('#'+SN.C.S.NoticeLat).val(data.lat);
538                     $('#'+SN.C.S.NoticeLon).val(data.lon);
539                     $('#'+SN.C.S.NoticeLocationNs).val(lns);
540                     $('#'+SN.C.S.NoticeLocationId).val(lid);
541                     $('#'+SN.C.S.NoticeDataGeo).attr('checked', true);
542
543                     var cookieValue = {
544                         NLat: data.lat,
545                         NLon: data.lon,
546                         NLNS: lns,
547                         NLID: lid,
548                         NLN: NLN_text,
549                         NLNU: location.url,
550                         NDG: true
551                     };
552
553                     $.cookie(SN.C.S.NoticeDataGeoCookie, JSON.stringify(cookieValue), { path: '/' });
554                 });
555             }
556
557             if (NDGe.length > 0) {
558                 if ($.cookie(SN.C.S.NoticeDataGeoCookie) == 'disabled') {
559                     NDGe.attr('checked', false);
560                 }
561                 else {
562                     NDGe.attr('checked', true);
563                 }
564
565                 var NGW = $('#notice_data-geo_wrap');
566                 var geocodeURL = NGW.attr('title');
567                 NGW.removeAttr('title');
568
569                 $('label[for='+SN.C.S.NoticeDataGeo+']')
570                     .attr('title', jQuery.trim($('label[for='+SN.C.S.NoticeDataGeo+']').text()));
571
572                 NDGe.change(function() {
573                     if ($('#'+SN.C.S.NoticeDataGeo).attr('checked') === true || $.cookie(SN.C.S.NoticeDataGeoCookie) === null) {
574                         $('label[for='+SN.C.S.NoticeDataGeo+']')
575                             .attr('title', NoticeDataGeo_text.ShareDisable)
576                             .addClass('checked');
577
578                         if ($.cookie(SN.C.S.NoticeDataGeoCookie) === null || $.cookie(SN.C.S.NoticeDataGeoCookie) == 'disabled') {
579                             if (navigator.geolocation) {
580                                 navigator.geolocation.getCurrentPosition(
581                                     function(position) {
582                                         $('#'+SN.C.S.NoticeLat).val(position.coords.latitude);
583                                         $('#'+SN.C.S.NoticeLon).val(position.coords.longitude);
584
585                                         var data = {
586                                             lat: position.coords.latitude,
587                                             lon: position.coords.longitude,
588                                             token: $('#token').val()
589                                         };
590
591                                         getJSONgeocodeURL(geocodeURL, data);
592                                     },
593
594                                     function(error) {
595                                         switch(error.code) {
596                                             case error.PERMISSION_DENIED:
597                                                 removeNoticeDataGeo();
598                                                 break;
599                                             case error.TIMEOUT:
600                                                 $('#'+SN.C.S.NoticeDataGeo).attr('checked', false);
601                                                 break;
602                                         }
603                                     },
604
605                                     {
606                                         timeout: 10000
607                                     }
608                                 );
609                             }
610                             else {
611                                 if (NLat.length > 0 && NLon.length > 0) {
612                                     var data = {
613                                         lat: NLat,
614                                         lon: NLon,
615                                         token: $('#token').val()
616                                     };
617
618                                     getJSONgeocodeURL(geocodeURL, data);
619                                 }
620                                 else {
621                                     removeNoticeDataGeo();
622                                     $('#'+SN.C.S.NoticeDataGeo).remove();
623                                     $('label[for='+SN.C.S.NoticeDataGeo+']').remove();
624                                 }
625                             }
626                         }
627                         else {
628                             var cookieValue = JSON.parse($.cookie(SN.C.S.NoticeDataGeoCookie));
629
630                             $('#'+SN.C.S.NoticeLat).val(cookieValue.NLat);
631                             $('#'+SN.C.S.NoticeLon).val(cookieValue.NLon);
632                             $('#'+SN.C.S.NoticeLocationNs).val(cookieValue.NLNS);
633                             $('#'+SN.C.S.NoticeLocationId).val(cookieValue.NLID);
634                             $('#'+SN.C.S.NoticeDataGeo).attr('checked', cookieValue.NDG);
635
636                             $('label[for='+SN.C.S.NoticeDataGeo+']')
637                                 .attr('title', NoticeDataGeo_text.ShareDisable + ' (' + cookieValue.NLN + ')')
638                                 .addClass('checked');
639                         }
640                     }
641                     else {
642                         removeNoticeDataGeo();
643                     }
644                 }).change();
645             }
646         },
647
648         NewDirectMessage: function() {
649             NDM = $('.entity_send-a-message a');
650             NDM.attr({'href':NDM.attr('href')+'&ajax=1'});
651             NDM.bind('click', function() {
652                 var NDMF = $('.entity_send-a-message form');
653                 if (NDMF.length === 0) {
654                     $(this).addClass(SN.C.S.Processing);
655                     $.get(NDM.attr('href'), null, function(data) {
656                         $('.entity_send-a-message').append(document._importNode($('form', data)[0], true));
657                         NDMF = $('.entity_send-a-message .form_notice');
658                         SN.U.FormNoticeXHR(NDMF);
659                         SN.U.FormNoticeEnhancements(NDMF);
660                         NDMF.append('<button class="close">&#215;</button>');
661                         $('.entity_send-a-message button').click(function(){
662                             NDMF.hide();
663                             return false;
664                         });
665                         NDM.removeClass(SN.C.S.Processing);
666                     });
667                 }
668                 else {
669                     NDMF.show();
670                     $('.entity_send-a-message textarea').focus();
671                 }
672                 return false;
673             });
674         },
675
676         GetFullYear: function(year, month, day) {
677             var date = new Date();
678             date.setFullYear(year, month, day);
679
680             return date;
681         },
682
683         StatusNetInstance: {
684             Set: function(value) {
685                 var SNI = SN.U.StatusNetInstance.Get();
686                 if (SNI !== null) {
687                     value = $.extend(SNI, value);
688                 }
689
690                 $.cookie(
691                     SN.C.S.StatusNetInstance,
692                     JSON.stringify(value),
693                     {
694                         path: '/',
695                         expires: SN.U.GetFullYear(2029, 0, 1)
696                     });
697             },
698
699             Get: function() {
700                 var cookieValue = $.cookie(SN.C.S.StatusNetInstance);
701                 if (cookieValue !== null) {
702                     return JSON.parse(cookieValue);
703                 }
704                 return null;
705             },
706
707             Delete: function() {
708                 $.cookie(SN.C.S.StatusNetInstance, null);
709             }
710         }
711     },
712
713     Init: {
714         NoticeForm: function() {
715             if ($('body.user_in').length > 0) {
716                 SN.U.NoticeLocationAttach();
717
718                 $('.'+SN.C.S.FormNotice).each(function() {
719                     SN.U.FormNoticeXHR($(this));
720                     SN.U.FormNoticeEnhancements($(this));
721                 });
722
723                 SN.U.NoticeDataAttach();
724             }
725         },
726
727         Notices: function() {
728             if ($('body.user_in').length > 0) {
729                 SN.U.NoticeFavor();
730                 SN.U.NoticeRepeat();
731                 SN.U.NoticeReply();
732             }
733
734             SN.U.NoticeAttachments();
735         },
736
737         EntityActions: function() {
738             if ($('body.user_in').length > 0) {
739                 $('.form_user_subscribe').live('click', function() { SN.U.FormXHR($(this)); return false; });
740                 $('.form_user_unsubscribe').live('click', function() { SN.U.FormXHR($(this)); return false; });
741                 $('.form_group_join').live('click', function() { SN.U.FormXHR($(this)); return false; });
742                 $('.form_group_leave').live('click', function() { SN.U.FormXHR($(this)); return false; });
743                 $('.form_user_nudge').live('click', function() { SN.U.FormXHR($(this)); return false; });
744
745                 SN.U.NewDirectMessage();
746             }
747         },
748
749         Login: function() {
750             if (SN.U.StatusNetInstance.Get() !== null) {
751                 var nickname = SN.U.StatusNetInstance.Get().Nickname;
752                 if (nickname !== null) {
753                     $('#form_login #nickname').val(nickname);
754                 }
755             }
756
757             $('#form_login').bind('submit', function() {
758                 SN.U.StatusNetInstance.Set({Nickname: $('#form_login #nickname').val()});
759                 return true;
760             });
761         }
762     }
763 };
764
765 $(document).ready(function(){
766     if ($('.'+SN.C.S.FormNotice).length > 0) {
767         SN.Init.NoticeForm();
768     }
769     if ($('#content .notices').length > 0) {
770         SN.Init.Notices();
771     }
772     if ($('#content .entity_actions').length > 0) {
773         SN.Init.EntityActions();
774     }
775     if ($('#form_login').length > 0) {
776         SN.Init.Login();
777     }
778 });
779