Pārlūkot izejas kodu

this is such a mess

Benoît Hubert 8 gadi atpakaļ
vecāks
revīzija
6aac2bd567
2 mainītis faili ar 27 papildinājumiem un 18 dzēšanām
  1. 21 13
      js/editor.js
  2. 6 5
      js/menu.js

+ 21 - 13
js/editor.js

@@ -51,6 +51,12 @@ $(document).ready(function() {
 
   });
 
+  _ws.events.on('rendered:tabs', function() {
+    console.log('rebind editor tabs');
+    $tabItems = $('#tabs li');
+    bindEditorTabs();
+  });
+
   if(_ws.files.length === 0) {
     return;
   }
@@ -95,20 +101,22 @@ $(document).ready(function() {
   /**
    * File list tabs click handler
    */
-  $tabItems.click(function() {
-    var clickedItem = $(this);
-    var type = clickedItem.data('type');
-    editorSession.setMode("ace/mode/" + mapTypes[type]);
-    var name = clickedItem.html();
-    var file = _ws.files.find(f => (f.name === name));
-    editorSession.setValue(file.content);
-    // saveToLocalStorage();
-    // var mode = $(this).prop('id').substr(5);
-    // console.log( .html() );
-    // setActiveTab(mode);
-  })
-
+  function bindEditorTabs() {
+    $tabItems.click(function() {
+      var clickedItem = $(this);
+      var type = clickedItem.data('type');
+      editorSession.setMode("ace/mode/" + mapTypes[type]);
+      var name = clickedItem.html();
+      var file = _ws.files.find(f => (f.name === name));
+      editorSession.setValue(file.content);
+      // saveToLocalStorage();
+      // var mode = $(this).prop('id').substr(5);
+      // console.log( .html() );
+      // setActiveTab(mode);
+    })
+  }
 
+  bindEditorTabs();
 
 
   // /**

+ 6 - 5
js/menu.js

@@ -27,8 +27,8 @@
     SandboxNavigator.prototype.bindLinkEvents = function(idx, linkEl) {
       var self = this;
       $(linkEl).click(function(e) {
-        var $link = $(this);
         e.preventDefault();
+        var $link = $(this);
         var originalColor = $link.css('backgroundColor');
         self.toggleMenu();
         $link.animate({
@@ -71,8 +71,8 @@
         rp.get('/parts/' + this.nav.repo + '/' + this.nav.example, 'json')
         .then(function(parts) {
           console.log(parts);
-          renderExample(parts);
-
+          renderDetailsExample(parts);
+          renderTabs(parts);
 
         });
       }
@@ -112,11 +112,12 @@
       $('#' + id).html( Mustache.render( tmpl, parts ) );
     }
 
-    function renderTabs() {
+    function renderTabs(parts) {
       renderInto('tabs', parts);
+      _ws.events.emit('rendered:tabs');
     }
 
-    function renderExample(parts) {
+    function renderDetailsExample(parts) {
       var tmpl = $('#details-example-tmpl').html();
       console.log(tmpl);
       $('#details-example').html( Mustache.render( tmpl, parts ) );