2 * StatusNet - a distributed open-source microblogging tool
3 * Copyright (C) 2008, StatusNet, Inc.
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.
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.
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/>.
18 * @category UI interaction
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/
27 var SN = { // StatusNet
30 CounterBlackout: false,
32 PatternUsername: /^[0-9a-zA-Z\-_.]*$/,
33 HTTP20x30x: [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307]
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'
64 if (typeof SN.messages[key] == "undefined") {
65 return '[' + key + ']';
67 return SN.messages[key];
72 FormNoticeEnhancements: function(form) {
73 if (jQuery.data(form[0], 'ElementData') === undefined) {
74 MaxLength = form.find('#'+SN.C.S.NoticeTextCount).text();
75 if (typeof(MaxLength) == 'undefined') {
76 MaxLength = SN.C.I.MaxLength;
78 jQuery.data(form[0], 'ElementData', {MaxLength:MaxLength});
82 NDT = form.find('#'+SN.C.S.NoticeDataText);
84 NDT.bind('keyup', function(e) {
88 NDT.bind('keydown', function(e) {
89 SN.U.SubmitOnReturn(e, form);
93 form.find('#'+SN.C.S.NoticeTextCount).text(jQuery.data(form[0], 'ElementData').MaxLength);
96 if ($('body')[0].id != 'conversation' && window.location.hash.length === 0 && $(window).scrollTop() == 0) {
97 form.find('textarea').focus();
101 SubmitOnReturn: function(event, el) {
102 if (event.keyCode == 13 || event.keyCode == 10) {
104 event.preventDefault();
105 event.stopPropagation();
106 $('#'+el[0].id+' #'+SN.C.S.NoticeDataText).blur();
113 Counter: function(form) {
114 SN.C.I.FormNoticeCurrent = form;
116 var MaxLength = jQuery.data(form[0], 'ElementData').MaxLength;
118 if (MaxLength <= 0) {
122 var remaining = MaxLength - SN.U.CharacterCount(form);
123 var counter = form.find('#'+SN.C.S.NoticeTextCount);
125 if (remaining.toString() != counter.text()) {
126 if (!SN.C.I.CounterBlackout || remaining === 0) {
127 if (counter.text() != String(remaining)) {
128 counter.text(remaining);
131 form.addClass(SN.C.S.Warning);
133 form.removeClass(SN.C.S.Warning);
135 // Skip updates for the next 500ms.
136 // On slower hardware, updating on every keypress is unpleasant.
137 if (!SN.C.I.CounterBlackout) {
138 SN.C.I.CounterBlackout = true;
139 SN.C.I.FormNoticeCurrent = form;
140 window.setTimeout("SN.U.ClearCounterBlackout(SN.C.I.FormNoticeCurrent);", 500);
146 CharacterCount: function(form) {
147 return form.find('#'+SN.C.S.NoticeDataText).val().length;
150 ClearCounterBlackout: function(form) {
151 // Allow keyup events to poke the counter again
152 SN.C.I.CounterBlackout = false;
153 // Check if the string changed since we last looked
157 FormXHR: function(form) {
161 url: form.attr('action'),
162 data: form.serialize() + '&ajax=1',
163 beforeSend: function(xhr) {
165 .addClass(SN.C.S.Processing)
167 .addClass(SN.C.S.Disabled)
168 .attr(SN.C.S.Disabled, SN.C.S.Disabled);
170 error: function (xhr, textStatus, errorThrown) {
171 alert(errorThrown || textStatus);
173 success: function(data, textStatus) {
174 if (typeof($('form', data)[0]) != 'undefined') {
175 form_new = document._importNode($('form', data)[0], true);
176 form.replaceWith(form_new);
179 form.replaceWith(document._importNode($('p', data)[0], true));
185 FormNoticeXHR: function(form) {
186 SN.C.I.NoticeDataGeo = {};
187 form.append('<input type="hidden" name="ajax" value="1"/>');
191 beforeSend: function(formData) {
192 if (form.find('#'+SN.C.S.NoticeDataText)[0].value.length === 0) {
193 form.addClass(SN.C.S.Warning);
197 .addClass(SN.C.S.Processing)
198 .find('#'+SN.C.S.NoticeActionSubmit)
199 .addClass(SN.C.S.Disabled)
200 .attr(SN.C.S.Disabled, SN.C.S.Disabled);
202 SN.C.I.NoticeDataGeo.NLat = $('#'+SN.C.S.NoticeLat).val();
203 SN.C.I.NoticeDataGeo.NLon = $('#'+SN.C.S.NoticeLon).val();
204 SN.C.I.NoticeDataGeo.NLNS = $('#'+SN.C.S.NoticeLocationNs).val();
205 SN.C.I.NoticeDataGeo.NLID = $('#'+SN.C.S.NoticeLocationId).val();
206 SN.C.I.NoticeDataGeo.NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked');
208 cookieValue = $.cookie(SN.C.S.NoticeDataGeoCookie);
210 if (cookieValue !== null && cookieValue != 'disabled') {
211 cookieValue = JSON.parse(cookieValue);
212 SN.C.I.NoticeDataGeo.NLat = $('#'+SN.C.S.NoticeLat).val(cookieValue.NLat).val();
213 SN.C.I.NoticeDataGeo.NLon = $('#'+SN.C.S.NoticeLon).val(cookieValue.NLon).val();
214 if ($('#'+SN.C.S.NoticeLocationNs).val(cookieValue.NLNS)) {
215 SN.C.I.NoticeDataGeo.NLNS = $('#'+SN.C.S.NoticeLocationNs).val(cookieValue.NLNS).val();
216 SN.C.I.NoticeDataGeo.NLID = $('#'+SN.C.S.NoticeLocationId).val(cookieValue.NLID).val();
219 if (cookieValue == 'disabled') {
220 SN.C.I.NoticeDataGeo.NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked', false).attr('checked');
223 SN.C.I.NoticeDataGeo.NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked', true).attr('checked');
228 error: function (xhr, textStatus, errorThrown) {
230 .removeClass(SN.C.S.Processing)
231 .find('#'+SN.C.S.NoticeActionSubmit)
232 .removeClass(SN.C.S.Disabled)
233 .removeAttr(SN.C.S.Disabled, SN.C.S.Disabled);
234 form.find('.form_response').remove();
235 if (textStatus == 'timeout') {
236 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>');
239 if ($('.'+SN.C.S.Error, xhr.responseXML).length > 0) {
240 form.append(document._importNode($('.'+SN.C.S.Error, xhr.responseXML)[0], true));
243 if (parseInt(xhr.status) === 0 || jQuery.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) >= 0) {
246 .find('#'+SN.C.S.NoticeDataAttachSelected).remove();
247 SN.U.FormNoticeEnhancements(form);
250 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>');
255 success: function(data, textStatus) {
256 form.find('.form_response').remove();
258 if ($('#'+SN.C.S.Error, data).length > 0) {
259 result = document._importNode($('p', data)[0], true);
260 result = result.textContent || result.innerHTML;
261 form.append('<p class="form_response error">'+result+'</p>');
264 if($('body')[0].id == 'bookmarklet') {
268 if ($('#'+SN.C.S.CommandResult, data).length > 0) {
269 result = document._importNode($('p', data)[0], true);
270 result = result.textContent || result.innerHTML;
271 form.append('<p class="form_response success">'+result+'</p>');
274 // New notice post was successful. If on our timeline, show it!
275 var notice = document._importNode($('li', data)[0], true);
276 var notices = $('#notices_primary .notices');
277 if (notices.length > 0 && SN.U.belongsOnTimeline(notice)) {
278 if ($('#'+notice.id).length === 0) {
279 var notice_irt_value = $('#'+SN.C.S.NoticeInReplyTo).val();
280 var notice_irt = '#notices_primary #notice-'+notice_irt_value;
281 if($('body')[0].id == 'conversation') {
282 if(notice_irt_value.length > 0 && $(notice_irt+' .notices').length < 1) {
283 $(notice_irt).append('<ul class="notices"></ul>');
285 $($(notice_irt+' .notices')[0]).append(notice);
288 notices.prepend(notice);
291 .css({display:'none'})
293 SN.U.NoticeWithAttachment($('#'+notice.id));
294 SN.U.NoticeReplyTo($('#'+notice.id));
298 // Not on a timeline that this belongs on?
299 // Just show a success message.
300 result = document._importNode($('title', data)[0], true);
301 result_title = result.textContent || result.innerHTML;
302 form.append('<p class="form_response success">'+result_title+'</p>');
306 form.find('#'+SN.C.S.NoticeInReplyTo).val('');
307 form.find('#'+SN.C.S.NoticeDataAttachSelected).remove();
308 SN.U.FormNoticeEnhancements(form);
311 complete: function(xhr, textStatus) {
313 .removeClass(SN.C.S.Processing)
314 .find('#'+SN.C.S.NoticeActionSubmit)
315 .removeAttr(SN.C.S.Disabled)
316 .removeClass(SN.C.S.Disabled);
318 $('#'+SN.C.S.NoticeLat).val(SN.C.I.NoticeDataGeo.NLat);
319 $('#'+SN.C.S.NoticeLon).val(SN.C.I.NoticeDataGeo.NLon);
320 if ($('#'+SN.C.S.NoticeLocationNs)) {
321 $('#'+SN.C.S.NoticeLocationNs).val(SN.C.I.NoticeDataGeo.NLNS);
322 $('#'+SN.C.S.NoticeLocationId).val(SN.C.I.NoticeDataGeo.NLID);
324 $('#'+SN.C.S.NoticeDataGeo).attr('checked', SN.C.I.NoticeDataGeo.NDG);
329 NoticeReply: function() {
330 if ($('#'+SN.C.S.NoticeDataText).length > 0 && $('#content .notice_reply').length > 0) {
331 $('#content .notice').each(function() { SN.U.NoticeReplyTo($(this)); });
335 NoticeReplyTo: function(notice) {
336 notice.find('.notice_reply').live('click', function() {
337 var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname.uid');
338 SN.U.NoticeReplySet(nickname.text(), $($('.notice_id', notice)[0]).text());
343 NoticeReplySet: function(nick,id) {
344 if (nick.match(SN.C.I.PatternUsername)) {
345 var text = $('#'+SN.C.S.NoticeDataText);
346 if (text.length > 0) {
347 replyto = '@' + nick + ' ';
348 text.val(replyto + text.val().replace(RegExp(replyto, 'i'), ''));
349 $('#'+SN.C.S.FormNotice+' #'+SN.C.S.NoticeInReplyTo).val(id);
352 if (text[0].setSelectionRange) {
353 var len = text.val().length;
354 text[0].setSelectionRange(len,len);
360 NoticeFavor: function() {
361 $('.form_favor').live('click', function() { SN.U.FormXHR($(this)); return false; });
362 $('.form_disfavor').live('click', function() { SN.U.FormXHR($(this)); return false; });
365 NoticeRepeat: function() {
366 $('.form_repeat').live('click', function(e) {
369 SN.U.NoticeRepeatConfirmation($(this));
374 NoticeRepeatConfirmation: function(form) {
375 var submit_i = form.find('.submit');
377 var submit = submit_i.clone();
379 .addClass('submit_dialogbox')
380 .removeClass('submit');
382 submit.bind('click', function() { SN.U.FormXHR(form); return false; });
387 .addClass('dialogbox')
388 .append('<button class="close">×</button>')
389 .closest('.notice-options')
392 form.find('button.close').click(function(){
396 .removeClass('dialogbox')
397 .closest('.notice-options')
398 .removeClass('opaque');
400 form.find('.submit_dialogbox').remove();
401 form.find('.submit').show();
407 NoticeAttachments: function() {
408 $('.notice a.attachment').each(function() {
409 SN.U.NoticeWithAttachment($(this).closest('.notice'));
413 NoticeWithAttachment: function(notice) {
414 if (notice.find('.attachment').length === 0) {
418 var attachment_more = notice.find('.attachment.more');
419 if (attachment_more.length > 0) {
420 $(attachment_more[0]).click(function() {
422 m.addClass(SN.C.S.Processing);
423 $.get(m.attr('href')+'/ajax', null, function(data) {
424 m.parent('.entry-content').html($(data).find('#attachment_view .entry-content').html());
428 }).attr('title', SN.msg('showmore_tooltip'));
431 //imgLoading : $('address .url')[0].href+'theme/base/images/illustrations/illu_progress_loading-01.gif',
433 notice.find('a.attachment').each(function() {
435 var attachId = ($(this).attr('id').substring('attachment'.length + 1));
437 var thumbUrl = $('address .url')[0].href+'attachment/' + attachId + '/thumb';
438 var thumb = $('<div class="attachment-thumb">Thumb: <img/></div>');
439 thumb.find('img').attr('src', thumbUrl).last();
440 notice.find('.entry-title .entry-content').append(thumb);
445 if ($('#shownotice').length == 0) {
448 notice.find('a.thumbnail').hover(
450 var anchor = $(this);
451 $('a.thumbnail').children('img').hide();
452 anchor.closest(".entry-title").addClass('ov');
454 if (anchor.children('img').length === 0) {
455 t = setTimeout(function() {
456 $.get($('address .url')[0].href+'attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) {
462 anchor.children('img').show();
467 $('a.thumbnail').children('img').hide();
468 $(this).closest('.entry-title').removeClass('ov');
476 NoticeDataAttach: function() {
477 NDA = $('#'+SN.C.S.NoticeDataAttach);
478 NDA.change(function() {
479 S = '<div id="'+SN.C.S.NoticeDataAttachSelected+'" class="'+SN.C.S.Success+'"><code>'+$(this).val()+'</code> <button class="close">×</button></div>';
480 NDAS = $('#'+SN.C.S.NoticeDataAttachSelected);
481 if (NDAS.length > 0) {
485 $('#'+SN.C.S.FormNotice).append(S);
487 $('#'+SN.C.S.NoticeDataAttachSelected+' button').click(function(){
488 $('#'+SN.C.S.NoticeDataAttachSelected).remove();
496 NoticeLocationAttach: function() {
497 var NLat = $('#'+SN.C.S.NoticeLat).val();
498 var NLon = $('#'+SN.C.S.NoticeLon).val();
499 var NLNS = $('#'+SN.C.S.NoticeLocationNs).val();
500 var NLID = $('#'+SN.C.S.NoticeLocationId).val();
501 var NLN = $('#'+SN.C.S.NoticeGeoName).text();
502 var NDGe = $('#'+SN.C.S.NoticeDataGeo);
504 function removeNoticeDataGeo() {
505 $('label[for='+SN.C.S.NoticeDataGeo+']')
506 .attr('title', jQuery.trim($('label[for='+SN.C.S.NoticeDataGeo+']').text()))
507 .removeClass('checked');
509 $('#'+SN.C.S.NoticeLat).val('');
510 $('#'+SN.C.S.NoticeLon).val('');
511 $('#'+SN.C.S.NoticeLocationNs).val('');
512 $('#'+SN.C.S.NoticeLocationId).val('');
513 $('#'+SN.C.S.NoticeDataGeo).attr('checked', false);
515 $.cookie(SN.C.S.NoticeDataGeoCookie, 'disabled', { path: '/' });
518 function getJSONgeocodeURL(geocodeURL, data) {
519 $.getJSON(geocodeURL, data, function(location) {
522 if (typeof(location.location_ns) != 'undefined') {
523 $('#'+SN.C.S.NoticeLocationNs).val(location.location_ns);
524 lns = location.location_ns;
527 if (typeof(location.location_id) != 'undefined') {
528 $('#'+SN.C.S.NoticeLocationId).val(location.location_id);
529 lid = location.location_id;
532 if (typeof(location.name) == 'undefined') {
533 NLN_text = data.lat + ';' + data.lon;
536 NLN_text = location.name;
539 $('label[for='+SN.C.S.NoticeDataGeo+']')
540 .attr('title', NoticeDataGeo_text.ShareDisable + ' (' + NLN_text + ')');
542 $('#'+SN.C.S.NoticeLat).val(data.lat);
543 $('#'+SN.C.S.NoticeLon).val(data.lon);
544 $('#'+SN.C.S.NoticeLocationNs).val(lns);
545 $('#'+SN.C.S.NoticeLocationId).val(lid);
546 $('#'+SN.C.S.NoticeDataGeo).attr('checked', true);
558 $.cookie(SN.C.S.NoticeDataGeoCookie, JSON.stringify(cookieValue), { path: '/' });
562 if (NDGe.length > 0) {
563 if ($.cookie(SN.C.S.NoticeDataGeoCookie) == 'disabled') {
564 NDGe.attr('checked', false);
567 NDGe.attr('checked', true);
570 var NGW = $('#notice_data-geo_wrap');
571 var geocodeURL = NGW.attr('title');
572 NGW.removeAttr('title');
574 $('label[for='+SN.C.S.NoticeDataGeo+']')
575 .attr('title', jQuery.trim($('label[for='+SN.C.S.NoticeDataGeo+']').text()));
577 NDGe.change(function() {
578 if ($('#'+SN.C.S.NoticeDataGeo).attr('checked') === true || $.cookie(SN.C.S.NoticeDataGeoCookie) === null) {
579 $('label[for='+SN.C.S.NoticeDataGeo+']')
580 .attr('title', NoticeDataGeo_text.ShareDisable)
581 .addClass('checked');
583 if ($.cookie(SN.C.S.NoticeDataGeoCookie) === null || $.cookie(SN.C.S.NoticeDataGeoCookie) == 'disabled') {
584 if (navigator.geolocation) {
585 navigator.geolocation.getCurrentPosition(
587 $('#'+SN.C.S.NoticeLat).val(position.coords.latitude);
588 $('#'+SN.C.S.NoticeLon).val(position.coords.longitude);
591 lat: position.coords.latitude,
592 lon: position.coords.longitude,
593 token: $('#token').val()
596 getJSONgeocodeURL(geocodeURL, data);
601 case error.PERMISSION_DENIED:
602 removeNoticeDataGeo();
605 $('#'+SN.C.S.NoticeDataGeo).attr('checked', false);
616 if (NLat.length > 0 && NLon.length > 0) {
620 token: $('#token').val()
623 getJSONgeocodeURL(geocodeURL, data);
626 removeNoticeDataGeo();
627 $('#'+SN.C.S.NoticeDataGeo).remove();
628 $('label[for='+SN.C.S.NoticeDataGeo+']').remove();
633 var cookieValue = JSON.parse($.cookie(SN.C.S.NoticeDataGeoCookie));
635 $('#'+SN.C.S.NoticeLat).val(cookieValue.NLat);
636 $('#'+SN.C.S.NoticeLon).val(cookieValue.NLon);
637 $('#'+SN.C.S.NoticeLocationNs).val(cookieValue.NLNS);
638 $('#'+SN.C.S.NoticeLocationId).val(cookieValue.NLID);
639 $('#'+SN.C.S.NoticeDataGeo).attr('checked', cookieValue.NDG);
641 $('label[for='+SN.C.S.NoticeDataGeo+']')
642 .attr('title', NoticeDataGeo_text.ShareDisable + ' (' + cookieValue.NLN + ')')
643 .addClass('checked');
647 removeNoticeDataGeo();
653 NewDirectMessage: function() {
654 NDM = $('.entity_send-a-message a');
655 NDM.attr({'href':NDM.attr('href')+'&ajax=1'});
656 NDM.bind('click', function() {
657 var NDMF = $('.entity_send-a-message form');
658 if (NDMF.length === 0) {
659 $(this).addClass(SN.C.S.Processing);
660 $.get(NDM.attr('href'), null, function(data) {
661 $('.entity_send-a-message').append(document._importNode($('form', data)[0], true));
662 NDMF = $('.entity_send-a-message .form_notice');
663 SN.U.FormNoticeXHR(NDMF);
664 SN.U.FormNoticeEnhancements(NDMF);
665 NDMF.append('<button class="close">×</button>');
666 $('.entity_send-a-message button').click(function(){
670 NDM.removeClass(SN.C.S.Processing);
675 $('.entity_send-a-message textarea').focus();
681 GetFullYear: function(year, month, day) {
682 var date = new Date();
683 date.setFullYear(year, month, day);
689 Set: function(value) {
690 var SNI = SN.U.StatusNetInstance.Get();
692 value = $.extend(SNI, value);
696 SN.C.S.StatusNetInstance,
697 JSON.stringify(value),
700 expires: SN.U.GetFullYear(2029, 0, 1)
705 var cookieValue = $.cookie(SN.C.S.StatusNetInstance);
706 if (cookieValue !== null) {
707 return JSON.parse(cookieValue);
713 $.cookie(SN.C.S.StatusNetInstance, null);
718 * Check if the current page is a timeline where the current user's
719 * posts should be displayed immediately on success.
721 * @fixme this should be done in a saner way, with machine-readable
722 * info about what page we're looking at.
724 belongsOnTimeline: function(notice) {
725 var action = $("body").attr('id');
726 if (action == 'public') {
730 var profileLink = $('#nav_profile a').attr('href');
732 var authorUrl = $(notice).find('.entry-title .author a.url').attr('href');
733 if (authorUrl == profileLink) {
734 if (action == 'all' || action == 'showstream') {
735 // Posts always show on your own friends and profile streams.
741 // @fixme tag, group, reply timelines should be feasible as well.
742 // Mismatch between id-based and name-based user/group links currently complicates
743 // the lookup, since all our inline mentions contain the absolute links but the
744 // UI links currently on the page use malleable names.
751 NoticeForm: function() {
752 if ($('body.user_in').length > 0) {
753 SN.U.NoticeLocationAttach();
755 $('.'+SN.C.S.FormNotice).each(function() {
756 SN.U.FormNoticeXHR($(this));
757 SN.U.FormNoticeEnhancements($(this));
760 SN.U.NoticeDataAttach();
764 Notices: function() {
765 if ($('body.user_in').length > 0) {
771 SN.U.NoticeAttachments();
774 EntityActions: function() {
775 if ($('body.user_in').length > 0) {
776 $('.form_user_subscribe').live('click', function() { SN.U.FormXHR($(this)); return false; });
777 $('.form_user_unsubscribe').live('click', function() { SN.U.FormXHR($(this)); return false; });
778 $('.form_group_join').live('click', function() { SN.U.FormXHR($(this)); return false; });
779 $('.form_group_leave').live('click', function() { SN.U.FormXHR($(this)); return false; });
780 $('.form_user_nudge').live('click', function() { SN.U.FormXHR($(this)); return false; });
782 SN.U.NewDirectMessage();
787 if (SN.U.StatusNetInstance.Get() !== null) {
788 var nickname = SN.U.StatusNetInstance.Get().Nickname;
789 if (nickname !== null) {
790 $('#form_login #nickname').val(nickname);
794 $('#form_login').bind('submit', function() {
795 SN.U.StatusNetInstance.Set({Nickname: $('#form_login #nickname').val()});
802 $(document).ready(function(){
803 if ($('.'+SN.C.S.FormNotice).length > 0) {
804 SN.Init.NoticeForm();
806 if ($('#content .notices').length > 0) {
809 if ($('#content .entity_actions').length > 0) {
810 SN.Init.EntityActions();
812 if ($('#form_login').length > 0) {
817 // Formerly in xbImportNode.js
819 /* is this stuff defined? */
820 if (!document.ELEMENT_NODE) {
821 document.ELEMENT_NODE = 1;
822 document.ATTRIBUTE_NODE = 2;
823 document.TEXT_NODE = 3;
824 document.CDATA_SECTION_NODE = 4;
825 document.ENTITY_REFERENCE_NODE = 5;
826 document.ENTITY_NODE = 6;
827 document.PROCESSING_INSTRUCTION_NODE = 7;
828 document.COMMENT_NODE = 8;
829 document.DOCUMENT_NODE = 9;
830 document.DOCUMENT_TYPE_NODE = 10;
831 document.DOCUMENT_FRAGMENT_NODE = 11;
832 document.NOTATION_NODE = 12;
835 document._importNode = function(node, allChildren) {
836 /* find the node type to import */
837 switch (node.nodeType) {
838 case document.ELEMENT_NODE:
839 /* create a new element */
840 var newNode = document.createElement(node.nodeName);
841 /* does the node have any attributes to add? */
842 if (node.attributes && node.attributes.length > 0)
843 /* add all of the attributes */
844 for (var i = 0, il = node.attributes.length; i < il;) {
845 if (node.attributes[i].nodeName == 'class') {
846 newNode.className = node.getAttribute(node.attributes[i++].nodeName);
848 newNode.setAttribute(node.attributes[i].nodeName, node.getAttribute(node.attributes[i++].nodeName));
851 /* are we going after children too, and does the node have any? */
852 if (allChildren && node.childNodes && node.childNodes.length > 0)
853 /* recursively get all of the child nodes */
854 for (var i = 0, il = node.childNodes.length; i < il;)
855 newNode.appendChild(document._importNode(node.childNodes[i++], allChildren));
858 case document.TEXT_NODE:
859 case document.CDATA_SECTION_NODE:
860 case document.COMMENT_NODE:
861 return document.createTextNode(node.nodeValue);
866 // A shim to implement the W3C Geolocation API Specification using Gears or the Ajax API
867 if (typeof navigator.geolocation == "undefined" || navigator.geolocation.shim ) { (function(){
869 // -- BEGIN GEARS_INIT
871 // We are already defined. Hooray!
872 if (window.google && google.gears) {
879 if (typeof GearsFactory != 'undefined') {
880 factory = new GearsFactory();
884 factory = new ActiveXObject('Gears.Factory');
885 // privateSetGlobalObject is only required and supported on WinCE.
886 if (factory.getBuildInfo().indexOf('ie_mobile') != -1) {
887 factory.privateSetGlobalObject(this);
891 if ((typeof navigator.mimeTypes != 'undefined') && navigator.mimeTypes["application/x-googlegears"]) {
892 factory = document.createElement("object");
893 factory.style.display = "none";
896 factory.type = "application/x-googlegears";
897 document.documentElement.appendChild(factory);
902 // *Do not* define any objects if Gears is not installed. This mimics the
903 // behavior of Gears defining the objects in the future.
908 // Now set up the objects, being careful not to overwrite anything.
910 // Note: In Internet Explorer for Windows Mobile, you can't add properties to
911 // the window object. However, global objects are automatically added as
912 // properties of the window object in all browsers.
913 if (!window.google) {
918 google.gears = {factory: factory};
923 var GearsGeoLocation = (function() {
925 var geo = google.gears.factory.create('beta.geolocation');
927 var wrapSuccess = function(callback, self) { // wrap it for lastPosition love
928 return function(position) {
930 self.lastPosition = position;
942 getCurrentPosition: function(successCallback, errorCallback, options) {
944 var sc = wrapSuccess(successCallback, self);
945 geo.getCurrentPosition(sc, errorCallback, options);
948 watchPosition: function(successCallback, errorCallback, options) {
949 geo.watchPosition(successCallback, errorCallback, options);
952 clearWatch: function(watchId) {
953 geo.clearWatch(watchId);
956 getPermission: function(siteName, imageUrl, extraMessage) {
957 geo.getPermission(siteName, imageUrl, extraMessage);
963 var AjaxGeoLocation = (function() {
966 var loadGoogleLoader = function() {
967 if (!hasGoogleLoader() && !loading) {
969 var s = document.createElement('script');
970 s.src = (document.location.protocol == "https:"?"https://":"http://") + 'www.google.com/jsapi?callback=_google_loader_apiLoaded';
971 s.type = "text/javascript";
972 document.getElementsByTagName('body')[0].appendChild(s);
977 var addLocationQueue = function(callback) {
978 queue.push(callback);
981 var runLocationQueue = function() {
982 if (hasGoogleLoader()) {
983 while (queue.length > 0) {
984 var call = queue.pop();
990 window['_google_loader_apiLoaded'] = function() {
994 var hasGoogleLoader = function() {
995 return (window['google'] && google['loader']);
998 var checkGoogleLoader = function(callback) {
999 if (hasGoogleLoader()) { return true; }
1001 addLocationQueue(callback);
1008 loadGoogleLoader(); // start to load as soon as possible just in case
1014 type: "ClientLocation",
1018 getCurrentPosition: function(successCallback, errorCallback, options) {
1020 if (!checkGoogleLoader(function() {
1021 self.getCurrentPosition(successCallback, errorCallback, options);
1024 if (google.loader.ClientLocation) {
1025 var cl = google.loader.ClientLocation;
1029 latitude: cl.latitude,
1030 longitude: cl.longitude,
1032 accuracy: 43000, // same as Gears accuracy over wifi?
1033 altitudeAccuracy: null,
1037 // extra info that is outside of the bounds of the core API
1039 city: cl.address.city,
1040 country: cl.address.country,
1041 country_code: cl.address.country_code,
1042 region: cl.address.region
1044 timestamp: new Date()
1047 successCallback(position);
1049 this.lastPosition = position;
1050 } else if (errorCallback === "function") {
1051 errorCallback({ code: 3, message: "Using the Google ClientLocation API and it is not able to calculate a location."});
1055 watchPosition: function(successCallback, errorCallback, options) {
1056 this.getCurrentPosition(successCallback, errorCallback, options);
1059 var watchId = setInterval(function() {
1060 self.getCurrentPosition(successCallback, errorCallback, options);
1066 clearWatch: function(watchId) {
1067 clearInterval(watchId);
1070 getPermission: function(siteName, imageUrl, extraMessage) {
1071 // for now just say yes :)
1078 // If you have Gears installed use that, else use Ajax ClientLocation
1079 navigator.geolocation = (window.google && google.gears) ? GearsGeoLocation() : AjaxGeoLocation();