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'
63 FormNoticeEnhancements: function(form) {
64 if (jQuery.data(form[0], 'ElementData') === undefined) {
65 MaxLength = form.find('#'+SN.C.S.NoticeTextCount).text();
66 if (typeof(MaxLength) == 'undefined') {
67 MaxLength = SN.C.I.MaxLength;
69 jQuery.data(form[0], 'ElementData', {MaxLength:MaxLength});
73 NDT = form.find('#'+SN.C.S.NoticeDataText);
75 NDT.bind('keyup', function(e) {
79 NDT.bind('keydown', function(e) {
80 SN.U.SubmitOnReturn(e, form);
84 form.find('#'+SN.C.S.NoticeTextCount).text(jQuery.data(form[0], 'ElementData').MaxLength);
87 if ($('body')[0].id != 'conversation' && window.location.hash.length === 0 && $(window).scrollTop() == 0) {
88 form.find('textarea').focus();
92 SubmitOnReturn: function(event, el) {
93 if (event.keyCode == 13 || event.keyCode == 10) {
95 event.preventDefault();
96 event.stopPropagation();
97 $('#'+el[0].id+' #'+SN.C.S.NoticeDataText).blur();
104 Counter: function(form) {
105 SN.C.I.FormNoticeCurrent = form;
107 var MaxLength = jQuery.data(form[0], 'ElementData').MaxLength;
109 if (MaxLength <= 0) {
113 var remaining = MaxLength - SN.U.CharacterCount(form);
114 var counter = form.find('#'+SN.C.S.NoticeTextCount);
116 if (remaining.toString() != counter.text()) {
117 if (!SN.C.I.CounterBlackout || remaining === 0) {
118 if (counter.text() != String(remaining)) {
119 counter.text(remaining);
122 form.addClass(SN.C.S.Warning);
124 form.removeClass(SN.C.S.Warning);
126 // Skip updates for the next 500ms.
127 // On slower hardware, updating on every keypress is unpleasant.
128 if (!SN.C.I.CounterBlackout) {
129 SN.C.I.CounterBlackout = true;
130 SN.C.I.FormNoticeCurrent = form;
131 window.setTimeout("SN.U.ClearCounterBlackout(SN.C.I.FormNoticeCurrent);", 500);
137 CharacterCount: function(form) {
138 return form.find('#'+SN.C.S.NoticeDataText).val().length;
141 ClearCounterBlackout: function(form) {
142 // Allow keyup events to poke the counter again
143 SN.C.I.CounterBlackout = false;
144 // Check if the string changed since we last looked
148 FormXHR: function(form) {
152 url: form.attr('action'),
153 data: form.serialize() + '&ajax=1',
154 beforeSend: function(xhr) {
156 .addClass(SN.C.S.Processing)
158 .addClass(SN.C.S.Disabled)
159 .attr(SN.C.S.Disabled, SN.C.S.Disabled);
161 error: function (xhr, textStatus, errorThrown) {
162 alert(errorThrown || textStatus);
164 success: function(data, textStatus) {
165 if (typeof($('form', data)[0]) != 'undefined') {
166 form_new = document._importNode($('form', data)[0], true);
167 form.replaceWith(form_new);
170 form.replaceWith(document._importNode($('p', data)[0], true));
176 FormNoticeXHR: function(form) {
177 SN.C.I.NoticeDataGeo = {};
178 form.append('<input type="hidden" name="ajax" value="1"/>');
182 beforeSend: function(formData) {
183 if (form.find('#'+SN.C.S.NoticeDataText)[0].value.length === 0) {
184 form.addClass(SN.C.S.Warning);
188 .addClass(SN.C.S.Processing)
189 .find('#'+SN.C.S.NoticeActionSubmit)
190 .addClass(SN.C.S.Disabled)
191 .attr(SN.C.S.Disabled, SN.C.S.Disabled);
193 SN.C.I.NoticeDataGeo.NLat = $('#'+SN.C.S.NoticeLat).val();
194 SN.C.I.NoticeDataGeo.NLon = $('#'+SN.C.S.NoticeLon).val();
195 SN.C.I.NoticeDataGeo.NLNS = $('#'+SN.C.S.NoticeLocationNs).val();
196 SN.C.I.NoticeDataGeo.NLID = $('#'+SN.C.S.NoticeLocationId).val();
197 SN.C.I.NoticeDataGeo.NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked');
199 cookieValue = $.cookie(SN.C.S.NoticeDataGeoCookie);
201 if (cookieValue !== null && cookieValue != 'disabled') {
202 cookieValue = JSON.parse(cookieValue);
203 SN.C.I.NoticeDataGeo.NLat = $('#'+SN.C.S.NoticeLat).val(cookieValue.NLat).val();
204 SN.C.I.NoticeDataGeo.NLon = $('#'+SN.C.S.NoticeLon).val(cookieValue.NLon).val();
205 if ($('#'+SN.C.S.NoticeLocationNs).val(cookieValue.NLNS)) {
206 SN.C.I.NoticeDataGeo.NLNS = $('#'+SN.C.S.NoticeLocationNs).val(cookieValue.NLNS).val();
207 SN.C.I.NoticeDataGeo.NLID = $('#'+SN.C.S.NoticeLocationId).val(cookieValue.NLID).val();
210 if (cookieValue == 'disabled') {
211 SN.C.I.NoticeDataGeo.NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked', false).attr('checked');
214 SN.C.I.NoticeDataGeo.NDG = $('#'+SN.C.S.NoticeDataGeo).attr('checked', true).attr('checked');
219 error: function (xhr, textStatus, errorThrown) {
221 .removeClass(SN.C.S.Processing)
222 .find('#'+SN.C.S.NoticeActionSubmit)
223 .removeClass(SN.C.S.Disabled)
224 .removeAttr(SN.C.S.Disabled, SN.C.S.Disabled);
225 form.find('.form_response').remove();
226 if (textStatus == 'timeout') {
227 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>');
230 if ($('.'+SN.C.S.Error, xhr.responseXML).length > 0) {
231 form.append(document._importNode($('.'+SN.C.S.Error, xhr.responseXML)[0], true));
234 if (parseInt(xhr.status) === 0 || jQuery.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) >= 0) {
237 .find('#'+SN.C.S.NoticeDataAttachSelected).remove();
238 SN.U.FormNoticeEnhancements(form);
241 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>');
246 success: function(data, textStatus) {
247 form.find('.form_response').remove();
249 if ($('#'+SN.C.S.Error, data).length > 0) {
250 result = document._importNode($('p', data)[0], true);
251 result = result.textContent || result.innerHTML;
252 form.append('<p class="form_response error">'+result+'</p>');
255 if($('body')[0].id == 'bookmarklet') {
259 if ($('#'+SN.C.S.CommandResult, data).length > 0) {
260 result = document._importNode($('p', data)[0], true);
261 result = result.textContent || result.innerHTML;
262 form.append('<p class="form_response success">'+result+'</p>');
265 // New notice post was successful. If on our timeline, show it!
266 var notice = document._importNode($('li', data)[0], true);
267 var notices = $('#notices_primary .notices');
268 if (notices.length > 0 && SN.U.belongsOnTimeline(notice)) {
269 if ($('#'+notice.id).length === 0) {
270 var notice_irt_value = $('#'+SN.C.S.NoticeInReplyTo).val();
271 var notice_irt = '#notices_primary #notice-'+notice_irt_value;
272 if($('body')[0].id == 'conversation') {
273 if(notice_irt_value.length > 0 && $(notice_irt+' .notices').length < 1) {
274 $(notice_irt).append('<ul class="notices"></ul>');
276 $($(notice_irt+' .notices')[0]).append(notice);
279 notices.prepend(notice);
282 .css({display:'none'})
284 SN.U.NoticeWithAttachment($('#'+notice.id));
285 SN.U.NoticeReplyTo($('#'+notice.id));
289 // Not on a timeline that this belongs on?
290 // Just show a success message.
291 result = document._importNode($('title', data)[0], true);
292 result_title = result.textContent || result.innerHTML;
293 form.append('<p class="form_response success">'+result_title+'</p>');
297 form.find('#'+SN.C.S.NoticeInReplyTo).val('');
298 form.find('#'+SN.C.S.NoticeDataAttachSelected).remove();
299 SN.U.FormNoticeEnhancements(form);
302 complete: function(xhr, textStatus) {
304 .removeClass(SN.C.S.Processing)
305 .find('#'+SN.C.S.NoticeActionSubmit)
306 .removeAttr(SN.C.S.Disabled)
307 .removeClass(SN.C.S.Disabled);
309 $('#'+SN.C.S.NoticeLat).val(SN.C.I.NoticeDataGeo.NLat);
310 $('#'+SN.C.S.NoticeLon).val(SN.C.I.NoticeDataGeo.NLon);
311 if ($('#'+SN.C.S.NoticeLocationNs)) {
312 $('#'+SN.C.S.NoticeLocationNs).val(SN.C.I.NoticeDataGeo.NLNS);
313 $('#'+SN.C.S.NoticeLocationId).val(SN.C.I.NoticeDataGeo.NLID);
315 $('#'+SN.C.S.NoticeDataGeo).attr('checked', SN.C.I.NoticeDataGeo.NDG);
320 NoticeReply: function() {
321 if ($('#'+SN.C.S.NoticeDataText).length > 0 && $('#content .notice_reply').length > 0) {
322 $('#content .notice').each(function() { SN.U.NoticeReplyTo($(this)); });
326 NoticeReplyTo: function(notice) {
327 notice.find('.notice_reply').live('click', function() {
328 var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname.uid');
329 SN.U.NoticeReplySet(nickname.text(), $($('.notice_id', notice)[0]).text());
334 NoticeReplySet: function(nick,id) {
335 if (nick.match(SN.C.I.PatternUsername)) {
336 var text = $('#'+SN.C.S.NoticeDataText);
337 if (text.length > 0) {
338 replyto = '@' + nick + ' ';
339 text.val(replyto + text.val().replace(RegExp(replyto, 'i'), ''));
340 $('#'+SN.C.S.FormNotice+' #'+SN.C.S.NoticeInReplyTo).val(id);
343 if (text[0].setSelectionRange) {
344 var len = text.val().length;
345 text[0].setSelectionRange(len,len);
351 NoticeFavor: function() {
352 $('.form_favor').live('click', function() { SN.U.FormXHR($(this)); return false; });
353 $('.form_disfavor').live('click', function() { SN.U.FormXHR($(this)); return false; });
356 NoticeRepeat: function() {
357 $('.form_repeat').live('click', function(e) {
360 SN.U.NoticeRepeatConfirmation($(this));
365 NoticeRepeatConfirmation: function(form) {
366 var submit_i = form.find('.submit');
368 var submit = submit_i.clone();
370 .addClass('submit_dialogbox')
371 .removeClass('submit');
373 submit.bind('click', function() { SN.U.FormXHR(form); return false; });
378 .addClass('dialogbox')
379 .append('<button class="close">×</button>')
380 .closest('.notice-options')
383 form.find('button.close').click(function(){
387 .removeClass('dialogbox')
388 .closest('.notice-options')
389 .removeClass('opaque');
391 form.find('.submit_dialogbox').remove();
392 form.find('.submit').show();
398 NoticeAttachments: function() {
399 $('.notice a.attachment').each(function() {
400 SN.U.NoticeWithAttachment($(this).closest('.notice'));
404 NoticeWithAttachment: function(notice) {
405 if (notice.find('.attachment').length === 0) {
409 var attachment_more = notice.find('.attachment.more');
410 if (attachment_more.length > 0) {
411 $(attachment_more[0]).click(function() {
413 m.addClass(SN.C.S.Processing);
414 $.get(m.attr('href')+'/ajax', null, function(data) {
415 m.parent('.entry-content').html($(data).find('#attachment_view .entry-content').html());
422 $.fn.jOverlay.options = {
430 imgLoading : $('address .url')[0].href+'theme/base/images/illustrations/illu_progress_loading-01.gif',
431 bgClickToClose : true,
432 success : function() {
433 $('#jOverlayContent').append('<button class="close">×</button>');
434 $('#jOverlayContent button').click($.closeOverlay);
438 css : {'max-width':'542px', 'top':'5%', 'left':'32.5%'}
441 notice.find('a.attachment').click(function() {
442 var attachId = ($(this).attr('id').substring('attachment'.length + 1));
444 $().jOverlay({url: $('address .url')[0].href+'attachment/' + attachId + '/ajax'});
449 if ($('#shownotice').length == 0) {
451 notice.find('a.thumbnail').hover(
453 var anchor = $(this);
454 $('a.thumbnail').children('img').hide();
455 anchor.closest(".entry-title").addClass('ov');
457 if (anchor.children('img').length === 0) {
458 t = setTimeout(function() {
459 $.get($('address .url')[0].href+'attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) {
465 anchor.children('img').show();
470 $('a.thumbnail').children('img').hide();
471 $(this).closest('.entry-title').removeClass('ov');
478 NoticeDataAttach: function() {
479 NDA = $('#'+SN.C.S.NoticeDataAttach);
480 NDA.change(function() {
481 S = '<div id="'+SN.C.S.NoticeDataAttachSelected+'" class="'+SN.C.S.Success+'"><code>'+$(this).val()+'</code> <button class="close">×</button></div>';
482 NDAS = $('#'+SN.C.S.NoticeDataAttachSelected);
483 if (NDAS.length > 0) {
487 $('#'+SN.C.S.FormNotice).append(S);
489 $('#'+SN.C.S.NoticeDataAttachSelected+' button').click(function(){
490 $('#'+SN.C.S.NoticeDataAttachSelected).remove();
498 NoticeLocationAttach: function() {
499 var NLat = $('#'+SN.C.S.NoticeLat).val();
500 var NLon = $('#'+SN.C.S.NoticeLon).val();
501 var NLNS = $('#'+SN.C.S.NoticeLocationNs).val();
502 var NLID = $('#'+SN.C.S.NoticeLocationId).val();
503 var NLN = $('#'+SN.C.S.NoticeGeoName).text();
504 var NDGe = $('#'+SN.C.S.NoticeDataGeo);
506 function removeNoticeDataGeo() {
507 $('label[for='+SN.C.S.NoticeDataGeo+']')
508 .attr('title', jQuery.trim($('label[for='+SN.C.S.NoticeDataGeo+']').text()))
509 .removeClass('checked');
511 $('#'+SN.C.S.NoticeLat).val('');
512 $('#'+SN.C.S.NoticeLon).val('');
513 $('#'+SN.C.S.NoticeLocationNs).val('');
514 $('#'+SN.C.S.NoticeLocationId).val('');
515 $('#'+SN.C.S.NoticeDataGeo).attr('checked', false);
517 $.cookie(SN.C.S.NoticeDataGeoCookie, 'disabled', { path: '/' });
520 function getJSONgeocodeURL(geocodeURL, data) {
521 $.getJSON(geocodeURL, data, function(location) {
524 if (typeof(location.location_ns) != 'undefined') {
525 $('#'+SN.C.S.NoticeLocationNs).val(location.location_ns);
526 lns = location.location_ns;
529 if (typeof(location.location_id) != 'undefined') {
530 $('#'+SN.C.S.NoticeLocationId).val(location.location_id);
531 lid = location.location_id;
534 if (typeof(location.name) == 'undefined') {
535 NLN_text = data.lat + ';' + data.lon;
538 NLN_text = location.name;
541 $('label[for='+SN.C.S.NoticeDataGeo+']')
542 .attr('title', NoticeDataGeo_text.ShareDisable + ' (' + NLN_text + ')');
544 $('#'+SN.C.S.NoticeLat).val(data.lat);
545 $('#'+SN.C.S.NoticeLon).val(data.lon);
546 $('#'+SN.C.S.NoticeLocationNs).val(lns);
547 $('#'+SN.C.S.NoticeLocationId).val(lid);
548 $('#'+SN.C.S.NoticeDataGeo).attr('checked', true);
560 $.cookie(SN.C.S.NoticeDataGeoCookie, JSON.stringify(cookieValue), { path: '/' });
564 if (NDGe.length > 0) {
565 if ($.cookie(SN.C.S.NoticeDataGeoCookie) == 'disabled') {
566 NDGe.attr('checked', false);
569 NDGe.attr('checked', true);
572 var NGW = $('#notice_data-geo_wrap');
573 var geocodeURL = NGW.attr('title');
574 NGW.removeAttr('title');
576 $('label[for='+SN.C.S.NoticeDataGeo+']')
577 .attr('title', jQuery.trim($('label[for='+SN.C.S.NoticeDataGeo+']').text()));
579 NDGe.change(function() {
580 if ($('#'+SN.C.S.NoticeDataGeo).attr('checked') === true || $.cookie(SN.C.S.NoticeDataGeoCookie) === null) {
581 $('label[for='+SN.C.S.NoticeDataGeo+']')
582 .attr('title', NoticeDataGeo_text.ShareDisable)
583 .addClass('checked');
585 if ($.cookie(SN.C.S.NoticeDataGeoCookie) === null || $.cookie(SN.C.S.NoticeDataGeoCookie) == 'disabled') {
586 if (navigator.geolocation) {
587 navigator.geolocation.getCurrentPosition(
589 $('#'+SN.C.S.NoticeLat).val(position.coords.latitude);
590 $('#'+SN.C.S.NoticeLon).val(position.coords.longitude);
593 lat: position.coords.latitude,
594 lon: position.coords.longitude,
595 token: $('#token').val()
598 getJSONgeocodeURL(geocodeURL, data);
603 case error.PERMISSION_DENIED:
604 removeNoticeDataGeo();
607 $('#'+SN.C.S.NoticeDataGeo).attr('checked', false);
618 if (NLat.length > 0 && NLon.length > 0) {
622 token: $('#token').val()
625 getJSONgeocodeURL(geocodeURL, data);
628 removeNoticeDataGeo();
629 $('#'+SN.C.S.NoticeDataGeo).remove();
630 $('label[for='+SN.C.S.NoticeDataGeo+']').remove();
635 var cookieValue = JSON.parse($.cookie(SN.C.S.NoticeDataGeoCookie));
637 $('#'+SN.C.S.NoticeLat).val(cookieValue.NLat);
638 $('#'+SN.C.S.NoticeLon).val(cookieValue.NLon);
639 $('#'+SN.C.S.NoticeLocationNs).val(cookieValue.NLNS);
640 $('#'+SN.C.S.NoticeLocationId).val(cookieValue.NLID);
641 $('#'+SN.C.S.NoticeDataGeo).attr('checked', cookieValue.NDG);
643 $('label[for='+SN.C.S.NoticeDataGeo+']')
644 .attr('title', NoticeDataGeo_text.ShareDisable + ' (' + cookieValue.NLN + ')')
645 .addClass('checked');
649 removeNoticeDataGeo();
655 NewDirectMessage: function() {
656 NDM = $('.entity_send-a-message a');
657 NDM.attr({'href':NDM.attr('href')+'&ajax=1'});
658 NDM.bind('click', function() {
659 var NDMF = $('.entity_send-a-message form');
660 if (NDMF.length === 0) {
661 $(this).addClass(SN.C.S.Processing);
662 $.get(NDM.attr('href'), null, function(data) {
663 $('.entity_send-a-message').append(document._importNode($('form', data)[0], true));
664 NDMF = $('.entity_send-a-message .form_notice');
665 SN.U.FormNoticeXHR(NDMF);
666 SN.U.FormNoticeEnhancements(NDMF);
667 NDMF.append('<button class="close">×</button>');
668 $('.entity_send-a-message button').click(function(){
672 NDM.removeClass(SN.C.S.Processing);
677 $('.entity_send-a-message textarea').focus();
683 GetFullYear: function(year, month, day) {
684 var date = new Date();
685 date.setFullYear(year, month, day);
691 Set: function(value) {
692 var SNI = SN.U.StatusNetInstance.Get();
694 value = $.extend(SNI, value);
698 SN.C.S.StatusNetInstance,
699 JSON.stringify(value),
702 expires: SN.U.GetFullYear(2029, 0, 1)
707 var cookieValue = $.cookie(SN.C.S.StatusNetInstance);
708 if (cookieValue !== null) {
709 return JSON.parse(cookieValue);
715 $.cookie(SN.C.S.StatusNetInstance, null);
720 * Check if the current page is a timeline where the current user's
721 * posts should be displayed immediately on success.
723 * @fixme this should be done in a saner way, with machine-readable
724 * info about what page we're looking at.
726 belongsOnTimeline: function(notice) {
727 var action = $("body").attr('id');
728 if (action == 'public') {
732 var profileLink = $('#nav_profile a').attr('href');
734 var authorUrl = $(notice).find('.entry-title .author a.url').attr('href');
735 if (authorUrl == profileLink) {
736 if (action == 'all' || action == 'showstream') {
737 // Posts always show on your own friends and profile streams.
743 // @fixme tag, group, reply timelines should be feasible as well.
744 // Mismatch between id-based and name-based user/group links currently complicates
745 // the lookup, since all our inline mentions contain the absolute links but the
746 // UI links currently on the page use malleable names.
753 NoticeForm: function() {
754 if ($('body.user_in').length > 0) {
755 SN.U.NoticeLocationAttach();
757 $('.'+SN.C.S.FormNotice).each(function() {
758 SN.U.FormNoticeXHR($(this));
759 SN.U.FormNoticeEnhancements($(this));
762 SN.U.NoticeDataAttach();
766 Notices: function() {
767 if ($('body.user_in').length > 0) {
773 SN.U.NoticeAttachments();
776 EntityActions: function() {
777 if ($('body.user_in').length > 0) {
778 $('.form_user_subscribe').live('click', function() { SN.U.FormXHR($(this)); return false; });
779 $('.form_user_unsubscribe').live('click', function() { SN.U.FormXHR($(this)); return false; });
780 $('.form_group_join').live('click', function() { SN.U.FormXHR($(this)); return false; });
781 $('.form_group_leave').live('click', function() { SN.U.FormXHR($(this)); return false; });
782 $('.form_user_nudge').live('click', function() { SN.U.FormXHR($(this)); return false; });
784 SN.U.NewDirectMessage();
789 if (SN.U.StatusNetInstance.Get() !== null) {
790 var nickname = SN.U.StatusNetInstance.Get().Nickname;
791 if (nickname !== null) {
792 $('#form_login #nickname').val(nickname);
796 $('#form_login').bind('submit', function() {
797 SN.U.StatusNetInstance.Set({Nickname: $('#form_login #nickname').val()});
804 $(document).ready(function(){
805 if ($('.'+SN.C.S.FormNotice).length > 0) {
806 SN.Init.NoticeForm();
808 if ($('#content .notices').length > 0) {
811 if ($('#content .entity_actions').length > 0) {
812 SN.Init.EntityActions();
814 if ($('#form_login').length > 0) {
819 // Formerly in xbImportNode.js
821 /* is this stuff defined? */
822 if (!document.ELEMENT_NODE) {
823 document.ELEMENT_NODE = 1;
824 document.ATTRIBUTE_NODE = 2;
825 document.TEXT_NODE = 3;
826 document.CDATA_SECTION_NODE = 4;
827 document.ENTITY_REFERENCE_NODE = 5;
828 document.ENTITY_NODE = 6;
829 document.PROCESSING_INSTRUCTION_NODE = 7;
830 document.COMMENT_NODE = 8;
831 document.DOCUMENT_NODE = 9;
832 document.DOCUMENT_TYPE_NODE = 10;
833 document.DOCUMENT_FRAGMENT_NODE = 11;
834 document.NOTATION_NODE = 12;
837 document._importNode = function(node, allChildren) {
838 /* find the node type to import */
839 switch (node.nodeType) {
840 case document.ELEMENT_NODE:
841 /* create a new element */
842 var newNode = document.createElement(node.nodeName);
843 /* does the node have any attributes to add? */
844 if (node.attributes && node.attributes.length > 0)
845 /* add all of the attributes */
846 for (var i = 0, il = node.attributes.length; i < il;) {
847 if (node.attributes[i].nodeName == 'class') {
848 newNode.className = node.getAttribute(node.attributes[i++].nodeName);
850 newNode.setAttribute(node.attributes[i].nodeName, node.getAttribute(node.attributes[i++].nodeName));
853 /* are we going after children too, and does the node have any? */
854 if (allChildren && node.childNodes && node.childNodes.length > 0)
855 /* recursively get all of the child nodes */
856 for (var i = 0, il = node.childNodes.length; i < il;)
857 newNode.appendChild(document._importNode(node.childNodes[i++], allChildren));
860 case document.TEXT_NODE:
861 case document.CDATA_SECTION_NODE:
862 case document.COMMENT_NODE:
863 return document.createTextNode(node.nodeValue);
868 // A shim to implement the W3C Geolocation API Specification using Gears or the Ajax API
869 if (typeof navigator.geolocation == "undefined" || navigator.geolocation.shim ) { (function(){
871 // -- BEGIN GEARS_INIT
873 // We are already defined. Hooray!
874 if (window.google && google.gears) {
881 if (typeof GearsFactory != 'undefined') {
882 factory = new GearsFactory();
886 factory = new ActiveXObject('Gears.Factory');
887 // privateSetGlobalObject is only required and supported on WinCE.
888 if (factory.getBuildInfo().indexOf('ie_mobile') != -1) {
889 factory.privateSetGlobalObject(this);
893 if ((typeof navigator.mimeTypes != 'undefined') && navigator.mimeTypes["application/x-googlegears"]) {
894 factory = document.createElement("object");
895 factory.style.display = "none";
898 factory.type = "application/x-googlegears";
899 document.documentElement.appendChild(factory);
904 // *Do not* define any objects if Gears is not installed. This mimics the
905 // behavior of Gears defining the objects in the future.
910 // Now set up the objects, being careful not to overwrite anything.
912 // Note: In Internet Explorer for Windows Mobile, you can't add properties to
913 // the window object. However, global objects are automatically added as
914 // properties of the window object in all browsers.
915 if (!window.google) {
920 google.gears = {factory: factory};
925 var GearsGeoLocation = (function() {
927 var geo = google.gears.factory.create('beta.geolocation');
929 var wrapSuccess = function(callback, self) { // wrap it for lastPosition love
930 return function(position) {
932 self.lastPosition = position;
944 getCurrentPosition: function(successCallback, errorCallback, options) {
946 var sc = wrapSuccess(successCallback, self);
947 geo.getCurrentPosition(sc, errorCallback, options);
950 watchPosition: function(successCallback, errorCallback, options) {
951 geo.watchPosition(successCallback, errorCallback, options);
954 clearWatch: function(watchId) {
955 geo.clearWatch(watchId);
958 getPermission: function(siteName, imageUrl, extraMessage) {
959 geo.getPermission(siteName, imageUrl, extraMessage);
965 var AjaxGeoLocation = (function() {
968 var loadGoogleLoader = function() {
969 if (!hasGoogleLoader() && !loading) {
971 var s = document.createElement('script');
972 s.src = (document.location.protocol == "https:"?"https://":"http://") + 'www.google.com/jsapi?callback=_google_loader_apiLoaded';
973 s.type = "text/javascript";
974 document.getElementsByTagName('body')[0].appendChild(s);
979 var addLocationQueue = function(callback) {
980 queue.push(callback);
983 var runLocationQueue = function() {
984 if (hasGoogleLoader()) {
985 while (queue.length > 0) {
986 var call = queue.pop();
992 window['_google_loader_apiLoaded'] = function() {
996 var hasGoogleLoader = function() {
997 return (window['google'] && google['loader']);
1000 var checkGoogleLoader = function(callback) {
1001 if (hasGoogleLoader()) { return true; }
1003 addLocationQueue(callback);
1010 loadGoogleLoader(); // start to load as soon as possible just in case
1016 type: "ClientLocation",
1020 getCurrentPosition: function(successCallback, errorCallback, options) {
1022 if (!checkGoogleLoader(function() {
1023 self.getCurrentPosition(successCallback, errorCallback, options);
1026 if (google.loader.ClientLocation) {
1027 var cl = google.loader.ClientLocation;
1031 latitude: cl.latitude,
1032 longitude: cl.longitude,
1034 accuracy: 43000, // same as Gears accuracy over wifi?
1035 altitudeAccuracy: null,
1039 // extra info that is outside of the bounds of the core API
1041 city: cl.address.city,
1042 country: cl.address.country,
1043 country_code: cl.address.country_code,
1044 region: cl.address.region
1046 timestamp: new Date()
1049 successCallback(position);
1051 this.lastPosition = position;
1052 } else if (errorCallback === "function") {
1053 errorCallback({ code: 3, message: "Using the Google ClientLocation API and it is not able to calculate a location."});
1057 watchPosition: function(successCallback, errorCallback, options) {
1058 this.getCurrentPosition(successCallback, errorCallback, options);
1061 var watchId = setInterval(function() {
1062 self.getCurrentPosition(successCallback, errorCallback, options);
1068 clearWatch: function(watchId) {
1069 clearInterval(watchId);
1072 getPermission: function(siteName, imageUrl, extraMessage) {
1073 // for now just say yes :)
1080 // If you have Gears installed use that, else use Ajax ClientLocation
1081 navigator.geolocation = (window.google && google.gears) ? GearsGeoLocation() : AjaxGeoLocation();