| @@ -1,8 +1,7 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * Quick Edit |
| 3 | 3 | * |
| 4 | - * @package ConvertKit | |
| 5 | 4 | * @author ConvertKit |
| 6 | 5 | */ |
| 7 | 6 | |
| 8 | 7 | /** |
| @@ -16,40 +15,55 @@ | ||
| 16 | 15 | * for Plugins that register settings, which is why we have this code here. |
| 17 | 16 | * |
| 18 | 17 | * @since 1.9.8.0 |
| 19 | 18 | */ |
| 20 | -jQuery( document ).ready( | |
| 21 | - function( $ ) { | |
| 22 | 19 | |
| 20 | +document.addEventListener('DOMContentLoaded', function () { | |
| 21 | + const convertKitQuickEditWrapper = document.querySelector( | |
| 22 | + 'tr#inline-edit .inline-edit-wrapper fieldset.inline-edit-col-left' | |
| 23 | + ), | |
| 24 | + convertKitQuickEdit = document.querySelector('#convertkit-quick-edit'), | |
| 25 | + convertKitInlineEditPost = inlineEditPost.edit; | |
| 26 | + | |
| 27 | + if (convertKitQuickEditWrapper) { | |
| 23 | 28 | // Move Quick Edit fields from footer into the hidden inline-edit table row. |
| 24 | - $( 'tr#inline-edit .inline-edit-wrapper fieldset.inline-edit-col-left' ).first().append( $( '#convertkit-quick-edit' ) ); | |
| 29 | + convertKitQuickEditWrapper.appendChild(convertKitQuickEdit); | |
| 25 | 30 | |
| 26 | 31 | // Show the Quick Edit fields, as they are now contained in the inline-edit row which WordPress will show/hide as necessary. |
| 27 | - $( '#convertkit-quick-edit' ).show(); | |
| 32 | + convertKitQuickEdit.style.display = 'block'; | |
| 28 | 33 | |
| 29 | - var convertKitInlineEditPost = inlineEditPost.edit; | |
| 30 | - | |
| 31 | 34 | // Extend WordPress' inline edit function to load the Plugin's Quick Edit fields. |
| 32 | - inlineEditPost.edit = function( id ) { | |
| 35 | + inlineEditPost.edit = function (id) { | |
| 36 | + // Merge arguments from the original function. | |
| 37 | + convertKitInlineEditPost.apply(this, arguments); | |
| 33 | 38 | |
| 34 | - // Merge arguments from original function. | |
| 35 | - convertKitInlineEditPost.apply( this, arguments ); | |
| 36 | - | |
| 37 | 39 | // Get Post ID. |
| 38 | - if ( typeof( id ) === 'object' ) { | |
| 39 | - id = parseInt( this.getId( id ) ); | |
| 40 | + if (typeof id === 'object') { | |
| 41 | + id = parseInt(this.getId(id)); | |
| 40 | 42 | } |
| 41 | 43 | |
| 42 | 44 | // Iterate through any ConvertKit inline data, assigning values to Quick Edit fields. |
| 43 | - $( '.convertkit', $( '#inline_' + id ) ).each( | |
| 44 | - function() { | |
| 45 | + document | |
| 46 | + .querySelectorAll('#inline_' + id + ' .convertkit') | |
| 47 | + .forEach(function (element) { | |
| 48 | + // Get Quick Edit field. | |
| 49 | + const convertKitQuickEditField = document.querySelector( | |
| 50 | + '#convertkit-quick-edit select[name="wp-convertkit[' + | |
| 51 | + element.dataset.setting + | |
| 52 | + ']"]' | |
| 53 | + ); | |
| 45 | 54 | |
| 55 | + // If the Quick Edit field doesn't exist for this setting, skip it. | |
| 56 | + // (e.g. we're editing a Post and this is a Landing Page setting, that isn't supported in Posts). | |
| 57 | + if (convertKitQuickEditField === null) { | |
| 58 | + return; | |
| 59 | + } | |
| 60 | + | |
| 46 | 61 | // Assign the setting's value to the setting's Quick Edit field. |
| 47 | - $( '#convertkit-quick-edit select[name="wp-convertkit[' + $( this ).data( 'setting' ) + ']"]' ).val( $( this ).data( 'value' ) ); | |
| 62 | + convertKitQuickEditField.value = element.dataset.value; | |
| 63 | + }); | |
| 48 | 64 | |
| 49 | - } | |
| 50 | - ); | |
| 51 | - | |
| 52 | - } | |
| 53 | - | |
| 65 | + // Bind refresh resource event listeners. | |
| 66 | + convertKitRefreshResourcesInitEventListeners(); | |
| 67 | + }; | |
| 54 | 68 | } |
| 55 | -); | |
| 69 | +}); | |