|
|
@@ -17,7 +17,8 @@ $(document).ready(function() {
|
|
|
var currentHash;
|
|
|
var editor;
|
|
|
var editorStorage = new LocalStorageDraft();
|
|
|
- var saveTimeout;
|
|
|
+ var saveTimeout1;
|
|
|
+ var saveTimeout2;
|
|
|
var exampleList;
|
|
|
|
|
|
$leftPanel.resizable({
|
|
|
@@ -42,6 +43,7 @@ $(document).ready(function() {
|
|
|
editor.getSession().setUseWrapMode(true);
|
|
|
|
|
|
function setCurrentHash(slug) {
|
|
|
+ console.log('setCurrentHash', slug)
|
|
|
if(slug) {
|
|
|
// console.log('save current hash', slug);
|
|
|
window.location.hash = currentHash = slug;
|
|
|
@@ -65,10 +67,13 @@ $(document).ready(function() {
|
|
|
}
|
|
|
|
|
|
function editorContentChanged() {
|
|
|
- if(saveTimeout) {
|
|
|
- clearTimeout(saveTimeout);
|
|
|
+ console.log('editorContent changed')
|
|
|
+ if(saveTimeout1 || saveTimeout2) {
|
|
|
+ clearTimeout(saveTimeout1);
|
|
|
+ clearTimeout(saveTimeout2);
|
|
|
}
|
|
|
- saveTimeout = setTimeout(saveToLocalStorage, 1000);
|
|
|
+ saveTimeout1 = setTimeout(saveToLocalStorage, 500);
|
|
|
+ // saveTimeout2 = setTimeout(saveChanges, 1000);
|
|
|
}
|
|
|
|
|
|
editor.getSession().on('change', editorContentChanged);
|
|
|
@@ -81,11 +86,9 @@ $(document).ready(function() {
|
|
|
$('#' + elementId).addClass('active');
|
|
|
var ed = $('#editor-' + mode);
|
|
|
setEditorMode(mode);
|
|
|
+ editor.getSession().off('change');
|
|
|
editor.getSession().setValue(ed[0].innerHTML);
|
|
|
- // var value = editorStorage.hasSource(mode) ?
|
|
|
- // editorStorage.getSource(mode) : ed[0].innerHTML;
|
|
|
- // editor.getSession().setValue(value);
|
|
|
-
|
|
|
+ editor.getSession().on('change', editorContentChanged);
|
|
|
}
|
|
|
|
|
|
$('#tabs button').click(function() {
|
|
|
@@ -110,6 +113,7 @@ $(document).ready(function() {
|
|
|
}
|
|
|
|
|
|
function loadExample(exampleSlug) {
|
|
|
+ console.log('loadExample', exampleSlug);
|
|
|
var serverPath = 'exemples/' + exampleSlug + '/';
|
|
|
loadAsync(serverPath + 'script.js', 'text')
|
|
|
.then(javascript => $editorJs.html(javascript))
|
|
|
@@ -129,9 +133,9 @@ $(document).ready(function() {
|
|
|
.then(() => {
|
|
|
var item = _.find(exampleList, { slug: exampleSlug });
|
|
|
// console.log(item.test ? 'test' : 'no test');
|
|
|
- loadJS('exemples/' + item.slug + '/test.js', function() {
|
|
|
- $('#tests').show();
|
|
|
- });
|
|
|
+ // loadJS('exemples/' + item.slug + '/test.js', function() {
|
|
|
+ // $('#tests').show();
|
|
|
+ // });
|
|
|
});
|
|
|
|
|
|
}
|
|
|
@@ -147,7 +151,7 @@ $(document).ready(function() {
|
|
|
function loadExampleList() {
|
|
|
$.get('exemples/liste.json', function(_exampleList) {
|
|
|
exampleList = _exampleList;
|
|
|
- var didRestore;
|
|
|
+ var restoredDraft;
|
|
|
exampleList.forEach(addFileSelectItem);
|
|
|
if(currentHash) {
|
|
|
$fileSelect.val(currentHash);
|
|
|
@@ -164,11 +168,11 @@ $(document).ready(function() {
|
|
|
setHtmlContent(restoredDraft.sources.html);
|
|
|
$editorJs.html(restoredDraft.sources.javascript);
|
|
|
loadJS('exemples/' + item.slug + '/script.js');
|
|
|
- if(item.test) {
|
|
|
- loadJS('exemples/' + item.slug + '/test.js', function() {
|
|
|
- $('#tests').show();
|
|
|
- });
|
|
|
- }
|
|
|
+ // if(item.test) {
|
|
|
+ // loadJS('exemples/' + item.slug + '/test.js', function() {
|
|
|
+ // $('#tests').show();
|
|
|
+ // });
|
|
|
+ // }
|
|
|
setActiveTab('html');
|
|
|
}
|
|
|
}
|