diff options
author | Mike Greiling <mike@pixelcog.com> | 2018-03-20 08:37:16 +0300 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2018-03-20 08:37:16 +0300 |
commit | 43ff14e0c5074311fd544d654108550253e0fd93 (patch) | |
tree | d8fb4532b314bb33fa35d378c4b5b0a5962ec524 /app | |
parent | 5f6754185fc8bca6bb510a0aa17410dbffa293ff (diff) |
refactor ConfirmDangerModal into ES module
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/confirm_danger_modal.js | 47 | ||||
-rw-r--r-- | app/assets/javascripts/main.js | 13 |
2 files changed, 23 insertions, 37 deletions
diff --git a/app/assets/javascripts/confirm_danger_modal.js b/app/assets/javascripts/confirm_danger_modal.js index 0932d836589..c21c52b0086 100644 --- a/app/assets/javascripts/confirm_danger_modal.js +++ b/app/assets/javascripts/confirm_danger_modal.js @@ -1,33 +1,22 @@ -/* eslint-disable func-names, space-before-function-paren, wrap-iife, one-var, no-var, camelcase, one-var-declaration-per-line, no-else-return, max-len */ - import $ from 'jquery'; import { rstrip } from './lib/utils/common_utils'; -window.ConfirmDangerModal = (function() { - function ConfirmDangerModal(form, text) { - var project_path, submit; - this.form = form; - $('.js-confirm-text').text(text || ''); - $('.js-confirm-danger-input').val(''); - $('#modal-confirm-danger').modal('show'); - project_path = $('.js-confirm-danger-match').text(); - submit = $('.js-confirm-danger-submit'); - submit.disable(); - $('.js-confirm-danger-input').off('input'); - $('.js-confirm-danger-input').on('input', function() { - if (rstrip($(this).val()) === project_path) { - return submit.enable(); - } else { - return submit.disable(); - } - }); - $('.js-confirm-danger-submit').off('click'); - $('.js-confirm-danger-submit').on('click', (function(_this) { - return function() { - return _this.form.submit(); - }; - })(this)); - } +export default function initConfirmDangerModal($form, text) { + $('.js-confirm-text').text(text || ''); + $('.js-confirm-danger-input').val(''); + $('#modal-confirm-danger').modal('show'); + + const confirmTextMatch = $('.js-confirm-danger-match').text(); + const $submit = $('.js-confirm-danger-submit'); + $submit.disable(); - return ConfirmDangerModal; -})(); + $('.js-confirm-danger-input').off('input').on('input', function handleInput() { + const confirmText = rstrip($(this).val()); + if (confirmText === confirmTextMatch) { + $submit.enable(); + } else { + $submit.disable(); + } + }); + $('.js-confirm-danger-submit').off('click').on('click', () => $form.submit()); +} diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index cedb6ef19f7..c867f5f3236 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -1,5 +1,4 @@ /* eslint-disable import/first */ -/* global ConfirmDangerModal */ /* global $ */ import jQuery from 'jquery'; @@ -21,7 +20,7 @@ import './behaviors/'; // everything else import loadAwardsHandler from './awards_handler'; import bp from './breakpoints'; -import './confirm_danger_modal'; +import initConfirmDangerModal from './confirm_danger_modal'; import Flash, { removeFlashClickListener } from './flash'; import './gl_dropdown'; import initTodoToggle from './header'; @@ -215,13 +214,11 @@ document.addEventListener('DOMContentLoaded', () => { }); $document.on('click', '.js-confirm-danger', (e) => { - const btn = $(e.target); - const form = btn.closest('form'); - const text = btn.data('confirmDangerMessage'); e.preventDefault(); - - // eslint-disable-next-line no-new - new ConfirmDangerModal(form, text); + const $btn = $(e.target); + const $form = $btn.closest('form'); + const text = $btn.data('confirmDangerMessage'); + initConfirmDangerModal($form, text); }); $document.on('breakpoint:change', (e, breakpoint) => { |