| 1 |
import $ from 'jquery'; |
| 2 |
|
| 3 |
function updateReusableBlockLinks($widgets) { |
| 4 |
if (!$widgets) { |
| 5 |
$widgets = $('[id*="ghostkit_reusable_widget"].widget'); |
| 6 |
} |
| 7 |
|
| 8 |
$widgets.each(function () { |
| 9 |
const $widget = $(this); |
| 10 |
const $buttonWrap = $widget.find('.gkt-reusable-block-edit-button'); |
| 11 |
const $select = $widget.find('.gkt-reusable-block-select'); |
| 12 |
|
| 13 |
if (!$buttonWrap.length || !$select.length) { |
| 14 |
return; |
| 15 |
} |
| 16 |
|
| 17 |
const adminURL = $buttonWrap.attr('data-admin-url'); |
| 18 |
const selectVal = $select.val(); |
| 19 |
|
| 20 |
if (selectVal) { |
| 21 |
$buttonWrap |
| 22 |
.find('a') |
| 23 |
.attr( |
| 24 |
'href', |
| 25 |
`${adminURL}post.php?post=${selectVal}&action=edit` |
| 26 |
); |
| 27 |
$buttonWrap.show(); |
| 28 |
} else { |
| 29 |
$buttonWrap.hide(); |
| 30 |
} |
| 31 |
}); |
| 32 |
} |
| 33 |
updateReusableBlockLinks(); |
| 34 |
|
| 35 |
$(document).on('widget-added widget-updated', (e, widget) => { |
| 36 |
updateReusableBlockLinks(widget); |
| 37 |
}); |
| 38 |
|
| 39 |
$(document).on('change', '.gkt-reusable-block-select', function () { |
| 40 |
updateReusableBlockLinks( |
| 41 |
$(this).closest('[id*="ghostkit_reusable_widget"].widget') |
| 42 |
); |
| 43 |
}); |
| 44 |
|