BigW Consortium Gitlab

remove global export except in test environments

parent 9fd89990
......@@ -285,7 +285,7 @@ const gfmRules = {
},
};
class CopyAsGFM {
export class CopyAsGFM {
constructor() {
$(document).on('copy', '.md, .wiki', (e) => { CopyAsGFM.copyAsGFM(e, CopyAsGFM.transformGFMSelection); });
$(document).on('copy', 'pre.code.highlight, .diff-content .line_content', (e) => { CopyAsGFM.copyAsGFM(e, CopyAsGFM.transformCodeSelection); });
......@@ -470,7 +470,12 @@ class CopyAsGFM {
}
}
window.gl = window.gl || {};
window.gl.CopyAsGFM = CopyAsGFM;
// Export CopyAsGFM as a global for rspec to access
// see /spec/features/copy_as_gfm_spec.rb
if (process.env.NODE_ENV !== 'production') {
window.CopyAsGFM = CopyAsGFM;
}
new CopyAsGFM();
export default function initCopyAsGFM() {
return new CopyAsGFM();
}
import './autosize';
import './bind_in_out';
import './copy_as_gfm';
import initCopyAsGFM from './copy_as_gfm';
import './details_behavior';
import installGlEmojiElement from './gl_emoji';
import './quick_submit';
......@@ -8,3 +8,4 @@ import './requires_input';
import './toggler_behavior';
installGlEmojiElement();
initCopyAsGFM();
......@@ -664,7 +664,7 @@ describe 'Copy as GFM', :js do
def html_to_gfm(html, transformer = 'transformGFMSelection', target: nil)
js = <<-JS.strip_heredoc
(function(html) {
var transformer = window.gl.CopyAsGFM[#{transformer.inspect}];
var transformer = window.CopyAsGFM[#{transformer.inspect}];
var node = document.createElement('div');
$(html).each(function() { node.appendChild(this) });
......@@ -678,7 +678,7 @@ describe 'Copy as GFM', :js do
node = transformer(node, target);
if (!node) return null;
return window.gl.CopyAsGFM.nodeToGFM(node);
return window.CopyAsGFM.nodeToGFM(node);
})("#{escape_javascript(html)}")
JS
page.evaluate_script(js)
......
import '~/copy_as_gfm';
import { CopyAsGFM } from '~/behaviors/copy_as_gfm';
(() => {
describe('gl.CopyAsGFM', () => {
describe('gl.CopyAsGFM.pasteGFM', () => {
describe('CopyAsGFM', () => {
describe('CopyAsGFM.pasteGFM', () => {
function callPasteGFM() {
const e = {
originalEvent: {
......@@ -24,7 +23,7 @@ import '~/copy_as_gfm';
preventDefault() {},
};
window.gl.CopyAsGFM.pasteGFM(e);
CopyAsGFM.pasteGFM(e);
}
it('wraps pasted code when not already in code tags', () => {
......@@ -45,5 +44,4 @@ import '~/copy_as_gfm';
callPasteGFM();
});
});
});
})();
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment