| 1 |
(function ($) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
function init(modal) { |
| 5 |
// Auto-select first reason card. |
| 6 |
var $firstLi = modal.find('ul.wd-de-reasons li').first(); |
| 7 |
var $firstRadio = $firstLi.find('input[type="radio"]'); |
| 8 |
$firstRadio.prop('checked', true); |
| 9 |
$firstLi.addClass('wd-de-reason-selected'); |
| 10 |
modal.find('.wd-dr-modal-reason-input').show(); |
| 11 |
modal.find('.wd-dr-modal-reason-input textarea').attr('placeholder', $firstLi.data('placeholder')); |
| 12 |
|
| 13 |
// Narrow modal. |
| 14 |
modal.find('.wd-dr-modal-wrap').css({ 'max-width': '700px', 'border-radius': '8px' }); |
| 15 |
|
| 16 |
// Focus textarea when modal opens. |
| 17 |
if ( modal[0] && window.MutationObserver ) { |
| 18 |
var observer = new MutationObserver(function (mutations) { |
| 19 |
mutations.forEach(function (mutation) { |
| 20 |
if ( mutation.attributeName === 'class' && modal.hasClass('modal-active') ) { |
| 21 |
modal.find('.wd-dr-modal-reason-input textarea').focus(); |
| 22 |
} |
| 23 |
}); |
| 24 |
}); |
| 25 |
observer.observe(modal[0], { attributes: true }); |
| 26 |
} |
| 27 |
|
| 28 |
// De-emphasise "Skip & Deactivate". |
| 29 |
modal.find('a.dont-bother-me').css({ |
| 30 |
'font-size': '11px', |
| 31 |
'color': '#a0aec0', |
| 32 |
'border': 'none', |
| 33 |
'padding': '5px 6px' |
| 34 |
}); |
| 35 |
} |
| 36 |
|
| 37 |
$(function () { |
| 38 |
var modal = $('#wpvr-wd-dr-modal'); |
| 39 |
if (modal.length) { |
| 40 |
init(modal); |
| 41 |
} |
| 42 |
}); |
| 43 |
|
| 44 |
}(jQuery)); |
| 45 |
|