Skip to content

Commit 4bb8998

Browse files
committed
minor
1 parent 2695e60 commit 4bb8998

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

js/script.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ var executeDataAndCode = function () {
112112
}).fail(onFail);
113113
}).fail(onFail);
114114
}
115-
setAlgorithmHash(category, algorithm, isScratchPaper(category) ? null : file);
115+
setPath(category, algorithm, isScratchPaper(category) ? null : file);
116116
};
117117
var checkLoading = function () {
118118
if (loading) {
@@ -262,15 +262,15 @@ var executeDataAndCode = function () {
262262
showDescription(data);
263263
showFiles(category, algorithm, files, requestedFile);
264264
});
265-
setAlgorithmHash(category, algorithm);
265+
setPath(category, algorithm);
266266
};
267267
var list = {};
268268
var anyOpened = false;
269269
$.getJSON('./algorithm/category.json', function (data) {
270-
var algorithmHash = getAlgorithmHash();
271-
var requestedCategory = algorithmHash['category'],
272-
requestedAlgorithm = algorithmHash['algorithm'],
273-
requestedFile = algorithmHash['file'];
270+
var path = getPath();
271+
var requestedCategory = path['category'],
272+
requestedAlgorithm = path['algorithm'],
273+
requestedFile = path['file'];
274274
var anyRequested = requestedCategory && requestedAlgorithm;
275275
anyOpened = false;
276276
var $selectedCategory = null, $selectedAlgorithm = null;
@@ -294,7 +294,7 @@ var executeDataAndCode = function () {
294294
.attr('data-algorithm', algorithm)
295295
.attr('data-category', category)
296296
.click(function () {
297-
loadAlgorithm(category, algorithm);
297+
loadAlgorithm(category, algorithm, requestedFile);
298298
});
299299
$('#list').append($algorithm);
300300
if (anyRequested) {
@@ -324,6 +324,7 @@ var executeDataAndCode = function () {
324324
showErrorToast('Oops! This link appears to be broken.');
325325
$('#scratch-paper').click();
326326
}
327+
requestedFile = null;
327328
});
328329
$('#powered-by').click(function () {
329330
$('#powered-by-list button').toggleClass('collapse');
@@ -580,12 +581,12 @@ var executeDataAndCode = function () {
580581
window.location.hash = '#' + newHash;
581582
};
582583

583-
var setAlgorithmHash = function (category, algorithm, file) {
584-
var algorithmHash = category ? category + (algorithm ? '/' + algorithm + (file ? '/' + file : '') : '') : '';
585-
setHashValue('algorithm', algorithmHash);
584+
var setPath = function (category, algorithm, file) {
585+
var path = category ? category + (algorithm ? '/' + algorithm + (file ? '/' + file : '') : '') : '';
586+
setHashValue('algorithm', path);
586587
};
587588

588-
var getAlgorithmHash = function () {
589+
var getPath = function () {
589590
var hash = getHashValue('algorithm');
590591
if (hash) {
591592
var parts = hash.split('/');
@@ -606,7 +607,7 @@ var executeDataAndCode = function () {
606607
};
607608
$.post('https://api.github.com/gists', JSON.stringify(gist), function (res) {
608609
var data = JSON.parse(res);
609-
setAlgorithmHash('scratch', data.id);
610+
setPath('scratch', data.id);
610611
if (callback) callback(location.href);
611612
});
612613
};

0 commit comments

Comments
 (0)