Passed
Pull Request — master (#308)
by
unknown
04:26
created

Components/ReusableComponent/admin.js   A

Complexity

Total Complexity 3
Complexity/F 1.5

Size

Lines of Code 21
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 15
mnd 1
bc 1
fnc 2
dl 0
loc 21
rs 10
bpm 0.5
cpm 1.5
noi 0
c 0
b 0
f 0
1
/* globals acf */
2
import $ from 'jquery'
3
4
acf.addAction('select2_init', function ($select, args, settings, field) {
5
  const $fieldEl = field.$el
6
7
  if ($fieldEl.data('name') === 'reusablePost') {
8
    $select.on('change', { $fieldEl: $fieldEl }, function () {
9
      const postId = $(this).val()
10
      const postTitle = $(this).find('option:selected').text()
11
      const $postLink = $fieldEl.find('.reusable-postLink')
12
      const oldPostId = $postLink.attr('data-postId')
13
      const $hiddenEl = $fieldEl.find('[hidden]')
14
      const href = $postLink.attr('href')
15
16
      $hiddenEl.removeAttr('hidden')
17
      $postLink.text(postTitle)
18
      $postLink.attr('data-postId', postId)
19
      $postLink.attr('href', href.replace(oldPostId, postId))
20
    })
21
  }
22
})
23