X Tutup
Skip to content

Commit 213f75c

Browse files
committed
update core js to be consistent with the latest gh-pages
1 parent ce63dd4 commit 213f75c

31 files changed

+646
-396
lines changed

js/app/constructor.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,29 @@
33
const Editor = require('../editor');
44
const TracerManager = require('../tracer_manager');
55
const DOM = require('../dom/setup');
6-
const {
7-
getFileDir
8-
} = require('../utils');
96

107
const Cache = require('./cache');
118

12-
const {
13-
each
14-
} = $;
15-
169
const state = {
1710
isLoading: null,
1811
editor: null,
1912
tracerManager: null,
20-
categories: null
13+
categories: null,
14+
loadedScratch: null
2115
};
2216

2317
const initState = (tracerManager) => {
2418
state.isLoading = false;
2519
state.editor = new Editor(tracerManager);
2620
state.tracerManager = tracerManager;
2721
state.categories = {};
22+
state.loadedScratch = null;
2823
};
2924

3025
/**
3126
* Global application singleton.
3227
*/
33-
const App = function() {
28+
const App = function () {
3429

3530
this.getIsLoading = () => {
3631
return state.isLoading;
@@ -69,6 +64,14 @@ const App = function() {
6964
return state.tracerManager;
7065
};
7166

67+
this.getLoadedScratch = () => {
68+
return state.loadedScratch;
69+
};
70+
71+
this.setLoadedScratch = (loadedScratch) => {
72+
state.loadedScratch = loadedScratch;
73+
};
74+
7275
const tracerManager = TracerManager.init();
7376

7477
initState(tracerManager);
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const appInstance = require('../app');
3+
const app = require('../app');
44
const Server = require('../server');
55
const showAlgorithm = require('./show_algorithm');
66

@@ -13,7 +13,7 @@ const addAlgorithmToCategoryDOM = (category, subList, algorithm) => {
1313
.append(subList[algorithm])
1414
.attr('data-algorithm', algorithm)
1515
.attr('data-category', category)
16-
.click(function() {
16+
.click(function () {
1717
Server.loadAlgorithm(category, algorithm).then((data) => {
1818
showAlgorithm(category, algorithm, data);
1919
});
@@ -27,14 +27,15 @@ const addCategoryToDOM = (category) => {
2727
const {
2828
name: categoryName,
2929
list: categorySubList
30-
} = appInstance.getCategory(category);
30+
} = app.getCategory(category);
3131

3232
const $category = $('<button class="category">')
3333
.append('<i class="fa fa-fw fa-caret-right">')
34-
.append(categoryName);
34+
.append(categoryName)
35+
.attr('data-category', category);
3536

36-
$category.click(function() {
37-
$(`[data-category="${category}"]`).toggleClass('collapse');
37+
$category.click(function () {
38+
$(`.indent[data-category="${category}"]`).toggleClass('collapse');
3839
$(this).find('i.fa').toggleClass('fa-caret-right fa-caret-down');
3940
});
4041

@@ -46,5 +47,5 @@ const addCategoryToDOM = (category) => {
4647
};
4748

4849
module.exports = () => {
49-
each(appInstance.getCategories(), addCategoryToDOM);
50+
each(app.getCategories(), addCategoryToDOM);
5051
};

js/dom/add_files.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
const Server = require('../server');
4+
5+
const {
6+
each
7+
} = $;
8+
9+
const addFileToDOM = (category, algorithm, file, explanation) => {
10+
var $file = $('<button>')
11+
.append(file)
12+
.attr('data-file', file)
13+
.click(function () {
14+
Server.loadFile(category, algorithm, file, explanation);
15+
$('.files_bar > .wrapper > button').removeClass('active');
16+
$(this).addClass('active');
17+
});
18+
$('.files_bar > .wrapper').append($file);
19+
return $file;
20+
};
21+
22+
module.exports = (category, algorithm, files, requestedFile) => {
23+
$('.files_bar > .wrapper').empty();
24+
25+
each(files, (file, explanation) => {
26+
var $file = addFileToDOM(category, algorithm, file, explanation);
27+
if (requestedFile && requestedFile == file) $file.click();
28+
});
29+
30+
if (!requestedFile) $('.files_bar > .wrapper > button').first().click();
31+
$('.files_bar > .wrapper').scroll();
32+
};

js/dom/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
'use strict';
22

33
const showAlgorithm = require('./show_algorithm');
4-
const showCategories = require('./show_categories');
4+
const addCategories = require('./add_categories');
55
const showDescription = require('./show_description');
6-
const showFiles = require('./show_files');
6+
const addFiles = require('./add_files');
77
const showFirstAlgorithm = require('./show_first_algorithm');
8+
const showRequestedAlgorithm = require('./show_requested_algorithm');
89

910
module.exports = {
1011
showAlgorithm,
11-
showCategories,
12+
addCategories,
1213
showDescription,
13-
showFiles,
14-
showFirstAlgorithm
14+
addFiles,
15+
showFirstAlgorithm,
16+
showRequestedAlgorithm
1517
};

js/dom/setup/setup_dividers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const appInstance = require('../../app');
1+
const app = require('../../app');
22

33
const addDividerToDom = (divider) => {
44
const [vertical, $first, $second] = divider;
@@ -37,7 +37,7 @@ const addDividerToDom = (divider) => {
3737
$first.css('right', (100 - percent) + '%');
3838
$second.css('left', percent + '%');
3939
x = pageX;
40-
appInstance.getTracerManager().resize();
40+
app.getTracerManager().resize();
4141
$('.files_bar > .wrapper').scroll();
4242
}
4343
});
@@ -75,7 +75,7 @@ const addDividerToDom = (divider) => {
7575
$first.css('bottom', (100 - percent) + '%');
7676
$second.css('top', percent + '%');
7777
y = pageY;
78-
appInstance.getTracerManager().resize();
78+
app.getTracerManager().resize();
7979
}
8080
});
8181

js/dom/setup/setup_document.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const appInstance = require('../../app');
1+
const app = require('../../app');
22

33
module.exports = () => {
44
$(document).on('click', 'a', (e) => {
@@ -10,6 +10,6 @@ module.exports = () => {
1010
});
1111

1212
$(document).mouseup(function(e) {
13-
appInstance.getTracerManager().command('mouseup', e);
13+
app.getTracerManager().command('mouseup', e);
1414
});
1515
};

js/dom/setup/setup_interval.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const appInstance = require('../../app');
1+
const app = require('../../app');
22
const Toast = require('../toast');
33

44
const {
@@ -40,7 +40,7 @@ module.exports = () => {
4040
});
4141

4242
$('#interval').on('change', function() {
43-
const tracerManager = appInstance.getTracerManager();
43+
const tracerManager = app.getTracerManager();
4444
const [seconds, message] = normalize(parseFloat($(this).val()));
4545

4646
$(this).val(seconds);
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
const appInstance = require('../../app');
1+
const app = require('../../app');
22

33
module.exports = () => {
44

55
const $module_container = $('.module_container');
66

77
$module_container.on('mousedown', '.module_wrapper', function(e) {
8-
appInstance.getTracerManager().findOwner(this).mousedown(e);
8+
app.getTracerManager().findOwner(this).mousedown(e);
99
});
1010

1111
$module_container.on('mousemove', '.module_wrapper', function(e) {
12-
appInstance.getTracerManager().findOwner(this).mousemove(e);
12+
app.getTracerManager().findOwner(this).mousemove(e);
1313
});
1414

1515
$module_container.on('DOMMouseScroll mousewheel', '.module_wrapper', function(e) {
16-
appInstance.getTracerManager().findOwner(this).mousewheel(e);
16+
app.getTracerManager().findOwner(this).mousewheel(e);
1717
});
1818
}

js/dom/setup/setup_scratch_paper.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
const app = require('../../app');
12
const Server = require('../../server');
23
const showAlgorithm = require('../show_algorithm');
34

45
module.exports = () => {
56
$('#scratch-paper').click(function() {
6-
const category = null;
7-
const algorithm = 'scratch_paper';
7+
const category = 'scratch';
8+
const algorithm = app.getLoadedScratch();
89
Server.loadAlgorithm(category, algorithm).then((data) => {
910
showAlgorithm(category, algorithm, data);
1011
});

js/dom/setup/setup_side_menu.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const appInstance = require('../../app');
1+
const app = require('../../app');
22

33
let sidemenu_percent;
44

@@ -20,6 +20,6 @@ module.exports = () => {
2020
$workspace.css('left', 0);
2121
}
2222

23-
appInstance.getTracerManager().resize();
23+
app.getTracerManager().resize();
2424
});
2525
}

0 commit comments

Comments
 (0)
X Tutup