Skip to content

Commit fc7258c

Browse files
committed
share scratch paper as separate files (code.js / data.js)
1 parent 2bd17c2 commit fc7258c

1 file changed

Lines changed: 19 additions & 28 deletions

File tree

js/script.js

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ $module_container.on('DOMMouseScroll mousewheel', '.module_wrapper', function (e
355355

356356
// Share scratch paper
357357

358-
var getParameterByName = function(name) {
359-
url = window.location.href;
358+
var getParameterByName = function (name) {
359+
var url = window.location.href;
360360
name = name.replace(/[\[\]]/g, "\\$&");
361361
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
362362
results = regex.exec(url);
@@ -365,39 +365,30 @@ var getParameterByName = function(name) {
365365
return decodeURIComponent(results[2].replace(/\+/g, " "));
366366
};
367367

368-
369-
$(document).ready(function() {
370-
if(/[?&]scratch-paper=/.test(location.search)){
371-
var gistID = getParameterByName('scratch-paper');
372-
console.log(gistID);
373-
loadScratchPaper(gistID);
374-
}
375-
});
376-
377-
var shareScratchPaper = function(){
378-
var json = {
379-
"data": dataEditor.getValue(),
380-
"code": codeEditor.getValue()
381-
};
368+
var shareScratchPaper = function () {
382369
var gist = {
383-
"description": "Shared scratch paper",
384-
"public": true,
385-
"files": {
386-
"scratch-paper.json": {
387-
"content": JSON.stringify(json)
388-
}
370+
'description': 'temp',
371+
'public': true,
372+
'files': {
373+
'code.js': {'content': dataEditor.getValue()},
374+
'data.js': {'content': codeEditor.getValue()}
389375
}
390376
};
391-
$.post("https://api.github.com/gists", JSON.stringify(gist), function(res) {
377+
$.post('https://api.github.com/gists', JSON.stringify(gist), function (res) {
392378
var data = JSON.parse(res);
393-
console.log(window.location.origin + "\/?scratch-paper=" + data.id);
379+
console.log(location.protocol + '//' + location.host + location.pathname + '?scratch-paper=' + data.id);
394380
});
395381
};
396382

397383
var loadScratchPaper = function (gistID) {
398-
$.get("https://api.github.com/gists/" + gistID, function(res) {
384+
$.get('https://api.github.com/gists/' + gistID, function (res) {
399385
var data = JSON.parse(res);
400-
var content = data.files["scratch-paper.json"].content;
401-
console.log(content);
386+
console.log(data);
402387
});
403-
};
388+
};
389+
390+
if (/[?&]scratch-paper=/.test(location.search)) {
391+
var gistID = getParameterByName('scratch-paper');
392+
console.log(gistID);
393+
loadScratchPaper(gistID);
394+
}

0 commit comments

Comments
 (0)