]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
QnA - Work on getting questions and answers to appear correctly inline
authorZach Copley <zach@status.net>
Tue, 12 Apr 2011 09:22:47 +0000 (02:22 -0700)
committerZach Copley <zach@status.net>
Mon, 18 Apr 2011 23:46:11 +0000 (16:46 -0700)
js/util.js
js/util.min.js
plugins/QnA/QnAPlugin.php
plugins/QnA/actions/qnanewanswer.php
plugins/QnA/css/qna.css
plugins/QnA/js/qna.js
plugins/QnA/lib/qnashowquestionform.php

index 9ec8fa8cd91cb465fc4653bc4267adb001c6286c..2cb370ef5f8922b4256999a0cdaf25802c4594a8 100644 (file)
@@ -95,6 +95,7 @@ var SN = { // StatusNet
          * @access private
          */
         FormNoticeEnhancements: function(form) {
+            console.log("FormNoticeEnhancements - begin");
             if (jQuery.data(form[0], 'ElementData') === undefined) {
                 MaxLength = form.find('.count').text();
                 if (typeof(MaxLength) == 'undefined') {
@@ -262,7 +263,7 @@ var SN = { // StatusNet
                         errorReported = $('#error', xhr.responseXML).text();
                     }
                     alert(errorReported || errorThrown || textStatus);
-                    
+
                     // Restore the form to original state.
                     // Hopefully. :D
                     form
@@ -320,6 +321,7 @@ var SN = { // StatusNet
          * @access public
          */
         FormNoticeXHR: function(form) {
+            console.log("FormNoticeXHR - begin");
             SN.C.I.NoticeDataGeo = {};
             form.append('<input type="hidden" name="ajax" value="1"/>');
 
@@ -506,7 +508,7 @@ var SN = { // StatusNet
                         results_placeholder.replaceWith(list);
                     }
                     else {
-                        var _error = $('<li/>').append(document._importNode($('p', data)[0], true)); 
+                        var _error = $('<li/>').append(document._importNode($('p', data)[0], true));
                         results_placeholder.html(_error);
                     }
                     form
@@ -777,6 +779,7 @@ var SN = { // StatusNet
          * popout before submitting.
          *
          * Uses 'live' rather than 'bind', so applies to future as well as present items.
+         *
          */
         NoticeRepeat: function() {
             $('.form_repeat').live('click', function(e) {
index f7d57c2f8d2f8284dc2c0361e3b0325275b877d7..187cd64862aab1f7280da245eb7a9bbde7533d91 100644 (file)
@@ -1 +1 @@
-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],NoticeFormMaster:null},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",StatusNetInstance:"StatusNetInstance"}},messages:{},msg:function(a){if(typeof SN.messages[a]=="undefined"){return"["+a+"]"}else{return SN.messages[a]}},U:{FormNoticeEnhancements:function(b){if(jQuery.data(b[0],"ElementData")===undefined){MaxLength=b.find(".count").text();if(typeof(MaxLength)=="undefined"){MaxLength=SN.C.I.MaxLength}jQuery.data(b[0],"ElementData",{MaxLength:MaxLength});SN.U.Counter(b);NDT=b.find(".notice_data-text:first");NDT.bind("keyup",function(c){SN.U.Counter(b)});var a=function(c){window.setTimeout(function(){SN.U.Counter(b)},50)};NDT.bind("cut",a).bind("paste",a)}else{b.find(".count").text(jQuery.data(b[0],"ElementData").MaxLength)}},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(".count");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(".notice_data-text:first").val().length},ClearCounterBlackout:function(a){SN.C.I.CounterBlackout=false;SN.U.Counter(a)},RewriteAjaxAction:function(a){if(document.location.protocol=="https:"&&a.substr(0,5)=="http:"){return a.replace(/^http:\/\/[^:\/]+/,"https://"+document.location.host)}else{return a}},FormXHR:function(a,b){$.ajax({type:"POST",dataType:"xml",url:SN.U.RewriteAjaxAction(a.attr("action")),data:a.serialize()+"&ajax=1",beforeSend:function(c){a.addClass(SN.C.S.Processing).find(".submit").addClass(SN.C.S.Disabled).attr(SN.C.S.Disabled,SN.C.S.Disabled)},error:function(e,f,d){var c=null;if(e.responseXML){c=$("#error",e.responseXML).text()}alert(c||d||f);a.removeClass(SN.C.S.Processing).find(".submit").removeClass(SN.C.S.Disabled).removeAttr(SN.C.S.Disabled)},success:function(c,d){if(typeof($("form",c)[0])!="undefined"){form_new=document._importNode($("form",c)[0],true);a.replaceWith(form_new);if(b){b()}}else{if(typeof($("p",c)[0])!="undefined"){a.replaceWith(document._importNode($("p",c)[0],true));if(b){b()}}else{alert("Unknown error.")}}}})},FormNoticeXHR:function(b){SN.C.I.NoticeDataGeo={};b.append('<input type="hidden" name="ajax" value="1"/>');b.attr("action",SN.U.RewriteAjaxAction(b.attr("action")));var c=function(d,e){b.append($('<p class="form_response"></p>').addClass(d).text(e))};var a=function(){b.find(".form_response").remove()};b.ajaxForm({dataType:"xml",timeout:"60000",beforeSend:function(d){if(b.find(".notice_data-text:first").val()==""){b.addClass(SN.C.S.Warning);return false}b.addClass(SN.C.S.Processing).find(".submit").addClass(SN.C.S.Disabled).attr(SN.C.S.Disabled,SN.C.S.Disabled);SN.U.normalizeGeoData(b);return true},error:function(f,g,e){b.removeClass(SN.C.S.Processing).find(".submit").removeClass(SN.C.S.Disabled).removeAttr(SN.C.S.Disabled,SN.C.S.Disabled);a();if(g=="timeout"){c("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 d=SN.U.GetResponseXML(f);if($("."+SN.C.S.Error,d).length>0){b.append(document._importNode($("."+SN.C.S.Error,d)[0],true))}else{if(parseInt(f.status)===0||jQuery.inArray(parseInt(f.status),SN.C.I.HTTP20x30x)>=0){b.resetForm().find(".attach-status").remove();SN.U.FormNoticeEnhancements(b)}else{c("error","(Sorry! We had trouble sending your notice ("+f.status+" "+f.statusText+"). Please report the problem to the site administrator if this happens again.")}}}},success:function(j,f){a();var p=$("#"+SN.C.S.Error,j);if(p.length>0){c("error",p.text())}else{if($("body")[0].id=="bookmarklet"){self.close()}var d=$("#"+SN.C.S.CommandResult,j);if(d.length>0){c("success",d.text())}else{var o=document._importNode($("li",j)[0],true);var k=$("#notices_primary .notices:first");var m=b.closest("li.notice-reply");if(m.length>0){var l=b.closest(".threaded-replies");var n=l.find(".notice-reply-placeholder");m.remove();var e=$(o).attr("id");if($("#"+e).length==0){$(o).insertBefore(n)}else{}n.show()}else{if(k.length>0&&SN.U.belongsOnTimeline(o)){if($("#"+o.id).length===0){var h=b.find("[name=inreplyto]").val();var g="#notices_primary #notice-"+h;if($("body")[0].id=="conversation"){if(h.length>0&&$(g+" .notices").length<1){$(g).append('<ul class="notices"></ul>')}$($(g+" .notices")[0]).append(o)}else{k.prepend(o)}$("#"+o.id).css({display:"none"}).fadeIn(2500);SN.U.NoticeWithAttachment($("#"+o.id));SN.U.switchInputFormTab("placeholder")}}else{c("success",$("title",j).text())}}}b.resetForm();b.find("[name=inreplyto]").val("");b.find(".attach-status").remove();SN.U.FormNoticeEnhancements(b)}},complete:function(d,e){b.removeClass(SN.C.S.Processing).find(".submit").removeAttr(SN.C.S.Disabled).removeClass(SN.C.S.Disabled);b.find("[name=lat]").val(SN.C.I.NoticeDataGeo.NLat);b.find("[name=lon]").val(SN.C.I.NoticeDataGeo.NLon);b.find("[name=location_ns]").val(SN.C.I.NoticeDataGeo.NLNS);b.find("[name=location_id]").val(SN.C.I.NoticeDataGeo.NLID);b.find("[name=notice_data-geo]").attr("checked",SN.C.I.NoticeDataGeo.NDG)}})},FormProfileSearchXHR: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(d,f){var b=$("#profile_search_results");if(typeof($("ul",d)[0])!="undefined"){var c=document._importNode($("ul",d)[0],true);b.replaceWith(c)}else{var e=$("<li/>").append(document._importNode($("p",d)[0],true));b.html(e)}a.removeClass(SN.C.S.Processing).find(".submit").removeClass(SN.C.S.Disabled).attr(SN.C.S.Disabled,false)}})},FormPeopletagsXHR:function(a){$.ajax({type:"POST",dataType:"xml",url:a.attr("action"),data:a.serialize()+"&ajax=1",beforeSend:function(b){a.find(".submit").addClass(SN.C.S.Processing).addClass(SN.C.S.Disabled).attr(SN.C.S.Disabled,SN.C.S.Disabled)},error:function(c,d,b){alert(b||d)},success:function(d,e){var c=a.parents(".entity_tags");if(typeof($(".entity_tags",d)[0])!="undefined"){var b=document._importNode($(".entity_tags",d)[0],true);$(b).find(".editable").append($('<button class="peopletags_edit_button"/>'));c.replaceWith(b)}else{c.find("p").remove();c.append(document._importNode($("p",d)[0],true));a.removeClass(SN.C.S.Processing).find(".submit").removeClass(SN.C.S.Disabled).attr(SN.C.S.Disabled,false)}}})},normalizeGeoData:function(a){SN.C.I.NoticeDataGeo.NLat=a.find("[name=lat]").val();SN.C.I.NoticeDataGeo.NLon=a.find("[name=lon]").val();SN.C.I.NoticeDataGeo.NLNS=a.find("[name=location_ns]").val();SN.C.I.NoticeDataGeo.NLID=a.find("[name=location_id]").val();SN.C.I.NoticeDataGeo.NDG=a.find("[name=notice_data-geo]").attr("checked");var b=$.cookie(SN.C.S.NoticeDataGeoCookie);if(b!==null&&b!="disabled"){b=JSON.parse(b);SN.C.I.NoticeDataGeo.NLat=a.find("[name=lat]").val(b.NLat).val();SN.C.I.NoticeDataGeo.NLon=a.find("[name=lon]").val(b.NLon).val();if(b.NLNS){SN.C.I.NoticeDataGeo.NLNS=a.find("[name=location_ns]").val(b.NLNS).val();SN.C.I.NoticeDataGeo.NLID=a.find("[name=location_id]").val(b.NLID).val()}else{a.find("[name=location_ns]").val("");a.find("[name=location_id]").val("")}}if(b=="disabled"){SN.C.I.NoticeDataGeo.NDG=a.find("[name=notice_data-geo]").attr("checked",false).attr("checked")}else{SN.C.I.NoticeDataGeo.NDG=a.find("[name=notice_data-geo]").attr("checked",true).attr("checked")}},GetResponseXML:function(b){try{return b.responseXML}catch(a){return(new DOMParser()).parseFromString(b.responseText,"text/xml")}},NoticeReply:function(){$("#content .notice_reply").live("click",function(b){b.preventDefault();var a=$(this).closest("li.notice");SN.U.NoticeInlineReplyTrigger(a);return false})},NoticeReplyTo:function(a){},NoticeInlineReplyTrigger:function(j,k){var b=$($(".notice_id",j)[0]).text();var e=j;var f=j.closest(".notices");if(f.hasClass("threaded-replies")){e=f.closest(".notice")}else{f=$("ul.threaded-replies",j);if(f.length==0){console.log("list = 0");SN.U.NoticeInlineReplyPlaceholder(j);f=$("ul.threaded-replies",j)}else{var h=$("li.notice-reply-placeholder",j);if(h.length==0){SN.U.NoticeInlineReplyPlaceholder(j)}}}var l=$(".notice-reply-form",f);var d=function(){l.find("input[name=inreplyto]").val(b);l.find("#notice_to").attr("disabled","disabled").hide();l.find("#notice_private").attr("disabled","disabled").hide();l.find("label[for=notice_to]").hide();l.find("label[for=notice_private]").hide();var o=l.find("textarea");if(o.length==0){throw"No textarea"}var n="";if(k){n=k+" "}o.val(n+o.val().replace(RegExp(n,"i"),""));o.data("initialText",$.trim(k+""));o.focus();if(o[0].setSelectionRange){var m=o.val().length;o[0].setSelectionRange(m,m)}};if(l.length>0){d()}else{var h=f.find("li.notice-reply-placeholder").hide();var g=$("li.notice-reply",f);if(g.length==0){g=$('<li class="notice-reply"></li>');var c=function(m){var n=document._importNode(m,true);g.append(n);f.append(g);var o=l=$(n);SN.Init.NoticeFormSetup(o);d()};if(SN.C.I.NoticeFormMaster){c(SN.C.I.NoticeFormMaster)}else{var a=$("#form_notice").attr("action");$.get(a,{ajax:1},function(m,o,n){c($("form",m)[0])})}}}},NoticeInlineReplyPlaceholder:function(b){var a=b.find("ul.threaded-replies");if(a.length==0){a=$('<ul class="notices threaded-replies xoxo"></ul>');b.append(a);a=b.find("ul.threaded-replies")}var c=$('<li class="notice-reply-placeholder"><input class="placeholder"></li>');c.find("input").val(SN.msg("reply_placeholder"));a.append(c)},NoticeInlineReplySetup:function(){$("li.notice-reply-placeholder input").live("focus",function(){var a=$(this).closest("li.notice");SN.U.NoticeInlineReplyTrigger(a);return false});$("li.notice-reply-comments a").live("click",function(){var a=$(this).attr("href");var b=$(this).closest(".threaded-replies");$.get(a,{ajax:1},function(d,f,e){var c=$(".threaded-replies",d);if(c.length){b.replaceWith(document._importNode(c[0],true))}});return false})},NoticeRepeat:function(){$(".form_repeat").live("click",function(a){a.preventDefault();SN.U.NoticeRepeatConfirmation($(this));return false})},NoticeRepeatConfirmation:function(a){var c=a.find(".submit");var b=c.clone();b.addClass("submit_dialogbox").removeClass("submit");a.append(b);b.bind("click",function(){SN.U.FormXHR(a);return false});c.hide();a.addClass("dialogbox").append('<button class="close">&#215;</button>').closest(".notice-options").addClass("opaque");a.find("button.close").click(function(){$(this).remove();a.removeClass("dialogbox").closest(".notice-options").removeClass("opaque");a.find(".submit_dialogbox").remove();a.find(".submit").show();return false})},NoticeAttachments:function(){$(".notice a.attachment").each(function(){SN.U.NoticeWithAttachment($(this).closest(".notice"))})},NoticeWithAttachment:function(b){if(b.find(".attachment").length===0){return}var a=b.find(".attachment.more");if(a.length>0){$(a[0]).click(function(){var c=$(this);c.addClass(SN.C.S.Processing);$.get(c.attr("href")+"/ajax",null,function(d){c.parent(".entry-content").html($(d).find("#attachment_view .entry-content").html())});return false}).attr("title",SN.msg("showmore_tooltip"))}},NoticeDataAttach:function(b){var a=b.find("input[type=file]");a.change(function(f){b.find(".attach-status").remove();var d=$(this).val();if(!d){return false}var c=$('<div class="attach-status '+SN.C.S.Success+'"><code></code> <button class="close">&#215;</button></div>');c.find("code").text(d);c.find("button").click(function(){c.remove();a.val("");return false});b.append(c);if(typeof this.files=="object"){for(var e=0;e<this.files.length;e++){SN.U.PreviewAttach(b,this.files[e])}}})},maxFileSize:function(b){var a=$(b).find("input[name=MAX_FILE_SIZE]").attr("value");if(a){return parseInt(a)}else{return 0}},PreviewAttach:function(d,c){var e=c.type+" "+Math.round(c.size/1024)+"KB";var f=true;var h;if(typeof window.createObjectURL!="undefined"){h=function(j,k){k(window.createObjectURL(j))}}else{if(typeof window.FileReader!="undefined"){h=function(k,l){var j=new FileReader();j.onload=function(m){l(j.result)};j.readAsDataURL(k)}}else{f=false}}var a=["image/png","image/jpeg","image/gif","image/svg+xml"];if($.inArray(c.type,a)==-1){f=false}var g=8*1024*1024;if(c.size>g){f=false}if(f){h(c,function(k){var j=$("<img>").attr("title",e).attr("alt",e).attr("src",k).attr("style","height: 120px");d.find(".attach-status").append(j)})}else{var b=$("<div></div>").text(e);d.find(".attach-status").append(b)}},NoticeLocationAttach:function(a){var e=a.find("[name=lat]");var l=a.find("[name=lon]");var g=a.find("[name=location_ns]").val();var m=a.find("[name=location_id]").val();var b="";var d=a.find("[name=notice_data-geo]");var c=a.find("[name=notice_data-geo]");var k=a.find("label.notice_data-geo");function f(o){k.attr("title",jQuery.trim(k.text())).removeClass("checked");a.find("[name=lat]").val("");a.find("[name=lon]").val("");a.find("[name=location_ns]").val("");a.find("[name=location_id]").val("");a.find("[name=notice_data-geo]").attr("checked",false);$.cookie(SN.C.S.NoticeDataGeoCookie,"disabled",{path:"/"});if(o){a.find(".geo_status_wrapper").removeClass("success").addClass("error");a.find(".geo_status_wrapper .geo_status").text(o)}else{a.find(".geo_status_wrapper").remove()}}function n(o,p){SN.U.NoticeGeoStatus(a,"Looking up place name...");$.getJSON(o,p,function(q){var r,s;if(typeof(q.location_ns)!="undefined"){a.find("[name=location_ns]").val(q.location_ns);r=q.location_ns}if(typeof(q.location_id)!="undefined"){a.find("[name=location_id]").val(q.location_id);s=q.location_id}if(typeof(q.name)=="undefined"){NLN_text=p.lat+";"+p.lon}else{NLN_text=q.name}SN.U.NoticeGeoStatus(a,NLN_text,p.lat,p.lon,q.url);k.attr("title",NoticeDataGeo_text.ShareDisable+" ("+NLN_text+")");a.find("[name=lat]").val(p.lat);a.find("[name=lon]").val(p.lon);a.find("[name=location_ns]").val(r);a.find("[name=location_id]").val(s);a.find("[name=notice_data-geo]").attr("checked",true);var t={NLat:p.lat,NLon:p.lon,NLNS:r,NLID:s,NLN:NLN_text,NLNU:q.url,NDG:true};$.cookie(SN.C.S.NoticeDataGeoCookie,JSON.stringify(t),{path:"/"})})}if(c.length>0){if($.cookie(SN.C.S.NoticeDataGeoCookie)=="disabled"){c.attr("checked",false)}else{c.attr("checked",true)}var h=a.find(".notice_data-geo_wrap");var j=h.attr("data-api");k.attr("title",k.text());c.change(function(){if(c.attr("checked")===true||$.cookie(SN.C.S.NoticeDataGeoCookie)===null){k.attr("title",NoticeDataGeo_text.ShareDisable).addClass("checked");if($.cookie(SN.C.S.NoticeDataGeoCookie)===null||$.cookie(SN.C.S.NoticeDataGeoCookie)=="disabled"){if(navigator.geolocation){SN.U.NoticeGeoStatus(a,"Requesting location from browser...");navigator.geolocation.getCurrentPosition(function(q){a.find("[name=lat]").val(q.coords.latitude);a.find("[name=lon]").val(q.coords.longitude);var r={lat:q.coords.latitude,lon:q.coords.longitude,token:$("#token").val()};n(j,r)},function(q){switch(q.code){case q.PERMISSION_DENIED:f("Location permission denied.");break;case q.TIMEOUT:f("Location lookup timeout.");break}},{timeout:10000})}else{if(e.length>0&&l.length>0){var o={lat:e,lon:l,token:$("#token").val()};n(j,o)}else{f();c.remove();k.remove()}}}else{var p=JSON.parse($.cookie(SN.C.S.NoticeDataGeoCookie));a.find("[name=lat]").val(p.NLat);a.find("[name=lon]").val(p.NLon);a.find("[name=location_ns]").val(p.NLNS);a.find("[name=location_id]").val(p.NLID);a.find("[name=notice_data-geo]").attr("checked",p.NDG);SN.U.NoticeGeoStatus(a,p.NLN,p.NLat,p.NLon,p.NLNU);k.attr("title",NoticeDataGeo_text.ShareDisable+" ("+p.NLN+")").addClass("checked")}}else{f()}}).change()}},NoticeGeoStatus:function(e,a,f,g,c){var h=e.find(".geo_status_wrapper");if(h.length==0){h=$('<div class="'+SN.C.S.Success+' geo_status_wrapper"><button class="close" style="float:right">&#215;</button><div class="geo_status"></div></div>');h.find("button.close").click(function(){e.find("[name=notice_data-geo]").removeAttr("checked").change();return false});e.append(h)}var b;if(c){b=$("<a></a>").attr("href",c)}else{b=$("<span></span>")}b.text(a);if(f||g){var d=f+";"+g;b.attr("title",d);if(!a){b.text(d)}}h.find(".geo_status").empty().append(b)},NewDirectMessage:function(){NDM=$(".entity_send-a-message a");NDM.attr({href:NDM.attr("href")+"&ajax=1"});NDM.bind("click",function(){var a=$(".entity_send-a-message form");if(a.length===0){$(this).addClass(SN.C.S.Processing);$.get(NDM.attr("href"),null,function(b){$(".entity_send-a-message").append(document._importNode($("form",b)[0],true));a=$(".entity_send-a-message .form_notice");SN.U.FormNoticeXHR(a);SN.U.FormNoticeEnhancements(a);a.append('<button class="close">&#215;</button>');$(".entity_send-a-message button").click(function(){a.hide();return false});NDM.removeClass(SN.C.S.Processing)})}else{a.show();$(".entity_send-a-message textarea").focus()}return false})},GetFullYear:function(c,d,a){var b=new Date();b.setFullYear(c,d,a);return b},StatusNetInstance:{Set:function(b){var a=SN.U.StatusNetInstance.Get();if(a!==null){b=$.extend(a,b)}$.cookie(SN.C.S.StatusNetInstance,JSON.stringify(b),{path:"/",expires:SN.U.GetFullYear(2029,0,1)})},Get:function(){var a=$.cookie(SN.C.S.StatusNetInstance);if(a!==null){return JSON.parse(a)}return null},Delete:function(){$.cookie(SN.C.S.StatusNetInstance,null)}},belongsOnTimeline:function(b){var a=$("body").attr("id");if(a=="public"){return true}var c=$("#nav_profile a").attr("href");if(c){var d=$(b).find(".vcard.author a.url").attr("href");if(d==c){if(a=="all"||a=="showstream"){return true}}}return false},switchInputFormTab:function(a){$(".input_form_nav_tab.current").removeClass("current");if(a=="placeholder"){$("#input_form_nav_status").addClass("current")}else{$("#input_form_nav_"+a).addClass("current")}var b=$(".input_form.current.nonav");if(b.length>0){return}$(".input_form.current").removeClass("current");$("#input_form_"+a).addClass("current").find(".ajax-notice").each(function(){var c=$(this);SN.Init.NoticeFormSetup(c)}).find(".notice_data-text").focus()}},Init:{NoticeForm:function(){if($("body.user_in").length>0){$("#input_form_placeholder input.placeholder").focus(function(){SN.U.switchInputFormTab("status")});$("body").bind("click",function(g){var d=$("#content .input_forms div.current");if(d.length>0){if($("#content .input_forms").has(g.target).length==0){var a=d.find('textarea, input[type=text], input[type=""]');var c=false;a.each(function(){c=c||$(this).val()});if(!c){SN.U.switchInputFormTab("placeholder")}}}var b=$("li.notice-reply");if(b.length>0){var f=$(g.target);b.each(function(){var k=$(this);if(k.has(g.target).length==0){var h=k.find(".notice_data-text:first");var j=$.trim(h.val());if(j==""||j==h.data("initialText")){var e=k.closest("li.notice");k.remove();e.find("li.notice-reply-placeholder").show()}}})}});$(".input_forms fieldset fieldset label").inFieldLabels({fadeOpacity:0})}},NoticeFormSetup:function(a){if(!a.data("NoticeFormSetup")){SN.U.NoticeLocationAttach(a);SN.U.FormNoticeXHR(a);SN.U.FormNoticeEnhancements(a);SN.U.NoticeDataAttach(a);a.data("NoticeFormSetup",true)}},Notices:function(){if($("body.user_in").length>0){var a=$(".form_notice:first");if(a.length>0){SN.C.I.NoticeFormMaster=document._importNode(a[0],true)}SN.U.NoticeRepeat();SN.U.NoticeReply();SN.U.NoticeInlineReplySetup()}SN.U.NoticeAttachments()},EntityActions:function(){if($("body.user_in").length>0){$(".form_user_subscribe").live("click",function(){SN.U.FormXHR($(this));return false});$(".form_user_unsubscribe").live("click",function(){SN.U.FormXHR($(this));return false});$(".form_group_join").live("click",function(){SN.U.FormXHR($(this));return false});$(".form_group_leave").live("click",function(){SN.U.FormXHR($(this));return false});$(".form_user_nudge").live("click",function(){SN.U.FormXHR($(this));return false});$(".form_peopletag_subscribe").live("click",function(){SN.U.FormXHR($(this));return false});$(".form_peopletag_unsubscribe").live("click",function(){SN.U.FormXHR($(this));return false});$(".form_user_add_peopletag").live("click",function(){SN.U.FormXHR($(this));return false});$(".form_user_remove_peopletag").live("click",function(){SN.U.FormXHR($(this));return false});SN.U.NewDirectMessage()}},ProfileSearch:function(){if($("body.user_in").length>0){$(".form_peopletag_edit_user_search input.submit").live("click",function(){SN.U.FormProfileSearchXHR($(this).parents("form"));return false})}},Login:function(){if(SN.U.StatusNetInstance.Get()!==null){var a=SN.U.StatusNetInstance.Get().Nickname;if(a!==null){$("#form_login #nickname").val(a)}}$("#form_login").bind("submit",function(){SN.U.StatusNetInstance.Set({Nickname:$("#form_login #nickname").val()});return true})},PeopletagAutocomplete:function(b){var a=function(d){return d.split(/\s+/)};var c=function(d){return a(d).pop()};b.live("keydown",function(d){if(d.keyCode===$.ui.keyCode.TAB&&$(this).data("autocomplete").menu.active){d.preventDefault()}}).autocomplete({minLength:0,source:function(e,d){d($.ui.autocomplete.filter(SN.C.PtagACData,c(e.term)))},focus:function(){return false},select:function(e,f){var d=a(this.value);d.pop();d.push(f.item.value);d.push("");this.value=d.join(" ");return false}}).data("autocomplete")._renderItem=function(e,f){var d='<a class="ptag-ac-line-tag">'+f.tag+' <em class="privacy_mode">'+f.mode+'</em><span class="freq">'+f.freq+"</span></a>";return $("<li/>").addClass("mode-"+f.mode).addClass("ptag-ac-line").data("item.autocomplete",f).append(d).appendTo(e)}},PeopleTags:function(){$(".user_profile_tags .editable").append($('<button class="peopletags_edit_button"/>'));$(".peopletags_edit_button").live("click",function(){var a=$(this).parents("dd").eq(0).find("form");$.ajax({url:_peopletagAC,dataType:"json",data:{token:$("#token").val()},ifModified:true,success:function(b){for(i=0;i<b.length;i++){b[i].label=b[i].tag}SN.C.PtagACData=b;SN.Init.PeopletagAutocomplete(a.find("#tags"))}});$(this).parents("ul").eq(0).fadeOut(200,function(){a.fadeIn(200).find("input#tags")})});$(".user_profile_tags form .submit").live("click",function(){SN.U.FormPeopletagsXHR($(this).parents("form"));return false})},AjaxForms:function(){$("form.ajax").live("submit",function(){SN.U.FormXHR($(this));return false});$("form.ajax input[type=submit]").live("click",function(){var a=$(this);var b=a.closest("form");b.find(".hidden-submit-button").remove();$('<input class="hidden-submit-button" type="hidden" />').attr("name",a.attr("name")).val(a.val()).appendTo(b)})},UploadForms:function(){$("input[type=file]").change(function(d){if(typeof this.files=="object"&&this.files.length>0){var c=0;for(var b=0;b<this.files.length;b++){c+=this.files[b].size}var a=SN.U.maxFileSize($(this.form));if(a>0&&c>a){var e="File too large: maximum upload size is %d bytes.";alert(e.replace("%d",a));$(this).val("");d.preventDefault();return false}}})},CheckBoxes:function(){$("span[class='checkbox-wrapper']").addClass("unchecked");$(".checkbox-wrapper").click(function(){if($(this).children("input").attr("checked")){$(this).children("input").attr({checked:""});$(this).removeClass("checked");$(this).addClass("unchecked");$(this).children("label").text("Private?")}else{$(this).children("input").attr({checked:"checked"});$(this).removeClass("unchecked");$(this).addClass("checked");$(this).children("label").text("Private")}})}}};$(document).ready(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($("#form_login").length>0){SN.Init.Login()}if($("#profile_search_results").length>0){SN.Init.ProfileSearch()}if($(".user_profile_tags .editable").length>0){SN.Init.PeopleTags()}});if(!document.ELEMENT_NODE){document.ELEMENT_NODE=1;document.ATTRIBUTE_NODE=2;document.TEXT_NODE=3;document.CDATA_SECTION_NODE=4;document.ENTITY_REFERENCE_NODE=5;document.ENTITY_NODE=6;document.PROCESSING_INSTRUCTION_NODE=7;document.COMMENT_NODE=8;document.DOCUMENT_NODE=9;document.DOCUMENT_TYPE_NODE=10;document.DOCUMENT_FRAGMENT_NODE=11;document.NOTATION_NODE=12}document._importNode=function(e,a){switch(e.nodeType){case document.ELEMENT_NODE:var d=document.createElement(e.nodeName);if(e.attributes&&e.attributes.length>0){for(var c=0,b=e.attributes.length;c<b;){if(e.attributes[c].nodeName=="class"){d.className=e.getAttribute(e.attributes[c++].nodeName)}else{d.setAttribute(e.attributes[c].nodeName,e.getAttribute(e.attributes[c++].nodeName))}}}if(a&&e.childNodes&&e.childNodes.length>0){for(var c=0,b=e.childNodes.length;c<b;){d.appendChild(document._importNode(e.childNodes[c++],a))}}return d;break;case document.TEXT_NODE:case document.CDATA_SECTION_NODE:case document.COMMENT_NODE:return document.createTextNode(e.nodeValue);break}};if(typeof navigator.geolocation=="undefined"||navigator.geolocation.shim){(function(){(function(){if(window.google&&google.gears){return}var c=null;if(typeof GearsFactory!="undefined"){c=new GearsFactory()}else{try{c=new ActiveXObject("Gears.Factory");if(c.getBuildInfo().indexOf("ie_mobile")!=-1){c.privateSetGlobalObject(this)}}catch(d){if((typeof navigator.mimeTypes!="undefined")&&navigator.mimeTypes["application/x-googlegears"]){c=document.createElement("object");c.style.display="none";c.width=0;c.height=0;c.type="application/x-googlegears";document.documentElement.appendChild(c)}}}if(!c){return}if(!window.google){google={}}if(!google.gears){google.gears={factory:c}}})();var a=(function(){var d=google.gears.factory.create("beta.geolocation");var c=function(f,e){return function(g){f(g);e.lastPosition=g}};return{shim:true,type:"Gears",lastPosition:null,getCurrentPosition:function(e,g,h){var f=this;var j=c(e,f);d.getCurrentPosition(j,g,h)},watchPosition:function(e,f,g){d.watchPosition(e,f,g)},clearWatch:function(e){d.clearWatch(e)},getPermission:function(g,e,f){d.getPermission(g,e,f)}}});var b=(function(){var j=false;var e=function(){if(!d()&&!j){j=true;var k=document.createElement("script");k.src=(document.location.protocol=="https:"?"https://":"http://")+"www.google.com/jsapi?callback=_google_loader_apiLoaded";k.type="text/javascript";document.getElementsByTagName("body")[0].appendChild(k)}};var c=[];var h=function(k){c.push(k)};var f=function(){if(d()){while(c.length>0){var k=c.pop();k()}}};window._google_loader_apiLoaded=function(){f()};var d=function(){return(window.google&&google.loader)};var g=function(k){if(d()){return true}h(k);e();return false};e();return{shim:true,type:"ClientLocation",lastPosition:null,getCurrentPosition:function(l,o,p){var n=this;if(!g(function(){n.getCurrentPosition(l,o,p)})){return}if(google.loader.ClientLocation){var m=google.loader.ClientLocation;var k={coords:{latitude:m.latitude,longitude:m.longitude,altitude:null,accuracy:43000,altitudeAccuracy:null,heading:null,speed:null},address:{city:m.address.city,country:m.address.country,country_code:m.address.country_code,region:m.address.region},timestamp:new Date()};l(k);this.lastPosition=k}else{if(o==="function"){o({code:3,message:"Using the Google ClientLocation API and it is not able to calculate a location."})}}},watchPosition:function(k,m,n){this.getCurrentPosition(k,m,n);var l=this;var o=setInterval(function(){l.getCurrentPosition(k,m,n)},10000);return o},clearWatch:function(k){clearInterval(k)},getPermission:function(m,k,l){return true}}});navigator.geolocation=(window.google&&google.gears)?a():b()})()};
\ No newline at end of file
+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],NoticeFormMaster:null},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",StatusNetInstance:"StatusNetInstance"}},messages:{},msg:function(a){if(typeof SN.messages[a]=="undefined"){return"["+a+"]"}else{return SN.messages[a]}},U:{FormNoticeEnhancements:function(b){if(jQuery.data(b[0],"ElementData")===undefined){MaxLength=b.find(".count").text();if(typeof(MaxLength)=="undefined"){MaxLength=SN.C.I.MaxLength}jQuery.data(b[0],"ElementData",{MaxLength:MaxLength});SN.U.Counter(b);NDT=b.find(".notice_data-text:first");NDT.bind("keyup",function(c){SN.U.Counter(b)});var a=function(c){window.setTimeout(function(){SN.U.Counter(b)},50)};NDT.bind("cut",a).bind("paste",a)}else{b.find(".count").text(jQuery.data(b[0],"ElementData").MaxLength)}},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(".count");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(".notice_data-text:first").val().length},ClearCounterBlackout:function(a){SN.C.I.CounterBlackout=false;SN.U.Counter(a)},RewriteAjaxAction:function(a){if(document.location.protocol=="https:"&&a.substr(0,5)=="http:"){return a.replace(/^http:\/\/[^:\/]+/,"https://"+document.location.host)}else{return a}},FormXHR:function(a,b){$.ajax({type:"POST",dataType:"xml",url:SN.U.RewriteAjaxAction(a.attr("action")),data:a.serialize()+"&ajax=1",beforeSend:function(c){a.addClass(SN.C.S.Processing).find(".submit").addClass(SN.C.S.Disabled).attr(SN.C.S.Disabled,SN.C.S.Disabled)},error:function(e,f,d){var c=null;if(e.responseXML){c=$("#error",e.responseXML).text()}alert(c||d||f);a.removeClass(SN.C.S.Processing).find(".submit").removeClass(SN.C.S.Disabled).removeAttr(SN.C.S.Disabled)},success:function(c,d){if(typeof($("form",c)[0])!="undefined"){form_new=document._importNode($("form",c)[0],true);a.replaceWith(form_new);if(b){b()}}else{if(typeof($("p",c)[0])!="undefined"){a.replaceWith(document._importNode($("p",c)[0],true));if(b){b()}}else{alert("Unknown error.")}}}})},FormNoticeXHR:function(b){SN.C.I.NoticeDataGeo={};b.append('<input type="hidden" name="ajax" value="1"/>');b.attr("action",SN.U.RewriteAjaxAction(b.attr("action")));var c=function(d,e){b.append($('<p class="form_response"></p>').addClass(d).text(e))};var a=function(){b.find(".form_response").remove()};b.ajaxForm({dataType:"xml",timeout:"60000",beforeSend:function(d){if(b.find(".notice_data-text:first").val()==""){b.addClass(SN.C.S.Warning);return false}b.addClass(SN.C.S.Processing).find(".submit").addClass(SN.C.S.Disabled).attr(SN.C.S.Disabled,SN.C.S.Disabled);SN.U.normalizeGeoData(b);return true},error:function(f,g,e){b.removeClass(SN.C.S.Processing).find(".submit").removeClass(SN.C.S.Disabled).removeAttr(SN.C.S.Disabled,SN.C.S.Disabled);a();if(g=="timeout"){c("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 d=SN.U.GetResponseXML(f);if($("."+SN.C.S.Error,d).length>0){b.append(document._importNode($("."+SN.C.S.Error,d)[0],true))}else{if(parseInt(f.status)===0||jQuery.inArray(parseInt(f.status),SN.C.I.HTTP20x30x)>=0){b.resetForm().find(".attach-status").remove();SN.U.FormNoticeEnhancements(b)}else{c("error","(Sorry! We had trouble sending your notice ("+f.status+" "+f.statusText+"). Please report the problem to the site administrator if this happens again.")}}}},success:function(j,f){a();var p=$("#"+SN.C.S.Error,j);if(p.length>0){c("error",p.text())}else{if($("body")[0].id=="bookmarklet"){self.close()}var d=$("#"+SN.C.S.CommandResult,j);if(d.length>0){c("success",d.text())}else{var o=document._importNode($("li",j)[0],true);var k=$("#notices_primary .notices:first");var m=b.closest("li.notice-reply");if(m.length>0){var l=b.closest(".threaded-replies");var n=l.find(".notice-reply-placeholder");m.remove();var e=$(o).attr("id");if($("#"+e).length==0){$(o).insertBefore(n)}else{}n.show()}else{if(k.length>0&&SN.U.belongsOnTimeline(o)){if($("#"+o.id).length===0){var h=b.find("[name=inreplyto]").val();var g="#notices_primary #notice-"+h;if($("body")[0].id=="conversation"){if(h.length>0&&$(g+" .notices").length<1){$(g).append('<ul class="notices"></ul>')}$($(g+" .notices")[0]).append(o)}else{k.prepend(o)}$("#"+o.id).css({display:"none"}).fadeIn(2500);SN.U.NoticeWithAttachment($("#"+o.id));SN.U.switchInputFormTab("placeholder")}}else{c("success",$("title",j).text())}}}b.resetForm();b.find("[name=inreplyto]").val("");b.find(".attach-status").remove();SN.U.FormNoticeEnhancements(b)}},complete:function(d,e){b.removeClass(SN.C.S.Processing).find(".submit").removeAttr(SN.C.S.Disabled).removeClass(SN.C.S.Disabled);b.find("[name=lat]").val(SN.C.I.NoticeDataGeo.NLat);b.find("[name=lon]").val(SN.C.I.NoticeDataGeo.NLon);b.find("[name=location_ns]").val(SN.C.I.NoticeDataGeo.NLNS);b.find("[name=location_id]").val(SN.C.I.NoticeDataGeo.NLID);b.find("[name=notice_data-geo]").attr("checked",SN.C.I.NoticeDataGeo.NDG)}})},FormProfileSearchXHR: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(d,f){var b=$("#profile_search_results");if(typeof($("ul",d)[0])!="undefined"){var c=document._importNode($("ul",d)[0],true);b.replaceWith(c)}else{var e=$("<li/>").append(document._importNode($("p",d)[0],true));b.html(e)}a.removeClass(SN.C.S.Processing).find(".submit").removeClass(SN.C.S.Disabled).attr(SN.C.S.Disabled,false)}})},FormPeopletagsXHR:function(a){$.ajax({type:"POST",dataType:"xml",url:a.attr("action"),data:a.serialize()+"&ajax=1",beforeSend:function(b){a.find(".submit").addClass(SN.C.S.Processing).addClass(SN.C.S.Disabled).attr(SN.C.S.Disabled,SN.C.S.Disabled)},error:function(c,d,b){alert(b||d)},success:function(d,e){var c=a.parents(".entity_tags");if(typeof($(".entity_tags",d)[0])!="undefined"){var b=document._importNode($(".entity_tags",d)[0],true);$(b).find(".editable").append($('<button class="peopletags_edit_button"/>'));c.replaceWith(b)}else{c.find("p").remove();c.append(document._importNode($("p",d)[0],true));a.removeClass(SN.C.S.Processing).find(".submit").removeClass(SN.C.S.Disabled).attr(SN.C.S.Disabled,false)}}})},normalizeGeoData:function(a){SN.C.I.NoticeDataGeo.NLat=a.find("[name=lat]").val();SN.C.I.NoticeDataGeo.NLon=a.find("[name=lon]").val();SN.C.I.NoticeDataGeo.NLNS=a.find("[name=location_ns]").val();SN.C.I.NoticeDataGeo.NLID=a.find("[name=location_id]").val();SN.C.I.NoticeDataGeo.NDG=a.find("[name=notice_data-geo]").attr("checked");var b=$.cookie(SN.C.S.NoticeDataGeoCookie);if(b!==null&&b!="disabled"){b=JSON.parse(b);SN.C.I.NoticeDataGeo.NLat=a.find("[name=lat]").val(b.NLat).val();SN.C.I.NoticeDataGeo.NLon=a.find("[name=lon]").val(b.NLon).val();if(b.NLNS){SN.C.I.NoticeDataGeo.NLNS=a.find("[name=location_ns]").val(b.NLNS).val();SN.C.I.NoticeDataGeo.NLID=a.find("[name=location_id]").val(b.NLID).val()}else{a.find("[name=location_ns]").val("");a.find("[name=location_id]").val("")}}if(b=="disabled"){SN.C.I.NoticeDataGeo.NDG=a.find("[name=notice_data-geo]").attr("checked",false).attr("checked")}else{SN.C.I.NoticeDataGeo.NDG=a.find("[name=notice_data-geo]").attr("checked",true).attr("checked")}},GetResponseXML:function(b){try{return b.responseXML}catch(a){return(new DOMParser()).parseFromString(b.responseText,"text/xml")}},NoticeReply:function(){$("#content .notice_reply").live("click",function(b){b.preventDefault();var a=$(this).closest("li.notice");SN.U.NoticeInlineReplyTrigger(a);return false})},NoticeReplyTo:function(a){},NoticeInlineReplyTrigger:function(j,k){var b=$($(".notice_id",j)[0]).text();var e=j;var f=j.closest(".notices");if(f.hasClass("threaded-replies")){e=f.closest(".notice")}else{f=$("ul.threaded-replies",j);if(f.length==0){console.log("list = 0");SN.U.NoticeInlineReplyPlaceholder(j);f=$("ul.threaded-replies",j)}else{var h=$("li.notice-reply-placeholder",j);if(h.length==0){SN.U.NoticeInlineReplyPlaceholder(j)}}}var l=$(".notice-reply-form",f);var d=function(){l.find("input[name=inreplyto]").val(b);l.find("#notice_to").attr("disabled","disabled").hide();l.find("#notice_private").attr("disabled","disabled").hide();l.find("label[for=notice_to]").hide();l.find("label[for=notice_private]").hide();var o=l.find("textarea");if(o.length==0){throw"No textarea"}var n="";if(k){n=k+" "}o.val(n+o.val().replace(RegExp(n,"i"),""));o.data("initialText",$.trim(k+""));o.focus();if(o[0].setSelectionRange){var m=o.val().length;o[0].setSelectionRange(m,m)}};if(l.length>0){d()}else{var h=f.find("li.notice-reply-placeholder").hide();var g=$("li.notice-reply",f);if(g.length==0){g=$('<li class="notice-reply"></li>');var c=function(m){var n=document._importNode(m,true);g.append(n);f.append(g);var o=l=$(n);SN.Init.NoticeFormSetup(o);d()};if(SN.C.I.NoticeFormMaster){c(SN.C.I.NoticeFormMaster)}else{var a=$("#form_notice").attr("action");$.get(a,{ajax:1},function(m,o,n){c($("form",m)[0])})}}}},NoticeInlineReplyPlaceholder:function(b){var a=b.find("ul.threaded-replies");if(a.length==0){a=$('<ul class="notices threaded-replies xoxo"></ul>');b.append(a);a=b.find("ul.threaded-replies")}var c=$('<li class="notice-reply-placeholder"><input class="placeholder"></li>');c.find("input").val(SN.msg("reply_placeholder"));a.append(c)},NoticeInlineReplySetup:function(){$("li.notice-reply-placeholder input").live("focus",function(){var a=$(this).closest("li.notice");SN.U.NoticeInlineReplyTrigger(a);return false});$("li.notice-reply-comments a").live("click",function(){var a=$(this).attr("href");var b=$(this).closest(".threaded-replies");$.get(a,{ajax:1},function(d,f,e){var c=$(".threaded-replies",d);if(c.length){b.replaceWith(document._importNode(c[0],true))}});return false})},NoticeRepeat:function(){$(".form_repeat").live("click",function(a){a.preventDefault();SN.U.NoticeRepeatConfirmation($(this));return false})},NoticeRepeatConfirmation:function(a){var c=a.find(".submit");var b=c.clone();b.addClass("submit_dialogbox").removeClass("submit");a.append(b);b.bind("click",function(){SN.U.FormXHR(a);return false});c.hide();a.addClass("dialogbox").append('<button class="close">&#215;</button>').closest(".notice-options").addClass("opaque");a.find("button.close").click(function(){$(this).remove();a.removeClass("dialogbox").closest(".notice-options").removeClass("opaque");a.find(".submit_dialogbox").remove();a.find(".submit").show();return false})},NoticeAttachments:function(){$(".notice a.attachment").each(function(){SN.U.NoticeWithAttachment($(this).closest(".notice"))})},NoticeWithAttachment:function(b){if(b.find(".attachment").length===0){return}var a=b.find(".attachment.more");if(a.length>0){$(a[0]).click(function(){var c=$(this);c.addClass(SN.C.S.Processing);$.get(c.attr("href")+"/ajax",null,function(d){c.parent(".entry-content").html($(d).find("#attachment_view .entry-content").html())});return false}).attr("title",SN.msg("showmore_tooltip"))}},NoticeDataAttach:function(b){var a=b.find("input[type=file]");a.change(function(f){b.find(".attach-status").remove();var d=$(this).val();if(!d){return false}var c=$('<div class="attach-status '+SN.C.S.Success+'"><code></code> <button class="close">&#215;</button></div>');c.find("code").text(d);c.find("button").click(function(){c.remove();a.val("");return false});b.append(c);if(typeof this.files=="object"){for(var e=0;e<this.files.length;e++){SN.U.PreviewAttach(b,this.files[e])}}})},maxFileSize:function(b){var a=$(b).find("input[name=MAX_FILE_SIZE]").attr("value");if(a){return parseInt(a)}else{return 0}},PreviewAttach:function(d,c){var e=c.type+" "+Math.round(c.size/1024)+"KB";var f=true;var h;if(typeof window.createObjectURL!="undefined"){h=function(j,k){k(window.createObjectURL(j))}}else{if(typeof window.FileReader!="undefined"){h=function(k,l){var j=new FileReader();j.onload=function(m){l(j.result)};j.readAsDataURL(k)}}else{f=false}}var a=["image/png","image/jpeg","image/gif","image/svg+xml"];if($.inArray(c.type,a)==-1){f=false}var g=8*1024*1024;if(c.size>g){f=false}if(f){h(c,function(k){var j=$("<img>").attr("title",e).attr("alt",e).attr("src",k).attr("style","height: 120px");d.find(".attach-status").append(j)})}else{var b=$("<div></div>").text(e);d.find(".attach-status").append(b)}},NoticeLocationAttach:function(a){var e=a.find("[name=lat]");var l=a.find("[name=lon]");var g=a.find("[name=location_ns]").val();var m=a.find("[name=location_id]").val();var b="";var d=a.find("[name=notice_data-geo]");var c=a.find("[name=notice_data-geo]");var k=a.find("label.notice_data-geo");function f(o){k.attr("title",jQuery.trim(k.text())).removeClass("checked");a.find("[name=lat]").val("");a.find("[name=lon]").val("");a.find("[name=location_ns]").val("");a.find("[name=location_id]").val("");a.find("[name=notice_data-geo]").attr("checked",false);$.cookie(SN.C.S.NoticeDataGeoCookie,"disabled",{path:"/"});if(o){a.find(".geo_status_wrapper").removeClass("success").addClass("error");a.find(".geo_status_wrapper .geo_status").text(o)}else{a.find(".geo_status_wrapper").remove()}}function n(o,p){SN.U.NoticeGeoStatus(a,"Looking up place name...");$.getJSON(o,p,function(q){var r,s;if(typeof(q.location_ns)!="undefined"){a.find("[name=location_ns]").val(q.location_ns);r=q.location_ns}if(typeof(q.location_id)!="undefined"){a.find("[name=location_id]").val(q.location_id);s=q.location_id}if(typeof(q.name)=="undefined"){NLN_text=p.lat+";"+p.lon}else{NLN_text=q.name}SN.U.NoticeGeoStatus(a,NLN_text,p.lat,p.lon,q.url);k.attr("title",NoticeDataGeo_text.ShareDisable+" ("+NLN_text+")");a.find("[name=lat]").val(p.lat);a.find("[name=lon]").val(p.lon);a.find("[name=location_ns]").val(r);a.find("[name=location_id]").val(s);a.find("[name=notice_data-geo]").attr("checked",true);var t={NLat:p.lat,NLon:p.lon,NLNS:r,NLID:s,NLN:NLN_text,NLNU:q.url,NDG:true};$.cookie(SN.C.S.NoticeDataGeoCookie,JSON.stringify(t),{path:"/"})})}if(c.length>0){if($.cookie(SN.C.S.NoticeDataGeoCookie)=="disabled"){c.attr("checked",false)}else{c.attr("checked",true)}var h=a.find(".notice_data-geo_wrap");var j=h.attr("data-api");k.attr("title",k.text());c.change(function(){if(c.attr("checked")===true||$.cookie(SN.C.S.NoticeDataGeoCookie)===null){k.attr("title",NoticeDataGeo_text.ShareDisable).addClass("checked");if($.cookie(SN.C.S.NoticeDataGeoCookie)===null||$.cookie(SN.C.S.NoticeDataGeoCookie)=="disabled"){if(navigator.geolocation){SN.U.NoticeGeoStatus(a,"Requesting location from browser...");navigator.geolocation.getCurrentPosition(function(q){a.find("[name=lat]").val(q.coords.latitude);a.find("[name=lon]").val(q.coords.longitude);var r={lat:q.coords.latitude,lon:q.coords.longitude,token:$("#token").val()};n(j,r)},function(q){switch(q.code){case q.PERMISSION_DENIED:f("Location permission denied.");break;case q.TIMEOUT:f("Location lookup timeout.");break}},{timeout:10000})}else{if(e.length>0&&l.length>0){var o={lat:e,lon:l,token:$("#token").val()};n(j,o)}else{f();c.remove();k.remove()}}}else{var p=JSON.parse($.cookie(SN.C.S.NoticeDataGeoCookie));a.find("[name=lat]").val(p.NLat);a.find("[name=lon]").val(p.NLon);a.find("[name=location_ns]").val(p.NLNS);a.find("[name=location_id]").val(p.NLID);a.find("[name=notice_data-geo]").attr("checked",p.NDG);SN.U.NoticeGeoStatus(a,p.NLN,p.NLat,p.NLon,p.NLNU);k.attr("title",NoticeDataGeo_text.ShareDisable+" ("+p.NLN+")").addClass("checked")}}else{f()}}).change()}},NoticeGeoStatus:function(e,a,f,g,c){var h=e.find(".geo_status_wrapper");if(h.length==0){h=$('<div class="'+SN.C.S.Success+' geo_status_wrapper"><button class="close" style="float:right">&#215;</button><div class="geo_status"></div></div>');h.find("button.close").click(function(){e.find("[name=notice_data-geo]").removeAttr("checked").change();return false});e.append(h)}var b;if(c){b=$("<a></a>").attr("href",c)}else{b=$("<span></span>")}b.text(a);if(f||g){var d=f+";"+g;b.attr("title",d);if(!a){b.text(d)}}h.find(".geo_status").empty().append(b)},NewDirectMessage:function(){NDM=$(".entity_send-a-message a");NDM.attr({href:NDM.attr("href")+"&ajax=1"});NDM.bind("click",function(){var a=$(".entity_send-a-message form");if(a.length===0){$(this).addClass(SN.C.S.Processing);$.get(NDM.attr("href"),null,function(b){$(".entity_send-a-message").append(document._importNode($("form",b)[0],true));a=$(".entity_send-a-message .form_notice");SN.U.FormNoticeXHR(a);SN.U.FormNoticeEnhancements(a);a.append('<button class="close">&#215;</button>');$(".entity_send-a-message button").click(function(){a.hide();return false});NDM.removeClass(SN.C.S.Processing)})}else{a.show();$(".entity_send-a-message textarea").focus()}return false})},GetFullYear:function(c,d,a){var b=new Date();b.setFullYear(c,d,a);return b},StatusNetInstance:{Set:function(b){var a=SN.U.StatusNetInstance.Get();if(a!==null){b=$.extend(a,b)}$.cookie(SN.C.S.StatusNetInstance,JSON.stringify(b),{path:"/",expires:SN.U.GetFullYear(2029,0,1)})},Get:function(){var a=$.cookie(SN.C.S.StatusNetInstance);if(a!==null){return JSON.parse(a)}return null},Delete:function(){$.cookie(SN.C.S.StatusNetInstance,null)}},belongsOnTimeline:function(b){var a=$("body").attr("id");if(a=="public"){return true}var c=$("#nav_profile a").attr("href");if(c){var d=$(b).find(".vcard.author a.url").attr("href");if(d==c){if(a=="all"||a=="showstream"){return true}}}return false},switchInputFormTab:function(a){$(".input_form_nav_tab.current").removeClass("current");if(a=="placeholder"){$("#input_form_nav_status").addClass("current")}else{$("#input_form_nav_"+a).addClass("current")}var b=$(".input_form.current.nonav");if(b.length>0){return}$(".input_form.current").removeClass("current");$("#input_form_"+a).addClass("current").find(".ajax-notice").each(function(){var c=$(this);SN.Init.NoticeFormSetup(c)}).find(".notice_data-text").focus()}},Init:{NoticeForm:function(){if($("body.user_in").length>0){$("#input_form_placeholder input.placeholder").focus(function(){SN.U.switchInputFormTab("status")});$("body").bind("click",function(g){var d=$("#content .input_forms div.current");if(d.length>0){if($("#content .input_forms").has(g.target).length==0){var a=d.find('textarea, input[type=text], input[type=""]');var c=false;a.each(function(){c=c||$(this).val()});if(!c){SN.U.switchInputFormTab("placeholder")}}}var b=$("li.notice-reply");if(b.length>0){var f=$(g.target);b.each(function(){var k=$(this);if(k.has(g.target).length==0){var h=k.find(".notice_data-text:first");var j=$.trim(h.val());if(j==""||j==h.data("initialText")){var e=k.closest("li.notice");k.remove();e.find("li.notice-reply-placeholder").show()}}})}});$(".input_forms fieldset fieldset label").inFieldLabels({fadeOpacity:0})}},NoticeFormSetup:function(a){if(!a.data("NoticeFormSetup")){SN.U.NoticeLocationAttach(a);SN.U.FormNoticeXHR(a);SN.U.FormNoticeEnhancements(a);SN.U.NoticeDataAttach(a);a.data("NoticeFormSetup",true)}},Notices:function(){if($("body.user_in").length>0){var a=$(".form_notice:first");if(a.length>0){SN.C.I.NoticeFormMaster=document._importNode(a[0],true)}SN.U.NoticeRepeat();SN.U.NoticeReply();SN.U.NoticeInlineReplySetup()}SN.U.NoticeAttachments()},EntityActions:function(){if($("body.user_in").length>0){$(".form_user_subscribe").live("click",function(){SN.U.FormXHR($(this));return false});$(".form_user_unsubscribe").live("click",function(){SN.U.FormXHR($(this));return false});$(".form_group_join").live("click",function(){SN.U.FormXHR($(this));return false});$(".form_group_leave").live("click",function(){SN.U.FormXHR($(this));return false});$(".form_user_nudge").live("click",function(){SN.U.FormXHR($(this));return false});$(".form_peopletag_subscribe").live("click",function(){SN.U.FormXHR($(this));return false});$(".form_peopletag_unsubscribe").live("click",function(){SN.U.FormXHR($(this));return false});$(".form_user_add_peopletag").live("click",function(){SN.U.FormXHR($(this));return false});$(".form_user_remove_peopletag").live("click",function(){SN.U.FormXHR($(this));return false});SN.U.NewDirectMessage()}},ProfileSearch:function(){if($("body.user_in").length>0){$(".form_peopletag_edit_user_search input.submit").live("click",function(){SN.U.FormProfileSearchXHR($(this).parents("form"));return false})}},Login:function(){if(SN.U.StatusNetInstance.Get()!==null){var a=SN.U.StatusNetInstance.Get().Nickname;if(a!==null){$("#form_login #nickname").val(a)}}$("#form_login").bind("submit",function(){SN.U.StatusNetInstance.Set({Nickname:$("#form_login #nickname").val()});return true})},PeopletagAutocomplete:function(b){var a=function(d){return d.split(/\s+/)};var c=function(d){return a(d).pop()};b.live("keydown",function(d){if(d.keyCode===$.ui.keyCode.TAB&&$(this).data("autocomplete").menu.active){d.preventDefault()}}).autocomplete({minLength:0,source:function(e,d){d($.ui.autocomplete.filter(SN.C.PtagACData,c(e.term)))},focus:function(){return false},select:function(e,f){var d=a(this.value);d.pop();d.push(f.item.value);d.push("");this.value=d.join(" ");return false}}).data("autocomplete")._renderItem=function(e,f){var d='<a class="ptag-ac-line-tag">'+f.tag+' <em class="privacy_mode">'+f.mode+'</em><span class="freq">'+f.freq+"</span></a>";return $("<li/>").addClass("mode-"+f.mode).addClass("ptag-ac-line").data("item.autocomplete",f).append(d).appendTo(e)}},PeopleTags:function(){$(".user_profile_tags .editable").append($('<button class="peopletags_edit_button"/>'));$(".peopletags_edit_button").live("click",function(){var a=$(this).parents("dd").eq(0).find("form");$.ajax({url:_peopletagAC,dataType:"json",data:{token:$("#token").val()},ifModified:true,success:function(b){for(i=0;i<b.length;i++){b[i].label=b[i].tag}SN.C.PtagACData=b;SN.Init.PeopletagAutocomplete(a.find("#tags"))}});$(this).parents("ul").eq(0).fadeOut(200,function(){a.fadeIn(200).find("input#tags")})});$(".user_profile_tags form .submit").live("click",function(){SN.U.FormPeopletagsXHR($(this).parents("form"));return false})},AjaxForms:function(){$("form.ajax").live("submit",function(){SN.U.FormXHR($(this));return false});$("form.ajax input[type=submit]").live("click",function(){var a=$(this);var b=a.closest("form");b.find(".hidden-submit-button").remove();$('<input class="hidden-submit-button" type="hidden" />').attr("name",a.attr("name")).val(a.val()).appendTo(b)})},UploadForms:function(){$("input[type=file]").change(function(d){if(typeof this.files=="object"&&this.files.length>0){var c=0;for(var b=0;b<this.files.length;b++){c+=this.files[b].size}var a=SN.U.maxFileSize($(this.form));if(a>0&&c>a){var e="File too large: maximum upload size is %d bytes.";alert(e.replace("%d",a));$(this).val("");d.preventDefault();return false}}})},CheckBoxes:function(){$("span[class='checkbox-wrapper']").addClass("unchecked");$(".checkbox-wrapper").click(function(){if($(this).children("input").attr("checked")){$(this).children("input").attr({checked:""});$(this).removeClass("checked");$(this).addClass("unchecked");$(this).children("label").text("Private?")}else{$(this).children("input").attr({checked:"checked"});$(this).removeClass("unchecked");$(this).addClass("checked");$(this).children("label").text("Private")}})}}};$(document).ready(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($("#form_login").length>0){SN.Init.Login()}if($("#profile_search_results").length>0){SN.Init.ProfileSearch()}if($(".user_profile_tags .editable").length>0){SN.Init.PeopleTags()}});if(!document.ELEMENT_NODE){document.ELEMENT_NODE=1;document.ATTRIBUTE_NODE=2;document.TEXT_NODE=3;document.CDATA_SECTION_NODE=4;document.ENTITY_REFERENCE_NODE=5;document.ENTITY_NODE=6;document.PROCESSING_INSTRUCTION_NODE=7;document.COMMENT_NODE=8;document.DOCUMENT_NODE=9;document.DOCUMENT_TYPE_NODE=10;document.DOCUMENT_FRAGMENT_NODE=11;document.NOTATION_NODE=12}document._importNode=function(e,a){switch(e.nodeType){case document.ELEMENT_NODE:var d=document.createElement(e.nodeName);if(e.attributes&&e.attributes.length>0){for(var c=0,b=e.attributes.length;c<b;){if(e.attributes[c].nodeName=="class"){d.className=e.getAttribute(e.attributes[c++].nodeName)}else{d.setAttribute(e.attributes[c].nodeName,e.getAttribute(e.attributes[c++].nodeName))}}}if(a&&e.childNodes&&e.childNodes.length>0){for(var c=0,b=e.childNodes.length;c<b;){d.appendChild(document._importNode(e.childNodes[c++],a))}}return d;break;case document.TEXT_NODE:case document.CDATA_SECTION_NODE:case document.COMMENT_NODE:return document.createTextNode(e.nodeValue);break}};if(typeof navigator.geolocation=="undefined"||navigator.geolocation.shim){(function(){(function(){if(window.google&&google.gears){return}var c=null;if(typeof GearsFactory!="undefined"){c=new GearsFactory()}else{try{c=new ActiveXObject("Gears.Factory");if(c.getBuildInfo().indexOf("ie_mobile")!=-1){c.privateSetGlobalObject(this)}}catch(d){if((typeof navigator.mimeTypes!="undefined")&&navigator.mimeTypes["application/x-googlegears"]){c=document.createElement("object");c.style.display="none";c.width=0;c.height=0;c.type="application/x-googlegears";document.documentElement.appendChild(c)}}}if(!c){return}if(!window.google){google={}}if(!google.gears){google.gears={factory:c}}})();var a=(function(){var d=google.gears.factory.create("beta.geolocation");var c=function(f,e){return function(g){f(g);e.lastPosition=g}};return{shim:true,type:"Gears",lastPosition:null,getCurrentPosition:function(e,g,h){var f=this;var j=c(e,f);d.getCurrentPosition(j,g,h)},watchPosition:function(e,f,g){d.watchPosition(e,f,g)},clearWatch:function(e){d.clearWatch(e)},getPermission:function(g,e,f){d.getPermission(g,e,f)}}});var b=(function(){var j=false;var e=function(){if(!d()&&!j){j=true;var k=document.createElement("script");k.src=(document.location.protocol=="https:"?"https://":"http://")+"www.google.com/jsapi?callback=_google_loader_apiLoaded";k.type="text/javascript";document.getElementsByTagName("body")[0].appendChild(k)}};var c=[];var h=function(k){c.push(k)};var f=function(){if(d()){while(c.length>0){var k=c.pop();k()}}};window._google_loader_apiLoaded=function(){f()};var d=function(){return(window.google&&google.loader)};var g=function(k){if(d()){return true}h(k);e();return false};e();return{shim:true,type:"ClientLocation",lastPosition:null,getCurrentPosition:function(l,o,p){var n=this;if(!g(function(){n.getCurrentPosition(l,o,p)})){return}if(google.loader.ClientLocation){var m=google.loader.ClientLocation;var k={coords:{latitude:m.latitude,longitude:m.longitude,altitude:null,accuracy:43000,altitudeAccuracy:null,heading:null,speed:null},address:{city:m.address.city,country:m.address.country,country_code:m.address.country_code,region:m.address.region},timestamp:new Date()};l(k);this.lastPosition=k}else{if(o==="function"){o({code:3,message:"Using the Google ClientLocation API and it is not able to calculate a location."})}}},watchPosition:function(k,m,n){this.getCurrentPosition(k,m,n);var l=this;var o=setInterval(function(){l.getCurrentPosition(k,m,n)},10000);return o},clearWatch:function(k){clearInterval(k)},getPermission:function(m,k,l){return true}}});navigator.geolocation=(window.google&&google.gears)?a():b()})()};
index f03f3e3395c36c780adae4c5e928c2460c5d1d5f..d768411d73aeabee2687409a299a8dae9b3a33a9 100644 (file)
@@ -375,20 +375,10 @@ class QnAPlugin extends MicroAppPlugin
         $question = QnA_Question::getByNotice($notice);
 
         if (!empty($question)) {
-            if (empty($user)) {
-                $form = new QnashowquestionForm($out, $question);
-                $form->show();
-            } else {
-                $profile = $user->getProfile();
-                $answer = $question->getAnswer($profile);
-                if (empty($answer)) {
-                    $form = new QnanewanswerForm($out, $question);
-                    $form->show();
-                } else {
-                    $form = new QnashowquestionForm($out, $question);
-                    $form->show();
-                }
-            }
+
+            $form = new QnashowquestionForm($out, $question);
+            $form->show();
+
         } else {
             $out->text(_m('Question data is missing.'));
         }
@@ -398,6 +388,66 @@ class QnAPlugin extends MicroAppPlugin
         $out->elementStart('div', array('class' => 'entry-content'));
     }
 
+
+    /**
+     * Output the HTML for this kind of object in a list
+     *
+     * @param NoticeListItem $nli The list item being shown.
+     *
+     * @return boolean hook value
+     *
+     * @fixme WARNING WARNING WARNING this closes a 'div' that is implicitly opened in BookmarkPlugin's showNotice implementation
+     */
+    function onStartShowNoticeItem($nli)
+    {
+        if (!$this->isMyNotice($nli->notice)) {
+            return true;
+        }
+
+        $out = $nli->out;
+        $notice = $nli->notice;
+
+        $this->showNotice($notice, $out);
+
+        $nli->showNoticeLink();
+        $nli->showNoticeSource();
+        $nli->showNoticeLocation();
+        $nli->showContext();
+        $nli->showRepeat();
+
+        $out->elementEnd('div');
+
+        $nli->showNoticeOptions();
+
+        if ($notice->object_type == QnA_Question::OBJECT_TYPE) {
+
+            $user = common_current_user();
+            $question = QnA_Question::getByNotice($notice);
+
+            if (!empty($user)) {
+
+                $profile = $user->getProfile();
+                $answer = $question->getAnswer($profile);
+
+                // Output a placeholder input -- clicking on it will
+                // bring up a real answer form
+                if (empty($answer) && empty($question->closed)) {
+                    $out->elementStart('ul', 'notices threaded-replies xoxo');
+                    $out->elementStart('li', 'notice-answer-placeholder');
+                    $out->element(
+                        'input',
+                        array('class' => 'placeholder', 'value' => 'Answer...')
+                    );
+                    $out->elementEnd('li');
+                    $out->elementEnd('ul');
+                }
+            }
+        }
+
+        return false;
+    }
+
+
     function showNoticeAnswer($notice, $out)
     {
         $user = common_current_user();
index 0c4938e6a9b2b0de77c32402e3e2a0328277d338..f5eedbfac997b1b3507e496a674e5fc9676f5f37 100644 (file)
@@ -93,8 +93,6 @@ class QnanewanswerAction extends Action
 
         $id = substr($this->trimmed('id'), 9);
 
-        common_debug("XXXXXXXXXXXXXXXXXX id = " . $id);
-
         $this->question = QnA_Question::staticGet('id', $id);
 
         if (empty($this->question)) {
@@ -124,7 +122,7 @@ class QnanewanswerAction extends Action
         if ($this->isPost()) {
             $this->newAnswer();
         } else {
-            $this->showPage();
+            $this->showForm();
         }
 
         return;
@@ -147,7 +145,7 @@ class QnanewanswerAction extends Action
             );
         } catch (ClientException $ce) {
             $this->error = $ce->getMessage();
-            $this->showPage();
+            $this->showForm($this->error);
             return;
         }
         if ($this->boolean('ajax')) {
@@ -230,4 +228,74 @@ class QnanewanswerAction extends Action
             return false;
         }
     }
+
+    /**
+     * Show an Ajax-y error message
+     *
+     * Goes back to the browser, where it's shown in a popup.
+     *
+     * @param string $msg Message to show
+     *
+     * @return void
+     */
+    function ajaxErrorMsg($msg)
+    {
+        $this->startHTML('text/xml;charset=utf-8', true);
+        $this->elementStart('head');
+        // TRANS: Page title after an AJAX error occurs on the post answer page.
+        $this->element('title', null, _('Ajax Error'));
+        $this->elementEnd('head');
+        $this->elementStart('body');
+        $this->element('p', array('id' => 'error'), $msg);
+        $this->elementEnd('body');
+        $this->elementEnd('html');
+    }
+
+    /**
+     * Show an Ajax-y answer form
+     *
+     * Goes back to the browser, where it's shown in a popup.
+     *
+     * @param string $msg Message to show
+     *
+     * @return void
+     */
+    function ajaxShowForm()
+    {
+        common_debug('ajaxShowForm()');
+        $this->startHTML('text/xml;charset=utf-8', true);
+        $this->elementStart('head');
+        // TRANS: Title for form to send answer to a question.
+        $this->element('title', null, _m('TITLE','Your answer'));
+        $this->elementEnd('head');
+        $this->elementStart('body');
+
+        $form = new QnanewanswerForm($this, $this->question);
+        $form->show();
+
+        $this->elementEnd('body');
+        $this->elementEnd('html');
+    }
+
+    /**
+     * @param string $msg An error message, if any
+     *
+     * @return void
+     */
+    function showForm($msg = null)
+    {
+        common_debug("show form - msg = $msg");
+        if ($this->boolean('ajax')) {
+            if ($msg) {
+                $this->ajaxErrorMsg($msg);
+            } else {
+                $this->ajaxShowForm();
+            }
+            return;
+        }
+
+        $this->msg = $msg;
+        $this->showPage();
+    }
+
 }
index 4701b5ab0372fdbf2c99125004fec41d2bb20834..1b89b6c2bb54dc33c5e45d6624bee6451e2c16e1 100644 (file)
@@ -1 +1,5 @@
-/* stubb for q&a css */
+/* Why doesn't this work? */
+input.answer-placeholder {
+    margin-left: 0;
+    width: 95%;
+}
index 82f9a24b1b1ca963a6e43df1c597820fd1d1cf01..5fa329f8933efd23a12402756f344295a37724e8 100644 (file)
@@ -5,21 +5,186 @@ var QnA = {
 
     // @fixme: Should use ID
     close: function(closeButt) {
-        $(closeButt)
-            .closest('li.hentry.notice.question')
-            .find('input[name=best],[name=close]')
-            .hide();
+        notice = $(closeButt).closest('li.hentry.notice.question');
+        notice.find('input[name=best],[name=close]').hide();
+        notice.find('textarea').hide();
+        notice.find('li.notice-answer-placeholder').hide();
+        notice.find('#answer-form').hide();
     },
 
     init: function() {
+
         var that = this;
+
+        QnA.NoticeInlineAnswerSetup();
+
         $('input[name=close]').live('click', function() {
             that.close(this);
         });
         $('input[name=best]').live('click', function() {
             that.close(this);
         });
+
+
+
+    },
+
+    /**
+     * Open up a question's inline answer box.
+     *
+     * @param {jQuery} notice: jQuery object containing one notice
+     */
+    NoticeInlineAnswerTrigger: function(notice) {
+        console.log('NoticeInlineAnswerTrigger - begin');
+
+        // Find the question notice we're answering...
+        var id = $($('.notice_id', notice)[0]).text();
+        console.log("parent notice id = " + id);
+        var parentNotice = notice;
+
+        // See if the form's already there...
+        var answerForm = $('#answer-form', parentNotice);
+
+        if (answerForm) {
+            console.log("Found the answer form.");
+        } else {
+            console.log("Did not find the answer form.");
+        }
+
+        var placeholder = parentNotice.find('li.notice-answer-placeholder');
+
+        // Pull the parents threaded list and we'll add on the end of it.
+        var list = $('ul.threaded-replies', notice);
+
+        if (list) {
+            console.log("Found the " + list.length + " notice place holders.");
+        } else {
+            console.log("Found the notice answer placeholder");
+        }
+
+        if (list.length == 0) {
+            console.log("list length = 0 adding <ul>");
+            list = $('<ul class="notices threaded-replies xoxo"></ul>');
+            notice.append(list);
+        } else if (list.length == 2) {
+            // remove duplicate ul added by util.js
+            list.last().remove();
+        }
+
+        var answerItem = $('li.notice-answer', list);
+
+        var nextStep = function() {
+            console.log("nextStep - enter");
+
+            // Set focus...
+            var text = answerForm.find('textarea');
+
+            if (text.length == 0) {
+                throw "No textarea";
+            }
+
+            $('body').click(function(e) {
+                console.log("got click");
+
+                var openAnswers = $('li.notice-answer');
+                    if (openAnswers.length > 0) {
+                        var target = $(e.target);
+                        openAnswers.each(function() {
+                            // Did we click outside this one?
+                            var answerItem = $(this);
+                            if (answerItem.has(e.target).length == 0) {
+                                var textarea = answerItem.find('.notice_data-text:first');
+                                var cur = $.trim(textarea.val());
+                                // Only close if there's been no edit.
+                                if (cur == '' || cur == textarea.data('initialText')) {
+                                    var parentNotice = answerItem.closest('li.notice');
+                                    answerItem.remove();
+                                    parentNotice.find('li.notice-answer-placeholder').show();
+                                }
+                            }
+                        });
+                    }
+                });
+
+            text.focus();
+        };
+
+        placeholder.hide();
+
+        if (answerItem.length > 0) {
+            console.log('answerItem length > 0');
+            // Update the existing form...
+            nextStep();
+        } else {
+
+             // Create the answer form entry at the end
+
+             if (answerItem.length == 0) {
+                 console.log("QQQQQ no notice-answer li");
+                 answerItem = $('<li class="notice-answer"></li>');
+
+                 var intermediateStep = function(formMaster) {
+                     console.log("Intermediate step");
+                     var formEl = document._importNode(formMaster, true);
+                     answerItem.append(formEl);
+                     console.log("appending answerItem");
+                     list.append(answerItem); // *after* the placeholder
+                     console.log("appended answerItem");
+                     console.log(answerItem);
+                     var form = answerForm = $(formEl);
+                     QnA.AnswerFormSetup(form);
+
+                     nextStep();
+                 };
+
+                 if (QnA.AnswerFormMaster) {
+                     // We've already saved a master copy of the form.
+                     // Clone it in!
+                     intermediateStep(QnA.AnswerFormMaster);
+                 } else {
+                     // Fetch a fresh copy of the answer form over AJAX.
+                     // Warning: this can have a delay, which looks bad.
+                     // @fixme this fallback may or may not work
+                     var url = $('#answer-action').attr('value');
+
+                     console.log("fetching new form via HXR");
+
+                     $.get(url, {ajax: 1}, function(data, textStatus, xhr) {
+                         intermediateStep($('form', data)[0]);
+                     });
+                 }
+             }
+         }
+         console.log('NoticeInlineAnswerTrigger - exit');
+
+     },
+
+
+    AnswerFormSetup: function(form) {
+        console.log("AnswerFormSetup - begin");
+        if (!form.data('AnswerFormSetup')) {
+            form.data('AnswerFormSetup', true);
+        }
+        console.log("AnswerFormSetup - exit");
+    },
+
+    /**
+     * Setup function -- DOES NOT apply immediately.
+     *
+     * Sets up event handlers for inline reply mini-form placeholders.
+     * Uses 'live' rather than 'bind', so applies to future as well as present items.
+     */
+    NoticeInlineAnswerSetup: function() {
+        console.log("NoticeInlineAnswerSetup - begin");
+        $('li.notice-answer-placeholder input.placeholder')
+            .live('focus', function() {
+                var notice = $(this).closest('li.notice');
+                QnA.NoticeInlineAnswerTrigger(notice);
+                return false;
+            });
+        console.log("NoticeInlineAnswerSetup - exit");
     }
+
 };
 
 $(document).ready(function() {
index 27abd42757fc3404f7c398a4f6c4226ccbeca61c..f11b0e36fa13950fe8521556be3cef1b1a188eda 100644 (file)
@@ -119,6 +119,15 @@ class QnashowquestionForm extends Form
             'id'
         );
 
+        $this->out->hidden(
+            'answer-action',
+            common_local_url(
+                'qnanewanswer',
+                null,
+                array('id' => 'question-' . $this->question->id)
+            )
+        );
+
         $this->out->raw($this->question->asHTML());
     }