PluginProbe
WPSSO Core – Complete Schema Markup and Meta Tags / 22.7.0
WPSSO Core – Complete Schema Markup and Meta Tags v22.7.0
22.7.0 22.6.1 22.6.0 22.5.3 22.5.2 22.5.1 22.4.0 22.3.0 22.2.1 22.2.0 22.1.3 22.1.2 22.1.1 22.1.0 22.0.0 21.13.3 21.13.2 trunk 21.13.1
wpsso / js / jquery-metabox.js

jquery-metabox.js in WPSSO Core – Complete Schema Markup and Meta Tags 22.7.0, at js/jquery-metabox.js

143 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1
2 /*
3 * This script is registered by WpssoScript->admin_enqueue_scripts() as 'wpsso-metabox' and depends on the 'sucom-metabox' script
4 * located in js/com/jquery-metabox.js. The 'sucom-metabox' script must be registered since this script depends on it.
5 */
6 jQuery( function() {
7
8 /*
9 * Initialize all the 'table.sucom-settings' metaboxes in the current page.
10 */
11 wpssoInitMetabox();
12 } );
13
14 /*
15 * Provide a parent container_id value to initialize a single metabox (when loading a single metabox via ajax, for example).
16 */
17 function wpssoInitMetabox( container_id, doing_ajax ) {
18
19 var table_id = 'table.sucom-settings';
20
21 if ( 'string' === typeof container_id && container_id ) {
22
23 table_id = container_id + ' ' + table_id;
24 }
25
26 /*
27 * When the Schema type is changed, maybe update the Open Graph type.
28 */
29 jQuery( table_id + ' select#select_og_schema_type' ).show( wpssoOgSchemaType );
30 jQuery( table_id + ' select#select_og_schema_type' ).change( wpssoOgSchemaType );
31
32 /*
33 * When an Organization ID is selected, disable the Place ID.
34 */
35 jQuery( table_id + ' select#select_schema_organization_id' ).show( wpssoSchemaOrgId );
36 jQuery( table_id + ' select#select_schema_organization_id' ).change( wpssoSchemaOrgId );
37
38 /*
39 * When a Place ID is selected, disable the Organization ID.
40 */
41 jQuery( table_id + ' select#select_schema_place_id' ).show( wpssoSchemaPlaceId );
42 jQuery( table_id + ' select#select_schema_place_id' ).change( wpssoSchemaPlaceId );
43
44 /*
45 * The sucomInitMetabox() function is located in the 'sucom-metabox' script located in js/com/jquery-metabox.js.
46 */
47 sucomInitMetabox( container_id, doing_ajax);
48 }
49
50 /*
51 * When the Schema type is changed, maybe update the Open Graph type.
52 */
53 function wpssoOgSchemaType() {
54
55 var pluginId = 'wpsso';
56 var adminPageL10n = 'wpssoAdminPageL10n';
57 var cfg = window[ adminPageL10n ];
58
59 if ( ! cfg[ '_ajax_actions' ][ 'schema_type_og_type' ] ) {
60
61 console.error( arguments.callee.name + ': missing _ajax_actions schema_type_og_type' );
62
63 return;
64 }
65
66 var select_schema_type = jQuery( this );
67 var schema_type_val = select_schema_type.val();
68
69 var ajaxData = {
70 action: cfg[ '_ajax_actions' ][ 'schema_type_og_type' ], // Returns schema_og_type_val.
71 schema_type: schema_type_val,
72 _ajax_nonce: cfg[ '_ajax_nonce' ],
73 }
74
75 jQuery.post( ajaxurl, ajaxData, function( schema_og_type_val ) {
76
77 var select_og_type = jQuery( 'select#select_og_type' );
78 var og_type_linked = jQuery( 'div#og_type_linked' ); /* May not exist. */
79 var og_type_option = jQuery( 'select#select_og_type option' );
80 var og_type_val = select_og_type.val();
81 var def_og_type_val = select_og_type.data( 'default-value' );
82
83 if ( og_type_linked.length ) {
84
85 jQuery( og_type_linked ).remove();
86 }
87
88 /*
89 * If we have an associated Open Graph type for this Schema type, then update the Open Graph value and disable the
90 * select.
91 */
92 if ( schema_og_type_val ) { // Can be false.
93
94 var schema_type_label = cfg[ '_option_labels' ][ 'schema_type' ];
95 var linked_to_label = cfg[ '_linked_to_transl' ].formatUnicorn( schema_type_label );
96
97 select_og_type.after( '<div id="og_type_linked" class="dashicons dashicons-admin-links linked_to_label" title="' + linked_to_label + '"></div>' );
98
99 if ( schema_og_type_val !== og_type_val ) {
100
101 og_type_option.removeAttr( 'selected' ).filter( '[value=' + schema_og_type_val + ']' ).attr( 'selected', true )
102
103 select_og_type.trigger( 'sucom_load_json' ).val( schema_og_type_val ).trigger( 'change' );
104 }
105
106 select_og_type.addClass( 'disabled' );
107
108 /*
109 * If we don't have an associated Open Graph type for this Schema type, then if previously disabled, reenable and
110 * set to the default value.
111 */
112 } else if ( og_type_linked.length ) {
113
114 if ( def_og_type_val.length ) {
115
116 if ( def_og_type_val !== og_type_val ) {
117
118 select_og_type.trigger( 'sucom_load_json' ).val( def_og_type_val ).trigger( 'change' );
119 }
120 }
121
122 select_og_type.removeClass( 'disabled' );
123 }
124 } );
125 }
126
127 /*
128 * When an Organization ID is selected, disable the Place ID.
129 */
130 function wpssoSchemaOrgId() {
131
132 sucomSelectUniquePair( this, 'select#select_schema_place_id' );
133 }
134
135 /*
136 * When a Place ID is selected, disable the Organization ID.
137 */
138 function wpssoSchemaPlaceId() {
139
140 sucomSelectUniquePair( this, 'select#select_schema_organization_id' );
141 }
142
143