]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - js/util.js
Merge branch 'inblob' of git@gitorious.org:~evan/statusnet/evans-mainline into inblob
[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: 'notice_data-geo_cookie',
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             var NDG, NLat, NLon, NLNS, NLID;
182             form_id = form.attr('id');
183             form.append('<input type="hidden" name="ajax" value="1"/>');
184             form.ajaxForm({
185                 dataType: 'xml',
186                 timeout: '60000',
187                 beforeSend: function(formData) {
188                     if ($('#'+form_id+' #'+SN.C.S.NoticeDataText)[0].value.length === 0) {
189                         form.addClass(SN.C.S.Warning);
190                         return false;
191                     }
192                     form.addClass(SN.C.S.Processing);
193                     $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).addClass(SN.C.S.Disabled);
194                     $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).attr(SN.C.S.Disabled, SN.C.S.Disabled);
195
196                     NLat = $('#'+SN.C.S.NoticeLat).val();
197                     NLon = $('#'+SN.C.S.NoticeLon).val();
198                     NLNS = $('#'+SN.C.S.NoticeLocationNs).val();
199                     NLID = $('#'+SN.C.S.NoticeLocationId).val();
200                     NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked');
201
202                     cookieValue = $.cookie(SN.C.S.NoticeDataGeoCookie);
203
204                     if (cookieValue !== null && cookieValue != 'disabled') {
205                         cookieValue = JSON.parse(cookieValue);
206                         NLat = $('#'+SN.C.S.NoticeLat).val(cookieValue.NLat).val();
207                         NLon = $('#'+SN.C.S.NoticeLon).val(cookieValue.NLon).val();
208                         NLNS = $('#'+SN.C.S.NoticeLocationNs).val(cookieValue.NLNS).val();
209                         NLID = $('#'+SN.C.S.NoticeLocationId).val(cookieValue.NLID).val();
210                     }
211                     if (cookieValue == 'disabled') {
212                         NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked', false).attr('checked');
213                     }
214                     else {
215                         NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked', true).attr('checked');
216                     }
217
218                     return true;
219                 },
220                 error: function (xhr, textStatus, errorThrown) {
221                     form.removeClass(SN.C.S.Processing);
222                     $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled);
223                     $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).removeAttr(SN.C.S.Disabled, SN.C.S.Disabled);
224                     $('#'+form_id+' .form_response').remove();
225                     if (textStatus == 'timeout') {
226                         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>');
227                     }
228                     else {
229                         if ($('.'+SN.C.S.Error, xhr.responseXML).length > 0) {
230                             form.append(document._importNode($('.'+SN.C.S.Error, xhr.responseXML)[0], true));
231                         }
232                         else {
233                             if (parseInt(xhr.status) === 0 || jQuery.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) >= 0) {
234                                 $('#'+form_id).resetForm();
235                                 $('#'+form_id+' #'+SN.C.S.NoticeDataAttachSelected).remove();
236                                 SN.U.FormNoticeEnhancements($('#'+form_id));
237                             }
238                             else {
239                                 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>');
240                             }
241                         }
242                     }
243                 },
244                 success: function(data, textStatus) {
245                     $('#'+form_id+' .form_response').remove();
246                     var result;
247                     if ($('#'+SN.C.S.Error, data).length > 0) {
248                         result = document._importNode($('p', data)[0], true);
249                         result = result.textContent || result.innerHTML;
250                         form.append('<p class="form_response error">'+result+'</p>');
251                     }
252                     else {
253                         if($('body')[0].id == 'bookmarklet') {
254                             self.close();
255                         }
256
257                         if ($('#'+SN.C.S.CommandResult, data).length > 0) {
258                             result = document._importNode($('p', data)[0], true);
259                             result = result.textContent || result.innerHTML;
260                             form.append('<p class="form_response success">'+result+'</p>');
261                         }
262                         else {
263                             var notices = $('#notices_primary .notices');
264                             if (notices.length > 0) {
265                                 var notice = document._importNode($('li', data)[0], true);
266                                 if ($('#'+notice.id).length === 0) {
267                                     var notice_irt_value = $('#'+SN.C.S.NoticeInReplyTo).val();
268                                     var notice_irt = '#notices_primary #notice-'+notice_irt_value;
269                                     if($('body')[0].id == 'conversation') {
270                                         if(notice_irt_value.length > 0 && $(notice_irt+' .notices').length < 1) {
271                                             $(notice_irt).append('<ul class="notices"></ul>');
272                                         }
273                                         $($(notice_irt+' .notices')[0]).append(notice);
274                                     }
275                                     else {
276                                         notices.prepend(notice);
277                                     }
278                                     $('#'+notice.id).css({display:'none'});
279                                     $('#'+notice.id).fadeIn(2500);
280                                     SN.U.NoticeWithAttachment($('#'+notice.id));
281                                     SN.U.NoticeReplyTo($('#'+notice.id));
282                                     SN.U.FormXHR($('#'+notice.id+' .form_favor'));
283                                 }
284                             }
285                             else {
286                                 result = document._importNode($('title', data)[0], true);
287                                 result_title = result.textContent || result.innerHTML;
288                                 form.append('<p class="form_response success">'+result_title+'</p>');
289                             }
290                         }
291                         $('#'+form_id).resetForm();
292                         $('#'+form_id+' #'+SN.C.S.NoticeDataAttachSelected).remove();
293                         SN.U.FormNoticeEnhancements($('#'+form_id));
294                     }
295                 },
296                 complete: function(xhr, textStatus) {
297                     form.removeClass(SN.C.S.Processing);
298                     $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).removeAttr(SN.C.S.Disabled);
299                     $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled);
300
301                     $('#'+SN.C.S.NoticeLat).val(NLat);
302                     $('#'+SN.C.S.NoticeLon).val(NLon);
303                     $('#'+SN.C.S.NoticeLocationNs).val(NLNS);
304                     $('#'+SN.C.S.NoticeLocationId).val(NLID);
305                     $('#'+SN.C.S.NoticeDataGeo).attr('checked', NDG);
306                 }
307             });
308         },
309
310         NoticeReply: function() {
311             if ($('#'+SN.C.S.NoticeDataText).length > 0 && $('#content .notice_reply').length > 0) {
312                 $('#content .notice').each(function() { SN.U.NoticeReplyTo($(this)); });
313             }
314         },
315
316         NoticeReplyTo: function(notice_item) {
317             var notice = notice_item[0];
318             var notice_reply = $('.notice_reply', notice)[0];
319
320             if (jQuery.data(notice_reply, "ElementData") === undefined) {
321                 jQuery.data(notice_reply, "ElementData", {Bind:'submit'});
322                 $(notice_reply).bind('click', function() {
323                     var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname.uid');
324                     SN.U.NoticeReplySet(nickname.text(), $($('.notice_id', notice)[0]).text());
325                     return false;
326                 });
327             }
328         },
329
330         NoticeReplySet: function(nick,id) {
331             if (nick.match(SN.C.I.PatternUsername)) {
332                 var text = $('#'+SN.C.S.NoticeDataText);
333                 if (text.length > 0) {
334                     replyto = '@' + nick + ' ';
335                     text.val(replyto + text.val().replace(RegExp(replyto, 'i'), ''));
336                     $('#'+SN.C.S.FormNotice+' #'+SN.C.S.NoticeInReplyTo).val(id);
337
338                     text[0].focus();
339                     if (text[0].setSelectionRange) {
340                         var len = text.val().length;
341                         text[0].setSelectionRange(len,len);
342                     }
343                 }
344             }
345         },
346
347         NoticeFavor: function() {
348             $('.form_favor').each(function() { SN.U.FormXHR($(this)); });
349             $('.form_disfavor').each(function() { SN.U.FormXHR($(this)); });
350         },
351
352         NoticeRepeat: function() {
353             $('.form_repeat').each(function() {
354                 SN.U.FormXHR($(this));
355                 SN.U.NoticeRepeatConfirmation($(this));
356             });
357         },
358
359         NoticeRepeatConfirmation: function(form) {
360             function NRC() {
361                 form.closest('.notice-options').addClass('opaque');
362                 form.addClass('dialogbox');
363
364                 form.append('<button class="close">&#215;</button>');
365                 form.find('button.close').click(function(){
366                     $(this).remove();
367
368                     form.closest('.notice-options').removeClass('opaque');
369                     form.removeClass('dialogbox');
370                     form.find('.submit_dialogbox').remove();
371                     form.find('.submit').show();
372
373                     return false;
374                 });
375             };
376
377             form.find('.submit').bind('click', function(e) {
378                 e.preventDefault();
379
380                 var submit = form.find('.submit').clone();
381                 submit.addClass('submit_dialogbox');
382                 submit.removeClass('submit');
383                 form.append(submit);
384
385                 $(this).hide();
386
387                 NRC();
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 ($('.attachment', notice).length === 0) {
399                 return;
400             }
401
402             var notice_id = notice.attr('id');
403
404             $.fn.jOverlay.options = {
405                 method : 'GET',
406                 data : '',
407                 url : '',
408                 color : '#000',
409                 opacity : '0.6',
410                 zIndex : 9999,
411                 center : false,
412                 imgLoading : $('address .url')[0].href+'theme/base/images/illustrations/illu_progress_loading-01.gif',
413                 bgClickToClose : true,
414                 success : function() {
415                     $('#jOverlayContent').append('<button class="close">&#215;</button>');
416                     $('#jOverlayContent button').click($.closeOverlay);
417                 },
418                 timeout : 0,
419                 autoHide : true,
420                 css : {'max-width':'542px', 'top':'5%', 'left':'32.5%'}
421             };
422
423             $('#'+notice_id+' a.attachment').click(function() {
424                 $().jOverlay({url: $('address .url')[0].href+'attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'});
425                 return false;
426             });
427
428             var t;
429             $("body:not(#shownotice) #"+notice_id+" a.thumbnail").hover(
430                 function() {
431                     var anchor = $(this);
432                     $("a.thumbnail").children('img').hide();
433                     anchor.closest(".entry-title").addClass('ov');
434
435                     if (anchor.children('img').length === 0) {
436                         t = setTimeout(function() {
437                             $.get($('address .url')[0].href+'attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) {
438                                 anchor.append(data);
439                             });
440                         }, 500);
441                     }
442                     else {
443                         anchor.children('img').show();
444                     }
445                 },
446                 function() {
447                     clearTimeout(t);
448                     $("a.thumbnail").children('img').hide();
449                     $(this).closest(".entry-title").removeClass('ov');
450                 }
451             );
452         },
453
454         NoticeDataAttach: function() {
455             NDA = $('#'+SN.C.S.NoticeDataAttach);
456             NDA.change(function() {
457                 S = '<div id="'+SN.C.S.NoticeDataAttachSelected+'" class="'+SN.C.S.Success+'"><code>'+$(this).val()+'</code> <button class="close">&#215;</button></div>';
458                 NDAS = $('#'+SN.C.S.NoticeDataAttachSelected);
459                 if (NDAS.length > 0) {
460                     NDAS.replaceWith(S);
461                 }
462                 else {
463                     $('#'+SN.C.S.FormNotice).append(S);
464                 }
465                 $('#'+SN.C.S.NoticeDataAttachSelected+' button').click(function(){
466                     $('#'+SN.C.S.NoticeDataAttachSelected).remove();
467                     NDA.val('');
468
469                     return false;
470                 });
471             });
472         },
473
474         NoticeLocationAttach: function() {
475             var NLat = $('#'+SN.C.S.NoticeLat).val();
476             var NLon = $('#'+SN.C.S.NoticeLon).val();
477             var NLNS = $('#'+SN.C.S.NoticeLocationNs).val();
478             var NLID = $('#'+SN.C.S.NoticeLocationId).val();
479             var NLN = $('#'+SN.C.S.NoticeGeoName).text();
480             var NDGe = $('#'+SN.C.S.NoticeDataGeo);
481
482             function removeNoticeDataGeo() {
483                 $('label[for='+SN.C.S.NoticeDataGeo+']').removeClass('checked').attr('title', jQuery.trim($('label[for='+SN.C.S.NoticeDataGeo+']').text()));
484                 $('#'+SN.C.S.NoticeDataGeoSelected).hide();
485
486                 $('#'+SN.C.S.NoticeLat).val('');
487                 $('#'+SN.C.S.NoticeLon).val('');
488                 $('#'+SN.C.S.NoticeLocationNs).val('');
489                 $('#'+SN.C.S.NoticeLocationId).val('');
490                 $('#'+SN.C.S.NoticeDataGeo).attr('checked', false);
491
492                 $.cookie(SN.C.S.NoticeDataGeoCookie, 'disabled');
493             }
494
495             function getJSONgeocodeURL(geocodeURL, data) {
496                 $.getJSON(geocodeURL, data, function(location) {
497                     var lns, lid;
498
499                     if (typeof(location.location_ns) != 'undefined') {
500                         $('#'+SN.C.S.NoticeLocationNs).val(location.location_ns);
501                         lns = location.location_ns;
502                     }
503
504                     if (typeof(location.location_id) != 'undefined') {
505                         $('#'+SN.C.S.NoticeLocationId).val(location.location_id);
506                         lid = location.location_id;
507                     }
508
509                     if (typeof(location.name) == 'undefined') {
510                         NLN_text = position.coords.latitude + ';' + position.coords.longitude;
511                     }
512                     else {
513                         NLN_text = location.name;
514                     }
515
516                     $('#'+SN.C.S.NoticeGeoName)
517                         .replaceWith('<a id="notice_data-geo_name"/>');
518
519                     $('#'+SN.C.S.NoticeGeoName)
520                         .attr('href', location.url)
521                         .text(NLN_text)
522                         .click(function() {
523                             window.open(location.url);
524
525                             return false;
526                         });
527
528                     $('#'+SN.C.S.NoticeLat).val(data.lat);
529                     $('#'+SN.C.S.NoticeLon).val(data.lon);
530                     $('#'+SN.C.S.NoticeLocationNs).val(lns);
531                     $('#'+SN.C.S.NoticeLocationId).val(lid);
532                     $('#'+SN.C.S.NoticeDataGeo).attr('checked', true);
533
534                     var cookieValue = {
535                         'NLat': data.lat,
536                         'NLon': data.lon,
537                         'NLNS': lns,
538                         'NLID': lid,
539                         'NLN': NLN_text,
540                         'NLNU': location.url,
541                         'NDG': true,
542                         'NDGSM': false
543                     };
544                     $.cookie(SN.C.S.NoticeDataGeoCookie, JSON.stringify(cookieValue));
545                 });
546             }
547
548             if (NDGe.length > 0) {
549                 if ($.cookie(SN.C.S.NoticeDataGeoCookie) == 'disabled') {
550                     NDGe.attr('checked', false);
551                 }
552                 else {
553                     NDGe.attr('checked', true);
554                 }
555
556                 var NGW = $('#notice_data-geo_wrap');
557                 var geocodeURL = NGW.attr('title');
558                 NGW.removeAttr('title');
559
560                 $('label[for='+SN.C.S.NoticeDataGeo+']').attr('title', jQuery.trim($('label[for='+SN.C.S.NoticeDataGeo+']').text()));
561
562                 NDGe.change(function() {
563                     var NLN = $('#'+SN.C.S.NoticeGeoName);
564                     if (NLN.length > 0) {
565                         NLN.remove();
566                     }
567
568                     if ($('#'+SN.C.S.NoticeDataGeo).attr('checked') === true || $.cookie(SN.C.S.NoticeDataGeoCookie) === null) {
569                         $('label[for='+SN.C.S.NoticeDataGeo+']').addClass('checked').attr('title', NoticeDataGeoShareDisable_text);
570
571                         var S = '<div id="'+SN.C.S.NoticeDataGeoSelected+'" class="'+SN.C.S.Success+'"/>';
572                         var NDGS = $('#'+SN.C.S.NoticeDataGeoSelected);
573
574                         if (NDGS.length > 0) {
575                             NDGS.replaceWith(S);
576                         }
577                         else {
578                             $('#'+SN.C.S.FormNotice).append(S);
579                         }
580
581                         NDGS = $('#'+SN.C.S.NoticeDataGeoSelected);
582                         NDGS.prepend('<span id="'+SN.C.S.NoticeGeoName+'">Geo</span> <button class="minimize" title="'+NoticeDataGeoInfoMinimize_text+'">&#95;</button> <button class="close" title="'+NoticeDataGeoShareDisable_text+'">&#215;</button>');
583
584                         var NLN = $('#'+SN.C.S.NoticeGeoName);
585                         NLN.addClass('processing');
586
587                         $('#'+SN.C.S.NoticeDataGeoSelected+' button.close').click(function(){
588                             removeNoticeDataGeo();
589
590                             $('#'+SN.C.S.NoticeDataGeoSelected).remove();
591
592                             $('#'+SN.C.S.NoticeDataText).focus();
593
594                             return false;
595                         });
596
597                         $('#'+SN.C.S.NoticeDataGeoSelected+' button.minimize').click(function(){
598                             $('#'+SN.C.S.NoticeDataGeoSelected).hide();
599
600                             var cookieValue = {
601                                 'NLat': $('#'+SN.C.S.NoticeLat).val(),
602                                 'NLon': $('#'+SN.C.S.NoticeLat).val(),
603                                 'NLNS': $('#'+SN.C.S.NoticeLocationNs).val(),
604                                 'NLID': $('#'+SN.C.S.NoticeLocationId).val(),
605                                 'NLN': $('#'+SN.C.S.NoticeGeoName).text(),
606                                 'NLNU': $('#'+SN.C.S.NoticeGeoName).attr('href'),
607                                 'NDG': true,
608                                 'NDGSM': true
609                             };
610                             $.cookie(SN.C.S.NoticeDataGeoCookie, JSON.stringify(cookieValue));
611
612                             $('#'+SN.C.S.NoticeDataText).focus();
613
614                             return false;
615                         });
616
617                         if ($.cookie(SN.C.S.NoticeDataGeoCookie) === null || $.cookie(SN.C.S.NoticeDataGeoCookie) == 'disabled') {
618                             if (navigator.geolocation) {
619                                 navigator.geolocation.getCurrentPosition(
620                                     function(position) {
621                                         $('#'+SN.C.S.NoticeLat).val(position.coords.latitude);
622                                         $('#'+SN.C.S.NoticeLon).val(position.coords.longitude);
623
624                                         var data = {
625                                             'lat': position.coords.latitude,
626                                             'lon': position.coords.longitude,
627                                             'token': $('#token').val()
628                                         };
629
630                                         getJSONgeocodeURL(geocodeURL, data);
631                                     },
632
633                                     function(error) {
634                                         if (error.PERMISSION_DENIED == 1) {
635                                             removeNoticeDataGeo();
636                                         }
637                                     }
638                                 );
639                             }
640                             else {
641                                 if (NLat.length > 0 && NLon.length > 0) {
642                                     var data = {
643                                         'lat': NLat,
644                                         'lon': NLon,
645                                         'token': $('#token').val()
646                                     };
647
648                                     getJSONgeocodeURL(geocodeURL, data);
649                                 }
650                                 else {
651                                     removeNoticeDataGeo();
652                                     $('#'+SN.C.S.NoticeDataGeo).remove();
653                                     $('label[for='+SN.C.S.NoticeDataGeo+']').remove();
654                                 }
655                             }
656                         }
657                         else {
658                             var cookieValue = JSON.parse($.cookie(SN.C.S.NoticeDataGeoCookie));
659
660                             if (cookieValue.NDGSM === true) {
661                                 $('#'+SN.C.S.NoticeDataGeoSelected).hide();
662                             }
663
664                             $('#'+SN.C.S.NoticeLat).val(cookieValue.NLat);
665                             $('#'+SN.C.S.NoticeLon).val(cookieValue.NLon);
666                             $('#'+SN.C.S.NoticeLocationNs).val(cookieValue.NLNS);
667                             $('#'+SN.C.S.NoticeLocationId).val(cookieValue.NLID);
668                             $('#'+SN.C.S.NoticeDataGeo).attr('checked', cookieValue.NDG);
669
670                             $('#'+SN.C.S.NoticeGeoName)
671                                 .replaceWith('<a id="notice_data-geo_name"/>');
672
673                             $('#'+SN.C.S.NoticeGeoName)
674                                 .attr('href', cookieValue.NLNU)
675                                 .text(cookieValue.NLN)
676                                 .click(function() {
677                                     window.open($(this).attr('href'));
678
679                                     return false;
680                                 });
681                         }
682                     }
683                     else {
684                         removeNoticeDataGeo();
685                     }
686
687                     $('#'+SN.C.S.NoticeDataText).focus();
688                 }).change();
689             }
690         },
691
692         NewDirectMessage: function() {
693             NDM = $('.entity_send-a-message a');
694             NDM.attr({'href':NDM.attr('href')+'&ajax=1'});
695             NDM.bind('click', function() {
696                 var NDMF = $('.entity_send-a-message form');
697                 if (NDMF.length === 0) {
698                     $(this).addClass('processing');
699                     $.get(NDM.attr('href'), null, function(data) {
700                         $('.entity_send-a-message').append(document._importNode($('form', data)[0], true));
701                         NDMF = $('.entity_send-a-message .form_notice');
702                         SN.U.FormNoticeXHR(NDMF);
703                         SN.U.FormNoticeEnhancements(NDMF);
704                         NDMF.append('<button class="close">&#215;</button>');
705                         $('.entity_send-a-message button').click(function(){
706                             NDMF.hide();
707                             return false;
708                         });
709                         NDM.removeClass('processing');
710                     });
711                 }
712                 else {
713                     NDMF.show();
714                     $('.entity_send-a-message textarea').focus();
715                 }
716                 return false;
717             });
718         }
719     },
720
721     Init: {
722         NoticeForm: function() {
723             if ($('body.user_in').length > 0) {
724                 SN.U.NoticeLocationAttach();
725
726                 $('.'+SN.C.S.FormNotice).each(function() {
727                     SN.U.FormNoticeXHR($(this));
728                     SN.U.FormNoticeEnhancements($(this));
729                 });
730
731                 SN.U.NoticeDataAttach();
732             }
733         },
734
735         Notices: function() {
736             if ($('body.user_in').length > 0) {
737                 SN.U.NoticeFavor();
738                 SN.U.NoticeRepeat();
739                 SN.U.NoticeReply();
740             }
741
742             SN.U.NoticeAttachments();
743         },
744
745         EntityActions: function() {
746             if ($('body.user_in').length > 0) {
747                 $('.form_user_subscribe').each(function() { SN.U.FormXHR($(this)); });
748                 $('.form_user_unsubscribe').each(function() { SN.U.FormXHR($(this)); });
749                 $('.form_group_join').each(function() { SN.U.FormXHR($(this)); });
750                 $('.form_group_leave').each(function() { SN.U.FormXHR($(this)); });
751                 $('.form_user_nudge').each(function() { SN.U.FormXHR($(this)); });
752
753                 SN.U.NewDirectMessage();
754             }
755         }
756     }
757 };
758
759 $(document).ready(function(){
760     if ($('.'+SN.C.S.FormNotice).length > 0) {
761         SN.Init.NoticeForm();
762     }
763     if ($('#content .notices').length > 0) {
764         SN.Init.Notices();
765     }
766     if ($('#content .entity_actions').length > 0) {
767         SN.Init.EntityActions();
768     }
769 });
770