| Server IP : 68.178.247.200 / Your IP : 216.73.216.110 Web Server : Apache System : Linux p3plzcpnl489463.prod.phx3.secureserver.net 4.18.0-553.126.2.lve.el8.x86_64 #1 SMP Thu May 28 14:12:30 UTC 2026 x86_64 User : x9dppmxs4rgd ( 8559391) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /proc/self/cwd/wp-content/plugins/publishpress/modules/calendar/lib/async-calendar/js/ |
Upload File : |
const $ = jQuery;
export default function Select(props) {
const selectRef = React.useRef(null);
const getAllowClearProp = () => {
if (typeof props.allowClear !== 'undefined' && props.allowClear !== null) {
return props.allowClear;
}
return true;
}
const initSelect2 = () => {
let params = {
placeholder: props.placeholder || false,
tags: true,
allowClear: getAllowClearProp()
};
if (props.ajaxUrl) {
params.ajax = {
delay: 250,
url: props.ajaxUrl,
dataType: 'json',
data: function (params) {
let args = {
q: params.term,
action: props.ajaxAction,
nonce: props.nonce,
}
if (props.ajaxArgs) {
for (const arg in props.ajaxArgs) {
if (props.ajaxArgs.hasOwnProperty(arg)) {
args[arg] = props.ajaxArgs[arg];
}
}
}
return args;
},
processResults: function (data) {
return {
results: data
};
}
};
}
$(selectRef.current).pp_select2(params)
.on('select2:select', (e) => {
if (typeof props.onSelect === 'function') {
props.onSelect(
e,
selectRef.current,
$(selectRef.current).pp_select2('data')
);
}
})
.on('select2:clear', (e) => {
if (typeof props.onClear === 'function') {
props.onClear(
e,
selectRef.current
);
}
});
return () => {
$(selectRef.current).pp_select2('destroy');
}
};
const blankOption = () => {
if (props.placeholder) {
return <option value="">{props.placeholder}</option>
}
return <></>;
};
React.useEffect(initSelect2, []);
let options;
if (props.options) {
options = props.options.map(option => {
return <option value={option.value} selected={option.value === props.value}>{option.text}</option>
});
}
let className = 'pp_select2';
if (props.className) {
className += ' ' + props.className;
}
return (
<select className={className}
id={props.id}
multiple={props.multiple}
ref={selectRef}>
{blankOption()}
{options}
</select>
)
}