Total Complexity | 6 |
Complexity/F | 1.5 |
Lines of Code | 27 |
Function Count | 4 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | /* globals acf jQuery */ |
||
3 | (function ($) { |
||
4 | const select2init = function () { |
||
5 | acf.addAction('select2_init', function ($select, args, settings, field) { |
||
|
|||
6 | const $fieldEl = field.$el |
||
7 | |||
8 | if ($fieldEl.data('name') === 'reusablePost') { |
||
9 | $select.on('change', { $fieldEl: $fieldEl }, function () { |
||
10 | const postId = $(this).val() |
||
11 | const postTitle = $(this).find('option:selected').text() |
||
12 | const $postLink = $fieldEl.find('.reusable-postLink') |
||
13 | const oldPostId = $postLink.attr('data-postId') |
||
14 | const $hiddenEl = $fieldEl.find('[hidden]') |
||
15 | const href = $postLink.attr('href') |
||
16 | |||
17 | $hiddenEl.removeAttr('hidden') |
||
18 | $postLink.text(postTitle) |
||
19 | $postLink.attr('data-postId', postId) |
||
20 | $postLink.attr('href', href.replace(oldPostId, postId)) |
||
21 | }) |
||
22 | } |
||
23 | }) |
||
24 | } |
||
25 | |||
26 | if (typeof acf !== 'undefined') { |
||
27 | select2init() |
||
28 | } |
||
29 | })(jQuery) |
||
30 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.