Benoît Hubert 8 years ago
parent
commit
1ac5937804
4 changed files with 10 additions and 213 deletions
  1. 0 121
      js/ws-editor.js
  2. 10 59
      js/ws-forms.js
  3. 0 30
      js/ws-menu.js
  4. 0 3
      js/ws-ui-parts.js

+ 0 - 121
js/ws-editor.js

@@ -110,25 +110,11 @@ $(document).ready(function() {
 
   _ws.makeView('sandbox-iframe', {
     render: function(src) {
-      // console.log('change iframe src', '/examples/' + navState.repo + '/' + navState.example);
       this.$elem.prop('src', src);
     }
   });
 
 
-  // /**
-  //  * Set the current hash. If none given, take it from lococation.hash
-  //  */
-  // function setCurrentHash(slug) {
-  //   if(slug) {
-  //     window.location.hash = currentHash = slug;
-  //   }
-  //   else {
-  //     currentHash = window.location.hash ?
-  //         window.location.hash.substr(1) : undefined;
-  //   }
-  // }
-
 
   // /**
   //  * Set editor mode (html, javascript, css)
@@ -163,93 +149,6 @@ $(document).ready(function() {
 
   // editor.getSession().on('change', editorContentChanged);
 
-  // function setActiveTab(mode) {
-  //   console.log('setting mode', mode);
-  //   var elementId = 'show-' + mode;
-  //   $('#show-' + activeMode).removeClass('active');
-  //   activeMode = mode;
-  //   $('#' + elementId).addClass('active');
-  //   var ed = $('#editor-' + mode);
-  //   setEditorMode(mode);
-  //   editor.getSession().off('change');
-  //   editor.getSession().setValue(ed[0].innerHTML);
-  //   editor.getSession().on('change', editorContentChanged);
-  // }
-
-
-  // function loadExample(exampleSlug) {
-  //   // console.log('loadExample', exampleSlug);
-  //   var serverPath = 'exemples/jquery/' + exampleSlug + '/';
-  //   rp.get(serverPath + 'script.js', 'text')
-  //   .then(javascript => $editorJs.html(javascript))
-  //   .then(() => rp.get(serverPath + 'example.html', 'text'))
-  //   .then(() => rp.get(serverPath + 'styles.css', 'text')
-  //     .then(css => $editorCss.html(css))
-  //     .catch(err => {
-  //       return '';
-  //     })
-  //   )
-  //   .then(html => {
-  //     $editorHtml.html(html);
-  //     $('iframe.panel-right')
-  //     .prop('src', '/examples/' + exampleSlug)
-  //     setActiveTab('html');
-  //     setCurrentHash(exampleSlug);
-  //     var sources = {
-  //       html: $editorHtml.html(),
-  //       javascript: $editorJs.html()
-  //     };
-  //     editorStorage.init(exampleSlug, sources);
-  //   })
-  //   .then(() => {
-  //     var item = _.find(exampleList, { slug: exampleSlug });
-  //     // console.log(item.test ? 'test' : 'no test');
-  //     // loadJS('exemples/' + item.slug + '/test.js', function() {
-  //     //   $('#tests').show();
-  //     // });
-  //   });
-
-  // }
-
-
-
-
-  // function loadExampleList() {
-  //   rp.get('/list/jquery', 'json')
-  //   .then(function(_exampleList) {
-  //     exampleList = _exampleList;
-  //     var restoredDraft;
-  //     resetFileSelect(exampleList);
-  //     if(currentHash) {
-  //       $fileSelect.val(currentHash);
-  //       var item = _.find(exampleList, { slug: currentHash });
-  //       if( ! item) {
-  //         return;
-  //       }
-  //       restoredDraft = editorStorage.restore(item.slug);
-  //       if(! restoredDraft) {
-  //         loadExample(item.slug);
-  //       }
-  //       else {
-  //         console.log('restore', item.slug, restoredDraft.sources);
-  //         $editorHtml.html(restoredDraft.sources.html);
-  //         $editorCss.html(restoredDraft.sources.css);
-  //         $editorJs.html(restoredDraft.sources.javascript);
-  //         $('iframe.panel-right')
-  //         .prop('src', '/examples/' + item.slug)
-
-  //         // loadJS('exemples/' + item.slug + '/script.js');
-  //         // if(item.test) {
-  //         //   loadJS('exemples/' + item.slug + '/test.js', function() {
-  //         //     $('#tests').show();
-  //         //   });
-  //         // }
-  //         setActiveTab('html');
-  //       }
-  //     }
-  //   });
-  // }
-
 
   // function revertEditor() {
   //   editorStorage.reset();
@@ -277,23 +176,3 @@ $(document).ready(function() {
   // loadExampleList();
 
 });
-
-
-
-
-  // var $editorJs      = $('#editor-javascript');
-  // var $editorHtml    = $('#editor-html');
-  // var $editorCss     = $('#editor-css');
-  // var $htmlContent   = $('#html-content');  // replaced by iframe
-  // var $selectorNav   = $('#selector');
-
-
-  // /**
-  //  * Handle window resize
-  //  */
-  // function onResize() {
-  //   $editor.width($panelLeft.width());
-  //   $panelWrap.height($window.height());
-  // }
-  // $window.resize(onResize);
-  // onResize();

+ 10 - 59
js/ws-forms.js

@@ -3,58 +3,18 @@
   $(document).ready(function() {
 
 
-  // var $addRepoBtn = $('#add-repo-btn');
-
-
-  // var $addExampleBtn = $('#add-example-btn');
-  // var $exampleForm   = $('#add-example-form');
-  // var $exampleFormIn = $exampleForm.find('input');
-  // var $exampleSave   = $('#add-example-save');
-  // var $exampleCancel = $('#add-example-cancel');
-
-
-  // /**
-  //  * Add new example
-  //  */
-  // function addExample(e) {
-  //   e.preventDefault();
-  //   var repoSlug = $detailsRepo.data('slug');
-  //   var title = $(this).find('input[name="title"]').val();
-  //   rp.post('/' + repoSlug + '/examples', { title: title })
-  //   .then(function(example) {
-  //     clearAndCloseEditor();
-  //     // $fileSelect.append(makeFileSelectOption(example));
-  //     // $fileSelect.val(example.slug);
-      
-  //     // var $exMenuItem = $('<li><a href="/' + repoSlug + '/' + example.slug + '">' + example.title + '</a></li>')
-  //     // .appendTo( $('#cat-' + example.category) );
-  //     notify('success', "Exemple créé !");
-  //     // navigateTo('/'+ repoSlug + '/' + example.slug);
-  //   })
-  //   .catch(errText => notify('error', 'Erreur: ' + errText));
-  // }
-
-  // function clearAndCloseEditor() {
-  //   $exampleFormIn.val('');
-  //   toggleEditor();
-  // }
-
-  // function toggleEditor() {
-  //   $addExampleBtn.toggle();
-  //   $exampleForm.toggleClass("hidden");
-  // }
-function checkPropsExist(obj, props) {
-  if(typeof obj !== 'object' || ! props) {
-    throw new Error('checkPropsExist was called with wrong arguments');
-  }
-  props = typeof props === 'string' ? [props] : props;
-  for(let p = 0 ; p < props.length ; p++) {
-    const prop = props[p];
-    if(! obj[prop]) {
-      throw new Error('obj does not have a `' + prop + '` parameter: please provide it.');
+  function checkPropsExist(obj, props) {
+    if(typeof obj !== 'object' || ! props) {
+      throw new Error('checkPropsExist was called with wrong arguments');
+    }
+    props = typeof props === 'string' ? [props] : props;
+    for(let p = 0 ; p < props.length ; p++) {
+      const prop = props[p];
+      if(! obj[prop]) {
+        throw new Error('obj does not have a `' + prop + '` parameter: please provide it.');
+      }
     }
   }
-}
 
   function makeFormView(elemId, options) {
     var callbacks = ['onSubmitAddPromise', 'onAddSuccess', 'onAddError'];
@@ -224,16 +184,7 @@ function checkPropsExist(obj, props) {
   );
 
 
-
   console.log(_ws.ui);
 
-  // _ws.ui.addRepoForm.$btn.click(_ws.ui.addRepoForm.render);
-
-
-  // console.log($addExampleBtn);
-  // $addExampleBtn.click(toggleEditor);
-  // $exampleCancel.click(clearAndCloseEditor);
-  // $exampleForm.submit(addExample);
-
   });
 })(jQuery);

+ 0 - 30
js/ws-menu.js

@@ -55,11 +55,9 @@
       history.pushState({}, 'New path', path);
       prevNavState = navState;
       navState = parsePath();
-      console.log('previous&new nav states', prevNavState, navState);
 
       if(navState.repo !== prevNavState.repo) {
         if(navState.repo === '') {
-          console.log('nav: back to root');
           _ws.events.emit('navToRoot');
           _ws.ui.addExample.$btn.removeClass('in');
           _ws.ui.addExample.hide();
@@ -68,11 +66,8 @@
           _ws.ui.shortcutExample.hide();
         }
         else {
-          console.log('nav: repo changed');
           rp.get('/parts/' + navState.repo, 'json')
           .then(function(parts) {
-            // renderMenuExample(parts.menuExample);
-            console.log('render with parts', parts);
             _ws.repo = parts.repo;
             _ws.ui.addExample.$btn.addClass('in');
             _ws.ui.addExample.show();
@@ -88,18 +83,14 @@
         if(navState.example !== '') {
           rp.get('/parts/' + navState.repo + '/' + navState.example, 'json')
           .then(function(parts) {
-            console.log('nav: example changed', parts);
             _ws.example = parts.example;
             _ws.files = parts.files;
-            console.log(_ws.ui);
-            // renderDetailsExample(parts);
             $('#editor-wrapper').show();
             _ws.ui.shortcutExample.hide();
             _ws.ui.detailsExample.render(parts);
             _ws.ui.editor.render(parts);
             _ws.ui.tabs.render(parts);
             _ws.ui.addFile.show();
-            console.log('#### render iframe with navState', navState);
             _ws.ui.sandboxIframe.render('/examples/' + navState.repo + '/' + navState.example);
           });
         }
@@ -188,7 +179,6 @@
     });
 
 
-
     /**
      * Handle click on links outside #menu-example
      */
@@ -212,25 +202,5 @@
     _ws.makeView('details-repo');
 
 
-
-
-
-    // window._ws.navigator = new SandboxNavigator();
-    // console.log('navigator init', _ws);
-
-    //     var $exMenuItem = $('<li><a href="/' + repoSlug + '/' + example.slug + '">' + example.title + '</a></li>')
-    //     .appendTo( $('#cat-' + example.category) );
-    //     notify('success', "Exemple créé !");
-    //     _ws.navigateTo('/'+ repoSlug + '/' + example.slug);
-    //   })
-    //   .catch(errText => notify('error', 'Erreur: ' + errText));
-    // }
-
-    // function clearAndCloseEditor() {
-    //   $exampleFormIn.val('');
-    //   toggleEditor();
-    // }
-
-
   });
 })(jQuery);

+ 0 - 3
js/ws-ui-parts.js

@@ -17,7 +17,6 @@
      */
     function viewDefaultRender(elemId) {
       return function(data) {
-        console.log('this is default render on', this, 'with data', data);
         if(! data) {
           throw new Error('WARNING! You should provide data for #' + elemId + "'s render()");
         }
@@ -50,7 +49,6 @@
         var evtName = bits.shift();
         var selector = bits.join(' ');
         var target = selector === '' ? this.$elem : this.$elem.find(selector);
-        // console.log('#### bind', descriptor, 'e:' + evtName, 's:[' + selector + '], target:', target);
         target.on(evtName, handler.bind(this));
       }
     }
@@ -117,7 +115,6 @@
       // Pass arbitrary properties
       for(var p in props) {
         if(['render', 'events', 'init'].indexOf(p) !== -1) {
-          // console.log('pass props: ignore', p);
           continue;
         }
         var prop = props[p];