|
|
@@ -17,7 +17,6 @@ $(document).ready(function() {
|
|
|
var editorStorage = new LocalStorageDraft();
|
|
|
var saveTimeout;
|
|
|
|
|
|
-
|
|
|
editor = ace.edit("editor");
|
|
|
editor.setTheme("ace/theme/eclipse");
|
|
|
editor.$blockScrolling = Infinity;
|
|
|
@@ -64,9 +63,14 @@ $(document).ready(function() {
|
|
|
var ed = $('#editor-' + mode);
|
|
|
setEditorMode(mode);
|
|
|
editor.getSession().setValue(ed[0].innerHTML);
|
|
|
+ // var value = editorStorage.hasSource(mode) ?
|
|
|
+ // editorStorage.getSource(mode) : ed[0].innerHTML;
|
|
|
+ // editor.getSession().setValue(value);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
$('#tabs button').click(function() {
|
|
|
+ saveToLocalStorage();
|
|
|
var mode = $(this).prop('id').substr(5);
|
|
|
setActiveTab(mode);
|
|
|
})
|
|
|
@@ -88,16 +92,6 @@ $(document).ready(function() {
|
|
|
|
|
|
function loadExample(exampleSlug) {
|
|
|
var serverPath = 'exemples/' + exampleSlug + '/';
|
|
|
- // $.get(serverPath + 'script.js', function(javascript) {
|
|
|
- // $editorJs.html(javascript);
|
|
|
- // }, 'text');
|
|
|
- // $.get(serverPath + '/contenu.html', function(html) {
|
|
|
- // $editorHtml.html(html);
|
|
|
- // $htmlContent.html(html);
|
|
|
- // setActiveTab('html');
|
|
|
- // setCurrentHash(exampleSlug);
|
|
|
- // loadJS(serverPath + 'script.js');
|
|
|
- // }, 'text');
|
|
|
loadAsync(serverPath + 'script.js', 'text')
|
|
|
.then(javascript => $editorJs.html(javascript))
|
|
|
.then(() => loadAsync(serverPath + '/contenu.html', 'text'))
|
|
|
@@ -129,20 +123,16 @@ $(document).ready(function() {
|
|
|
var didRestore;
|
|
|
liste.forEach(addFileSelectItem);
|
|
|
if(currentHash) {
|
|
|
- // console.log('I have current hash', currentHash);
|
|
|
$fileSelect.val(currentHash);
|
|
|
var item = _.find(liste, { slug: currentHash });
|
|
|
if( ! item) {
|
|
|
return;
|
|
|
}
|
|
|
- // console.log('I have current item', item);
|
|
|
restoredDraft = editorStorage.restore(item.slug);
|
|
|
if(! restoredDraft) {
|
|
|
- // console.log('I did not restore');
|
|
|
loadExample(item.slug);
|
|
|
}
|
|
|
else {
|
|
|
- // console.log('I did restore', restoredDraft);
|
|
|
$editorHtml.html(restoredDraft.sources.html);
|
|
|
setHtmlContent(restoredDraft.sources.html);
|
|
|
$editorJs.html(restoredDraft.sources.javascript);
|
|
|
@@ -178,8 +168,6 @@ $(document).ready(function() {
|
|
|
$exampleForm.toggle();
|
|
|
}
|
|
|
|
|
|
- // function ajaxPost(url, data, success, error) {}
|
|
|
-
|
|
|
function saveExample(e) {
|
|
|
e.preventDefault();
|
|
|
var title = $(this).find('input[name="title"]').val();
|
|
|
@@ -190,10 +178,11 @@ $(document).ready(function() {
|
|
|
success: function(newExample) {
|
|
|
clearAndCloseEditor();
|
|
|
addFileSelectItem(newExample);
|
|
|
+ $fileSelect.val(newExample.slug);
|
|
|
+ $fileSelect.trigger('change');
|
|
|
notify('success', "Exemple créé !");
|
|
|
},
|
|
|
error: function(jqXHR, textStatus, errorThrown ) {
|
|
|
- // console.log(jqXHR, textStatus, errorThrown);
|
|
|
notify('error', 'Erreur: ' + jqXHR.responseText);
|
|
|
},
|
|
|
contentType: 'application/json',
|
|
|
@@ -218,7 +207,6 @@ $(document).ready(function() {
|
|
|
loadExample(currentHash);
|
|
|
},
|
|
|
error: function(jqXHR, textStatus, errorThrown ) {
|
|
|
- // console.log(jqXHR, textStatus, errorThrown);
|
|
|
notify('error', 'Erreur: ' + jqXHR.responseText);
|
|
|
},
|
|
|
contentType: 'application/json',
|
|
|
@@ -236,5 +224,4 @@ $(document).ready(function() {
|
|
|
$saveChanges.click(saveChanges);
|
|
|
$exampleForm.submit(saveExample);
|
|
|
loadExampleList();
|
|
|
- // setActiveTab('html');
|
|
|
});
|