提交 0b1add48 编写于 作者: T TornjV

Merge branch 'gh-pages' of https://github.com/parkjs814/AlgorithmVisualizer...

Merge branch 'gh-pages' of https://github.com/parkjs814/AlgorithmVisualizer into fix/dijkstra-visualization
......@@ -28,6 +28,22 @@ Array1DTracer.prototype = $.extend(true, Object.create(Array2DTracer.prototype),
}
return this;
},
_separate: function (idx) {
this.manager.pushStep(this.capsule, {
type: 'separate',
x: 0,
y: idx
});
return this;
},
_deseparate: function (idx) {
this.manager.pushStep(this.capsule, {
type: 'deseparate',
x: 0,
y: idx
});
return this;
},
setData: function (D) {
return Array2DTracer.prototype.setData.call(this, [D]);
}
......
......@@ -130,7 +130,7 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
processStep: function (step, options) {
switch (step.type) {
case 'notify':
if (step.v) {
if (step.v === 0 || step.v) {
var $row = this.$table.find('.mtbl-row').eq(step.x);
var $col = $row.find('.mtbl-col').eq(step.y);
$col.text(TracerUtil.refineByType(step.v));
......
......@@ -158,7 +158,10 @@ var executeDataAndCode = function () {
}
$('.sidemenu button').removeClass('active');
$menu.addClass('active');
$('#btn_desc').click();
var requestedTab = getAlgorithmHash('algorithm')['tab'];
if(requestedTab === 'trace') $('#btn_trace').click();
else $('#btn_desc').click();
$('#category').html(category_name);
$('#algorithm').html(algorithm_name);
......@@ -249,10 +252,19 @@ var executeDataAndCode = function () {
showDescription(data);
showFiles(category, algorithm, files);
});
var hash = isScratchPaper(category, algorithm) ? algorithm : category + '/' + algorithm;
setHashValue('algorithm', hash);
};
var list = {};
var anyOpened = false;
$.getJSON('./algorithm/category.json', function (data) {
var algorithmHash = getAlgorithmHash();
console.log(algorithmHash);
var requestedCategory = algorithmHash['category'],
requestedAlgorithm = algorithmHash['algorithm'];
var anyRequested = requestedCategory && requestedAlgorithm;
anyOpened = anyRequested;
list = data;
for (var category in list) {
(function (category) {
......@@ -283,6 +295,16 @@ var executeDataAndCode = function () {
}
})(category);
}
if(anyRequested) {
if(!list[requestedCategory] || !list[requestedCategory].list[requestedAlgorithm]) {
showErrorToast('Oops! This link appears to be broken.');
$('#scratch-paper').click();
} else {
$('[data-category="' + requestedCategory + '"]').toggleClass('collapse');
loadAlgorithm(requestedCategory, requestedAlgorithm);
}
}
});
$('#powered-by').click(function () {
$('#powered-by-list button').toggleClass('collapse');
......@@ -334,6 +356,7 @@ var executeDataAndCode = function () {
$('#btn_share').click(function () {
var $icon = $(this).find('.fa-share');
$icon.addClass('fa-spin fa-spin-faster');
shareScratchPaper(function (url) {
$icon.removeClass('fa-spin fa-spin-faster');
$('#shared').removeClass('collapse');
......@@ -372,12 +395,16 @@ var executeDataAndCode = function () {
$('#tab_desc').addClass('active');
$('.tab_bar > button').removeClass('active');
$(this).addClass('active');
var algorithmHash = getAlgorithmHash();
setHashValue('algorithm', algorithmHash['category'] + '/' + algorithmHash['algorithm']);
});
$('#btn_trace').click(function () {
$('.tab_container > .tab').removeClass('active');
$('#tab_module').addClass('active');
$('.tab_bar > button').removeClass('active');
$(this).addClass('active');
var algorithmHash = getAlgorithmHash();
setHashValue('algorithm', algorithmHash['category'] + '/' + algorithmHash['algorithm'] + '/trace');
});
$(window).resize(function () {
......@@ -476,6 +503,74 @@ var executeDataAndCode = function () {
tracerManager.findOwner(this).mousewheel(e);
});
var getHashValue = function (key) {
if(!key) return null;
var hash = window.location.hash.substr(1);
var params = hash ? hash.split('&') : [];
for(var i = 0; i < params.length; i++) {
var pair = params[i].split('=');
if(pair[0] === key) {
return pair[1];
}
}
return null;
}
var setHashValue = function (key, value) {
if(!key || !value) return;
var hash = window.location.hash.substr(1);
var params = hash ? hash.split('&') : [];
var found = false;
for(var i = 0; i < params.length && !found; i++) {
var pair = params[i].split('=');
if(pair[0] === key) {
pair[1] = value;
params[i] = pair.join('=');
found = true;
}
}
if(!found) {
params.push([key, value].join('='));
}
var newHash = params.join('&');
window.location.hash = '#' + newHash;
}
var removeHashValue = function (key) {
if(!key) return;
var hash = window.location.hash.substr(1);
var params = hash ? hash.split('&') : [];
for(var i = 0; i < params.length; i++) {
var pair = params[i].split('=');
if(pair[0] === key) {
params.splice(i, 1);
break;
}
}
var newHash = params.join('&');
window.location.hash = '#' + newHash;
}
var getAlgorithmHash = function () {
var hash = getHashValue('algorithm');
if(hash){
var regex = /(?:[^\/\\]+|\\.)+/g;
var tmp = null, algorithmHash = {}, i = 0;
while(tmp = regex.exec(hash)){
if(i === 0) algorithmHash['category'] = tmp[0];
if(i === 1) algorithmHash['algorithm'] = tmp[0];
if(i === 2) algorithmHash['tab'] = tmp[0];
i++;
}
return algorithmHash;
} else
return false;
}
// Share scratch paper
var getParameterByName = function (name) {
......@@ -499,7 +594,7 @@ var executeDataAndCode = function () {
};
$.post('https://api.github.com/gists', JSON.stringify(gist), function (res) {
var data = JSON.parse(res);
if (callback) callback(location.protocol + '//' + location.host + location.pathname + '?scratch-paper=' + data.id);
if (callback) callback(location.protocol + '//' + location.host + location.pathname + '#scratch-paper=' + data.id);
});
};
......@@ -519,8 +614,8 @@ var executeDataAndCode = function () {
});
};
var gistID = getParameterByName('scratch-paper');
var gistID = getHashValue('scratch-paper');
if (gistID) {
loadScratchPaper(gistID);
}
})();
\ No newline at end of file
})();
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册