-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathacf-cpt-logic.js
52 lines (46 loc) · 1.64 KB
/
acf-cpt-logic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
jQuery(document).ready(function ($) {
var $container = $('.acf-cpt-register'),
subpage_translate = $container.data('subpage'),
checkboxes = $('input[type="checkbox"]', $container),
plusHTML = '<span class="dashicons dashicons-plus-alt"></span>',
trashHTML = '<span class="dashicons dashicons-trash"></span>';
checkboxes.change(function(){
var _t = $(this);
if( _t.prop('checked') ) {
_t.parents('h4').append(plusHTML);
} else {
_t.parents('h4').find('.dashicons').remove();
}
});
$(this).on('click', '.dashicons-plus-alt', function () {
var _n = $(this).prev().find('input').val();
$(this).parents('.cpt-row').append(
'<p class="sub-line"><span>'+ subpage_translate +'</span>' +
'<input type="text" name="cpts['+ _n +'][]">' +
trashHTML +
'</p>'
);
});
$(this).on('click', '.dashicons-trash', function () {
$(this).parent().remove();
});
$('.sub-line input[type="text"]').on('change',function(){
var arr = [],
$siblings = $(this).siblings();
$.each($siblings, function (i, key) {
arr.push($(key).val());
});
if ($.inArray($(this).val(), arr) !== -1)
{
alert("duplicate has been found");
}
});
var timeOutSelect;
$("input[type=text][readonly]").focus(function() {
var save_this = $(this);
clearTimeout(timeOutSelect);
timeOutSelect = window.setTimeout (function(){
save_this.select();
}, 100);
});
});