1 // Library for wraping JavaScript code for different evaluation contexts.
4 transform_each_character: function(str
, transform
) {
5 var result
= new Array();
6 for (var i
=0; i
< str
.length
; ++i
)
7 result
.push(transform(str
.charAt(i
)));
8 return result
.join('');
11 escape_for_single_quote: function(str
) {
12 function transform(ch
) {
21 return this.transform_each_character(str
, transform
);
24 escape_for_html: function(str
) {
25 function transform(ch
) {
38 return this.transform_each_character(str
, transform
);
41 in_string: function(code
) {
42 return "'" + this.escape_for_single_quote(code
) + "'";
45 in_script_tag: function(code
) {
46 return "<script>" + code
+ "</scr" + "ipt>";
49 in_document_write: function(code
) {
50 return "document.write(" + this.in_string(this.in_script_tag(code
)) + ")";
53 in_javascript_url: function(code
) {
54 return this.in_string("javascript:void(" + code
+ ")");
57 in_javascript_document: function(code
) {
58 return this.in_string("javascript:" +
59 this.in_string(this.in_script_tag(code
)));