...

View Full Version : src escape:



swmr
11-04-2003, 05:43 AM
Something simple I put together to adapt src-code for a string variable.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
<title>srcEscape</title>
<script type="text/JavaScript">
function srcEscape(){
var inp, txt, Tabs = "", Spaces = "", TbSp, v, c, s, ss = "", vName;
inp = document.getElementsByTagName("input");
txt = document.getElementsByTagName("textarea");
while (Tabs.length < Math.abs(inp[0].value)){Tabs += "\t"}
while (Spaces.length < Math.abs(inp[1].value)){Spaces += "\x20"}
TbSp = Tabs + Spaces;
v = txt[0].value;
for (i = 0; i < v.length; i++){c = v.charAt(i);
switch (c){
case "\x09" : s = "\\t";
break;
case "\x0A" : s = "\\n\" + " + "\r\n" + TbSp + "\"";
break;
case "\x0D" : s = "\\r";
break;
case "\x22" : s = "\\\"";
break;
case "\x2F" : s = "\\/";
break;
case "\x5C" : s = "\\\\";
break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default : s = c;
break;}
ss += s;}
vName = inp[2].value;
txt[1].value = TbSp + "var " + vName + " = " + "\r\n" + TbSp + "\"" + ss + "\"\x3B";
txt[1].select();}
</script>
<style type="text/css">
p{white-space:nowrap}
textarea{width:100%;height:150px;overflow:scroll;
word-wrap:normal}
input{width:100px;margin-right:20px;vertical-align:middle;text-align:center}
div{text-align:right}
button{padding-left:10px;padding-right:10px}
</style>
</head>
<body>
<form id="f" action="">
<p style="margin-bottom:0">
<label>Paste: html-source</label><br><textarea cols="95" rows="10"></textarea><br>
</p>
<div><button onclick="document.getElementById('f').reset();return false;">Reset</button></div>
<p style="text-align:center">
<label>indent # Tabs: </label><input value="0">
<label>indent # Spaces: </label><input value="0">
<label>variable Name: </label><input value="sCode">
</p>
<p>
<button onclick="srcEscape();return false;">Convert</button><br>
<textarea cols="95" rows="10"></textarea><br>
<label>Copy: js-code</label>
</p>
</form>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum