diff options
Diffstat (limited to 'app/assets/javascripts/shortcuts_blob.js')
-rw-r--r-- | app/assets/javascripts/shortcuts_blob.js | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/app/assets/javascripts/shortcuts_blob.js b/app/assets/javascripts/shortcuts_blob.js index d50ddd98de1..bfe90aef71e 100644 --- a/app/assets/javascripts/shortcuts_blob.js +++ b/app/assets/javascripts/shortcuts_blob.js @@ -1,29 +1,29 @@ -/* eslint-disable func-names, space-before-function-paren, max-len, one-var, no-var, no-restricted-syntax, vars-on-top, no-use-before-define, no-param-reassign, new-cap, no-underscore-dangle, wrap-iife, consistent-return */ -/* global Shortcuts */ /* global Mousetrap */ +/* global Shortcuts */ -/*= require shortcuts */ +require('./shortcuts'); -(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; +const defaults = { + skipResetBindings: false, + fileBlobPermalinkUrl: null, +}; - this.ShortcutsBlob = (function(superClass) { - extend(ShortcutsBlob, superClass); +class ShortcutsBlob extends Shortcuts { + constructor(opts) { + const options = Object.assign({}, defaults, opts); + super(options.skipResetBindings); + this.options = options; - function ShortcutsBlob(skipResetBindings) { - ShortcutsBlob.__super__.constructor.call(this, skipResetBindings); - Mousetrap.bind('y', ShortcutsBlob.copyToClipboard); - } + Mousetrap.bind('y', this.moveToFilePermalink.bind(this)); + } - ShortcutsBlob.copyToClipboard = function() { - var clipboardButton; - clipboardButton = $('.btn-clipboard'); - if (clipboardButton) { - return clipboardButton.click(); - } - }; + moveToFilePermalink() { + if (this.options.fileBlobPermalinkUrl) { + const hash = gl.utils.getLocationHash(); + const hashUrlString = hash ? `#${hash}` : ''; + gl.utils.visitUrl(`${this.options.fileBlobPermalinkUrl}${hashUrlString}`); + } + } +} - return ShortcutsBlob; - })(Shortcuts); -}).call(this); +module.exports = ShortcutsBlob; |