jQuery(document).ready(function($){ // video thumbnail upload $(document).on('click', '.siteseo-video-thumbnail-upload', function(e){ e.preventDefault(); var button = $(this); var frame = wp.media({ title: 'Select or Upload Video Thumbnail', button: { text: 'Use this image' }, multiple: false }); frame.on('select', function() { var attachment = frame.state().get('selection').first().toJSON(); button.prev('input').val(attachment.url); }); frame.open(); }); // Podcast Episode Image Upload $(document).on('click', '.siteseo-image-upload-btn', function(e){ e.preventDefault(); let button = $(this); let input = button.prev('input'); let frame = wp.media({ title: 'Select or Upload Image', button: { text: 'Use this image' }, multiple: false }); frame.on('select', function() { var attachment = frame.state().get('selection').first().toJSON(); input.val(attachment.url).trigger('input'); // preview update }); frame.open(); }); $(document).on('click', '#siteseo_validate_schema', function(e){ e.preventDefault(); // Fetch Schema var schemaContentWrap = $('.siteseo_schema_preview #siteseo_raw_schema'); if(!schemaContentWrap.length){ schemaContentWrap = $('.siteseo_schema_preview'); } let schemaContent = ''; // This is to ensure we dont end up having 2 values of the schema. if(schemaContentWrap.length > 1){ schemaContent = schemaContentWrap.eq(0).text(); } else { schemaContent = schemaContentWrap.text(); } let $form = $('
', { 'method': 'POST', 'action': 'https://search.google.com/test/rich-results', 'target': '_blank' }), $input = $('', { 'type': 'hidden', 'name': 'code_snippet', 'value': schemaContent }); $form.append($input); $("body").append($form); $form.submit(); $form.remove(); }); // Custom schema json invalid $(document.body).on('blur', '.siteseo_structured_data_custom', function(e){ e.preventDefault(); let json_str = $(this).val().trim(), error_box = $('.siteseo-json-error'); if(json_str === ''){ error_box.hide(); // empty allowed return; } try { JSON.parse(json_str); error_box.hide(); } catch(e){ error_box.text("⚠ Invalid JSON: " + e.message); error_box.show(); } }); $(document).on('change', '.siteseo_structured_data_type', function(e){ e.preventDefault(); let schemaType = $(this).val(), propertiesContainer = $('.siteseo-metabox-schema'), customSchemaContainer = $('.siteseo_custom_schema_container'), propertiesDiv = $('.siteseo-schema-properties'); preview = $('.siteseo-schema-preview'); $('.siteseo_structured_data_type').val(schemaType); propertiesDiv.empty(); if(schemaType === ''){ propertiesContainer.hide(); customSchemaContainer.hide(); preview.hide(); $('.siteseo_schema_preview').html(''); $('#siteseo_raw_schema').text(''); return; } if(schemaType === 'CustomSchema'){ propertiesContainer.hide(); preview.show(); customSchemaContainer.show(); updateCustomSchemaPreview(); return; } else{ propertiesContainer.show(); customSchemaContainer.hide(); preview.show(); } // schemas load let properties = structuredDataMetabox.propertyTemplates[schemaType] || {}; // Create form fields for each property $.each(properties, function(property, defaultValue){ let field = '', is_textarea_fields = ['description', 'instructions', 'reviewBody', 'questions', 'step', 'ingredients', 'recipeInstructions', 'courseDescription', 'bookDescription', 'softwareRequirements', 'menu'], is_date_type_fields = ['datePublished', 'dateModified', 'uploadDate', 'startDate', 'endDate', 'foundingDate', 'releaseDate'], is_required_field = ['contentUrl'], is_bool_fields = ['isFamilyFriendly']; if(typeof defaultValue !== 'object'){ let label = property.replace(/([a-z])([A-Z])/g, '$1 $2'); label = label.charAt(0).toUpperCase() + label.slice(1); if(is_textarea_fields.includes(property)){ field = $('