12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688 |
- var SN = {
- C: {
- I: {
- CounterBlackout: false,
- MaxLength: 140,
- PatternUsername: /^[0-9a-zA-Z\-_.]*$/,
- HTTP20x30x: [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307],
- },
-
- S: {
- Disabled: 'disabled',
- Warning: 'warning',
- Error: 'error',
- Success: 'success',
- Processing: 'processing',
- CommandResult: 'command_result',
- FormNotice: 'form_notice',
- NoticeDataGeo: 'notice_data-geo',
- NoticeDataGeoCookie: 'NoticeDataGeo',
- NoticeDataGeoSelected: 'notice_data-geo_selected',
- }
- },
- V: {
-
- },
-
- _callbacks: {},
-
- messages: {},
-
- msg: function (key) {
- if (SN.messages[key] === undefined) {
- return '[' + key + ']';
- }
- return SN.messages[key];
- },
- U: {
-
- FormNoticeEnhancements: function (form) {
- if ($.data(form[0], 'ElementData') === undefined) {
- var MaxLength = form.find('.count').text();
- if (MaxLength === undefined) {
- MaxLength = SN.C.I.MaxLength;
- }
- $.data(form[0], 'ElementData', {MaxLength: MaxLength});
- SN.U.Counter(form);
- var NDT = form.find('.notice_data-text:first');
- NDT.on('keyup', function (e) {
- SN.U.Counter(form);
- });
- var delayedUpdate = function (e) {
-
-
-
-
- window.setTimeout(function () {
- SN.U.Counter(form);
- }, 50);
- };
-
- NDT.on('cut', delayedUpdate)
- .on('paste', delayedUpdate);
- } else {
- form.find('.count').text($.data(form[0], 'ElementData').MaxLength);
- }
- },
-
- Counter: function (form) {
- SN.C.I.FormNoticeCurrent = form;
- var MaxLength = $.data(form[0], 'ElementData').MaxLength;
- if (MaxLength <= 0) {
- return;
- }
- var remaining = MaxLength - SN.U.CharacterCount(form);
- var counter = form.find('.count');
- if (remaining.toString() != counter.text()) {
- if (!SN.C.I.CounterBlackout || remaining === 0) {
- if (counter.text() != String(remaining)) {
- counter.text(remaining);
- }
- if (remaining < 0) {
- form.addClass(SN.C.S.Warning);
- } else {
- form.removeClass(SN.C.S.Warning);
- }
-
-
- if (!SN.C.I.CounterBlackout) {
- SN.C.I.CounterBlackout = true;
- SN.C.I.FormNoticeCurrent = form;
- window.setTimeout("SN.U.ClearCounterBlackout(SN.C.I.FormNoticeCurrent);", 500);
- }
- }
- }
- },
-
- CharacterCount: function (form) {
- return form.find('.notice_data-text:first').val().length;
- },
-
- ClearCounterBlackout: function (form) {
-
- SN.C.I.CounterBlackout = false;
-
- SN.U.Counter(form);
- },
-
- RewriteAjaxAction: function (url) {
-
- if (document.location.protocol === 'https:' && url.substr(0, 5) === 'http:') {
- return url.replace(/^http:\/\/[^:\/]+/, 'https://' + document.location.host);
- }
- return url;
- },
- FormNoticeUniqueID: function (form) {
- var oldId = form.attr('id');
- var newId = 'form_notice_' + Math.floor(Math.random()*999999999);
- var attrs = ['name', 'for', 'id'];
- for (var key in attrs) {
- if (form.attr(attrs[key]) === undefined) {
- continue;
- }
- form.attr(attrs[key], form.attr(attrs[key]).replace(oldId, newId));
- }
- for (var key in attrs) {
- form.find("[" + attrs[key] + "*='" + oldId + "']").each(function () {
- if ($(this).attr(attrs[key]) === undefined) {
- return;
- }
- var newAttr = $(this).attr(attrs[key]).replace(oldId, newId);
- $(this).attr(attrs[key], newAttr);
- });
- }
- },
-
- FormXHR: function (form, onSuccess) {
- $.ajax({
- type: 'POST',
- dataType: 'xml',
- url: SN.U.RewriteAjaxAction(form.attr('action')),
- data: form.serialize() + '&ajax=1',
- beforeSend: function (xhr) {
- form
- .addClass(SN.C.S.Processing)
- .find('.submit')
- .addClass(SN.C.S.Disabled)
- .prop(SN.C.S.Disabled, true);
- },
- error: function (xhr, textStatus, errorThrown) {
-
-
-
- var errorReported = null;
- if (xhr.responseXML) {
- errorReported = $('#error', xhr.responseXML).text();
- }
- window.alert(errorReported || errorThrown || textStatus);
-
-
- form
- .removeClass(SN.C.S.Processing)
- .find('.submit')
- .removeClass(SN.C.S.Disabled)
- .prop(SN.C.S.Disabled, false);
- },
- success: function (data, textStatus) {
- if ($('form', data)[0] !== undefined) {
- var form_new = document._importNode($('form', data)[0], true);
- form.replaceWith(form_new);
- if (onSuccess) {
- onSuccess();
- }
- } else if ($('p', data)[0] !== undefined) {
- form.replaceWith(document._importNode($('p', data)[0], true));
- if (onSuccess) {
- onSuccess();
- }
- } else {
- window.alert('Unknown error.');
- }
- }
- });
- },
-
- FormNoticeXHR: function (form) {
- SN.C.I.NoticeDataGeo = {};
- form.append('<input type="hidden" name="ajax" value="1"/>');
-
- form.attr('action', SN.U.RewriteAjaxAction(form.attr('action')));
-
- var removeFeedback = function () {
- form.find('.form_response').remove();
- };
- form.ajaxForm({
- dataType: 'xml',
- timeout: SN.V.xhrTimeout,
- beforeSend: function (formData) {
- if (form.find('.notice_data-text:first').val() == '') {
- form.addClass(SN.C.S.Warning);
- return false;
- }
- form
- .addClass(SN.C.S.Processing)
- .find('.submit')
- .addClass(SN.C.S.Disabled)
- .prop(SN.C.S.Disabled, true);
- SN.U.normalizeGeoData(form);
- return true;
- },
- error: function (xhr, textStatus, errorThrown) {
- form
- .removeClass(SN.C.S.Processing)
- .find('.submit')
- .removeClass(SN.C.S.Disabled)
- .prop(SN.C.S.Disabled, false);
- removeFeedback();
- if (textStatus == 'timeout') {
-
- SN.U.showFeedback(form, 'error', 'Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists.');
- } else {
- var response = SN.U.GetResponseXML(xhr);
- if ($('.' + SN.C.S.Error, response).length > 0) {
- form.append(document._importNode($('.' + SN.C.S.Error, response)[0], true));
- } else {
- if (parseInt(xhr.status) === 0 || $.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) >= 0) {
- form
- .resetForm()
- .find('.attach-status').remove();
- SN.U.FormNoticeEnhancements(form);
- } else {
-
- SN.U.showFeedback(form, 'error', '(Sorry! We had trouble sending your notice (' + xhr.status + ' ' + xhr.statusText + '). Please report the problem to the site administrator if this happens again.');
- }
- }
- }
- },
- success: function (data, textStatus) {
- removeFeedback();
- var errorResult = $('#' + SN.C.S.Error, data);
- if (errorResult.length > 0) {
- SN.U.showFeedback(form, 'error', errorResult.text());
- } else {
- SN.E.ajaxNoticePosted(form, data, textStatus);
- }
- },
- complete: function (xhr, textStatus) {
- form
- .removeClass(SN.C.S.Processing)
- .find('.submit')
- .prop(SN.C.S.Disabled, false)
- .removeClass(SN.C.S.Disabled);
- form.find('[name=lat]').val(SN.C.I.NoticeDataGeo.NLat);
- form.find('[name=lon]').val(SN.C.I.NoticeDataGeo.NLon);
- form.find('[name=location_ns]').val(SN.C.I.NoticeDataGeo.NLNS);
- form.find('[name=location_id]').val(SN.C.I.NoticeDataGeo.NLID);
- form.find('[name=notice_data-geo]').prop('checked', SN.C.I.NoticeDataGeo.NDG);
- }
- });
- },
- FormProfileSearchXHR: function (form) {
- $.ajax({
- type: 'POST',
- dataType: 'xml',
- url: form.attr('action'),
- data: form.serialize() + '&ajax=1',
- beforeSend: function (xhr) {
- form
- .addClass(SN.C.S.Processing)
- .find('.submit')
- .addClass(SN.C.S.Disabled)
- .prop(SN.C.S.Disabled, true);
- },
- error: function (xhr, textStatus, errorThrown) {
- window.alert(errorThrown || textStatus);
- },
- success: function (data, textStatus) {
- var results_placeholder = $('#profile_search_results');
- if ($('ul', data)[0] !== undefined) {
- var list = document._importNode($('ul', data)[0], true);
- results_placeholder.replaceWith(list);
- } else {
- var _error = $('<li/>').append(document._importNode($('p', data)[0], true));
- results_placeholder.html(_error);
- }
- form
- .removeClass(SN.C.S.Processing)
- .find('.submit')
- .removeClass(SN.C.S.Disabled)
- .prop(SN.C.S.Disabled, false);
- }
- });
- },
- FormPeopletagsXHR: function (form) {
- $.ajax({
- type: 'POST',
- dataType: 'xml',
- url: form.attr('action'),
- data: form.serialize() + '&ajax=1',
- beforeSend: function (xhr) {
- form.find('.submit')
- .addClass(SN.C.S.Processing)
- .addClass(SN.C.S.Disabled)
- .prop(SN.C.S.Disabled, true);
- },
- error: function (xhr, textStatus, errorThrown) {
- window.alert(errorThrown || textStatus);
- },
- success: function (data, textStatus) {
- var results_placeholder = form.parents('.entity_tags');
- if ($('.entity_tags', data)[0] !== undefined) {
- var tags = document._importNode($('.entity_tags', data)[0], true);
- $(tags).find('.editable').append($('<button class="peopletags_edit_button"/>'));
- results_placeholder.replaceWith(tags);
- } else {
- results_placeholder.find('p').remove();
- results_placeholder.append(document._importNode($('p', data)[0], true));
- form.removeClass(SN.C.S.Processing)
- .find('.submit')
- .removeClass(SN.C.S.Disabled)
- .prop(SN.C.S.Disabled, false);
- }
- }
- });
- },
- normalizeGeoData: function (form) {
- SN.C.I.NoticeDataGeo.NLat = form.find('[name=lat]').val();
- SN.C.I.NoticeDataGeo.NLon = form.find('[name=lon]').val();
- SN.C.I.NoticeDataGeo.NLNS = form.find('[name=location_ns]').val();
- SN.C.I.NoticeDataGeo.NLID = form.find('[name=location_id]').val();
- SN.C.I.NoticeDataGeo.NDG = form.find('[name=notice_data-geo]').prop('checked');
- var cookieValue = $.cookie(SN.C.S.NoticeDataGeoCookie);
- if (cookieValue !== undefined && cookieValue != 'disabled') {
- cookieValue = JSON.parse(cookieValue);
- SN.C.I.NoticeDataGeo.NLat = form.find('[name=lat]').val(cookieValue.NLat).val();
- SN.C.I.NoticeDataGeo.NLon = form.find('[name=lon]').val(cookieValue.NLon).val();
- if (cookieValue.NLNS) {
- SN.C.I.NoticeDataGeo.NLNS = form.find('[name=location_ns]').val(cookieValue.NLNS).val();
- SN.C.I.NoticeDataGeo.NLID = form.find('[name=location_id]').val(cookieValue.NLID).val();
- } else {
- form.find('[name=location_ns]').val('');
- form.find('[name=location_id]').val('');
- }
- }
- if (cookieValue == 'disabled') {
- SN.C.I.NoticeDataGeo.NDG = form.find('[name=notice_data-geo]').prop('checked', false).prop('checked');
- } else {
- SN.C.I.NoticeDataGeo.NDG = form.find('[name=notice_data-geo]').prop('checked', true).prop('checked');
- }
- },
-
- GetResponseXML: function (xhr) {
- try {
- return xhr.responseXML;
- } catch (e) {
- return (new DOMParser()).parseFromString(xhr.responseText, "text/xml");
- }
- },
-
- NoticeOptionsAjax: function () {
- $(document).on('click', '.notice-options > a.popup', function (e) {
- e.preventDefault();
- var noticeEl = $(this).closest('.notice');
- $.ajax({
- url: $(this).attr('href'),
- data: {ajax: 1},
- success: function (data, textStatus, xhr) {
- SN.U.NoticeOptionPopup(data, noticeEl);
- },
- });
- return false;
- });
- },
- NoticeOptionPopup: function (data, noticeEl) {
- title = $('head > title', data).text();
- body = $('body', data).html();
- dialog = $(body).dialog({
- height: "auto",
- width: "auto",
- modal: true,
- resizable: true,
- title: title,
- });
- },
-
- NoticeReply: function () {
- $(document).on('click', '#content .notice_reply', function (e) {
- e.preventDefault();
- var notice = $(this).closest('li.notice');
- SN.U.NoticeInlineReplyTrigger(notice);
- return false;
- });
- },
-
- NoticeReplyTo: function (notice) {
- },
-
- NoticeInlineReplyTrigger: function (notice, initialText) {
-
- var id = $($('.notice_id', notice)[0]).text();
- var replyForm;
- var parentNotice = notice;
- var stripForm = true;
- var list = notice.find('.threaded-replies');
- if (list.length == 0) {
- list = notice.closest('.threaded-replies');
- }
- if (list.length == 0) {
- list = $('<ul class="notices threaded-replies xoxo"></ul>');
- notice.append(list);
- list = notice.find('.threaded-replies');
- }
- var nextStep = function () {
-
- replyForm.find('input[name=inreplyto]').val(id);
- if (stripForm) {
-
- replyForm.find('#notice_to').prop('disabled', true).hide();
- replyForm.find('#notice_private').prop('disabled', true).hide();
- replyForm.find('label[for=notice_to]').hide();
- replyForm.find('label[for=notice_private]').hide();
- }
- replyItem.show();
-
- var text = replyForm.find('textarea');
- if (text.length == 0) {
- throw "No textarea";
- }
- var replyto = '';
- if (initialText) {
- replyto = initialText + ' ';
- }
- text.val(replyto + text.val().replace(new RegExp(replyto, 'i'), ''));
- text.data('initialText', $.trim(initialText));
- text.focus();
- if (text[0].setSelectionRange) {
- var len = text.val().length;
- text[0].setSelectionRange(len, len);
- }
- };
-
- var replyItem = $('li.notice-reply', list);
- if (replyItem.length == 0) {
- replyItem = $('<li class="notice-reply"></li>');
- }
- replyForm = replyItem.children('form');
- if (replyForm.length == 0) {
-
- var noticeForm = $('#input_form_status > form');
- if (noticeForm.length == 0) {
-
-
- $.ajax({
- url: SN.V.urlNewNotice,
- data: {ajax: 1, inreplyto: id},
- success: function (data, textStatus, xhr) {
- var formEl = document._importNode($('form', data)[0], true);
- replyForm = $(formEl);
- replyItem.append(replyForm);
- list.append(replyItem);
- SN.Init.NoticeFormSetup(replyForm);
- nextStep();
- },
- });
-
- return;
- }
- replyForm = noticeForm.clone();
- SN.Init.NoticeFormSetup(replyForm);
- replyItem.append(replyForm);
- list.append(replyItem);
- }
-
-
- nextStep();
- },
-
- NoticeInlineReplySetup: function () {
-
- $(document).on('click', 'li.notice-reply-comments a', function () {
- var url = $(this).attr('href');
- var area = $(this).closest('.threaded-replies');
- $.ajax({
- url: url,
- data: {ajax: 1},
- success: function (data, textStatus, xhr) {
- var replies = $('.threaded-replies', data);
- if (replies.length) {
- area.replaceWith(document._importNode(replies[0], true));
- }
- },
- });
- return false;
- });
- },
-
- NoticeRepeat: function () {
- $('body').on('click', '.form_repeat', function (e) {
- e.preventDefault();
- SN.U.NoticeRepeatConfirmation($(this));
- return false;
- });
- },
-
- NoticeRepeatConfirmation: function (form) {
- var submit_i = form.find('.submit');
- var submit = submit_i.clone();
- submit
- .addClass('submit_dialogbox')
- .removeClass('submit');
- form.append(submit);
- submit.on('click', function () { SN.U.FormXHR(form); return false; });
- submit_i.hide();
- form
- .addClass('dialogbox')
- .append('<button class="close" title="' + SN.msg('popup_close_button') + '">×</button>')
- .closest('.notice-options')
- .addClass('opaque');
- form.find('button.close').click(function () {
- $(this).remove();
- form
- .removeClass('dialogbox')
- .closest('.notice-options')
- .removeClass('opaque');
- form.find('.submit_dialogbox').remove();
- form.find('.submit').show();
- return false;
- });
- },
-
- NoticeAttachments: function () {
- $('.notice a.attachment').each(function () {
- SN.U.NoticeWithAttachment($(this).closest('.notice'));
- });
- },
-
- NoticeWithAttachment: function (notice) {
- if (notice.find('.attachment').length === 0) {
- return;
- }
- $(document).on('click','.attachment.more',function () {
- var m = $(this);
- m.addClass(SN.C.S.Processing);
- $.get(m.attr('href'), {ajax: 1}, function (data) {
- m.parent('.e-content').html($(data).find('#attachment_view .e-content').html());
- });
- return false;
- });
- },
-
- NoticeDataAttach: function (form) {
- var i;
- var NDA = form.find('input[type=file]');
- NDA.change(function (event) {
- form.find('.attach-status').remove();
- if (typeof this.files === "object") {
- var attachStatus = $('<ul class="attach-status ' + SN.C.S.Success + '"></ul>');
- form.append(attachStatus);
-
- for (i = 0; i < this.files.length; i++) {
- SN.U.PreviewAttach(form, this.files[i]);
- }
- } else {
- var filename = $(this).val();
- if (!filename) {
-
- return false;
- }
- var attachStatus = $('<div class="attach-status ' + SN.C.S.Success + '"><code></code> <button class="close">×</button></div>');
- attachStatus.find('code').text(filename);
- attachStatus.find('button').click(function () {
- attachStatus.remove();
- NDA.val('');
- return false;
- });
- form.append(attachStatus);
- }
- });
- },
-
- maxFileSize: function (form) {
- var max = $(form).find('input[name=MAX_FILE_SIZE]').attr('value');
- if (max) {
- return parseInt(max);
- }
- return 0;
- },
-
- PreviewAttach: function (form, file) {
- var tooltip = file.type + ' ' + Math.round(file.size / 1024) + 'KB';
- var preview = true;
- var blobAsDataURL;
- if (window.createObjectURL !== undefined) {
-
- blobAsDataURL = function (blob, callback) {
- callback(window.createObjectURL(blob));
- };
- } else if (window.FileReader !== undefined) {
-
- blobAsDataURL = function (blob, callback) {
- var reader = new FileReader();
- reader.onload = function (event) {
- callback(reader.result);
- };
- reader.readAsDataURL(blob);
- };
- } else {
- preview = false;
- }
- var imageTypes = ['image/png', 'image/jpeg', 'image/gif', 'image/svg+xml'];
- if ($.inArray(file.type, imageTypes) == -1) {
-
- preview = false;
- }
- var maxSize = 8 * 1024 * 1024;
- if (file.size > maxSize) {
-
- preview = false;
- }
- if (preview) {
- blobAsDataURL(file, function (url) {
- var fileentry = $('<li class="attachment"></li>');
- fileentry.append($('<code>' + file.name + '</code>'));
- var img = $('<img>')
- .attr('title', tooltip)
- .attr('alt', tooltip)
- .attr('src', url)
- .attr('style', 'height: 120px');
- fileentry.append(img);
- form.find('.attach-status').append(fileentry);
- });
- } else {
- var img = $('<div></div>').text(tooltip);
- form.find('.attach-status').append(img);
- }
- },
-
- NoticeLocationAttach: function (form) {
-
- var NLat = form.find('[name=lat]');
- var NLon = form.find('[name=lon]');
- var NLNS = form.find('[name=location_ns]').val();
- var NLID = form.find('[name=location_id]').val();
- var NLN = '';
- var NDGe = form.find('[name=notice_data-geo]');
- var check = form.find('[name=notice_data-geo]');
- var label = form.find('label.notice_data-geo');
- function removeNoticeDataGeo(error) {
- label
- .attr('title', $.trim(label.text()))
- .removeClass('checked');
- form.find('[name=lat]').val('');
- form.find('[name=lon]').val('');
- form.find('[name=location_ns]').val('');
- form.find('[name=location_id]').val('');
- form.find('[name=notice_data-geo]').prop('checked', false);
- $.cookie(SN.C.S.NoticeDataGeoCookie, 'disabled', { path: '/' });
- if (error) {
- form.find('.geo_status_wrapper').removeClass('success').addClass('error');
- form.find('.geo_status_wrapper .geo_status').text(error);
- } else {
- form.find('.geo_status_wrapper').remove();
- }
- }
- function getJSONgeocodeURL(geocodeURL, data) {
- SN.U.NoticeGeoStatus(form, 'Looking up place name...');
- $.getJSON(geocodeURL, data, function (location) {
- var lns, lid, NLN_text;
- if (location.location_ns !== undefined) {
- form.find('[name=location_ns]').val(location.location_ns);
- lns = location.location_ns;
- }
- if (location.location_id !== undefined) {
- form.find('[name=location_id]').val(location.location_id);
- lid = location.location_id;
- }
- if (location.name === undefined) {
- NLN_text = data.lat + ';' + data.lon;
- } else {
- NLN_text = location.name;
- }
- SN.U.NoticeGeoStatus(form, NLN_text, data.lat, data.lon, location.url);
- label
- .attr('title', NoticeDataGeo_text.ShareDisable + ' (' + NLN_text + ')');
- form.find('[name=lat]').val(data.lat);
- form.find('[name=lon]').val(data.lon);
- form.find('[name=location_ns]').val(lns);
- form.find('[name=location_id]').val(lid);
- form.find('[name=notice_data-geo]').prop('checked', true);
- var cookieValue = {
- NLat: data.lat,
- NLon: data.lon,
- NLNS: lns,
- NLID: lid,
- NLN: NLN_text,
- NLNU: location.url,
- NDG: true
- };
- $.cookie(SN.C.S.NoticeDataGeoCookie, JSON.stringify(cookieValue), { path: '/' });
- });
- }
- if (check.length > 0) {
- if ($.cookie(SN.C.S.NoticeDataGeoCookie) == 'disabled') {
- check.prop('checked', false);
- } else {
- check.prop('checked', true);
- }
- var NGW = form.find('.notice_data-geo_wrap');
- var geocodeURL = NGW.attr('data-api');
- label.attr('title', label.text());
- check.change(function () {
- if (check.prop('checked') === true || $.cookie(SN.C.S.NoticeDataGeoCookie) === undefined) {
- label
- .attr('title', NoticeDataGeo_text.ShareDisable)
- .addClass('checked');
- if ($.cookie(SN.C.S.NoticeDataGeoCookie) === undefined || $.cookie(SN.C.S.NoticeDataGeoCookie) == 'disabled') {
- if (navigator.geolocation) {
- SN.U.NoticeGeoStatus(form, 'Requesting location from browser...');
- navigator.geolocation.getCurrentPosition(
- function (position) {
- form.find('[name=lat]').val(position.coords.latitude);
- form.find('[name=lon]').val(position.coords.longitude);
- var data = {
- lat: position.coords.latitude,
- lon: position.coords.longitude,
- token: $('#token').val()
- };
- getJSONgeocodeURL(geocodeURL, data);
- },
- function (error) {
- switch(error.code) {
- case error.PERMISSION_DENIED:
- removeNoticeDataGeo('Location permission denied.');
- break;
- case error.TIMEOUT:
-
- removeNoticeDataGeo('Location lookup timeout.');
- break;
- }
- },
- {
- timeout: 10000
- }
- );
- } else {
- if (NLat.length > 0 && NLon.length > 0) {
- var data = {
- lat: NLat,
- lon: NLon,
- token: $('#token').val()
- };
- getJSONgeocodeURL(geocodeURL, data);
- } else {
- removeNoticeDataGeo();
- check.remove();
- label.remove();
- }
- }
- } else {
- try {
- var cookieValue = JSON.parse($.cookie(SN.C.S.NoticeDataGeoCookie));
- form.find('[name=lat]').val(cookieValue.NLat);
- form.find('[name=lon]').val(cookieValue.NLon);
- form.find('[name=location_ns]').val(cookieValue.NLNS);
- form.find('[name=location_id]').val(cookieValue.NLID);
- form.find('[name=notice_data-geo]').prop('checked', cookieValue.NDG);
- SN.U.NoticeGeoStatus(form, cookieValue.NLN, cookieValue.NLat, cookieValue.NLon, cookieValue.NLNU);
- label
- .attr('title', NoticeDataGeo_text.ShareDisable + ' (' + cookieValue.NLN + ')')
- .addClass('checked');
- } catch (e) {
- console.log('Parsing error:', e);
- }
- }
- } else {
- removeNoticeDataGeo();
- }
- }).change();
- }
- },
-
- NoticeGeoStatus: function (form, status, lat, lon, url)
- {
- var wrapper = form.find('.geo_status_wrapper');
- if (wrapper.length == 0) {
- wrapper = $('<div class="' + SN.C.S.Success + ' geo_status_wrapper"><button class="close" style="float:right">×</button><div class="geo_status"></div></div>');
- wrapper.find('button.close').click(function () {
- form.find('[name=notice_data-geo]').prop('checked', false).change();
- return false;
- });
- form.append(wrapper);
- }
- var label;
- if (url) {
- label = $('<a></a>').attr('href', url);
- } else {
- label = $('<span></span>');
- }
- label.text(status);
- if (lat || lon) {
- var latlon = lat + ';' + lon;
- label.attr('title', latlon);
- if (!status) {
- label.text(latlon)
- }
- }
- wrapper.find('.geo_status').empty().append(label);
- },
-
- NewDirectMessage: function () {
- NDM = $('.entity_send-a-message a');
- NDM.attr({'href': NDM.attr('href') + '&ajax=1'});
- NDM.on('click', function () {
- var NDMF = $('.entity_send-a-message form');
- if (NDMF.length === 0) {
- $(this).addClass(SN.C.S.Processing);
- $.get(NDM.attr('href'), null, function (data) {
- $('.entity_send-a-message').append(document._importNode($('form', data)[0], true));
- NDMF = $('.entity_send-a-message .form_notice');
- SN.U.FormNoticeXHR(NDMF);
- SN.U.FormNoticeEnhancements(NDMF);
- NDMF.append('<button class="close">×</button>');
- $('.entity_send-a-message button').click(function () {
- NDMF.hide();
- return false;
- });
- NDM.removeClass(SN.C.S.Processing);
- });
- } else {
- NDMF.show();
- $('.entity_send-a-message textarea').focus();
- }
- return false;
- });
- },
-
- GetFullYear: function (year, month, day) {
- var date = new Date();
- date.setFullYear(year, month, day);
- return date;
- },
-
- belongsOnTimeline: function (notice) {
- var action = $("body").attr('id');
- if (action == 'public') {
- return true;
- }
- var profileLink = $('#nav_profile a').attr('href');
- if (profileLink) {
- var authorUrl = $(notice).find('.h-card.p-author').attr('href');
- if (authorUrl == profileLink) {
- if (action == 'all' || action == 'showstream') {
-
- return true;
- }
- }
- }
-
-
-
-
-
- return false;
- },
-
- switchInputFormTab: function (tag, setFocus) {
- if (typeof setFocus === 'undefined') { setFocus = true; }
-
- $('.input_form_nav_tab.current').removeClass('current');
- if (tag != null) {
- $('#input_form_nav_' + tag).addClass('current');
- }
-
-
-
- var nonav = $('.input_form.current.nonav');
- if (nonav.length > 0) {
- return;
- }
- $('.input_form.current').removeClass('current');
- if (tag == null) {
-
- return false;
- }
- var noticeForm = $('#input_form_' + tag)
- .addClass('current')
- .find('.ajax-notice').each(function () {
- var form = $(this);
- SN.Init.NoticeFormSetup(form);
- });
- if (setFocus) {
- noticeForm.find('.notice_data-text').focus();
- }
- return false;
- },
- showMoreMenuItems: function (menuid) {
- $('#' + menuid + ' .more_link').remove();
- var selector = '#' + menuid + ' .extended_menu';
- var extended = $(selector);
- extended.removeClass('extended_menu');
- return void(0);
- },
-
- showFeedback: function (form, cls, text) {
- form.append(
- $('<p class="form_response"></p>')
- .addClass(cls)
- .text(text)
- );
- },
- addCallback: function (ename, callback) {
-
- if (typeof SN._callbacks[ename] === 'undefined') {
- SN._callbacks[ename] = [];
- }
- SN._callbacks[ename].push(callback);
- },
- runCallbacks: function (ename, data) {
- if (typeof SN._callbacks[ename] === 'undefined') {
- return;
- }
- for (cbname in SN._callbacks[ename]) {
- SN._callbacks[ename][cbname](data);
- }
- }
- },
- E: {
-
- ajaxNoticePosted: function (form, data, textStatus) {
- var commandResult = $('#' + SN.C.S.CommandResult, data);
- if (commandResult.length > 0) {
- SN.U.showFeedback(form, 'success', commandResult.text());
- } else {
-
- var notice = document._importNode($('li', data)[0], true);
- var notices = $('#notices_primary .notices:first');
- var replyItem = form.closest('li.notice-reply');
- if (replyItem.length > 0) {
-
- var list = form.closest('.threaded-replies');
- var id = $(notice).attr('id');
- if ($('#' + id).length == 0) {
- $(notice).insertBefore(replyItem);
- }
- replyItem.remove();
- } else if (notices.length > 0 && SN.U.belongsOnTimeline(notice)) {
-
- if ($('#' + notice.id).length === 0) {
- var notice_irt_value = form.find('[name=inreplyto]').val();
- var notice_irt = '#notices_primary #notice-' + notice_irt_value;
- if ($('body')[0].id == 'conversation') {
- if (notice_irt_value.length > 0 && $(notice_irt + ' .notices').length < 1) {
- $(notice_irt).append('<ul class="notices"></ul>');
- }
- $($(notice_irt + ' .notices')[0]).append(notice);
- } else {
- notices.prepend(notice);
- }
- $('#' + notice.id)
- .css({display: 'none'})
- .fadeIn(2500);
- SN.U.NoticeWithAttachment($('#' + notice.id));
- SN.U.switchInputFormTab(null);
- }
- } else {
-
-
-
- SN.U.showFeedback(form, 'success', $('title', data).text());
- }
- }
- form.resetForm();
- form.find('[name=inreplyto]').val('');
- form.find('.attach-status').remove();
- SN.U.FormNoticeEnhancements(form);
- SN.U.runCallbacks('notice_posted', {"notice": notice});
- },
- },
- Init: {
-
- NoticeForm: function () {
- if ($('body.user_in').length > 0) {
-
-
-
- $('#input_form_nav .input_form_nav_tab.current').each(function () {
- current_tab_id = $(this).attr('id').substring('input_form_nav_'.length);
- SN.U.switchInputFormTab(current_tab_id, false);
- });
-
- $('body').on('click', function (e) {
- var openReplies = $('li.notice-reply');
- if (openReplies.length > 0) {
- var target = $(e.target);
- openReplies.each(function () {
-
- var replyItem = $(this);
- if (replyItem.has(e.target).length == 0) {
- var textarea = replyItem.find('.notice_data-text:first');
- var cur = $.trim(textarea.val());
-
- if (cur == '' || cur == textarea.data('initialText')) {
- var parentNotice = replyItem.closest('li.notice');
- replyItem.hide();
- parentNotice.find('li.notice-reply-placeholder').show();
- }
- }
- });
- }
- });
- }
- },
-
- NoticeFormSetup: function (form) {
- if (form.data('NoticeFormSetup')) {
- return false;
- }
- SN.U.NoticeLocationAttach(form);
- SN.U.FormNoticeUniqueID(form);
- SN.U.FormNoticeXHR(form);
- SN.U.FormNoticeEnhancements(form);
- SN.U.NoticeDataAttach(form);
- form.data('NoticeFormSetup', true);
- },
-
- Notices: function () {
- if ($('body.user_in').length > 0) {
- SN.U.NoticeRepeat();
- SN.U.NoticeReply();
- SN.U.NoticeInlineReplySetup();
- SN.U.NoticeOptionsAjax();
- }
- SN.U.NoticeAttachments();
- },
-
- EntityActions: function () {
- if ($('body.user_in').length > 0) {
- $(document).on('click', '.form_user_subscribe', function () { SN.U.FormXHR($(this)); return false; });
- $(document).on('click', '.form_user_unsubscribe', function () { SN.U.FormXHR($(this)); return false; });
- $(document).on('click', '.form_group_join', function () { SN.U.FormXHR($(this)); return false; });
- $(document).on('click', '.form_group_leave', function () { SN.U.FormXHR($(this)); return false; });
- $(document).on('click', '.form_user_nudge', function () { SN.U.FormXHR($(this)); return false; });
- $(document).on('click', '.form_peopletag_subscribe', function () { SN.U.FormXHR($(this)); return false; });
- $(document).on('click', '.form_peopletag_unsubscribe', function () { SN.U.FormXHR($(this)); return false; });
- $(document).on('click', '.form_user_add_peopletag', function () { SN.U.FormXHR($(this)); return false; });
- $(document).on('click', '.form_user_remove_peopletag', function () { SN.U.FormXHR($(this)); return false; });
- SN.U.NewDirectMessage();
- }
- },
- ProfileSearch: function () {
- if ($('body.user_in').length > 0) {
- $(document).on('click', '.form_peopletag_edit_user_search input.submit', function () {
- SN.U.FormProfileSearchXHR($(this).parents('form')); return false;
- });
- }
- },
-
- PeopleTags: function () {
- $('.user_profile_tags .editable').append($('<button class="peopletags_edit_button"/>'));
- $(document).on('click', '.peopletags_edit_button', function () {
- var form = $(this).parents('dd').eq(0).find('form');
-
- $.ajax({
- url: _peopletagAC,
- dataType: 'json',
- data: {token: $('#token').val()},
- ifModified: true,
- success: function (data) {
-
- for (i=0; i < data.length; i++) {
- data[i].label = data[i].tag;
- }
- SN.C.PtagACData = data;
- }
- });
- $(this).parents('ul').eq(0).fadeOut(200, function () {form.fadeIn(200).find('input#tags')});
- });
- $(document).on('click', '.user_profile_tags form .submit', function () {
- SN.U.FormPeopletagsXHR($(this).parents('form')); return false;
- });
- },
-
- AjaxForms: function () {
- $(document).on('submit', 'form.ajax', function () {
- SN.U.FormXHR($(this));
- return false;
- });
- $(document).on('click', 'form.ajax input[type=submit]', function () {
-
-
-
- var button = $(this);
- var form = button.closest('form');
- form.find('.hidden-submit-button').remove();
- $('<input class="hidden-submit-button" type="hidden" />')
- .attr('name', button.attr('name'))
- .val(button.val())
- .appendTo(form);
- });
- },
-
- UploadForms: function () {
- $('input[type=file]').change(function (event) {
- if (typeof this.files === "object" && this.files.length > 0) {
- var size = 0;
- for (var i = 0; i < this.files.length; i++) {
- size += this.files[i].size;
- }
- var max = SN.U.maxFileSize($(this.form));
- if (max > 0 && size > max) {
- var msg = 'File too large: maximum upload size is %d bytes.';
- alert(msg.replace('%d', max));
-
- $(this).val('');
- event.preventDefault();
- return false;
- }
- }
- });
- },
- CheckBoxes: function () {
- $("span[class='checkbox-wrapper']").addClass("unchecked");
- $(".checkbox-wrapper").click(function () {
- if ($(this).children("input").prop("checked")) {
-
- $(this).children("input").prop("checked", false);
- $(this).removeClass("checked");
- $(this).addClass("unchecked");
- $(this).children("label").text("Private?");
- } else {
-
- $(this).children("input").prop("checked", true);
- $(this).removeClass("unchecked");
- $(this).addClass("checked");
- $(this).children("label").text("Private");
- }
- });
- }
- }
- };
- $(function () {
- SN.Init.AjaxForms();
- SN.Init.UploadForms();
- SN.Init.CheckBoxes();
- if ($('.' + SN.C.S.FormNotice).length > 0) {
- SN.Init.NoticeForm();
- }
- if ($('#content .notices').length > 0) {
- SN.Init.Notices();
- }
- if ($('#content .entity_actions').length > 0) {
- SN.Init.EntityActions();
- }
- if ($('#profile_search_results').length > 0) {
- SN.Init.ProfileSearch();
- }
- if ($('.user_profile_tags .editable').length > 0) {
- SN.Init.PeopleTags();
- }
- });
|