Passed
Pull Request — master (#308)
by
unknown
07:17 queued 02:43
created

Components/ReusableComponent/admin.js   A

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 19
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 14
mnd 0
bc 0
fnc 2
dl 0
loc 19
rs 10
bpm 0
cpm 1
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
  $select.on('change', { $fieldEl: $fieldEl }, function () {
8
    const postId = $(this).val()
9
    const postTitle = $(this).find('option:selected').text()
10
    const $postLink = $fieldEl.find('.reusable-postLink')
11
    const oldPostId = $postLink.attr('data-postId')
12
    const $hiddenEl = $fieldEl.find('[hidden]')
13
    const href = $postLink.attr('href')
14
15
    $hiddenEl.removeAttr('hidden')
16
    $postLink.text(postTitle)
17
    $postLink.attr('data-postId', postId)
18
    $postLink.attr('href', href.replace(oldPostId, postId))
19
  })
20
})
21