proc/RunCodeEditor()
var/code = file2text(file("[filelink]"))
usr << browse({"
<html>
<head><title>Code Editor</title></head>
<body bgcolor="stone">
<form method="get" action="byond://?" name="CodeEdit">
Edit the code here.
<TEXTAREA NAME="Code" ROWS=30 COLS=50 WRAP="virtual">[code]</TEXTAREA>
<input type="button" value="Save" name="submit" onClick="JSmessage()">
</form>
<script language="Javascript">
var codemsg
function JSmessage()
{
codemsg = escape(document.CodeEdit.Code.value)
JScheck(codemsg)
}
function JScheck(codemsg)
{
if(codemsg.length<=210)
{
document.location.href="BYOND://?action=go;ctxt=" + codemsg
document.location.href="BYOND://?action=end;link=[filelink]"
return 1
}
else
{
if(codemsg.substring(209,209)=='%')
{
document.location.href="BYOND://?action=go;ctxt=" + codemsg.substring(0,208)
codemsg = codemsg.substring(209,codemsg.length)
return JScheck(codemsg)
}
else if(codemsg.substring(210,210)=='%')
{
document.location.href="BYOND://?action=go;ctxt=" + codemsg.substring(0,209)
codemsg = codemsg.substring(210,codemsg.length)
return JScheck(codemsg)
}
else
{
document.location.href="BYOND://?action=go;ctxt=" + codemsg.substring(0,210)
codemsg = codemsg.substring(211,codemsg.length)
return JScheck(codemsg)
}
}
}
</script>
</body>
</html>"},"window=CodeEditor;size=490x390;can_resize=0")
Problem description:
When I open a file with the code editor and the file has a in it. All of the files contents after that html code is outputed as text instead of being in the textarea element form.
I think I am suppose to use html_encode() but couldnt get it to work. Every time the data of the file came back it had 20 and other such stuff where a space or other character value should be. For that reason I am also including the Topic() proc bellow. Thanks for any help.
client/Topic(href,href_list[])
if(href_list["action"]=="end")
world.log << "data send!"
fdel(file(href_list["link"]))
text2file(Hmain.code,file(href_list["link"]))
Hmain.code = ""
usr << browse(null,"window=CodeEditor")
else
Hmain.code = Hmain.code + url_decode(href_list["ctxt"])
world.log << "Sending data.. " + url_decode(href_list["ctxt"])
return ..()
Well I fixed the </textarea > problem but now I have spawned a new bread of problem. It seems any +'s in the file I am editing come back as spaces. Uhh could any one tell me the reason why? From what I have gathered with my debug messages. It has somthing too do with the escape() javascript function so I looked it up.
"The value returned by the escape function is a string of the form "%xx," where xx is the ASCII encoding of a character in the argument. If you pass the escape function an alphanumeric character, the escape function returns the same character. escape is a top-level function not associated with any object."
Byond reference of the url_decode() function which I have in my Topic() proc. "The url_decode() instruction takes a text string containing such escaped symbols and turns them into their literal counterparts. Usually this is done for you automatically in Topic()."
So What I did is try and get the ctxt message from the href_list[]. But it outputed like it all ready had been unescaped. So I think the Topic is automaticalling added spaces where the +'s should be.