Commit 84f22562 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'remove_var_from_preview_markdown_js' into 'master'

Remove var from preview_markdown.js

See merge request gitlab-org/gitlab!20115
parents 40731cbd b8b5df31
/* eslint-disable func-names, no-var */ /* eslint-disable func-names */
import $ from 'jquery'; import $ from 'jquery';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
...@@ -12,11 +12,8 @@ import { __ } from '~/locale'; ...@@ -12,11 +12,8 @@ import { __ } from '~/locale';
// more than `x` users are referenced. // more than `x` users are referenced.
// //
var lastTextareaPreviewed; let lastTextareaHeight;
var lastTextareaHeight = null; let lastTextareaPreviewed;
var markdownPreview;
var previewButtonSelector;
var writeButtonSelector;
function MarkdownPreview() {} function MarkdownPreview() {}
...@@ -27,14 +24,13 @@ MarkdownPreview.prototype.emptyMessage = __('Nothing to preview.'); ...@@ -27,14 +24,13 @@ MarkdownPreview.prototype.emptyMessage = __('Nothing to preview.');
MarkdownPreview.prototype.ajaxCache = {}; MarkdownPreview.prototype.ajaxCache = {};
MarkdownPreview.prototype.showPreview = function($form) { MarkdownPreview.prototype.showPreview = function($form) {
var mdText; const preview = $form.find('.js-md-preview');
var preview = $form.find('.js-md-preview'); const url = preview.data('url');
var url = preview.data('url');
if (preview.hasClass('md-preview-loading')) { if (preview.hasClass('md-preview-loading')) {
return; return;
} }
mdText = $form.find('textarea.markdown-area').val(); const mdText = $form.find('textarea.markdown-area').val();
if (mdText === undefined) { if (mdText === undefined) {
return; return;
...@@ -46,7 +42,7 @@ MarkdownPreview.prototype.showPreview = function($form) { ...@@ -46,7 +42,7 @@ MarkdownPreview.prototype.showPreview = function($form) {
} else { } else {
preview.addClass('md-preview-loading').text(__('Loading...')); preview.addClass('md-preview-loading').text(__('Loading...'));
this.fetchMarkdownPreview(mdText, url, response => { this.fetchMarkdownPreview(mdText, url, response => {
var body; let body;
if (response.body.length > 0) { if (response.body.length > 0) {
({ body } = response); ({ body } = response);
} else { } else {
...@@ -91,8 +87,7 @@ MarkdownPreview.prototype.hideReferencedUsers = function($form) { ...@@ -91,8 +87,7 @@ MarkdownPreview.prototype.hideReferencedUsers = function($form) {
}; };
MarkdownPreview.prototype.renderReferencedUsers = function(users, $form) { MarkdownPreview.prototype.renderReferencedUsers = function(users, $form) {
var referencedUsers; const referencedUsers = $form.find('.referenced-users');
referencedUsers = $form.find('.referenced-users');
if (referencedUsers.length) { if (referencedUsers.length) {
if (users.length >= this.referenceThreshold) { if (users.length >= this.referenceThreshold) {
referencedUsers.show(); referencedUsers.show();
...@@ -108,8 +103,7 @@ MarkdownPreview.prototype.hideReferencedCommands = function($form) { ...@@ -108,8 +103,7 @@ MarkdownPreview.prototype.hideReferencedCommands = function($form) {
}; };
MarkdownPreview.prototype.renderReferencedCommands = function(commands, $form) { MarkdownPreview.prototype.renderReferencedCommands = function(commands, $form) {
var referencedCommands; const referencedCommands = $form.find('.referenced-commands');
referencedCommands = $form.find('.referenced-commands');
if (commands.length > 0) { if (commands.length > 0) {
referencedCommands.html(commands); referencedCommands.html(commands);
referencedCommands.show(); referencedCommands.show();
...@@ -119,15 +113,15 @@ MarkdownPreview.prototype.renderReferencedCommands = function(commands, $form) { ...@@ -119,15 +113,15 @@ MarkdownPreview.prototype.renderReferencedCommands = function(commands, $form) {
} }
}; };
markdownPreview = new MarkdownPreview(); const markdownPreview = new MarkdownPreview();
previewButtonSelector = '.js-md-preview-button'; const previewButtonSelector = '.js-md-preview-button';
writeButtonSelector = '.js-md-write-button'; const writeButtonSelector = '.js-md-write-button';
lastTextareaPreviewed = null; lastTextareaPreviewed = null;
const markdownToolbar = $('.md-header-toolbar'); const markdownToolbar = $('.md-header-toolbar');
$.fn.setupMarkdownPreview = function() { $.fn.setupMarkdownPreview = function() {
var $form = $(this); const $form = $(this);
$form.find('textarea.markdown-area').on('input', () => { $form.find('textarea.markdown-area').on('input', () => {
markdownPreview.hideReferencedUsers($form); markdownPreview.hideReferencedUsers($form);
}); });
...@@ -188,7 +182,7 @@ $(document).on('markdown-preview:hide', (e, $form) => { ...@@ -188,7 +182,7 @@ $(document).on('markdown-preview:hide', (e, $form) => {
}); });
$(document).on('markdown-preview:toggle', (e, keyboardEvent) => { $(document).on('markdown-preview:toggle', (e, keyboardEvent) => {
var $target; let $target;
$target = $(keyboardEvent.target); $target = $(keyboardEvent.target);
if ($target.is('textarea.markdown-area')) { if ($target.is('textarea.markdown-area')) {
$(document).triggerHandler('markdown-preview:show', [$target.closest('form')]); $(document).triggerHandler('markdown-preview:show', [$target.closest('form')]);
...@@ -201,16 +195,14 @@ $(document).on('markdown-preview:toggle', (e, keyboardEvent) => { ...@@ -201,16 +195,14 @@ $(document).on('markdown-preview:toggle', (e, keyboardEvent) => {
}); });
$(document).on('click', previewButtonSelector, function(e) { $(document).on('click', previewButtonSelector, function(e) {
var $form;
e.preventDefault(); e.preventDefault();
$form = $(this).closest('form'); const $form = $(this).closest('form');
$(document).triggerHandler('markdown-preview:show', [$form]); $(document).triggerHandler('markdown-preview:show', [$form]);
}); });
$(document).on('click', writeButtonSelector, function(e) { $(document).on('click', writeButtonSelector, function(e) {
var $form;
e.preventDefault(); e.preventDefault();
$form = $(this).closest('form'); const $form = $(this).closest('form');
$(document).triggerHandler('markdown-preview:hide', [$form]); $(document).triggerHandler('markdown-preview:hide', [$form]);
}); });
......
---
title: Remove var from preview_markdown.js
merge_request: 20115
author: Lee Tickett
type: other
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