Skip to content

Commit c4be790

Browse files
committed
refactor: Move Sprocket JS files to Webpack (Part 2)
Code editor modules are moved and modularized for later removal from global scope. Relates to #3021
1 parent 12f21d0 commit c4be790

File tree

13 files changed

+48
-22
lines changed

13 files changed

+48
-22
lines changed

app/assets/javascripts/application.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@
2121
//= require base
2222
// 2. Programming groups are required by "channels/synchronized_editor_channel.js"
2323
//= require programming_groups
24-
// 3. The turtle library is required by "editor/turtle.js"
25-
//= require turtle
26-
// 4. Some channels are required by "editor/editor.js.erb"
24+
// 3. Some channels are required by "editor/editor.js.erb"
2725
//= require_tree ./channels
28-
// 5. Require the editor components, as needed by "./editor.js" and "./community_solution.js"
29-
//= require_tree ./editor
3026
//
3127
// All remaining assets are loaded in alphabetical order
3228
//= require_tree .

app/assets/javascripts/editor/ajax.js renamed to app/javascript/sprocket_asset_import/editor/ajax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CodeOceanEditorAJAX = {
1+
export default {
22
ajax: function(options) {
33
return $.ajax(_.extend({
44
dataType: 'json',

app/assets/javascripts/editor/editor.js renamed to app/javascript/sprocket_asset_import/editor/editor.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
var CodeOceanEditor = {
1+
import { CodeOceanEditorTips } from './participantsupport';
2+
3+
const CodeOceanEditor = {
24
THEME: window.getCurrentTheme() === 'dark' ? 'ace/theme/tomorrow_night' : 'ace/theme/tomorrow',
35

46
//Color-Encoding for Percentages in Progress Bars (For submissions)
@@ -28,8 +30,8 @@ var CodeOceanEditor = {
2830
lastCopyText: null,
2931

3032
sendEvents: null,
31-
eventURL: Routes.events_path(),
32-
fileTypeURL: Routes.file_types_path(),
33+
eventURL: Routes.events_path,
34+
fileTypeURL: Routes.file_types_path,
3335

3436
confirmDestroy: function (event) {
3537
event.preventDefault();
@@ -389,7 +391,7 @@ var CodeOceanEditor = {
389391
updateEditorModeToFileTypeID: function (editor, fileTypeID) {
390392
var newMode = 'ace/mode/text'
391393

392-
$.ajax(this.fileTypeURL + '/' + fileTypeID, {
394+
$.ajax(this.fileTypeURL() + '/' + fileTypeID, {
393395
dataType: 'json'
394396
}).done(function (data) {
395397
if (data['editor_mode'] !== null) {
@@ -668,7 +670,7 @@ var CodeOceanEditor = {
668670

669671
publishCodeOceanEvent: function (payload) {
670672
if (this.sendEvents) {
671-
$.ajax(this.eventURL, {
673+
$.ajax(this.eventURL(), {
672674
type: 'POST',
673675
cache: false,
674676
dataType: 'JSON',
@@ -1170,3 +1172,5 @@ var CodeOceanEditor = {
11701172
CodeOceanEditor.editors = [];
11711173
}
11721174
};
1175+
1176+
export default CodeOceanEditor;

app/assets/javascripts/editor/evaluation.js renamed to app/javascript/sprocket_asset_import/editor/evaluation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CodeOceanEditorEvaluation = {
1+
export default {
22
// A list of non-printable characters that are not allowed in the code output.
33
// Taken from https://stackoverflow.com/a/69024306
44
nonPrintableRegEx: /[\u0000-\u0008\u000B\u000C\u000F-\u001F\u007F-\u009F\u2000-\u200F\u2028-\u202F\u205F-\u206F\u3000\uFEFF]/g,

app/assets/javascripts/editor/execution.js renamed to app/javascript/sprocket_asset_import/editor/execution.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
CodeOceanEditorWebsocket = {
1+
import CommandSocket from './websocket'
2+
3+
export default {
24
websocket: null,
35
// Replace `http` with `ws` for the WebSocket connection. This also works with `https` and `wss`.
46
webSocketProtocol: window.location.protocol.replace(/^http/, 'ws').split(':')[0],
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import CodeOceanEditorAJAX from './ajax';
2+
import CodeOceanEditor from './editor';
3+
import CodeOceanEditorEvaluation from './evaluation';
4+
import CodeOceanEditorWebsocket from './execution';
5+
import { CodeOceanEditorFlowr, CodeOceanEditorRequestForComments } from './participantsupport';
6+
import CodeOceanEditorPrompt from './prompt';
7+
import CodeOceanEditorSubmissions from './submissions';
8+
import CodeOceanEditorTurtle from './turtle';
9+
10+
// TODO: Import explicitly in Part 3 of the asset migration.
11+
window.CodeOceanEditorAJAX = CodeOceanEditorAJAX;
12+
window.CodeOceanEditor = CodeOceanEditor;
13+
window.CodeOceanEditorEvaluation = CodeOceanEditorEvaluation;
14+
window.CodeOceanEditorWebsocket = CodeOceanEditorWebsocket;
15+
window.CodeOceanEditorFlowr = CodeOceanEditorFlowr;
16+
window.CodeOceanEditorPrompt = CodeOceanEditorPrompt;
17+
window.CodeOceanEditorRequestForComments = CodeOceanEditorRequestForComments;
18+
window.CodeOceanEditorSubmissions = CodeOceanEditorSubmissions;
19+
window.CodeOceanEditorTurtle = CodeOceanEditorTurtle;

app/assets/javascripts/editor/participantsupport.js renamed to app/javascript/sprocket_asset_import/editor/participantsupport.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CodeOceanEditorFlowr = {
1+
export const CodeOceanEditorFlowr = {
22
flowrResultHtml:
33
'<div class="card mb-2">' +
44
'<div id="{{headingId}}" role="tab" class="card-header">' +
@@ -111,7 +111,7 @@ CodeOceanEditorFlowr = {
111111
}
112112
};
113113

114-
CodeOceanEditorRequestForComments = {
114+
export const CodeOceanEditorRequestForComments = {
115115
requestComments: function () {
116116
const cause = $('#requestComments');
117117
this.newSentryTransaction(cause, async () => {
@@ -172,7 +172,7 @@ CodeOceanEditorRequestForComments = {
172172
}
173173
};
174174

175-
CodeOceanEditorTips = {
175+
export const CodeOceanEditorTips = {
176176
initializeEventHandlers: function() {
177177
const card_headers = $('#tips .card-collapse');
178178
for (let tip of card_headers) {

app/assets/javascripts/editor/prompt.js renamed to app/javascript/sprocket_asset_import/editor/prompt.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CodeOceanEditorPrompt = {
1+
export default {
22
prompt: '#prompt',
33

44
showPrompt: function(msg) {
@@ -42,4 +42,4 @@ CodeOceanEditorPrompt = {
4242
this.submitPromptInput();
4343
}
4444
}
45-
};
45+
};

app/assets/javascripts/editor/submissions.js renamed to app/javascript/sprocket_asset_import/editor/submissions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CodeOceanEditorSubmissions = {
1+
export default {
22
AUTOSAVE_INTERVAL: 15 * 1000,
33
autosaveTimer: null,
44
autosaveLabel: "#statusbar #autosave",

app/assets/javascripts/editor/turtle.js renamed to app/javascript/sprocket_asset_import/editor/turtle.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
CodeOceanEditorTurtle = {
1+
import Turtle from '../turtle';
2+
3+
export default {
24
turtlecanvas: null,
35
turtlescreen: null,
46
resetTurtle: true,

0 commit comments

Comments
 (0)