From b6b83f3c50384c956950dedb6f55739c1605579e Mon Sep 17 00:00:00 2001 From: geoandri Date: Wed, 29 Mar 2017 14:47:34 +0300 Subject: Refactor shortcuts_wiki.js --- app/assets/javascripts/dispatcher.js | 1 + app/assets/javascripts/shortcuts_wiki.js | 37 ++++++++------------------- app/views/help/_shortcuts.html.haml | 2 +- spec/features/projects/wiki/shortcuts_spec.rb | 2 +- 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/app/assets/javascripts/dispatcher.js b/app/assets/javascripts/dispatcher.js index d6a019333b7..d88b7cd0e17 100644 --- a/app/assets/javascripts/dispatcher.js +++ b/app/assets/javascripts/dispatcher.js @@ -47,6 +47,7 @@ import BlobLinePermalinkUpdater from './blob/blob_line_permalink_updater'; import BlobForkSuggestion from './blob/blob_fork_suggestion'; import UserCallout from './user_callout'; import { ProtectedTagCreate, ProtectedTagEditList } from './protected_tags'; +import ShortcutsWiki from './shortcuts_wiki'; const ShortcutsBlob = require('./shortcuts_blob'); diff --git a/app/assets/javascripts/shortcuts_wiki.js b/app/assets/javascripts/shortcuts_wiki.js index f09215fdd6d..00d0d8f3a62 100644 --- a/app/assets/javascripts/shortcuts_wiki.js +++ b/app/assets/javascripts/shortcuts_wiki.js @@ -1,32 +1,15 @@ -/* eslint-disable func-names, space-before-function-paren, max-len, no-var, one-var, no-restricted-syntax, vars-on-top, no-use-before-define, no-param-reassign, new-cap, no-underscore-dangle, wrap-iife, one-var-declaration-per-line, quotes, prefer-arrow-callback, consistent-return, prefer-template, no-mixed-operators */ /* global Mousetrap */ /* global ShortcutsNavigation */ -require('mousetrap'); -require('./shortcuts_navigation'); +class ShortcutsWiki extends ShortcutsNavigation { + constructor() { + super(); + Mousetrap.bind('e', this.editWiki); + } -(function() { - var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - hasProp = {}.hasOwnProperty; + editWiki() { + this.gl.utils.visitUrl($('.wiki-edit').attr('href')); + } +} - this.ShortcutsWiki = (function(superClass) { - extend(ShortcutsWiki, superClass); - - function ShortcutsWiki() { - ShortcutsWiki.__super__.constructor.call(this); - Mousetrap.bind('e', (function(_this) { - return function() { - _this.editWiki(); - return false; - }; - })(this)); - } - - ShortcutsWiki.prototype.editWiki = function() { - var $editBtn; - $editBtn = $('.wiki-edit'); - return gl.utils.visitUrl($editBtn.attr('href')); - }; - return ShortcutsWiki; - })(ShortcutsNavigation); -}).call(window); +module.exports = ShortcutsWiki; diff --git a/app/views/help/_shortcuts.html.haml b/app/views/help/_shortcuts.html.haml index 83d03a82a9b..c6b4ba20b63 100644 --- a/app/views/help/_shortcuts.html.haml +++ b/app/views/help/_shortcuts.html.haml @@ -113,7 +113,7 @@ %td.shortcut .key y %td Go to file permalink - %tbody.hidden-shortcut.merge_requests{ style: 'display:none' } + %tbody.hidden-shortcut.wiki{ style: 'display:none' } %tr %th %th Wiki pages diff --git a/spec/features/projects/wiki/shortcuts_spec.rb b/spec/features/projects/wiki/shortcuts_spec.rb index add4b7f6190..c1f6b0cce3b 100644 --- a/spec/features/projects/wiki/shortcuts_spec.rb +++ b/spec/features/projects/wiki/shortcuts_spec.rb @@ -12,7 +12,7 @@ feature 'Wiki shortcuts', :feature, :js do visit namespace_project_wiki_path(project.namespace, project, wiki_page) end - scenario 'Visit edit wiki page using "e" heyboard shortcut' do + scenario 'Visit edit wiki page using "e" keyboard shortcut' do find('body').native.send_key('e') expect(find('.wiki-page-title')).to have_content('Edit Page') -- cgit v1.2.1