gnu-social/js/util.min.js

1 line
19 KiB
JavaScript
Raw Normal View History

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",NoticeDataText:"notice_data-text",NoticeTextCount:"notice_text-count",NoticeInReplyTo:"notice_in-reply-to",NoticeDataAttach:"notice_data-attach",NoticeDataAttachSelected:"notice_data-attach_selected",NoticeActionSubmit:"notice_action-submit",NoticeLat:"notice_data-lat",NoticeLon:"notice_data-lon",NoticeLocationId:"notice_data-location_id",NoticeLocationNs:"notice_data-location_ns",NoticeGeoName:"notice_data-geo_name",NoticeDataGeo:"notice_data-geo",NoticeDataGeoCookie:"NoticeDataGeo",NoticeDataGeoSelected:"notice_data-geo_selected",StatusNetInstance:"StatusNetInstance"}},messages:{},msg:function(a){if(typeof SN.messages[a]=="undefined"){return"["+a+"]"}else{return SN.messages[a]}},U:{FormNoticeEnhancements:function(a){if(jQuery.data(a[0],"ElementData")===undefined){MaxLength=a.find("#"+SN.C.S.NoticeTextCount).text();if(typeof(MaxLength)=="undefined"){MaxLength=SN.C.I.MaxLength}jQuery.data(a[0],"ElementData",{MaxLength:MaxLength});SN.U.Counter(a);NDT=a.find("#"+SN.C.S.NoticeDataText);NDT.bind("keyup",function(b){SN.U.Counter(a)});NDT.bind("keydown",function(b){SN.U.SubmitOnReturn(b,a)})}else{a.find("#"+SN.C.S.NoticeTextCount).text(jQuery.data(a[0],"ElementData").MaxLength)}if($("body")[0].id!="conversation"&&window.location.hash.length===0&&$(window).scrollTop()==0){a.find("textarea").focus()}},SubmitOnReturn:function(b,a){if(b.keyCode==13||b.keyCode==10){a.submit();b.preventDefault();b.stopPropagation();$("#"+a[0].id+" #"+SN.C.S.NoticeDataText).blur();$("body").focus();return false}return true},Counter:function(d){SN.C.I.FormNoticeCurrent=d;var b=jQuery.data(d[0],"ElementData").MaxLength;if(b<=0){return}var c=b-SN.U.CharacterCount(d);var a=d.find("#"+SN.C.S.NoticeTextCount);if(c.toString()!=a.text()){if(!SN.C.I.CounterBlackout||c===0){if(a.text()!=String(c)){a.text(c)}if(c<0){d.addClass(SN.C.S.Warning)}else{d.removeClass(SN.C.S.Warning)}if(!SN.C.I.CounterBlackout){SN.C.I.CounterBlackout=true;SN.C.I.FormNoticeCurrent=d;window.setTimeout("SN.U.ClearCounterBlackout(SN.C.I.FormNoticeCurrent);",500)}}}},CharacterCount:function(a){return a.find("#"+SN.C.S.NoticeDataText).val().length},ClearCounterBlackout:function(a){SN.C.I.CounterBlackout=false;SN.U.Counter(a)},FormXHR:function(a){$.ajax({type:"POST",dataType:"xml",url:a.attr("action"),data:a.serialize()+"&ajax=1",beforeSend:function(b){a.addClass(SN.C.S.Processing).find(".submit").addClass(SN.C.S.Disabled).attr(SN.C.S.Disabled,SN.C.S.Disabled)},error:function(c,d,b){alert(b||d)},success:function(b,c){if(typeof($("form",b)[0])!="undefined"){form_new=document._importNode($("form",b)[0],true);a.replaceWith(form_new)}else{a.replaceWith(document._importNode($("p",b)[0],true))}}})},FormNoticeXHR:function(a){SN.C.I.NoticeDataGeo={};a.append('<input type="hidden" name="ajax" value="1"/>');a.ajaxForm({dataType:"xml",timeout:"60000",beforeSend:function(b){if(a.find("#"+SN.C.S.NoticeDataText)[0].value.length===0){a.addClass(SN.C.S.Warning);return false}a.addClass(SN.C.S.Processing).find("#"+SN.C.S.NoticeActionSubmit).addClass(SN.C.S.Disabled).attr(SN.C.S.Disabled,SN.C.S.Disabled);SN.C.I.NoticeDataGeo.NLat=$("#"+SN.C.S.NoticeLat).val();SN.C.I.NoticeDataGeo.NLon=$("#"+SN.C.S.NoticeLon).val();SN.C.I.NoticeDataGeo.NLNS=$("#"+SN.C.S.NoticeLocationNs).val();SN.C.I.NoticeDataGeo.NLID=$("#"+SN.C.S.NoticeLocationId).val();SN.C.I.NoticeDataGeo.NDG=$("#"+SN.C.S.NoticeDataGeo).attr("checked");cookieValue=$.cookie(SN.C.S.NoticeDataGeoCookie);if(cookieValue!==null&&cookieValue!="disabled"){cookieValue=JSON.parse(cookieValue);SN.C.I.NoticeDataGeo.NLat=$("#"+SN.C.S.NoticeLat).val(cookieValue.NLat).val();SN.C.I.NoticeDataGeo.NLon=$("#"+SN.C.S.NoticeLon).val(cookieValue.NLon).val();if($("#"+SN.C.S.NoticeLocationNs).val(cookieValue.NLNS)){SN.C.I.NoticeDataGeo.NLNS=$("#"+SN.C.S.NoticeLocationNs).