提交 d966ce9c 编写于 作者: J Jason Park

now can share code!

上级 392e194e
...@@ -32,7 +32,18 @@ a { ...@@ -32,7 +32,18 @@ a {
user-select: none; user-select: none;
} }
.btn {
display: inline-table;
}
.btn > .wrapper {
display: table-cell;
vertical-align: middle;
}
.btn,
button { button {
vertical-align: top;
border: none; border: none;
height: 100%; height: 100%;
padding: 0 12px; padding: 0 12px;
...@@ -45,14 +56,24 @@ button { ...@@ -45,14 +56,24 @@ button {
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.btn:hover,
button:hover { button:hover {
background: rgba(0, 0, 0, .15) !important; background: rgba(0, 0, 0, .15) !important;
} }
.btn.active,
button.active { button.active {
background: rgb(44, 44, 44); background: rgb(44, 44, 44);
} }
.btn input,
button input {
outline: none;
background: rgba(0, 0, 0, .3);
padding: 4px;
border: none;
}
.divider { .divider {
position: absolute !important; position: absolute !important;
z-index: 3; z-index: 3;
...@@ -80,16 +101,25 @@ nav h3 { ...@@ -80,16 +101,25 @@ nav h3 {
padding: 0 4px; padding: 0 4px;
} }
#category:empty + .nav-arrow {
display: none;
}
.buttons { .buttons {
float: right; float: right;
height: 100%; height: 100%;
} }
button input { #shared {
outline: none; width: 128px;
background: none; }
border: none;
width: 20px; #shared.collapse {
display: none;
}
#interval {
width: 24px;
text-align: right; text-align: right;
} }
...@@ -122,11 +152,10 @@ button.category { ...@@ -122,11 +152,10 @@ button.category {
button.indent { button.indent {
padding-left: 28px; padding-left: 28px;
display: none;
} }
button.collapse { button.collapse {
display: block; display: none;
} }
.workspace { .workspace {
...@@ -199,7 +228,7 @@ section { ...@@ -199,7 +228,7 @@ section {
background: rgb(44, 44, 44); background: rgb(44, 44, 44);
} }
.module_wrapper .wrapper { .module_wrapper > .wrapper {
padding: 24px 16px; padding: 24px 16px;
box-sizing: border-box; box-sizing: border-box;
} }
...@@ -302,6 +331,11 @@ pre { ...@@ -302,6 +331,11 @@ pre {
background-color: #333; background-color: #333;
} }
.fa-spin-faster {
-webkit-animation: fa-spin 1s infinite ease-in-out;
animation: fa-spin 1s infinite ease-in-out;
}
.mtbl-wrapper { .mtbl-wrapper {
width: 100%; width: 100%;
height: 100%; height: 100%;
......
...@@ -26,11 +26,20 @@ ...@@ -26,11 +26,20 @@
</h3> </h3>
</button> </button>
<div class="buttons"> <div class="buttons">
<div class="btn" id="btn_share">
<div class="wrapper">
<i class="fa fa-share" aria-hidden="true"></i> Share <input type="text" class="collapse" id="shared">
</div>
</div>
<button id="btn_run"><i class="fa fa-play" aria-hidden="true"></i> Run</button> <button id="btn_run"><i class="fa fa-play" aria-hidden="true"></i> Run</button>
<button id="btn_prev"><i class="fa fa-chevron-left" aria-hidden="true"></i> Prev</button> <button id="btn_prev"><i class="fa fa-chevron-left" aria-hidden="true"></i> Prev</button>
<button id="btn_pause"><i class="fa fa-pause" aria-hidden="true"></i> Pause</button> <button id="btn_pause"><i class="fa fa-pause" aria-hidden="true"></i> Pause</button>
<button id="btn_next">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></button> <button id="btn_next">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></button>
<button id="btn_interval">Interval: <input type="text" value="0.5"> sec</button> <div class="btn">
<div class="wrapper">
Interval: <input type="text" value="0.5" id="interval"> sec
</div>
</div>
</div> </div>
</nav> </nav>
<section class="sidemenu active"> <section class="sidemenu active">
......
...@@ -83,7 +83,7 @@ TracerManager.prototype = { ...@@ -83,7 +83,7 @@ TracerManager.prototype = {
return this.pause; return this.pause;
}, },
setInterval: function (interval) { setInterval: function (interval) {
$('#btn_interval input').val(interval); $('#interval').val(interval);
}, },
reset: function () { reset: function () {
this.traces = []; this.traces = [];
......
...@@ -7,10 +7,13 @@ $(document).on('click', 'a', function (e) { ...@@ -7,10 +7,13 @@ $(document).on('click', 'a', function (e) {
alert('Please allow popups for this site'); alert('Please allow popups for this site');
} }
}); });
$('.btn input').click(function (e) {
e.stopPropagation();
});
var tm = new TracerManager(); var tm = new TracerManager();
$('#btn_interval input').on('change', function () { $('#interval').on('change', function () {
tm.interval = Number.parseFloat($(this).val() * 1000); tm.interval = Number.parseFloat($(this).val() * 1000);
showInfoToast('Tracing interval has been set to ' + tm.interval / 1000 + ' second(s).'); showInfoToast('Tracing interval has been set to ' + tm.interval / 1000 + ' second(s).');
}); });
...@@ -181,9 +184,9 @@ var loadAlgorithm = function (category, algorithm) { ...@@ -181,9 +184,9 @@ var loadAlgorithm = function (category, algorithm) {
}); });
}; };
var list = {}; var list = {};
var anyOpened = false;
$.getJSON('./algorithm/category.json', function (data) { $.getJSON('./algorithm/category.json', function (data) {
list = data; list = data;
var init = false;
for (var category in list) { for (var category in list) {
(function (category) { (function (category) {
var $category = $('<button class="category">').append(list[category].name); var $category = $('<button class="category">').append(list[category].name);
...@@ -194,7 +197,7 @@ $.getJSON('./algorithm/category.json', function (data) { ...@@ -194,7 +197,7 @@ $.getJSON('./algorithm/category.json', function (data) {
var subList = list[category].list; var subList = list[category].list;
for (var algorithm in subList) { for (var algorithm in subList) {
(function (category, subList, algorithm) { (function (category, subList, algorithm) {
var $algorithm = $('<button class="indent">') var $algorithm = $('<button class="indent collapse">')
.append(subList[algorithm]) .append(subList[algorithm])
.attr('data-algorithm', algorithm) .attr('data-algorithm', algorithm)
.attr('data-category', category) .attr('data-category', category)
...@@ -202,8 +205,8 @@ $.getJSON('./algorithm/category.json', function (data) { ...@@ -202,8 +205,8 @@ $.getJSON('./algorithm/category.json', function (data) {
loadAlgorithm(category, algorithm); loadAlgorithm(category, algorithm);
}); });
$('#list').append($algorithm); $('#list').append($algorithm);
if (!init) { if (!anyOpened) {
init = true; anyOpened = true;
$algorithm.click(); $algorithm.click();
} }
})(category, subList, algorithm); })(category, subList, algorithm);
...@@ -255,6 +258,15 @@ var showInfoToast = function (info) { ...@@ -255,6 +258,15 @@ var showInfoToast = function (info) {
}, 3000); }, 3000);
}; };
$('#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');
$('#shared').val(url);
});
});
$('#btn_run').click(function () { $('#btn_run').click(function () {
$('#btn_trace').click(); $('#btn_trace').click();
try { try {
...@@ -393,8 +405,6 @@ $module_container.on('DOMMouseScroll mousewheel', '.module_wrapper', function (e ...@@ -393,8 +405,6 @@ $module_container.on('DOMMouseScroll mousewheel', '.module_wrapper', function (e
tm.findOwner(this).mousewheel(e); tm.findOwner(this).mousewheel(e);
}); });
// Share scratch paper
var getParameterByName = function (name) { var getParameterByName = function (name) {
var url = window.location.href; var url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&"); name = name.replace(/[\[\]]/g, "\\$&");
...@@ -405,30 +415,38 @@ var getParameterByName = function (name) { ...@@ -405,30 +415,38 @@ var getParameterByName = function (name) {
return decodeURIComponent(results[2].replace(/\+/g, " ")); return decodeURIComponent(results[2].replace(/\+/g, " "));
}; };
var shareScratchPaper = function () { var shareScratchPaper = function (callback) {
var gist = { var gist = {
'description': 'temp', 'description': 'temp',
'public': true, 'public': true,
'files': { 'files': {
'code.js': {'content': dataEditor.getValue()}, 'code.js': {'content': codeEditor.getValue()},
'data.js': {'content': codeEditor.getValue()} 'data.js': {'content': dataEditor.getValue()}
} }
}; };
$.post('https://api.github.com/gists', JSON.stringify(gist), function (res) { $.post('https://api.github.com/gists', JSON.stringify(gist), function (res) {
var data = JSON.parse(res); var data = JSON.parse(res);
console.log(location.protocol + '//' + location.host + location.pathname + '?scratch-paper=' + data.id); if (callback) callback(location.protocol + '//' + location.host + location.pathname + '?scratch-paper=' + data.id);
}); });
}; };
var loadScratchPaper = function (gistID) { var loadScratchPaper = function (gistID) {
anyOpened = true;
$.get('https://api.github.com/gists/' + gistID, function (res) { $.get('https://api.github.com/gists/' + gistID, function (res) {
var data = JSON.parse(res); var data = JSON.parse(res);
console.log(data); var category = null;
var algorithm = 'scratch_paper';
var dir = getFileDir(category, algorithm, 'scratch_paper');
cachedFile[dir] = {
data: data.files['data.js'].content,
code: data.files['code.js'].content
};
loadAlgorithm(category, algorithm);
}); });
}; };
if (/[?&]scratch-paper=/.test(location.search)) { var gistID = getParameterByName('scratch-paper');
var gistID = getParameterByName('scratch-paper'); if (gistID) {
console.log(gistID); console.log(gistID);
loadScratchPaper(gistID); loadScratchPaper(gistID);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册