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