Browse Source

fix: set first tab + cleanup

Benoît Hubert 8 years ago
parent
commit
2f69757fcc
6 changed files with 21 additions and 28 deletions
  1. 14 12
      js/ws-editor.js
  2. 0 1
      js/ws-events.js
  3. 0 8
      js/ws-forms.js
  4. 1 2
      js/ws-menu.js
  5. 0 1
      js/ws-notify.js
  6. 6 4
      js/ws-ui-parts.js

+ 14 - 12
js/ws-editor.js

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

+ 0 - 1
js/ws-events.js

@@ -1,7 +1,6 @@
 "use strict";
 (function($) {
   $(document).ready(function() {
-    console.log('ws: init events');
     _ws.events = new EventEmitter();
   });
 })(jQuery);

+ 0 - 8
js/ws-forms.js

@@ -2,7 +2,6 @@
 (function($) {
   $(document).ready(function() {
 
-
   function checkPropsExist(obj, props) {
     if(typeof obj !== 'object' || ! props) {
       throw new Error('checkPropsExist was called with wrong arguments');
@@ -41,7 +40,6 @@
       },
 
       reset: function() {
-        console.log('reset', this);
         this.$btn.addClass('in');
         this.$form.removeClass('in');
         this.$input.val('');
@@ -133,7 +131,6 @@
 
       onAddSuccess: function(file) {
         _ws.notify('success', 'Fichier crée: ' + file.name);
-        console.log('****** onAddSuccess file', file, _ws.files);
         _ws.files.push(file);
         _ws.ui.tabs.render({ files: _ws.files });
       },
@@ -142,7 +139,6 @@
       },
 
       postInit: function() {
-        console.log('### exec postInit', this);
         function onKeyup(e) {
           var filename = this.$input.val();
           var bits = filename.split('.');
@@ -160,7 +156,6 @@
           // show error if provided extension is invalid
           else {
             var ext = (bits[lastIdx]).toLowerCase();
-            console.log(bits);
 
             if( ['html', 'js', 'css'].indexOf( ext ) === -1 ) {
               this.cantSubmit = 'Impossible de valider: extension ' + ext + ' invalide (autorisées: .html/.js/.css)';
@@ -183,8 +178,5 @@
     }
   );
 
-
-  console.log(_ws.ui);
-
   });
 })(jQuery);

+ 1 - 2
js/ws-menu.js

@@ -1,7 +1,7 @@
 "use strict";
 (function($) {
   $(document).ready(function() {
-    console.log('ws: init menu');
+    // console.log('ws: init menu');
 
     /**
      * Main menu
@@ -109,7 +109,6 @@
     function menuItemClicked(e) {
       e.preventDefault();
       var $link = $(e.target);
-      console.log($link.prop('href'));
       var originalColor = $link.css('backgroundColor');
       toggleMainMenu();
       $link.animate({

+ 0 - 1
js/ws-notify.js

@@ -1,7 +1,6 @@
 "use strict";
 (function($) {
   $(document).ready(function() {
-    console.log('ws: init notify');
 
     var $notification = $('#notification');
 

+ 6 - 4
js/ws-ui-parts.js

@@ -1,7 +1,7 @@
 "use strict";
 (function($) {
   $(document).ready(function() {
-    console.log('ws: init UI parts');
+    // console.log('ws: init UI parts');
 
 
     /**
@@ -25,6 +25,10 @@
         this.$elem.removeClass('hidden');
         this.$elem.show();
         this.bindEvents();
+        // call if an afterRender function was provided
+        if(typeof this.afterRender === 'function') {
+          this.afterRender();
+        }
       }
     }
 
@@ -57,9 +61,7 @@
     /**
      * Bind events: nop
      */
-    function viewBindEventsNop() {
-      console.log(this.partName, 'bindEvents:nop');
-    }
+    function viewBindEventsNop() {}
 
 
     /**