index.js
2.5 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { registerBlockType } from '@wordpress/blocks';
import ServerSideRender from '@wordpress/server-side-render';
import {InspectorControls, useBlockProps} from '@wordpress/block-editor';
import {PanelBody, SelectControl} from "@wordpress/components";
registerBlockType('um-block/um-account', {
edit: function (props) {
let { tab, setAttributes } = props.attributes;
const blockProps = useBlockProps();
function get_options() {
var option = [];
option.push( { label: wp.i18n.__( 'All', 'ultimate-member' ), value: 'all' } );
for ( var key in um_account_settings ) {
if ( um_account_settings.hasOwnProperty( key ) && um_account_settings[ key ]['enabled'] ) {
option.push(
{
label: um_account_settings[ key ]['label'],
value: key
}
)
}
}
return option;
}
function umShortcode( value ) {
var shortcode = '[ultimatemember_account';
if ( value !== 'all' ) {
shortcode = shortcode + ' tab="' + value + '"';
}
shortcode = shortcode + ']';
props.setAttributes({ content: shortcode });
}
return (
<div {...blockProps}>
<ServerSideRender block="um-block/um-account" attributes={props.attributes} />
<InspectorControls>
<PanelBody title={wp.i18n.__('Account Tab', 'ultimate-member')}>
<SelectControl
label={wp.i18n.__('Select Tab', 'ultimate-member')}
className="um_select_account_tab"
value={tab}
options={get_options()}
style={{ height: '35px', lineHeight: '20px', padding: '0 7px' }}
onChange={(value) => {
props.setAttributes({ tab: value });
umShortcode(value);
}}
/>
</PanelBody>
</InspectorControls>
</div>
);
},
save: function save(props) {
return null;
}
});
jQuery(window).on( 'load', function($) {
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
jQuery(mutation.addedNodes).find('.um.um-account').each(function() {
var current_tab = jQuery(this).find('.um-account-main').attr('data-current_tab');
if ( current_tab ) {
jQuery(this).find('.um-account-tab[data-tab="'+current_tab+'"]').show();
jQuery(this).find('.um-account-tab:not(:visible)').find( 'input, select, textarea' ).not( ':disabled' ).addClass('um_account_inactive').prop( 'disabled', true ).attr( 'disabled', true );
um_responsive();
um_modal_responsive();
}
});
});
});
observer.observe(document, {attributes: false, childList: true, characterData: false, subtree:true});
});