diff options
author | Luke "Jared" Bennett <lbennett@gitlab.com> | 2017-07-28 17:18:32 +0100 |
---|---|---|
committer | Luke "Jared" Bennett <lbennett@gitlab.com> | 2017-07-28 17:52:15 +0100 |
commit | efabd07cc5688a8b6acf2cf6f3375a5e209f2e9d (patch) | |
tree | 035903c2c1c91eb2ef324a2e2e60190437a35628 | |
parent | 46f44fab205fe44493d8c57e39d05f2fcd9c00d1 (diff) | |
download | gitlab-ce-efabd07cc5688a8b6acf2cf6f3375a5e209f2e9d.tar.gz |
Add tree.js back and run only if not treeview
-rw-r--r-- | app/assets/javascripts/dispatcher.js | 20 | ||||
-rw-r--r-- | app/assets/javascripts/tree.js | 64 |
2 files changed, 84 insertions, 0 deletions
diff --git a/app/assets/javascripts/dispatcher.js b/app/assets/javascripts/dispatcher.js index e625bf24a98..799b9643212 100644 --- a/app/assets/javascripts/dispatcher.js +++ b/app/assets/javascripts/dispatcher.js @@ -54,6 +54,7 @@ import ShortcutsBlob from './shortcuts_blob'; import SigninTabsMemoizer from './signin_tabs_memoizer'; import Star from './star'; import Todos from './todos'; +import TreeView from './tree'; import UsagePing from './usage_ping'; import UsernameValidator from './username_validator'; import VersionCheckImage from './version_check_image'; @@ -68,6 +69,7 @@ import initNotes from './init_notes'; import initLegacyFilters from './init_legacy_filters'; import initIssuableSidebar from './init_issuable_sidebar'; import GpgBadges from './gpg_badges'; +import FeatureHelper from './helpers/feature_helper'; (function() { var Dispatcher; @@ -323,6 +325,11 @@ import GpgBadges from './gpg_badges'; case 'projects:show': shortcut_handler = new ShortcutsNavigation(); new NotificationsForm(); + + if (FeatureHelper.isNewRepo()) break; + + if ($('#tree-slider').length) new TreeView(); + if ($('#blob-viewer').length) new BlobViewer(); break; case 'projects:edit': setupProjectEdit(); @@ -376,9 +383,22 @@ import GpgBadges from './gpg_badges'; case 'admin:groups:edit': new GroupAvatar(); break; + case 'projects:tree:show': + shortcut_handler = new ShortcutsNavigation(); + + if (FeatureHelper.isNewRepo()) break; + + new TreeView(); + new BlobViewer(); + break; case 'projects:find_file:show': shortcut_handler = true; break; + case 'projects:blob:show': + if (FeatureHelper.isNewRepo()) break; + new BlobViewer(); + initBlob(); + break; case 'projects:blame:show': initBlob(); break; diff --git a/app/assets/javascripts/tree.js b/app/assets/javascripts/tree.js new file mode 100644 index 00000000000..7777ed1c3dc --- /dev/null +++ b/app/assets/javascripts/tree.js @@ -0,0 +1,64 @@ +/* eslint-disable func-names, space-before-function-paren, wrap-iife, max-len, quotes, consistent-return, no-var, one-var, one-var-declaration-per-line, no-else-return, prefer-arrow-callback, class-methods-use-this */ + +export default class TreeView { + constructor() { + this.initKeyNav(); + // Code browser tree slider + // Make the entire tree-item row clickable, but not if clicking another link (like a commit message) + $(".tree-content-holder .tree-item").on('click', function(e) { + var $clickedEl, path; + $clickedEl = $(e.target); + path = $('.tree-item-file-name a', this).attr('href'); + if (!$clickedEl.is('a') && !$clickedEl.is('.str-truncated')) { + if (e.metaKey || e.which === 2) { + e.preventDefault(); + return window.open(path, '_blank'); + } else { + return gl.utils.visitUrl(path); + } + } + }); + // Show the "Loading commit data" for only the first element + $('span.log_loading:first').removeClass('hide'); + } + + initKeyNav() { + var li, liSelected; + li = $("tr.tree-item"); + liSelected = null; + return $('body').keydown(function(e) { + var next, path; + if ($("input:focus").length > 0 && (e.which === 38 || e.which === 40)) { + return false; + } + if (e.which === 40) { + if (liSelected) { + next = liSelected.next(); + if (next.length > 0) { + liSelected.removeClass("selected"); + liSelected = next.addClass("selected"); + } + } else { + liSelected = li.eq(0).addClass("selected"); + } + return $(liSelected).focus(); + } else if (e.which === 38) { + if (liSelected) { + next = liSelected.prev(); + if (next.length > 0) { + liSelected.removeClass("selected"); + liSelected = next.addClass("selected"); + } + } else { + liSelected = li.last().addClass("selected"); + } + return $(liSelected).focus(); + } else if (e.which === 13) { + path = $('.tree-item.selected .tree-item-file-name a').attr('href'); + if (path) { + return gl.utils.visitUrl(path); + } + } + }); + } +} |