User:Yair rand/DiscussionSandbox.js

$(function($){ $("#discussionstartbutton").click(function(e){ e.preventDefault; $(this).append($(" ").css({"text-align":"left","padding":"7px"}).append( "Title: ", $(" ").css("width","80%"), $(" ").attr("rows","6"), $(" ").append("Save").click(function{       var a = $(this.parentNode).find("input").val, b = $(this.parentNode).find("textarea").val, c = 2;        if( !a || !b ){return}        document.body.style.cursor = "wait";        JsMwApi({action:"query",prop:"info",titles:wgPageName+"/"+a+"|"+wgPageName,intoken:"edit"},function(res){ res = res.query.pages; if( ! res[-1] ){ $("#previewbox").empty.append($(" ").css("color","#F00").text("Error: A discussion with this title already exists. Please choose a different title.")); document.body.style.cursor = ""; return; }         JsMwApi({action:"edit",title:wgPageName+"/"+a,createonly:"",text:"\n"+b,watchlist:"watch",token:res[-1].edittoken},function{            for(var i in res){              i != -1 && JsMwApi({action:"edit",title:wgPageName,summary:"/* " + a + " */ new section", appendtext:"\n\n",token:res[i].edittoken}, function{ location.href = location.pathname + "#" + a;               location.reload; })           }          })        })      }),      $(" ").append("Preview").click(function{        $("#previewbox").empty.append("Loading...");        JsMwApi({action:"parse",prop:"text",title:wgPageName+"/"+$(this.parentNode).find("input").val,text:$(this.parentNode).find("textarea").val},function(res){ console.log(res); $("#previewbox").html(res.parse.text['*']); })     })),      $(" ").attr("id","previewbox")    ).unbind("click"); }) })