|
@@ -1,7 +1,7 @@
|
|
|
/* global window,$,ace,setTimeout,rp,_ws */
|
|
/* global window,$,ace,setTimeout,rp,_ws */
|
|
|
"use strict";
|
|
"use strict";
|
|
|
$(document).ready(function() {
|
|
$(document).ready(function() {
|
|
|
- console.log('ws: init editor');
|
|
|
|
|
|
|
+ // console.log('ws: init editor');
|
|
|
|
|
|
|
|
var $editorWrapper = $('#editor-wrapper');
|
|
var $editorWrapper = $('#editor-wrapper');
|
|
|
var $editor = $('#editor');
|
|
var $editor = $('#editor');
|
|
@@ -29,7 +29,6 @@ $(document).ready(function() {
|
|
|
html: 'html', js: 'javascript', css: 'css'
|
|
html: 'html', js: 'javascript', css: 'css'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- console.log('log events from editor', _ws);
|
|
|
|
|
_ws.events.on('navToRoot', function() {
|
|
_ws.events.on('navToRoot', function() {
|
|
|
$editorWrapper.hide();
|
|
$editorWrapper.hide();
|
|
|
$detailsRepo.hide();
|
|
$detailsRepo.hide();
|
|
@@ -37,7 +36,6 @@ $(document).ready(function() {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
_ws.events.on('navToRepo', function(repoSlug) {
|
|
_ws.events.on('navToRepo', function(repoSlug) {
|
|
|
- console.log('got navToRepo', repoSlug);
|
|
|
|
|
$editorWrapper.hide();
|
|
$editorWrapper.hide();
|
|
|
$detailsRepo.show();
|
|
$detailsRepo.show();
|
|
|
$detailsExmp.hide();
|
|
$detailsExmp.hide();
|
|
@@ -81,7 +79,6 @@ $(document).ready(function() {
|
|
|
function onTabClicked(e) {
|
|
function onTabClicked(e) {
|
|
|
var clickedItem = $(e.target);
|
|
var clickedItem = $(e.target);
|
|
|
var activeTab = _ws.ui.tabs.getActiveTab();
|
|
var activeTab = _ws.ui.tabs.getActiveTab();
|
|
|
- console.log('onTabClicked', clickedItem, activeTab);
|
|
|
|
|
if(activeTab[0] === clickedItem[0] || clickedItem[0].tagName === 'SPAN') {
|
|
if(activeTab[0] === clickedItem[0] || clickedItem[0].tagName === 'SPAN') {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -97,10 +94,8 @@ $(document).ready(function() {
|
|
|
editorSession.setMode("ace/mode/" + mapTypes[type]);
|
|
editorSession.setMode("ace/mode/" + mapTypes[type]);
|
|
|
var name = clickedItem.data('name');
|
|
var name = clickedItem.data('name');
|
|
|
var file = _ws.files.find(f => (f.name === name));
|
|
var file = _ws.files.find(f => (f.name === name));
|
|
|
- console.log('activate', name, file);
|
|
|
|
|
_ws.ui.tabs.setActiveTab(file);
|
|
_ws.ui.tabs.setActiveTab(file);
|
|
|
|
|
|
|
|
- console.log('remove change handler', _ws.ui.editor.contentChanged)
|
|
|
|
|
editor.getSession().off('change', _ws.ui.editor.contentChanged);
|
|
editor.getSession().off('change', _ws.ui.editor.contentChanged);
|
|
|
editorSession.setValue(file.content);
|
|
editorSession.setValue(file.content);
|
|
|
editor.getSession().on('change', _ws.ui.editor.contentChanged);
|
|
editor.getSession().on('change', _ws.ui.editor.contentChanged);
|
|
@@ -112,6 +107,11 @@ $(document).ready(function() {
|
|
|
// setActiveTab(mode);
|
|
// setActiveTab(mode);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function setFirstActiveTab() {
|
|
|
|
|
+ var firstHtml = _ws.files.find(f => (f.type === 'html'));
|
|
|
|
|
+ this.setActiveTab(firstHtml);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
_ws.makeView('tabs', {
|
|
_ws.makeView('tabs', {
|
|
|
setActiveTab: function(file) {
|
|
setActiveTab: function(file) {
|
|
@@ -121,9 +121,10 @@ $(document).ready(function() {
|
|
|
}
|
|
}
|
|
|
var idx = this.fileIdx = _ws.files.indexOf(this.file);
|
|
var idx = this.fileIdx = _ws.files.indexOf(this.file);
|
|
|
this.activeTab = this.$elem.find('li:eq(' + idx + ')');
|
|
this.activeTab = this.$elem.find('li:eq(' + idx + ')');
|
|
|
- console.log('set active tab', idx, this.file, this.activeTab);
|
|
|
|
|
this.activeTab.addClass('bold');
|
|
this.activeTab.addClass('bold');
|
|
|
},
|
|
},
|
|
|
|
|
+ setFirstActiveTab: setFirstActiveTab,
|
|
|
|
|
+ afterRender: setFirstActiveTab,
|
|
|
getActiveTab: function() {
|
|
getActiveTab: function() {
|
|
|
return this.activeTab;
|
|
return this.activeTab;
|
|
|
},
|
|
},
|
|
@@ -148,7 +149,7 @@ $(document).ready(function() {
|
|
|
* React to changes in editor by saving a copy
|
|
* React to changes in editor by saving a copy
|
|
|
*/
|
|
*/
|
|
|
contentChanged: function() {
|
|
contentChanged: function() {
|
|
|
- console.log('content changed handler', editorSession.getValue());
|
|
|
|
|
|
|
+ // console.log('content changed handler', editorSession.getValue());
|
|
|
_ws.ui.tabs.getActiveTab()
|
|
_ws.ui.tabs.getActiveTab()
|
|
|
.addClass('dirty');
|
|
.addClass('dirty');
|
|
|
// if(saveTimeout1 || saveTimeout2) {
|
|
// if(saveTimeout1 || saveTimeout2) {
|
|
@@ -161,7 +162,7 @@ $(document).ready(function() {
|
|
|
|
|
|
|
|
|
|
|
|
|
render: function() {
|
|
render: function() {
|
|
|
- console.log('render editor', this);
|
|
|
|
|
|
|
+ // console.log('render editor', this);
|
|
|
setDefaultEditorContent();
|
|
setDefaultEditorContent();
|
|
|
$editorWrapper.show();
|
|
$editorWrapper.show();
|
|
|
this.$elem.removeClass('hidden');
|
|
this.$elem.removeClass('hidden');
|
|
@@ -203,7 +204,7 @@ $(document).ready(function() {
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
function onSaveChanges() {
|
|
function onSaveChanges() {
|
|
|
- console.log('Saving', this.file, editorSession.getValue())
|
|
|
|
|
|
|
+ // console.log('Saving', this.file, editorSession.getValue())
|
|
|
var filename = this.file.name;
|
|
var filename = this.file.name;
|
|
|
var payload = {
|
|
var payload = {
|
|
|
content: editorSession.getValue()
|
|
content: editorSession.getValue()
|
|
@@ -212,11 +213,12 @@ $(document).ready(function() {
|
|
|
// var payload = editorStorage.getSources();
|
|
// var payload = editorStorage.getSources();
|
|
|
// rp.put('/examples/' + currentHash, payload)
|
|
// rp.put('/examples/' + currentHash, payload)
|
|
|
.then(function(updatedFile) {
|
|
.then(function(updatedFile) {
|
|
|
- console.log(updatedFile);
|
|
|
|
|
|
|
+ // console.log(updatedFile);
|
|
|
_ws.notify('success', "Fichier " + filename + " sauvegardé !");
|
|
_ws.notify('success', "Fichier " + filename + " sauvegardé !");
|
|
|
|
|
+ _ws.ui.tabs.getActiveTab().removeClass('dirty');
|
|
|
})
|
|
})
|
|
|
.catch(function(err) {
|
|
.catch(function(err) {
|
|
|
- console.error(err);
|
|
|
|
|
|
|
+ // console.error(err);
|
|
|
_ws.notify('error', 'Erreur: ' + err.message);
|
|
_ws.notify('error', 'Erreur: ' + err.message);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|