zahmis 5 лет назад
Родитель
Сommit
b2c2cda088
1 измененных файлов с 71 добавлено и 0 удалено
  1. 71 0
      src/client/js/legacy/crowi.js

+ 71 - 0
src/client/js/legacy/crowi.js

@@ -152,11 +152,15 @@ Crowi.highlightSelectedSection = function(hash) {
 };
 
 $(() => {
+  const appContainer = window.appContainer;
+  const config = appContainer.getConfig();
+
   const pageId = $('#content-main').data('page-id');
   // const revisionId = $('#content-main').data('page-revision-id');
   // const revisionCreatedAt = $('#content-main').data('page-revision-created');
   // const currentUser = $('#content-main').data('current-user');
   const isSeen = $('#content-main').data('page-is-seen');
+  const isSavedStatesOfTabChanges = config.isSavedStatesOfTabChanges;
 
   $('[data-toggle="popover"]').popover();
   $('[data-toggle="tooltip"]').tooltip();
@@ -195,6 +199,73 @@ $(() => {
     }
   } // end if pageId
 
+  // TODO clean code after GW-3605
+  // tab changing handling
+  $('a[href="#revision-body"]').on('show.bs.tab', () => {
+    const navigationContainer = appContainer.getContainer('NavigationContainer');
+    navigationContainer.setEditorMode(null);
+  });
+  $('a[href="#edit"]').on('show.bs.tab', () => {
+    const navigationContainer = appContainer.getContainer('NavigationContainer');
+    navigationContainer.setEditorMode('builtin');
+    $('body').addClass('on-edit');
+    $('body').addClass('builtin-editor');
+  });
+  $('a[href="#edit"]').on('hide.bs.tab', () => {
+    $('body').removeClass('on-edit');
+    $('body').removeClass('builtin-editor');
+  });
+  $('a[href="#hackmd"]').on('show.bs.tab', () => {
+    const navigationContainer = appContainer.getContainer('NavigationContainer');
+    navigationContainer.setEditorMode('hackmd');
+    $('body').addClass('on-edit');
+    $('body').addClass('hackmd');
+  });
+
+  $('a[href="#hackmd"]').on('hide.bs.tab', () => {
+    $('body').removeClass('on-edit');
+    $('body').removeClass('hackmd');
+  });
+
+  // hash handling
+  if (isSavedStatesOfTabChanges) {
+    $('a[data-toggle="tab"][href="#revision-history"]').on('show.bs.tab', () => {
+      window.location.hash = '#revision-history';
+      window.history.replaceState('', 'History', '#revision-history');
+    });
+    $('a[data-toggle="tab"][href="#edit"]').on('show.bs.tab', () => {
+      window.location.hash = '#edit';
+      window.history.replaceState('', 'Edit', '#edit');
+    });
+    $('a[data-toggle="tab"][href="#hackmd"]').on('show.bs.tab', () => {
+      window.location.hash = '#hackmd';
+      window.history.replaceState('', 'HackMD', '#hackmd');
+    });
+    $('a[data-toggle="tab"][href="#revision-body"]').on('show.bs.tab', () => {
+      // couln't solve https://github.com/weseek/crowi-plus/issues/119 completely -- 2017.07.03 Yuki Takei
+      window.location.hash = '#';
+      window.history.replaceState('', '', window.location.href);
+    });
+  }
+  else {
+    $('a[data-toggle="tab"][href="#revision-history"]').on('show.bs.tab', () => {
+      window.history.replaceState('', 'History', '#revision-history');
+    });
+    $('a[data-toggle="tab"][href="#edit"]').on('show.bs.tab', () => {
+      window.history.replaceState('', 'Edit', '#edit');
+    });
+    $('a[data-toggle="tab"][href="#hackmd"]').on('show.bs.tab', () => {
+      window.history.replaceState('', 'HackMD', '#hackmd');
+    });
+    $('a[data-toggle="tab"][href="#revision-body"]').on('show.bs.tab', () => {
+      window.history.replaceState('', '', window.location.href.replace(window.location.hash, ''));
+    });
+    // replace all href="#edit" link behaviors
+    $(document).on('click', 'a[href="#edit"]', () => {
+      window.location.replace('#edit');
+    });
+  }
+
   // focus to editor when 'shown.bs.tab' event fired
   $('a[href="#edit"]').on('shown.bs.tab', (e) => {
     Crowi.setCaretLineAndFocusToEditor();