123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692 |
- 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',
- 'image/bmp', 'image/webp', 'image/vnd.microsoft.icon'];
- if ($.inArray(file.type, imageTypes) == -1) {
-
- preview = false;
- }
- var maxSize = 8 * 1024 * 1024;
- if (file.size > maxSize) {
-
- preview = false;
- }
- var fileentry = $('<li>')
- .attr('class', 'attachment')
- .attr('style', 'text-align: center');
- if (preview) {
- blobAsDataURL(file, function (url) {
- var img = $('<img>')
- .attr('title', tooltip)
- .attr('alt', tooltip)
- .attr('src', url)
- .attr('style', 'height: 120px');
- fileentry.append(img);
- fileentry.append($('<br><code>' + file.name + '</code>'));
- form.find('.attach-status').append(fileentry);
- });
- } else {
- fileentry.append($('<code>' + file.type + '</code>'));
- fileentry.append($('<br><code>' + file.name + '</code>'));
- form.find('.attach-status').append(fileentry);
- }
- },
-
- 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();
- }
- });
|