Passed
Pull Request — master (#258)
by Dominik
05:19
created

Components/ReusableComponent/admin.js   A

Complexity

Total Complexity 6
Complexity/F 1.5

Size

Lines of Code 27
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 19
mnd 2
bc 2
fnc 4
dl 0
loc 27
rs 10
bpm 0.5
cpm 1.5
noi 2
c 0
b 0
f 0
1
/* globals acf jQuery */
2
3
(function ($) {
4
  const select2init = function () {
5
    acf.addAction('select2_init', function ($select, args, settings, field) {
0 ignored issues
show
Bug introduced by
The variable acf seems to be never declared. If this is a global, consider adding a /** global: acf */ comment.

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.

Loading history...
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') {
0 ignored issues
show
Bug introduced by
The variable acf seems to be never declared. If this is a global, consider adding a /** global: acf */ comment.

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.

Loading history...
27
    select2init()
28
  }
29
})(jQuery)
30