Skip to content

Commit 82a05a6

Browse files
committed
refactor: Move Sprocket JS files to Webpack (Part 2)
Code editor modules are moved with minimal changes. Relates to #3021
1 parent 12f21d0 commit 82a05a6

File tree

13 files changed

+30
-19
lines changed

13 files changed

+30
-19
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+
window.CodeOceanEditorAJAX = {
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var CodeOceanEditor = {
1+
window.CodeOceanEditor = {
22
THEME: window.getCurrentTheme() === 'dark' ? 'ace/theme/tomorrow_night' : 'ace/theme/tomorrow',
33

44
//Color-Encoding for Percentages in Progress Bars (For submissions)
@@ -28,8 +28,8 @@ var CodeOceanEditor = {
2828
lastCopyText: null,
2929

3030
sendEvents: null,
31-
eventURL: Routes.events_path(),
32-
fileTypeURL: Routes.file_types_path(),
31+
eventURL: () => Routes.events_path(),
32+
fileTypeURL: () => Routes.file_types_path(),
3333

3434
confirmDestroy: function (event) {
3535
event.preventDefault();
@@ -389,7 +389,7 @@ var CodeOceanEditor = {
389389
updateEditorModeToFileTypeID: function (editor, fileTypeID) {
390390
var newMode = 'ace/mode/text'
391391

392-
$.ajax(this.fileTypeURL + '/' + fileTypeID, {
392+
$.ajax(this.fileTypeURL() + '/' + fileTypeID, {
393393
dataType: 'json'
394394
}).done(function (data) {
395395
if (data['editor_mode'] !== null) {
@@ -668,7 +668,7 @@ var CodeOceanEditor = {
668668

669669
publishCodeOceanEvent: function (payload) {
670670
if (this.sendEvents) {
671-
$.ajax(this.eventURL, {
671+
$.ajax(this.eventURL(), {
672672
type: 'POST',
673673
cache: false,
674674
dataType: 'JSON',

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+
window.CodeOceanEditorEvaluation = {
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CodeOceanEditorWebsocket = {
1+
window.CodeOceanEditorWebsocket = {
22
websocket: null,
33
// Replace `http` with `ws` for the WebSocket connection. This also works with `https` and `wss`.
44
webSocketProtocol: window.location.protocol.replace(/^http/, 'ws').split(':')[0],
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import './ajax';
2+
import './editor';
3+
import './evaluation';
4+
import './execution';
5+
import './participantsupport';
6+
import './prompt';
7+
import './submissions';
8+
import './turtle';
9+
import './websocket';
10+

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CodeOceanEditorFlowr = {
1+
window.CodeOceanEditorFlowr = {
22
flowrResultHtml:
33
'<div class="card mb-2">' +
44
'<div id="{{headingId}}" role="tab" class="card-header">' +

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+
window.CodeOceanEditorPrompt = {
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+
window.CodeOceanEditorSubmissions = {
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+
window.CodeOceanEditorTurtle = {
24
turtlecanvas: null,
35
turtlescreen: null,
46
resetTurtle: true,

0 commit comments

Comments
 (0)