Skip to content

Commit 04dc96c

Browse files
committed
bam
1 parent be0306d commit 04dc96c

File tree

5 files changed

+22
-27
lines changed

5 files changed

+22
-27
lines changed

v5-unity/composingprograms.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212

1313
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
1414

15-
<script type="text/javascript">
16-
window.optOverride = {}
17-
</script>
18-
1915
<!-- let Webpack take care of everything. Use the [hash] feature to
2016
create unique filenames for releases:
2117
https://webpack.github.io/docs/long-term-caching.html -->

v5-unity/js/composingprograms.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var optFrontend: OptFrontend;
1919
// augment with a "Create test cases" pane
2020
export class OptFrontendComposingprograms extends OptFrontendSharedSessions {
2121
constructor(params={}) {
22+
params.disableLocalStorageToggles = true;
2223
super(params);
2324
this.originFrontendJsFile = 'composingprograms.js';
2425
}
@@ -32,7 +33,5 @@ $(document).ready(function() {
3233

3334
optFrontend = new OptFrontendComposingprograms();
3435
optFrontend.setSurveyHTML();
35-
36-
$('#pythonVersionSelector').change(optFrontend.setAceMode.bind(optFrontend));
3736
optFrontend.setAceMode();
3837
});

v5-unity/js/opt-frontend-common.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ export abstract class AbstractBaseFrontend {
100100
abstract handleUncaughtException(trace: any[]) : any; // called by executeCodeAndCreateViz
101101

102102
constructor(params: any = {}) {
103+
// OMG nasty wtf?!?
104+
// From: http://stackoverflow.com/questions/21159301/quotaexceedederror-dom-exception-22-an-attempt-was-made-to-add-something-to-st
105+
// Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem
106+
// throw QuotaExceededError. We're going to detect this and just silently drop any calls to setItem
107+
// to avoid the entire page breaking, without having to do a check at each usage of Storage.
108+
if (typeof localStorage === 'object') {
109+
try {
110+
localStorage.setItem('localStorage', '1');
111+
localStorage.removeItem('localStorage');
112+
} catch (e) {
113+
(Storage as any).prototype._setItem = Storage.prototype.setItem;
114+
Storage.prototype.setItem = function() {}; // make it a NOP
115+
alert('Your web browser does not support storing settings locally. In Safari, the most common cause of this is using "Private Browsing Mode". Some features may not work properly for you.');
116+
}
117+
}
118+
103119
if (supports_html5_storage()) {
104120
// generate a unique UUID per "user" (as indicated by a single browser
105121
// instance on a user's machine, which can be more precise than IP

v5-unity/js/opt-frontend.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,30 +117,11 @@ export class OptFrontend extends AbstractBaseFrontend {
117117
$('#urlOutput').val(urlStr);
118118
});
119119

120-
// OMG nasty wtf?!?
121-
// From: http://stackoverflow.com/questions/21159301/quotaexceedederror-dom-exception-22-an-attempt-was-made-to-add-something-to-st
122-
// Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem
123-
// throw QuotaExceededError. We're going to detect this and just silently drop any calls to setItem
124-
// to avoid the entire page breaking, without having to do a check at each usage of Storage.
125-
if (typeof localStorage === 'object') {
126-
try {
127-
localStorage.setItem('localStorage', '1');
128-
localStorage.removeItem('localStorage');
129-
} catch (e) {
130-
(Storage as any).prototype._setItem = Storage.prototype.setItem;
131-
Storage.prototype.setItem = function() {}; // make it a NOP
132-
alert('Your web browser does not support storing settings locally. In Safari, the most common cause of this is using "Private Browsing Mode". Some features may not work properly for you.');
133-
}
134-
}
135120

136121
// first initialize options from HTML LocalStorage. very important
137122
// that this code runs FIRST so that options get overridden by query
138123
// string options and anything else the user wants to override with.
139-
//
140-
// super hacky using window.optOverride global -- if that's in
141-
// effect, then don't load/save from HTML5 storage so that we don't
142-
// mess up the overridden settings
143-
if (supports_html5_storage() && typeof (window as any).optOverride === 'undefined') {
124+
if (supports_html5_storage() && !params.disableLocalStorageToggles) {
144125
var lsKeys = ['cumulative',
145126
'heapPrimitives',
146127
'py',

v5-unity/js/visualize.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,12 @@ $(document).ready(function() {
146146
$("#exampleSnippets")
147147
.append(exampleHeaderHtml);
148148

149+
var params = {};
149150
var optOverride = (window as any).optOverride;
150151
// super hacky!
151152
if (optOverride) {
153+
(params as any).disableLocalStorageToggles = true;
154+
152155
if (optOverride.frontendLang === 'java') {
153156
$("#exampleSnippets").append(javaExamplesHtml);
154157
} else if (optOverride.frontendLang === 'js') {
@@ -175,7 +178,7 @@ $(document).ready(function() {
175178
$("#footer").append(footerHtml);
176179

177180

178-
optFrontend = new OptFrontendWithTestcases();
181+
optFrontend = new OptFrontendWithTestcases(params);
179182
optFrontend.setSurveyHTML();
180183

181184
// canned examples

0 commit comments

Comments
 (0)