Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit caafe31

Browse files
modified run_prettyprint.js to use the new /loader URLs that contain snapshots of minified JS and CSS
1 parent 7819105 commit caafe31

File tree

3 files changed

+33
-77
lines changed

3 files changed

+33
-77
lines changed

js-modules/run_prettify.js

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434
// | | | google-code-prettify/source/ | |
3535
// | | | browse/trunk/styles | |
3636
// +------------------+---------------+------------------------------+--------+
37-
// | namespace= | dotted ident | Attaches prettyPrint and | none |
38-
// | | | related functions to the | |
39-
// | | | global object at that path | |
40-
// | | | so they are accessible to | |
41-
// | | | client code. | |
42-
// +------------------+---------------+------------------------------+--------+
4337
// | callback= | JS identifier | When "prettyPrint" finishes | none |
4438
// | | | window.exports[js_ident] is | |
4539
// | | | called. | |
@@ -81,29 +75,29 @@
8175
pre = doc.addEventListener ? '' : 'on',
8276

8377
init = function(e) {
84-
if (e.type == 'readystatechange' && doc.readyState != 'complete') {
78+
if (e.type == 'readystatechange' && doc.readyState != 'complete') {
8579
return;
8680
}
87-
(e.type == 'load' ? win : doc)[rem](pre + e.type, init, false);
88-
if (!done && (done = true)) { callback.call(win, e.type || e); }
89-
},
81+
(e.type == 'load' ? win : doc)[rem](pre + e.type, init, false);
82+
if (!done && (done = true)) { callback.call(win, e.type || e); }
83+
},
9084

9185
poll = function() {
92-
try {
86+
try {
9387
root.doScroll('left');
9488
} catch(e) {
9589
setTimeout(poll, 50);
9690
return;
9791
}
98-
init('poll');
99-
};
92+
init('poll');
93+
};
10094

10195
if (doc.readyState == 'complete') {
10296
callback.call(win, 'lazy');
10397
} else {
10498
if (doc.createEventObject && root.doScroll) {
105-
try { top = !win.frameElement; } catch(e) { }
106-
if (top) { poll(); }
99+
try { top = !win.frameElement; } catch(e) { }
100+
if (top) { poll(); }
107101
}
108102
doc[add](pre + 'DOMContentLoaded', init, false);
109103
doc[add](pre + 'readystatechange', init, false);
@@ -155,7 +149,6 @@
155149
var autorun = true;
156150
var langs = [];
157151
var skins = [];
158-
var namespaces = [];
159152
var callbacks = [];
160153
scriptQuery.replace(
161154
/[?&]([^&=]+)=([^&]+)/g,
@@ -165,48 +158,34 @@
165158
if (name == 'autorun') { autorun = !/^[0fn]/i.test(value); } else
166159
if (name == 'lang') { langs.push(value); } else
167160
if (name == 'skin') { skins.push(value); } else
168-
if (name == 'namespace') { namespaces.push(value); } else
169161
if (name == 'callback') { callbacks.push(value); }
170162
});
171163

172164
// Use https to avoid mixed content warnings in client pages and to
173165
// prevent a MITM from rewrite prettify mid-flight.
174166
// This only works if this script is loaded via https : something
175167
// over which we exercise no control.
176-
var PRETTIFY_CODE_HOME =
177-
'https://google-code-prettify.googlecode.com/svn/trunk';
168+
var LOADER_BASE_URL =
169+
'https://google-code-prettify.googlecode.com/svn/loader';
178170

179171
for (var i = 0, n = langs.length; i < n; ++i) {
180172
var script = doc.createElement('script');
181173
script.type = 'text/javascript';
182-
script.src = PRETTIFY_CODE_HOME
183-
+ '/src/lang-' + encodeURIComponent(langs[i]) + '.js';
174+
script.src = LOADER_BASE_URL
175+
+ '/lang-' + encodeURIComponent(langs[i]) + '.js';
184176
head.appendChild(script);
185177
}
186178

187179
var skinUrls = [];
188180
for (var i = 0, n = skins.length; i < n; ++i) {
189-
skinUrls.push(PRETTIFY_CODE_HOME
190-
+ '/styles/' + encodeURIComponent(skins[i]) + '.css');
181+
skinUrls.push(LOADER_BASE_URL
182+
+ '/skins/' + encodeURIComponent(skins[i]) + '.css');
191183
}
192-
skinUrls.push(PRETTIFY_CODE_HOME + '/src/prettify.css');
184+
skinUrls.push(LOADER_BASE_URL + '/prettify.css');
193185
loadStylesheetsFallingBack(skinUrls);
194186

195187
var prettyPrint = (function () {
196188
include("prettify.js");
197-
for (var i = 0, n = namespaces.length; i < n; ++i) {
198-
var namespace = namespaces[i];
199-
var namespaceObj = win;
200-
if (namespace) {
201-
var parts = namespace.split('.');
202-
for (var j = 0, nParts = parts.length; j < nParts; ++j) {
203-
var part = parts[j];
204-
namespaceObj = (namespaceObj[part] || (namespaceObj[part] = {}));
205-
}
206-
}
207-
namespaceObj['prettyPrint'] = prettyPrint;
208-
namespaceObj['prettyPrintOne'] = prettyPrintOne;
209-
}
210189
return prettyPrint;
211190
})();
212191

src/run_prettify.js

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434
// | | | google-code-prettify/source/ | |
3535
// | | | browse/trunk/styles | |
3636
// +------------------+---------------+------------------------------+--------+
37-
// | namespace= | dotted ident | Attaches prettyPrint and | none |
38-
// | | | related functions to the | |
39-
// | | | global object at that path | |
40-
// | | | so they are accessible to | |
41-
// | | | client code. | |
42-
// +------------------+---------------+------------------------------+--------+
4337
// | callback= | JS identifier | When "prettyPrint" finishes | none |
4438
// | | | window.exports[js_ident] is | |
4539
// | | | called. | |
@@ -58,7 +52,6 @@
5852
// stylesheet.
5953
// A gallery of stylesheets is available at
6054
// https://google-code-prettify.googlecode.com/svn/trunk/styles/index.html
61-
// http://google-code-prettify.googlecode.com/svn/trunk/styles/index.html
6255
// 3. Since autorun=false is not specified, calls prettyPrint() on page load.
6356

6457

@@ -86,29 +79,29 @@ var IN_GLOBAL_SCOPE = false;
8679
pre = doc.addEventListener ? '' : 'on',
8780

8881
init = function(e) {
89-
if (e.type == 'readystatechange' && doc.readyState != 'complete') {
82+
if (e.type == 'readystatechange' && doc.readyState != 'complete') {
9083
return;
9184
}
92-
(e.type == 'load' ? win : doc)[rem](pre + e.type, init, false);
93-
if (!done && (done = true)) { callback.call(win, e.type || e); }
94-
},
85+
(e.type == 'load' ? win : doc)[rem](pre + e.type, init, false);
86+
if (!done && (done = true)) { callback.call(win, e.type || e); }
87+
},
9588

9689
poll = function() {
97-
try {
90+
try {
9891
root.doScroll('left');
9992
} catch(e) {
10093
setTimeout(poll, 50);
10194
return;
10295
}
103-
init('poll');
104-
};
96+
init('poll');
97+
};
10598

10699
if (doc.readyState == 'complete') {
107100
callback.call(win, 'lazy');
108101
} else {
109102
if (doc.createEventObject && root.doScroll) {
110-
try { top = !win.frameElement; } catch(e) { }
111-
if (top) { poll(); }
103+
try { top = !win.frameElement; } catch(e) { }
104+
if (top) { poll(); }
112105
}
113106
doc[add](pre + 'DOMContentLoaded', init, false);
114107
doc[add](pre + 'readystatechange', init, false);
@@ -160,7 +153,6 @@ var IN_GLOBAL_SCOPE = false;
160153
var autorun = true;
161154
var langs = [];
162155
var skins = [];
163-
var namespaces = [];
164156
var callbacks = [];
165157
scriptQuery.replace(
166158
/[?&]([^&=]+)=([^&]+)/g,
@@ -170,31 +162,30 @@ var IN_GLOBAL_SCOPE = false;
170162
if (name == 'autorun') { autorun = !/^[0fn]/i.test(value); } else
171163
if (name == 'lang') { langs.push(value); } else
172164
if (name == 'skin') { skins.push(value); } else
173-
if (name == 'namespace') { namespaces.push(value); } else
174165
if (name == 'callback') { callbacks.push(value); }
175166
});
176167

177168
// Use https to avoid mixed content warnings in client pages and to
178169
// prevent a MITM from rewrite prettify mid-flight.
179170
// This only works if this script is loaded via https : something
180171
// over which we exercise no control.
181-
var PRETTIFY_CODE_HOME =
182-
'https://google-code-prettify.googlecode.com/svn/trunk';
172+
var LOADER_BASE_URL =
173+
'https://google-code-prettify.googlecode.com/svn/loader';
183174

184175
for (var i = 0, n = langs.length; i < n; ++i) {
185176
var script = doc.createElement('script');
186177
script.type = 'text/javascript';
187-
script.src = PRETTIFY_CODE_HOME
188-
+ '/src/lang-' + encodeURIComponent(langs[i]) + '.js';
178+
script.src = LOADER_BASE_URL
179+
+ '/lang-' + encodeURIComponent(langs[i]) + '.js';
189180
head.appendChild(script);
190181
}
191182

192183
var skinUrls = [];
193184
for (var i = 0, n = skins.length; i < n; ++i) {
194-
skinUrls.push(PRETTIFY_CODE_HOME
195-
+ '/styles/' + encodeURIComponent(skins[i]) + '.css');
185+
skinUrls.push(LOADER_BASE_URL
186+
+ '/skins/' + encodeURIComponent(skins[i]) + '.css');
196187
}
197-
skinUrls.push(PRETTIFY_CODE_HOME + '/src/prettify.css');
188+
skinUrls.push(LOADER_BASE_URL + '/prettify.css');
198189
loadStylesheetsFallingBack(skinUrls);
199190

200191
var prettyPrint = (function () {
@@ -1798,19 +1789,6 @@ var IN_GLOBAL_SCOPE = false;
17981789
});
17991790
}
18001791
})();
1801-
for (var i = 0, n = namespaces.length; i < n; ++i) {
1802-
var namespace = namespaces[i];
1803-
var namespaceObj = win;
1804-
if (namespace) {
1805-
var parts = namespace.split('.');
1806-
for (var j = 0, nParts = parts.length; j < nParts; ++j) {
1807-
var part = parts[j];
1808-
namespaceObj = (namespaceObj[part] || (namespaceObj[part] = {}));
1809-
}
1810-
}
1811-
namespaceObj['prettyPrint'] = prettyPrint;
1812-
namespaceObj['prettyPrintOne'] = prettyPrintOne;
1813-
}
18141792
return prettyPrint;
18151793
})();
18161794

tests/run_prettify_test.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
+ '&callback=print_done'
4141
+ '&skin=sunburst'
4242
+ '&callback=bogus'
43-
+ '&callback=dump_globals'
44-
+ '&namespace=foo.bar"><\/script>');
43+
+ '&callback=dump_globals"><\/script>');
4544
})();
4645
</script>
4746

0 commit comments

Comments
 (0)