Skip to content

Commit f174f80

Browse files
committedJul 20, 2011
Update jquery; move config into fragid; prep for enabling CSP
1 parent 33ff844 commit f174f80

File tree

8 files changed

+339
-315
lines changed

8 files changed

+339
-315
lines changed
 

‎lib/formatter/html.py

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"""
2929

3030
import codecs
31+
import json
3132
import operator
3233
import os
3334
import re
@@ -80,6 +81,11 @@ def start_output(self):
8081
'version': droid.__version__,
8182
'html_uri': e(self.uri),
8283
'js_uri': e_js(self.uri),
84+
'config': urllib.quote(json.dumps({
85+
'redbot_uri': self.uri,
86+
'redbot_req_hdrs': self.req_hdrs,
87+
'redbot_version': droid.__version__
88+
})),
8389
'js_req_hdrs': ", ".join(['["%s", "%s"]' % (
8490
e_js(n), e_js(v)) for n,v in self.req_hdrs]),
8591
'extra_js': self.format_extra('.js'),

‎lib/formatter/html_header.py

+2-18
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,7 @@
1313
float: left;
1414
</style>
1515
<![endif]-->
16-
<script type="text/javascript">
17-
var redbot_uri = "%(js_uri)s";
18-
var redbot_req_hdrs = [%(js_req_hdrs)s];
19-
var redbot_version = "%(version)s";
20-
function loadJS() {
21-
var element = document.createElement("script");
22-
element.src = "%(static)s/script.js";
23-
document.body.appendChild(element);
24-
}
25-
if (window.addEventListener)
26-
window.addEventListener("load", loadJS, false);
27-
else if (window.attachEvent)
28-
window.attachEvent("onload", loadJS);
29-
else
30-
window.onload = loadJS;
31-
</script>
32-
<!--script src="%(static)s/script.js" type="text/javascript"></script -->
16+
<script src='%(static)s/script.js#%(config)s' type="text/javascript"></script>
3317
%(extra_js)s
3418
</head>
3519
@@ -43,7 +27,7 @@
4327
<div id="request">
4428
<h1><a href="?"><span class="hilight"><abbr title="Resource Expert Droid">RED</abbr></span>bot</a>%(extra_title)s</h1>
4529
46-
<form method="GET" onLoad="init_req_hdrs();" id="request_form">
30+
<form method="GET" id="request_form">
4731
<input type="url" name="uri" value="%(html_uri)s" id="uri"/><br />
4832
<div id="req_hdrs"></div>
4933
<div class="add_req_hdr">

‎share/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
JSFILES = jquery.js jquery.hoverIntent.js prettify.js red_popup.js red_req_headers.js red_script.js
1+
JSFILES = jquery.js jquery.hoverIntent.js prettify.js red_script.js red_popup.js red_req_headers.js
22
CSSFILES = red_style.css prettify.css
33
YUI_COMPRESSOR_JAR = ~/Applications/yuicompressor-2.4.3.jar
44

‎share/jquery.js

+14-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎share/red_popup.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ jQuery.fn.hoverPopup = function(fnText, fnOver, fnOut) {
5555
return jQuery.fn.hoverIntent.call(this, fnOverPopup, fnOutPopup);
5656
};
5757

58-
$("#popup").hoverIntent(function(){
59-
if (tid != false) {
60-
clearTimeout(tid);
61-
tid = false;
62-
}
63-
}, function(){
64-
$("#popup").fadeOut("fast");
58+
$(document).ready(function() {
59+
$("#popup").hoverIntent(function(){
60+
if (tid != false) {
61+
clearTimeout(tid);
62+
tid = false;
63+
}
64+
}, function(){
65+
$("#popup").fadeOut("fast");
66+
});
67+
6568
});

‎share/red_req_headers.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var known_req_hdrs = {
88
'Cookie': null,
99
'Referer': null,
1010
'User-Agent': [
11-
"RED/" + redbot_version + " (http://redbot.org/about)",
11+
"RED/" + config.redbot_version + " (http://redbot.org/about)",
1212
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0)",
1313
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; )",
1414
"Mozilla/5.0 (X11; U; Linux x86_64; en-US) Gecko Firefox/3.0.8",
@@ -25,10 +25,6 @@ var red_req_hdrs = [
2525
'content-length'
2626
];
2727

28-
$("#add_req_hdr").click(function(){
29-
add_req_hdr();
30-
return false;
31-
});
3228

3329

3430
function add_req_hdr(hdr_name, hdr_val){
@@ -155,12 +151,15 @@ function bind_text_changes(req_hdr) {
155151
});
156152
}
157153

158-
function init_req_hdrs() {
159-
for (i in redbot_req_hdrs) {
160-
var req_hdr = redbot_req_hdrs[i];
161-
add_req_hdr(req_hdr[0], req_hdr[1]);
162-
}
163-
return false;
164-
}
165154

166-
init_req_hdrs();
155+
$(document).ready(function() {
156+
for (i in config.redbot_req_hdrs) {
157+
var hdr = config.redbot_req_hdrs[i];
158+
add_req_hdr(hdr[0], hdr[1]);
159+
}
160+
161+
$("#add_req_hdr").click(function(){
162+
add_req_hdr();
163+
return false;
164+
});
165+
});

‎share/red_script.js

+122-106
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,139 @@
11

2-
/* URI */
2+
/* Configuration */
3+
34

4-
var check_phrase = "Enter a http:// URI to check";
5-
if (redbot_uri) {
6-
$("#uri").val(redbot_uri);
7-
} else if (! $("#uri").val()) {
8-
$("#uri").val(check_phrase);
9-
$("#uri").css({'color': '#ccc'});
5+
6+
function get_config () {
7+
var scripts = document.getElementsByTagName('script');
8+
var myScript = scripts[ scripts.length - 1 ];
9+
var frag = unescape(myScript.src.replace(/^[^\#]+\#?/,''));
10+
return jQuery.parseJSON(frag);
1011
}
12+
var config = get_config();
1113

12-
$("#uri").focus(function(){
13-
if ($(this).val() == check_phrase) {
14-
$(this).val("");
15-
$("#uri").css({'color': '#111'});
16-
}
17-
});
14+
/* URI */
1815

19-
/* catch enter to work around IE8 */
20-
$("input").keypress(function (e) {
21-
if (e.which == 13) {
22-
$("#request_form").submit();
23-
}
24-
});
25-
26-
27-
/* single response display */
28-
29-
var hidden_list = $("#hidden_list");
30-
31-
$("span.hdr").hoverPopup(
32-
function(e){
33-
var name = $(this).attr('name');
34-
return $("li#" + name, hidden_list).html();
35-
},
36-
function(e){
37-
var name = $(this).attr('name');
38-
$("span." + name).css({"font-weight": "bold", "color": "white"});
39-
$("li.msg:not(." + name + ")").fadeTo(100, 0.15);
40-
$("li.msg." + name).fadeTo(50, 1.0);
41-
},
42-
function(e){
43-
var name = $(this).attr('name');
44-
$("span." + name).css({"font-weight": "normal", "color": "#ddd"});
45-
$("li.msg").fadeTo(100, 1.0);
16+
$(document).ready(function() {
17+
18+
var check_phrase = "Enter a http:// URI to check";
19+
if (config.redbot_uri) {
20+
$("#uri").val(config.redbot_uri);
21+
} else if (! $("#uri").val()) {
22+
$("#uri").val(check_phrase);
23+
$("#uri").css({'color': '#ccc'});
4624
}
47-
);
48-
49-
$("li.msg span").hoverPopup(
50-
function(e){
51-
return $("li#" + $(this).parent().attr('name'), hidden_list).html();
52-
},
53-
function(e){
54-
var classes = $(this).parent().attr("class").split(" ");
55-
for (var i=0; i < classes.length; i++) {
56-
var c = classes[i];
57-
$("span.hdr[name='" + c +"']")
58-
.css({"font-weight": "bold", "color": "white"});
25+
26+
$("#uri").focus(function(){
27+
if ($(this).val() == check_phrase) {
28+
$(this).val("");
29+
$("#uri").css({'color': '#111'});
5930
}
60-
},
61-
function(e){
62-
var classes = $(this).parent().attr("class").split(" ");
63-
for (var i=0; i < classes.length; i++) {
64-
var c = classes[i];
65-
$("span.hdr[name='" + c +"']")
66-
.css({"font-weight": "normal", "color": "#ddd"});
31+
});
32+
33+
/* catch enter to work around IE8 */
34+
$("input").keypress(function (e) {
35+
if (e.which == 13) {
36+
$("#request_form").submit();
6737
}
68-
}
69-
);
38+
});
7039

71-
$("h3").click(function(){
72-
$(this).next().slideToggle("normal");
73-
});
7440

75-
$("#body_view").toggle(function() {
76-
$("#details").fadeOut('fast', function() {
77-
$("#body").fadeIn('fast');
78-
prettyPrint();
79-
$("#body_view").text("show messages");
41+
/* single response display */
42+
43+
var hidden_list = $("#hidden_list");
44+
45+
$("span.hdr").hoverPopup(
46+
function(e){
47+
var name = $(this).attr('name');
48+
return $("li#" + name, hidden_list).html();
49+
},
50+
function(e){
51+
var name = $(this).attr('name');
52+
$("span." + name).css({"font-weight": "bold", "color": "white"});
53+
$("li.msg:not(." + name + ")").fadeTo(100, 0.15);
54+
$("li.msg." + name).fadeTo(50, 1.0);
55+
},
56+
function(e){
57+
var name = $(this).attr('name');
58+
$("span." + name).css({"font-weight": "normal", "color": "#ddd"});
59+
$("li.msg").fadeTo(100, 1.0);
60+
}
61+
);
62+
63+
$("li.msg span").hoverPopup(
64+
function(e){
65+
return $("li#" + $(this).parent().attr('name'), hidden_list).html();
66+
},
67+
function(e){
68+
var classes = $(this).parent().attr("class").split(" ");
69+
for (var i=0; i < classes.length; i++) {
70+
var c = classes[i];
71+
$("span.hdr[name='" + c +"']")
72+
.css({"font-weight": "bold", "color": "white"});
73+
}
74+
},
75+
function(e){
76+
var classes = $(this).parent().attr("class").split(" ");
77+
for (var i=0; i < classes.length; i++) {
78+
var c = classes[i];
79+
$("span.hdr[name='" + c +"']")
80+
.css({"font-weight": "normal", "color": "#ddd"});
81+
}
82+
}
83+
);
84+
85+
$("h3").click(function(){
86+
$(this).next().slideToggle("normal");
8087
});
81-
return false;
82-
}, function() {
83-
$("#body").fadeOut('fast', function() {
84-
$("#details").fadeIn('fast');
85-
$("#body_view").text("show body");
88+
89+
$("#body_view").toggle(function() {
90+
$("#details").fadeOut('fast', function() {
91+
$("#body").fadeIn('fast');
92+
prettyPrint();
93+
$("#body_view").text("show messages");
94+
});
95+
return false;
96+
}, function() {
97+
$("#body").fadeOut('fast', function() {
98+
$("#details").fadeIn('fast');
99+
$("#body_view").text("show body");
100+
});
101+
return false;
86102
});
87-
return false;
88-
});
89103

90-
$("#save").click(function() {
91-
$("#save_form").submit();
92-
})
104+
$("#save").click(function() {
105+
$("#save_form").submit();
106+
})
93107

94108

95-
/* multiple result display */
109+
/* multiple result display */
96110

97-
$("tr.droid").hoverIntent(function() {
98-
var classes = this.className.split(" ");
99-
$("li.msg").fadeTo(100, 0.15);
100-
for (var i=0; i < classes.length; i++) {
101-
var c = classes[i];
102-
if (c != 'droid') {
103-
$("li.msg:eq(" + c +")").fadeTo(50, 1.0);
111+
$("tr.droid").hoverIntent(function() {
112+
var classes = this.className.split(" ");
113+
$("li.msg").fadeTo(100, 0.15);
114+
for (var i=0; i < classes.length; i++) {
115+
var c = classes[i];
116+
if (c != 'droid') {
117+
$("li.msg:eq(" + c +")").fadeTo(50, 1.0);
118+
}
104119
}
105-
}
106-
if (tid != false) {
107-
clearTimeout(tid);
108-
tid = false;
109-
}
110-
}, function(){
111-
tid = setTimeout(function() {
112-
$("li.msg").fadeTo(50, 1.0);
113-
}, 100);
114-
});
115-
116-
$("span.prob_num").hoverPopup(function(e) {
117-
return $(this).children(".hidden").html();
118-
});
119-
120-
$("a.preview").hoverPopup(function(e) {
121-
var link = (this.title != "") ? this.title : this.href;
122-
return "<img src='" + link + "'/><br />" + link;
123-
});
120+
if (tid != false) {
121+
clearTimeout(tid);
122+
tid = false;
123+
}
124+
}, function(){
125+
tid = setTimeout(function() {
126+
$("li.msg").fadeTo(50, 1.0);
127+
}, 100);
128+
});
129+
130+
$("span.prob_num").hoverPopup(function(e) {
131+
return $(this).children(".hidden").html();
132+
});
133+
134+
$("a.preview").hoverPopup(function(e) {
135+
var link = (this.title != "") ? this.title : this.href;
136+
return "<img src='" + link + "'/><br />" + link;
137+
});
138+
139+
});

‎share/script.js

+172-155
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.