Plugin Directory

Changeset 3417744


Ignore:
Timestamp:
12/11/2025 09:08:02 PM (4 months ago)
Author:
chillcode
Message:

improv(ui): allow to disable confirmation prompts

Location:
simple-menu-order-column/trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • simple-menu-order-column/trunk/assets/js/simple-menu-order-column.js

    r3407262 r3417744  
    99 */
    1010(function () {
    11 
    12     const { __ } = wp.i18n;
    13 
    14     function smocInit() {
    15         document.removeEventListener("DOMContentLoaded", smocInit);
    16         window.removeEventListener("load", smocInit);
    17 
    18         const smocInputs = document.querySelectorAll('input[id^=smoc]');
    19 
    20         smocInputs.forEach(smocInput => {
    21             smocInput.addEventListener('focus', () => {
    22                 smocInput.currentValue = smocInput.value;
    23                 smocInput.title = parseInt(smocInput.value);
    24 
    25                 const { postId } = smocInput.dataset;
    26                 if (!postId) { return; };
    27 
    28                 const hideElement = id => {
    29                     const smocElement = document.getElementById(id);
    30                     if (smocElement) { smocElement.style.display = 'none'; }
    31                 };
    32 
    33                 const smocBaseId = `smoc-${postId}`;
    34 
    35                 hideElement(`${smocBaseId}-loader-container`);
    36                 hideElement(`${smocBaseId}-success`);
    37                 hideElement(`${smocBaseId}-error`);
    38             });
    39 
    40             smocInput.addEventListener('focusout', () => {
    41                 if (smocInput.disabled) { return; };
    42 
    43                 if (smocInput.currentValue !== smocInput.value) {
    44                     if (window.confirm(__('Should the menu order value be updated?', 'simple-menu-order-column'))) {
    45                         smocDoReorder(smocInput);
    46                     } else {
    47                         smocInput.value = smocInput.defaultValue;
    48                     }
    49                 }
    50             });
    51 
    52             smocInput.addEventListener('keydown', (smocKeydownEvent) => {
    53                 const allowedKeys = [
    54                     'Backspace', 'Tab', 'ArrowLeft', 'ArrowRight',
    55                     'ArrowUp', 'ArrowDown', 'Delete', 'Home', 'End', 'Enter', 'Subtract', '-'
    56                 ];
    57 
    58                 // Allow: Ctrl/Cmd + A/C/V/X
    59                 if ((smocKeydownEvent.ctrlKey || smocKeydownEvent.metaKey) && ['a', 'c', 'v', 'x'].includes(smocKeydownEvent.key.toLowerCase())) { return; }
    60 
    61                 // Allow navigation/edit keys
    62                 if (allowedKeys.includes(smocKeydownEvent.key)) { return; }
    63 
    64                 // Block any key that is not a digit (0-9)
    65                 if (!/^\d$/.test(smocKeydownEvent.key)) {
    66                     smocKeydownEvent.preventDefault();
    67                 }
    68             });
    69 
    70             smocInput.addEventListener('paste', (smocPasteEvent) => {
    71                 const pasted = smocPasteEvent.clipboardData.getData('text');
    72                 if (!/^\d+$/.test(pasted)) {
    73                     smocPasteEvent.preventDefault();
    74                 }
    75             });
    76 
    77             smocInput.addEventListener('keypress', smocKeypressEvent => {
    78                 if (smocKeypressEvent.key === 'Enter') {
    79                     smocKeypressEvent.preventDefault();
    80                     smocDoReorder(smocInput);
    81                 }
    82             });
    83         });
    84     }
    85 
    86     function smocDoReorder(smocInput) {
    87         if (!smocInput || smocInput.disabled) { return; }
    88 
    89         const smocContainer = smocInput.closest('.smoc-container'), postId = parseInt(smocInput.dataset.postId);
    90 
    91         if (!postId || isNaN(postId)) {
    92             disableInput(null, __('The post_id is invalid.', 'simple-menu-order-column'), true, smocInput);
    93             return;
    94         }
    95 
    96         const loaderId = `smoc-${postId}`, menuOrder = parseInt(smocInput.value);
    97 
    98         if (isNaN(menuOrder)) {
    99             const errorEl = document.getElementById(`${loaderId}-error`);
    100             disableInput(errorEl, __('The menu order value is invalid.', 'simple-menu-order-column'), false, smocInput);
    101             return;
    102         }
    103 
    104         const nonce = smocInput.dataset.wpnonce;
    105         if (!nonce) {
    106             const errorEl = document.getElementById(`${loaderId}-error`);
    107             disableInput(errorEl, __('The postNonce is invalid.', 'simple-menu-order-column'), true, smocInput);
    108             return;
    109         }
    110 
    111         if (typeof ajaxurl === 'undefined' || typeof typenow === 'undefined') {
    112             const errorEl = document.getElementById(`${loaderId}-error`);
    113             disableInput(errorEl, __('Invalid WP installation, variables typenow or ajaxurl are not initialized.', 'simple-menu-order-column'), true, smocInput);
    114             return;
    115         }
    116 
    117         smocInput.disabled = true;
    118 
    119         const showLoader = () => {
    120             let smocLoaderContainer = document.getElementById(`${loaderId}-loader-container`);
    121             if (!smocLoaderContainer) {
    122                 const smocLoader = document.createElement('span');
    123                 smocLoader.id = `${loaderId}-loader`;
    124                 smocLoader.className = 'smoc-loader dashicons dashicons-update';
    125                 smocLoader.setAttribute('role', 'img');
    126                 smocLoader.setAttribute('aria-label', __('Updating menu order...', 'simple-menu-order-column'));
    127                 smocLoader.style.cssText = 'color: #2ea2cc; animation: iconrotation 2s infinite linear; display: inline-block;';
    128 
    129                 smocLoaderContainer = document.createElement('div');
    130                 smocLoaderContainer.id = `${loaderId}-loader-container`;
    131                 smocLoaderContainer.style.cssText = 'padding-top: 5px; display: inline-block;';
    132                 smocLoaderContainer.appendChild(smocLoader);
    133                 smocContainer.appendChild(smocLoaderContainer);
    134             } else {
    135                 smocLoaderContainer.style.display = 'inline-block';
    136             }
    137         };
    138 
    139         const showSuccess = () => {
    140             let smocSuccess = document.getElementById(`${loaderId}-success`);
    141             if (!smocSuccess) {
    142                 smocSuccess = document.createElement('span');
    143                 smocSuccess.id = `${loaderId}-success`;
    144                 smocSuccess.className = 'smoc-success dashicons dashicons-yes-alt';
    145                 smocSuccess.setAttribute('role', 'img');
    146                 smocSuccess.setAttribute('aria-label', __('The menu order has been updated successfully.', 'simple-menu-order-column'));
    147                 smocSuccess.style.cssText = 'padding-top: 5px; color: #7ad03a; display: inline-block;';
    148                 smocContainer.appendChild(smocSuccess);
    149             } else {
    150                 smocSuccess.style.display = 'inline-block';
    151             }
    152         };
    153 
    154         const showError = () => {
    155             let smocError = document.getElementById(`${loaderId}-error`);
    156             if (!smocError) {
    157                 smocError = document.createElement('span');
    158                 smocError.id = `${loaderId}-error`;
    159                 smocError.className = 'smoc-error dashicons dashicons-dismiss';
    160                 smocError.setAttribute('role', 'img');
    161                 smocError.setAttribute('aria-label', __('An error ocurred while updating menu order.', 'simple-menu-order-column'));
    162                 smocError.style.cssText = 'padding-top: 5px; color: #a00; display: inline-block;';
    163                 smocContainer.appendChild(smocError);
    164             } else {
    165                 smocError.style.display = 'inline-block';
    166             }
    167         };
    168 
    169         const hideLoader = () => {
    170             const smocLoaderContainer = document.getElementById(`${loaderId}-loader-container`);
    171             if (smocLoaderContainer) { smocLoaderContainer.style.display = 'none'; }
    172         };
    173 
    174         showLoader();
    175 
    176         fetch(`${ajaxurl}?action=smoc_reorder&_wpnonce=${encodeURIComponent(nonce)}`, {
    177             method: 'POST',
    178             headers: {
    179                 'Content-Type': 'application/x-www-form-urlencoded',
    180             },
    181             body: new URLSearchParams({
    182                 post_type: typenow,
    183                 post_id: postId,
    184                 post_menu_order: menuOrder,
    185             }),
    186         })
    187             .then(res => res.json())
    188             .then(response => {
    189                 if (response.success) {
    190                     showSuccess();
    191                     smocInput.title = menuOrder;
    192                     smocInput.currentValue = menuOrder;
    193                     smocInput.defaultValue = menuOrder;
    194 
    195                     const inputs = Array.from(document.querySelectorAll('input[id^=smoc]')), pos = inputs.indexOf(smocInput) + 1;
    196                     if (inputs[pos]) { inputs[pos].select(); }
    197                 } else {
    198                     smocInput.value = smocInput.defaultValue;
    199                     showError();
    200                 }
    201             })
    202             .catch(() => {
    203                 smocInput.value = smocInput.defaultValue;
    204                 hideLoader();
    205                 showError();
    206             })
    207             .finally(() => {
    208                 hideLoader();
    209                 smocInput.disabled = false;
    210             });
    211     }
    212 
    213     function disableInput(errorContainer, message, disable, input) {
    214         input.value = input.defaultValue;
    215         if (errorContainer) { errorContainer.style.display = 'inline-block'; }
    216         input.disabled = disable;
    217         input.title = message;
    218         console.warn(`[Simple Menu Order Column] ${message}`);
    219     }
    220 
    221     /**
    222      * Initilize Script
    223      */
    224     if (document.readyState === "loading") {
    225         document.addEventListener('DOMContentLoaded', smocInit);
    226         window.addEventListener("load", smocInit);
    227     } else {
    228         window.setTimeout(smocInit);
    229     }
     11    const { __ } = wp.i18n;
     12    let smocInputs = null;
     13
     14    /* global smoc_ui */
     15    // Ensure smoc_ui exists, fallback to default
     16    const smocConfig = window.smoc_ui ?? {};
     17
     18    // Provide defaults for missing keys
     19    const config = {
     20        enableConfirm: smocConfig.enable_confirm ?? true,
     21        tabToNext: smocConfig.tab_to_next ?? true
     22    };
     23
     24    function smocInit() {
     25        document.removeEventListener("DOMContentLoaded", smocInit);
     26        window.removeEventListener("load", smocInit);
     27
     28        smocInputs = document.querySelectorAll('input[id^=smoc]');
     29
     30        smocInputs.forEach(smocInput => {
     31            smocInput.addEventListener('focus', () => {
     32                smocInput.currentValue = smocInput.value;
     33                smocInput.title = parseInt(smocInput.value);
     34
     35                const { postId } = smocInput.dataset;
     36                if (!postId) { return; };
     37
     38                const hideElement = id => {
     39                    const smocElement = document.getElementById(id);
     40                    if (smocElement) { smocElement.style.display = 'none'; }
     41                };
     42
     43                const smocBaseId = `smoc-${postId}`;
     44
     45                hideElement(`${smocBaseId}-loader-container`);
     46                hideElement(`${smocBaseId}-success`);
     47                hideElement(`${smocBaseId}-error`);
     48            });
     49
     50            smocInput.addEventListener('focusout', () => {
     51                if (smocInput.disabled) { return; };
     52
     53                if (smocInput.currentValue !== smocInput.value) {
     54                    if (!config.enableConfirm || window.confirm(__('Should the menu order value be updated?', 'simple-menu-order-column'))) {
     55                        smocDoReorder(smocInput);
     56                    } else {
     57                        smocInput.value = smocInput.defaultValue;
     58                    }
     59                }
     60            });
     61
     62            smocInput.addEventListener('keydown', (smocKeydownEvent) => {
     63                const allowedKeys = [
     64                    'Backspace', 'Tab', 'ArrowLeft', 'ArrowRight',
     65                    'ArrowUp', 'ArrowDown', 'Delete', 'Home', 'End', 'Enter', 'Subtract', '-'
     66                ];
     67
     68                // Allow: Ctrl/Cmd + A/C/V/X
     69                if ((smocKeydownEvent.ctrlKey || smocKeydownEvent.metaKey) && ['a', 'c', 'v', 'x'].includes(smocKeydownEvent.key.toLowerCase())) { return; }
     70
     71                // Allow navigation/edit keys
     72                if (allowedKeys.includes(smocKeydownEvent.key)) { return; }
     73
     74                // Block any key that is not a digit (0-9)
     75                if (!/^\d$/.test(smocKeydownEvent.key)) {
     76                    smocKeydownEvent.preventDefault();
     77                }
     78            });
     79
     80            smocInput.addEventListener('paste', (smocPasteEvent) => {
     81                const pasted = smocPasteEvent.clipboardData.getData('text');
     82                if (!/^\d+$/.test(pasted)) {
     83                    smocPasteEvent.preventDefault();
     84                }
     85            });
     86
     87            smocInput.addEventListener('keypress', smocKeypressEvent => {
     88                if (smocKeypressEvent.key === 'Enter') {
     89                    smocKeypressEvent.preventDefault();
     90                    smocDoReorder(smocInput);
     91                }
     92            });
     93        });
     94    }
     95
     96    function smocDoReorder(smocInput) {
     97        if (!smocInput || smocInput.disabled) { return; }
     98
     99        const smocContainer = smocInput.closest('.smoc-container'), postId = parseInt(smocInput.dataset.postId);
     100
     101        if (!postId || isNaN(postId)) {
     102            disableInput(null, __('The post_id is invalid.', 'simple-menu-order-column'), true, smocInput);
     103            return;
     104        }
     105
     106        const loaderId = `smoc-${postId}`, menuOrder = parseInt(smocInput.value);
     107
     108        if (isNaN(menuOrder)) {
     109            const errorEl = document.getElementById(`${loaderId}-error`);
     110            disableInput(errorEl, __('The menu order value is invalid.', 'simple-menu-order-column'), false, smocInput);
     111            return;
     112        }
     113
     114        const nonce = smocInput.dataset.wpnonce;
     115        if (!nonce) {
     116            const errorEl = document.getElementById(`${loaderId}-error`);
     117            disableInput(errorEl, __('The postNonce is invalid.', 'simple-menu-order-column'), true, smocInput);
     118            return;
     119        }
     120
     121        if (typeof ajaxurl === 'undefined' || typeof typenow === 'undefined') {
     122            const errorEl = document.getElementById(`${loaderId}-error`);
     123            disableInput(errorEl, __('Invalid WP installation, variables typenow or ajaxurl are not initialized.', 'simple-menu-order-column'), true, smocInput);
     124            return;
     125        }
     126
     127        smocInput.disabled = true;
     128
     129        const showLoader = () => {
     130            let smocLoaderContainer = document.getElementById(`${loaderId}-loader-container`);
     131            if (!smocLoaderContainer) {
     132                const smocLoader = document.createElement('span');
     133                smocLoader.id = `${loaderId}-loader`;
     134                smocLoader.className = 'smoc-loader dashicons dashicons-update';
     135                smocLoader.setAttribute('role', 'img');
     136                smocLoader.setAttribute('aria-label', __('Updating menu order...', 'simple-menu-order-column'));
     137                smocLoader.style.cssText = 'color: #2ea2cc; animation: iconrotation 2s infinite linear; display: inline-block;';
     138
     139                smocLoaderContainer = document.createElement('div');
     140                smocLoaderContainer.id = `${loaderId}-loader-container`;
     141                smocLoaderContainer.style.cssText = 'padding-top: 5px; display: inline-block;';
     142                smocLoaderContainer.appendChild(smocLoader);
     143                smocContainer.appendChild(smocLoaderContainer);
     144            } else {
     145                smocLoaderContainer.style.display = 'inline-block';
     146            }
     147        };
     148
     149        const showSuccess = () => {
     150            let smocSuccess = document.getElementById(`${loaderId}-success`);
     151            if (!smocSuccess) {
     152                smocSuccess = document.createElement('span');
     153                smocSuccess.id = `${loaderId}-success`;
     154                smocSuccess.className = 'smoc-success dashicons dashicons-yes-alt';
     155                smocSuccess.setAttribute('role', 'img');
     156                smocSuccess.setAttribute('aria-label', __('The menu order has been updated successfully.', 'simple-menu-order-column'));
     157                smocSuccess.style.cssText = 'padding-top: 5px; color: #7ad03a; display: inline-block;';
     158                smocContainer.appendChild(smocSuccess);
     159            } else {
     160                smocSuccess.style.display = 'inline-block';
     161            }
     162        };
     163
     164        const showError = () => {
     165            let smocError = document.getElementById(`${loaderId}-error`);
     166            if (!smocError) {
     167                smocError = document.createElement('span');
     168                smocError.id = `${loaderId}-error`;
     169                smocError.className = 'smoc-error dashicons dashicons-dismiss';
     170                smocError.setAttribute('role', 'img');
     171                smocError.setAttribute('aria-label', __('An error ocurred while updating menu order.', 'simple-menu-order-column'));
     172                smocError.style.cssText = 'padding-top: 5px; color: #a00; display: inline-block;';
     173                smocContainer.appendChild(smocError);
     174            } else {
     175                smocError.style.display = 'inline-block';
     176            }
     177        };
     178
     179        const hideLoader = () => {
     180            const smocLoaderContainer = document.getElementById(`${loaderId}-loader-container`);
     181            if (smocLoaderContainer) { smocLoaderContainer.style.display = 'none'; }
     182        };
     183
     184        showLoader();
     185
     186        fetch(`${ajaxurl}?action=smoc_reorder&_wpnonce=${encodeURIComponent(nonce)}`, {
     187            method: 'POST',
     188            headers: {
     189                'Content-Type': 'application/x-www-form-urlencoded',
     190            },
     191            body: new URLSearchParams({
     192                post_type: typenow,
     193                post_id: postId,
     194                post_menu_order: menuOrder,
     195            }),
     196        })
     197            .then(res => res.json())
     198            .then(response => {
     199                if (response.success) {
     200                    showSuccess();
     201                    smocInput.title = menuOrder;
     202                    smocInput.currentValue = menuOrder;
     203                    smocInput.defaultValue = menuOrder;
     204                    if (smocConfig.tab_to_next) {
     205                        tabToNextInput(smocInput);
     206                    }
     207                } else {
     208                    smocInput.value = smocInput.defaultValue;
     209                    showError();
     210                }
     211            })
     212            .catch(() => {
     213                smocInput.value = smocInput.defaultValue;
     214                hideLoader();
     215                showError();
     216            })
     217            .finally(() => {
     218                hideLoader();
     219                smocInput.disabled = false;
     220            });
     221    }
     222
     223    function disableInput(errorContainer, message, disable, input) {
     224        input.value = input.defaultValue;
     225        if (errorContainer) { errorContainer.style.display = 'inline-block'; }
     226        input.disabled = disable;
     227        input.title = message;
     228        // eslint-disable-next-line no-console
     229        console.warn(`[Simple Menu Order Column] ${message}`);
     230    }
     231
     232    function tabToNextInput(smocInput) {
     233        const inputs = Array.from(smocInputs);
     234        const pos = inputs.indexOf(smocInput) + 1;
     235        if (inputs[pos]) { inputs[pos].select(); }
     236    }
     237
     238    /**
     239     * Initilize Script
     240     */
     241    if (document.readyState === "loading") {
     242        document.addEventListener('DOMContentLoaded', smocInit);
     243        window.addEventListener("load", smocInit);
     244    } else {
     245        window.setTimeout(smocInit);
     246    }
    230247})();
  • simple-menu-order-column/trunk/assets/js/simple-menu-order-column.min.js

    r3407262 r3417744  
    88 * @license Released under the General Public License v3.0 https://www.gnu.org/licenses/gpl-3.0.html
    99 */
    10 !function(){const{__:e}=wp.i18n;function t(){document.removeEventListener("DOMContentLoaded",t),window.removeEventListener("load",t);document.querySelectorAll("input[id^=smoc]").forEach(t=>{t.addEventListener("focus",()=>{t.currentValue=t.value,t.title=parseInt(t.value);const{postId:e}=t.dataset;if(!e)return;const n=e=>{const t=document.getElementById(e);t&&(t.style.display="none")},o=`smoc-${e}`;n(`${o}-loader-container`),n(`${o}-success`),n(`${o}-error`)}),t.addEventListener("focusout",()=>{t.disabled||t.currentValue!==t.value&&(window.confirm(e("Should the menu order value be updated?","simple-menu-order-column"))?n(t):t.value=t.defaultValue)}),t.addEventListener("keydown",e=>{(e.ctrlKey||e.metaKey)&&["a","c","v","x"].includes(e.key.toLowerCase())||["Backspace","Tab","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Delete","Home","End","Enter","Subtract","-"].includes(e.key)||/^\d$/.test(e.key)||e.preventDefault()}),t.addEventListener("paste",e=>{const t=e.clipboardData.getData("text");/^\d+$/.test(t)||e.preventDefault()}),t.addEventListener("keypress",e=>{"Enter"===e.key&&(e.preventDefault(),n(t))})})}function n(t){if(!t||t.disabled)return;const n=t.closest(".smoc-container"),d=parseInt(t.dataset.postId);if(!d||isNaN(d))return void o(null,e("The post_id is invalid.","simple-menu-order-column"),!0,t);const l=`smoc-${d}`,a=parseInt(t.value);if(isNaN(a)){return void o(document.getElementById(`${l}-error`),e("The menu order value is invalid.","simple-menu-order-column"),!1,t)}const r=t.dataset.wpnonce;if(!r){return void o(document.getElementById(`${l}-error`),e("The postNonce is invalid.","simple-menu-order-column"),!0,t)}if("undefined"==typeof ajaxurl||"undefined"==typeof typenow){return void o(document.getElementById(`${l}-error`),e("Invalid WP installation, variables typenow or ajaxurl are not initialized.","simple-menu-order-column"),!0,t)}t.disabled=!0;const s=()=>{let t=document.getElementById(`${l}-error`);t?t.style.display="inline-block":(t=document.createElement("span"),t.id=`${l}-error`,t.className="smoc-error dashicons dashicons-dismiss",t.setAttribute("role","img"),t.setAttribute("aria-label",e("An error ocurred while updating menu order.","simple-menu-order-column")),t.style.cssText="padding-top: 5px; color: #a00; display: inline-block;",n.appendChild(t))},i=()=>{const e=document.getElementById(`${l}-loader-container`);e&&(e.style.display="none")};(()=>{let t=document.getElementById(`${l}-loader-container`);if(t)t.style.display="inline-block";else{const o=document.createElement("span");o.id=`${l}-loader`,o.className="smoc-loader dashicons dashicons-update",o.setAttribute("role","img"),o.setAttribute("aria-label",e("Updating menu order...","simple-menu-order-column")),o.style.cssText="color: #2ea2cc; animation: iconrotation 2s infinite linear; display: inline-block;",t=document.createElement("div"),t.id=`${l}-loader-container`,t.style.cssText="padding-top: 5px; display: inline-block;",t.appendChild(o),n.appendChild(t)}})(),fetch(`${ajaxurl}?action=smoc_reorder&_wpnonce=${encodeURIComponent(r)}`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({post_type:typenow,post_id:d,post_menu_order:a})}).then(e=>e.json()).then(o=>{if(o.success){(()=>{let t=document.getElementById(`${l}-success`);t?t.style.display="inline-block":(t=document.createElement("span"),t.id=`${l}-success`,t.className="smoc-success dashicons dashicons-yes-alt",t.setAttribute("role","img"),t.setAttribute("aria-label",e("The menu order has been updated successfully.","simple-menu-order-column")),t.style.cssText="padding-top: 5px; color: #7ad03a; display: inline-block;",n.appendChild(t))})(),t.title=a,t.currentValue=a,t.defaultValue=a;const o=Array.from(document.querySelectorAll("input[id^=smoc]")),d=o.indexOf(t)+1;o[d]&&o[d].select()}else t.value=t.defaultValue,s()}).catch(()=>{t.value=t.defaultValue,i(),s()}).finally(()=>{i(),t.disabled=!1})}function o(e,t,n,o){o.value=o.defaultValue,e&&(e.style.display="inline-block"),o.disabled=n,o.title=t,console.warn(`[Simple Menu Order Column] ${t}`)}"loading"===document.readyState?(document.addEventListener("DOMContentLoaded",t),window.addEventListener("load",t)):window.setTimeout(t)}();
     10!function(){const{__:e}=wp.i18n;let t=null;const n=window.smoc_ui??{},o=n.enable_confirm??!0;n.tab_to_next;function a(){document.removeEventListener("DOMContentLoaded",a),window.removeEventListener("load",a),t=document.querySelectorAll("input[id^=smoc]"),t.forEach(t=>{t.addEventListener("focus",()=>{t.currentValue=t.value,t.title=parseInt(t.value);const{postId:e}=t.dataset;if(!e)return;const n=e=>{const t=document.getElementById(e);t&&(t.style.display="none")},o=`smoc-${e}`;n(`${o}-loader-container`),n(`${o}-success`),n(`${o}-error`)}),t.addEventListener("focusout",()=>{t.disabled||t.currentValue!==t.value&&(!o||window.confirm(e("Should the menu order value be updated?","simple-menu-order-column"))?l(t):t.value=t.defaultValue)}),t.addEventListener("keydown",e=>{(e.ctrlKey||e.metaKey)&&["a","c","v","x"].includes(e.key.toLowerCase())||["Backspace","Tab","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Delete","Home","End","Enter","Subtract","-"].includes(e.key)||/^\d$/.test(e.key)||e.preventDefault()}),t.addEventListener("paste",e=>{const t=e.clipboardData.getData("text");/^\d+$/.test(t)||e.preventDefault()}),t.addEventListener("keypress",e=>{"Enter"===e.key&&(e.preventDefault(),l(t))})})}function l(o){if(!o||o.disabled)return;const a=o.closest(".smoc-container"),l=parseInt(o.dataset.postId);if(!l||isNaN(l))return void d(null,e("The post_id is invalid.","simple-menu-order-column"),!0,o);const s=`smoc-${l}`,r=parseInt(o.value);if(isNaN(r)){return void d(document.getElementById(`${s}-error`),e("The menu order value is invalid.","simple-menu-order-column"),!1,o)}const i=o.dataset.wpnonce;if(!i){return void d(document.getElementById(`${s}-error`),e("The postNonce is invalid.","simple-menu-order-column"),!0,o)}if("undefined"==typeof ajaxurl||"undefined"==typeof typenow){return void d(document.getElementById(`${s}-error`),e("Invalid WP installation, variables typenow or ajaxurl are not initialized.","simple-menu-order-column"),!0,o)}o.disabled=!0;const c=()=>{let t=document.getElementById(`${s}-error`);t?t.style.display="inline-block":(t=document.createElement("span"),t.id=`${s}-error`,t.className="smoc-error dashicons dashicons-dismiss",t.setAttribute("role","img"),t.setAttribute("aria-label",e("An error ocurred while updating menu order.","simple-menu-order-column")),t.style.cssText="padding-top: 5px; color: #a00; display: inline-block;",a.appendChild(t))},u=()=>{const e=document.getElementById(`${s}-loader-container`);e&&(e.style.display="none")};(()=>{let t=document.getElementById(`${s}-loader-container`);if(t)t.style.display="inline-block";else{const n=document.createElement("span");n.id=`${s}-loader`,n.className="smoc-loader dashicons dashicons-update",n.setAttribute("role","img"),n.setAttribute("aria-label",e("Updating menu order...","simple-menu-order-column")),n.style.cssText="color: #2ea2cc; animation: iconrotation 2s infinite linear; display: inline-block;",t=document.createElement("div"),t.id=`${s}-loader-container`,t.style.cssText="padding-top: 5px; display: inline-block;",t.appendChild(n),a.appendChild(t)}})(),fetch(`${ajaxurl}?action=smoc_reorder&_wpnonce=${encodeURIComponent(i)}`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({post_type:typenow,post_id:l,post_menu_order:r})}).then(e=>e.json()).then(l=>{l.success?((()=>{let t=document.getElementById(`${s}-success`);t?t.style.display="inline-block":(t=document.createElement("span"),t.id=`${s}-success`,t.className="smoc-success dashicons dashicons-yes-alt",t.setAttribute("role","img"),t.setAttribute("aria-label",e("The menu order has been updated successfully.","simple-menu-order-column")),t.style.cssText="padding-top: 5px; color: #7ad03a; display: inline-block;",a.appendChild(t))})(),o.title=r,o.currentValue=r,o.defaultValue=r,n.tab_to_next&&function(e){const n=Array.from(t),o=n.indexOf(e)+1;n[o]&&n[o].select()}(o)):(o.value=o.defaultValue,c())}).catch(()=>{o.value=o.defaultValue,u(),c()}).finally(()=>{u(),o.disabled=!1})}function d(e,t,n,o){o.value=o.defaultValue,e&&(e.style.display="inline-block"),o.disabled=n,o.title=t,console.warn(`[Simple Menu Order Column] ${t}`)}"loading"===document.readyState?(document.addEventListener("DOMContentLoaded",a),window.addEventListener("load",a)):window.setTimeout(a)}();
  • simple-menu-order-column/trunk/changelog.txt

    r3407281 r3417744  
    11== Changelog ==
     2
     3= 2.1.0 2025-12-10 =
     4
     5* Allow to disable confirm window
     6* Allow to disable tab to next input field when data is updated
     7* Minor code changes
    28
    39= 2.0.1 2025-12-01 =
  • simple-menu-order-column/trunk/i18n/languages/simple-menu-order-column-ca-3fe84e529a0f3cc0a871b18c31074e39.json

    r3259857 r3417744  
    1 {"translation-revision-date":"2024-12-15 23:46+0000","generator":"Loco https:\/\/localise.biz\/","source":"assets\/js\/simple-menu-order-column.min.js","domain":"simple-menu-order-column","locale_data":{"simple-menu-order-column":{"":{"domain":"","lang":"ca","plural-forms":"nplurals=2; plural=n != 1;"},"An error ocurred while updating menu order.":["S'ha produ\u00eft un error en actualitzar l'ordre del men\u00fa."],"Invalid WP installation, variables typenow or ajaxurl are not initialized.":["La instal\u00b7laci\u00f3 de WP no \u00e9s v\u00e0lida, les variables typenow o ajaxurl no estan inicialitzades."],"Should the menu order value be updated?":["S'ha d'actualitzar el valor de la comanda del men\u00fa?"],"The menu order has been updated successfully.":["L'ordre del men\u00fa s'ha actualitzat correctament."],"The menu order value is invalid.":["El valor de l'ordre del men\u00fa no \u00e9s v\u00e0lid."],"The post_id is invalid.":["El post_id no \u00e9s v\u00e0lid."],"The postNonce is invalid.":["El postNonce no \u00e9s v\u00e0lid."],"Updating menu order...":["Actualitzant l'ordre de men\u00fa..."]}}}
     1{"translation-revision-date":"2025-12-11 00:45+0000","generator":"Loco https:\/\/localise.biz\/","source":"assets\/js\/simple-menu-order-column.min.js","domain":"simple-menu-order-column","locale_data":{"simple-menu-order-column":{"":{"domain":"","lang":"ca","plural-forms":"nplurals=2; plural=n != 1;"},"An error ocurred while updating menu order.":["S'ha produ\u00eft un error en actualitzar l'ordre del men\u00fa."],"Invalid WP installation, variables typenow or ajaxurl are not initialized.":["La instal\u00b7laci\u00f3 de WP no \u00e9s v\u00e0lida, les variables typenow o ajaxurl no estan inicialitzades."],"Should the menu order value be updated?":["S'ha d'actualitzar el valor de la comanda del men\u00fa?"],"The menu order has been updated successfully.":["L'ordre del men\u00fa s'ha actualitzat correctament."],"The menu order value is invalid.":["El valor de l'ordre del men\u00fa no \u00e9s v\u00e0lid."],"The post_id is invalid.":["El post_id no \u00e9s v\u00e0lid."],"The postNonce is invalid.":["El postNonce no \u00e9s v\u00e0lid."],"Updating menu order...":["Actualitzant l'ordre de men\u00fa..."]}}}
  • simple-menu-order-column/trunk/i18n/languages/simple-menu-order-column-ca.po

    r3259831 r3417744  
    44"Report-Msgid-Bugs-To: \n"
    55"POT-Creation-Date: 2024-03-08 01:56+0000\n"
    6 "PO-Revision-Date: 2024-12-15 23:46+0000\n"
     6"PO-Revision-Date: 2025-12-11 00:45+0000\n"
    77"Last-Translator: \n"
    88"Language-Team: Catalan\n"
     
    2121msgstr "Afegiu una columna d'ordre de menú als vostres llistats."
    2222
    23 #: assets/js/simple-menu-order-column.js:130
     23#: assets/js/simple-menu-order-column.js:171
    2424msgid "An error ocurred while updating menu order."
    2525msgstr "S'ha produït un error en actualitzar l'ordre del menú."
     
    2828msgid "Chillcode"
    2929msgstr "Chillcode"
     30
     31#: includes/class-simplemenuordercolumn.php:164
     32msgid "Controls how the plugin handles UI confirmations."
     33msgstr "Controla com el connector gestiona les confirmacions."
     34
     35#: includes/class-simplemenuordercolumn.php:135
     36msgid "Go to next field on update"
     37msgstr "Anar al camp següent en actualitzar"
    3038
    3139#. Author URI of the plugin
     
    3745msgstr "https://github.com/chillcode/simple-menu-order-column"
    3846
    39 #: assets/js/simple-menu-order-column.js:147
     47#: includes/class-simplemenuordercolumn.php:141
     48msgid ""
     49"If disabled, the cursor will remain in the input field after menu order is "
     50"updated."
     51msgstr ""
     52"Si està desactivat, el cursor romandrà al camp d'entrada després que "
     53"s'actualitzi l'ordre del menú."
     54
     55#: includes/class-simplemenuordercolumn.php:119
     56msgid "If disabled, the value will be updated automatically without prompting."
     57msgstr ""
     58"Si està desactivat, el valor s'actualitzarà automàticament sense demanar "
     59"confirmació."
     60
     61#: assets/js/simple-menu-order-column.js:123
    4062msgid ""
    4163"Invalid WP installation, variables typenow or ajaxurl are not initialized."
     
    4466"inicialitzades."
    4567
    46 #: includes/class-simplemenuordercolumn.php:225
     68#: includes/class-simplemenuordercolumn.php:387
    4769msgid "Order"
    4870msgstr "Ordre"
    4971
    50 #: assets/js/simple-menu-order-column.js:252
     72#: assets/js/simple-menu-order-column.js:54
    5173msgid "Should the menu order value be updated?"
    5274msgstr "S'ha d'actualitzar el valor de la comanda del menú?"
     75
     76#: includes/class-simplemenuordercolumn.php:113
     77msgid "Show confirmation prompt"
     78msgstr "Mostra missatge de confirmació"
    5379
    5480#. Name of the plugin
     
    5682msgstr "Simple Menu Order Column"
    5783
    58 #: assets/js/simple-menu-order-column.js:105
     84#: assets/js/simple-menu-order-column.js:156
    5985msgid "The menu order has been updated successfully."
    6086msgstr "L'ordre del menú s'ha actualitzat correctament."
    6187
    62 #: assets/js/simple-menu-order-column.js:159
     88#: assets/js/simple-menu-order-column.js:110
    6389msgid "The menu order value is invalid."
    6490msgstr "El valor de l'ordre del menú no és vàlid."
    6591
    66 #: assets/js/simple-menu-order-column.js:39
     92#: assets/js/simple-menu-order-column.js:102
    6793msgid "The post_id is invalid."
    6894msgstr "El post_id no és vàlid."
    6995
    70 #: assets/js/simple-menu-order-column.js:171
     96#: assets/js/simple-menu-order-column.js:117
    7197msgid "The postNonce is invalid."
    7298msgstr "El postNonce no és vàlid."
    7399
    74 #: assets/js/simple-menu-order-column.js:63
     100#: assets/js/simple-menu-order-column.js:136
    75101#| msgid "Updating Menu Order"
    76102msgid "Updating menu order..."
  • simple-menu-order-column/trunk/i18n/languages/simple-menu-order-column-es_ES-3fe84e529a0f3cc0a871b18c31074e39.json

    r3259857 r3417744  
    1 {"translation-revision-date":"2024-12-15 23:35+0000","generator":"Loco https:\/\/localise.biz\/","source":"assets\/js\/simple-menu-order-column.min.js","domain":"simple-menu-order-column","locale_data":{"simple-menu-order-column":{"":{"domain":"","lang":"es_ES","plural-forms":"nplurals=2; plural=n != 1;"},"An error ocurred while updating menu order.":["Se produjo un error al actualizar el orden de men\u00fa."],"Invalid WP installation, variables typenow or ajaxurl are not initialized.":["Instalaci\u00f3n de WordPress no v\u00e1lida, las variables typenow o ajaxurl no est\u00e1n inicializadas."],"Should the menu order value be updated?":["\u00bfSe debe actualizar el valor del orden de men\u00fa?"],"The menu order has been updated successfully.":["El orden de men\u00fa se actualiz\u00f3 correctamente."],"The menu order value is invalid.":["El valor de orden de men\u00fa no es v\u00e1lido."],"The post_id is invalid.":["El identificador de publicaci\u00f3n no es v\u00e1lido."],"The postNonce is invalid.":["El identificador \u00fanico no es v\u00f1aido"],"Updating menu order...":["Actualizando el orden de men\u00fa..."]}}}
     1{"translation-revision-date":"2025-12-11 00:48+0000","generator":"Loco https:\/\/localise.biz\/","source":"assets\/js\/simple-menu-order-column.min.js","domain":"simple-menu-order-column","locale_data":{"simple-menu-order-column":{"":{"domain":"","lang":"es_ES","plural-forms":"nplurals=2; plural=n != 1;"},"An error ocurred while updating menu order.":["Se produjo un error al actualizar el orden de men\u00fa."],"Invalid WP installation, variables typenow or ajaxurl are not initialized.":["Instalaci\u00f3n de WordPress no v\u00e1lida, las variables typenow o ajaxurl no est\u00e1n inicializadas."],"Should the menu order value be updated?":["\u00bfSe debe actualizar el valor del orden de men\u00fa?"],"The menu order has been updated successfully.":["El orden de men\u00fa se actualiz\u00f3 correctamente."],"The menu order value is invalid.":["El valor de orden de men\u00fa no es v\u00e1lido."],"The post_id is invalid.":["El identificador de publicaci\u00f3n no es v\u00e1lido."],"The postNonce is invalid.":["El identificador \u00fanico no es v\u00f1aido"],"Updating menu order...":["Actualizando el orden de men\u00fa..."]}}}
  • simple-menu-order-column/trunk/i18n/languages/simple-menu-order-column-es_ES.po

    r3259831 r3417744  
    44"Report-Msgid-Bugs-To: \n"
    55"POT-Creation-Date: 2024-03-08 01:56+0000\n"
    6 "PO-Revision-Date: 2024-12-15 23:35+0000\n"
     6"PO-Revision-Date: 2025-12-11 00:48+0000\n"
    77"Last-Translator: \n"
    8 "Language-Team: Español\n"
     8"Language-Team: Spanish (Spain)\n"
    99"Language: es_ES\n"
    1010"Plural-Forms: nplurals=2; plural=n != 1;\n"
     
    2121msgstr "Añade una columna de orden de menú a sus listados."
    2222
    23 #: assets/js/simple-menu-order-column.js:130
     23#: assets/js/simple-menu-order-column.js:171
    2424msgid "An error ocurred while updating menu order."
    2525msgstr "Se produjo un error al actualizar el orden de menú."
     
    2828msgid "Chillcode"
    2929msgstr "Chillcode"
     30
     31#: includes/class-simplemenuordercolumn.php:164
     32msgid "Controls how the plugin handles UI confirmations."
     33msgstr "Controla cómo la extensión maneja las confirmaciones."
     34
     35#: includes/class-simplemenuordercolumn.php:135
     36msgid "Go to next field on update"
     37msgstr "Ir al siguiente campo después de actualizar"
    3038
    3139#. Author URI of the plugin
     
    3745msgstr "https://github.com/chillcode/simple-menu-order-column"
    3846
    39 #: assets/js/simple-menu-order-column.js:147
     47#: includes/class-simplemenuordercolumn.php:141
     48msgid ""
     49"If disabled, the cursor will remain in the input field after menu order is "
     50"updated."
     51msgstr ""
     52"Si está deshabilitado, el cursor permanecerá en el campo de entrada después "
     53"de que se actualice el orden del menú."
     54
     55#: includes/class-simplemenuordercolumn.php:119
     56msgid "If disabled, the value will be updated automatically without prompting."
     57msgstr ""
     58"Si está deshabilitado, el valor se actualizará automáticamente sin preguntar."
     59
     60#: assets/js/simple-menu-order-column.js:123
    4061msgid ""
    4162"Invalid WP installation, variables typenow or ajaxurl are not initialized."
     
    4465"inicializadas."
    4566
    46 #: includes/class-simplemenuordercolumn.php:225
     67#: includes/class-simplemenuordercolumn.php:387
    4768msgid "Order"
    4869msgstr "Orden"
    4970
    50 #: assets/js/simple-menu-order-column.js:252
     71#: assets/js/simple-menu-order-column.js:54
    5172msgid "Should the menu order value be updated?"
    5273msgstr "¿Se debe actualizar el valor del orden de menú?"
     74
     75#: includes/class-simplemenuordercolumn.php:113
     76msgid "Show confirmation prompt"
     77msgstr "Mostrar mensaje de confirmación"
    5378
    5479#. Name of the plugin
     
    5681msgstr "Simple Menu Order Column"
    5782
    58 #: assets/js/simple-menu-order-column.js:105
     83#: assets/js/simple-menu-order-column.js:156
    5984msgid "The menu order has been updated successfully."
    6085msgstr "El orden de menú se actualizó correctamente."
    6186
    62 #: assets/js/simple-menu-order-column.js:159
     87#: assets/js/simple-menu-order-column.js:110
    6388msgid "The menu order value is invalid."
    6489msgstr "El valor de orden de menú no es válido."
    6590
    66 #: assets/js/simple-menu-order-column.js:39
     91#: assets/js/simple-menu-order-column.js:102
    6792msgid "The post_id is invalid."
    6893msgstr "El identificador de publicación no es válido."
    6994
    70 #: assets/js/simple-menu-order-column.js:171
     95#: assets/js/simple-menu-order-column.js:117
    7196msgid "The postNonce is invalid."
    7297msgstr "El identificador único no es vñaido"
    7398
    74 #: assets/js/simple-menu-order-column.js:63
     99#: assets/js/simple-menu-order-column.js:136
    75100msgid "Updating menu order..."
    76101msgstr "Actualizando el orden de menú..."
  • simple-menu-order-column/trunk/i18n/languages/simple-menu-order-column.pot

    r3259831 r3417744  
    44"Project-Id-Version: Simple Menu Order Column\n"
    55"Report-Msgid-Bugs-To: \n"
    6 "POT-Creation-Date: 2024-12-15 21:37+0000\n"
     6"POT-Creation-Date: 2025-12-11 00:40+0000\n"
    77"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    88"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    2121msgstr ""
    2222
    23 #: assets/js/simple-menu-order-column.js:130
     23#: assets/js/simple-menu-order-column.js:171
    2424msgid "An error ocurred while updating menu order."
    2525msgstr ""
     
    2727#. Author of the plugin
    2828msgid "Chillcode"
     29msgstr ""
     30
     31#: includes/class-simplemenuordercolumn.php:164
     32msgid "Controls how the plugin handles UI confirmations."
     33msgstr ""
     34
     35#: includes/class-simplemenuordercolumn.php:135
     36msgid "Go to next field on update"
    2937msgstr ""
    3038
     
    3745msgstr ""
    3846
    39 #: assets/js/simple-menu-order-column.js:147
     47#: includes/class-simplemenuordercolumn.php:141
     48msgid ""
     49"If disabled, the cursor will remain in the input field after menu order is "
     50"updated."
     51msgstr ""
     52
     53#: includes/class-simplemenuordercolumn.php:119
     54msgid "If disabled, the value will be updated automatically without prompting."
     55msgstr ""
     56
     57#: assets/js/simple-menu-order-column.js:123
    4058msgid ""
    4159"Invalid WP installation, variables typenow or ajaxurl are not initialized."
    4260msgstr ""
    4361
    44 #: includes/class-simplemenuordercolumn.php:225
     62#: includes/class-simplemenuordercolumn.php:387
    4563msgid "Order"
    4664msgstr ""
    4765
    48 #: assets/js/simple-menu-order-column.js:252
     66#: assets/js/simple-menu-order-column.js:54
    4967msgid "Should the menu order value be updated?"
     68msgstr ""
     69
     70#: includes/class-simplemenuordercolumn.php:113
     71msgid "Show confirmation prompt"
    5072msgstr ""
    5173
     
    5476msgstr ""
    5577
    56 #: assets/js/simple-menu-order-column.js:105
     78#: assets/js/simple-menu-order-column.js:156
    5779msgid "The menu order has been updated successfully."
    5880msgstr ""
    5981
    60 #: assets/js/simple-menu-order-column.js:159
     82#: assets/js/simple-menu-order-column.js:110
    6183msgid "The menu order value is invalid."
    6284msgstr ""
    6385
    64 #: assets/js/simple-menu-order-column.js:39
     86#: assets/js/simple-menu-order-column.js:102
    6587msgid "The post_id is invalid."
    6688msgstr ""
    6789
    68 #: assets/js/simple-menu-order-column.js:171
     90#: assets/js/simple-menu-order-column.js:117
    6991msgid "The postNonce is invalid."
    7092msgstr ""
    7193
    72 #: assets/js/simple-menu-order-column.js:63
     94#: assets/js/simple-menu-order-column.js:136
    7395msgid "Updating menu order..."
    7496msgstr ""
  • simple-menu-order-column/trunk/includes/class-simplemenuordercolumn.php

    r3407262 r3417744  
    3535    private static $smoc_allowed_types = array( 'post', 'page', 'product', 'attachment' );
    3636
     37    public const SMOC_OPTION_UI_CONFIRM     = 'smoc_ui_confirmation';
     38    public const SMOC_OPTION_UI_TAB_TO_NEXT = 'smoc_ui_tab_to_next';
     39
    3740    /**
    3841     * Construtor.
     
    7881            load_plugin_textdomain( 'simple-menu-order-column', false, dirname( plugin_basename( SMOC_PLUGIN_FILE ) ) . '/i18n/languages/' );
    7982        }
     83
     84        add_action( 'admin_init', array( $this, 'add_setting' ) );
     85    }
     86
     87    /**
     88     * Add setting to wriring dashboard to disable UI confirmation.
     89     *
     90     * @return void
     91     */
     92    public function add_setting() {
     93
     94        add_settings_section(
     95            'smoc_section',
     96            'Simple Menu Order Column',
     97            array( __CLASS__, 'output_section_description' ),
     98            'writing'
     99        );
     100
     101        register_setting(
     102            'writing',
     103            self::SMOC_OPTION_UI_CONFIRM,
     104            array(
     105                'type'              => 'boolean',
     106                'sanitize_callback' => array( __CLASS__, 'input_sanitize_checkbox' ),
     107                'default'           => true,
     108            )
     109        );
     110
     111        add_settings_field(
     112            self::SMOC_OPTION_UI_CONFIRM,
     113            __( 'Show confirmation prompt', 'simple-menu-order-column' ),
     114            array( __CLASS__, 'output_admin_setting' ),
     115            'writing',
     116            'smoc_section',
     117            array(
     118                'option_name' => self::SMOC_OPTION_UI_CONFIRM,
     119                'option_desc' => esc_attr__( 'If disabled, the value will be updated automatically without prompting.', 'simple-menu-order-column' ),
     120            )
     121        );
     122
     123        register_setting(
     124            'writing',
     125            self::SMOC_OPTION_UI_TAB_TO_NEXT,
     126            array(
     127                'type'              => 'boolean',
     128                'sanitize_callback' => array( __CLASS__, 'input_sanitize_checkbox' ),
     129                'default'           => true,
     130            )
     131        );
     132
     133        add_settings_field(
     134            self::SMOC_OPTION_UI_TAB_TO_NEXT,
     135            __( 'Go to next field on update', 'simple-menu-order-column' ),
     136            array( __CLASS__, 'output_admin_setting' ),
     137            'writing',
     138            'smoc_section',
     139            array(
     140                'option_name' => self::SMOC_OPTION_UI_TAB_TO_NEXT,
     141                'option_desc' => esc_attr__( 'If disabled, the cursor will remain in the input field after menu order is updated.', 'simple-menu-order-column' ),
     142            )
     143        );
     144    }
     145
     146    /**
     147     * Sanitize checkbox value.
     148     *
     149     * @param mixed $value Value to sanitize.
     150     *
     151     * @return int
     152     */
     153    public static function input_sanitize_checkbox( $value ) {
     154
     155        return $value ? 1 : 0;
     156    }
     157
     158    /**
     159     * Generate html checkbox to disable UI confirmation section
     160     *
     161     * @return void
     162     */
     163    public static function output_section_description() {
     164        echo '<p>' . esc_html__(
     165            'Controls how the plugin handles UI confirmations.',
     166            'simple-menu-order-column'
     167        ) . '</p>';
     168    }
     169
     170    /**
     171     * Generate html checkbox to disable UI confirmation.
     172     *
     173     * @param array $options Option name.
     174     *
     175     * @return void
     176     */
     177    public static function output_admin_setting( array $options ) {
     178        $checked = filter_var( get_option( $options['option_name'], true ), FILTER_VALIDATE_BOOLEAN, array( 'default' => true ) );
     179
     180        print '<label>';
     181        print '<input name="' . esc_attr( $options['option_name'] ) . '" type="checkbox" ' . checked( $checked, true, false ) . ' class="smoc-input" value="1" />';
     182        print esc_attr( $options['option_desc'] );
     183        print '</label>';
    80184    }
    81185
     
    121225        $wp_scripts_get_suffix = wp_scripts_get_suffix();
    122226
    123         wp_enqueue_script( 'simple-menu-order-column', plugins_url( 'assets/js/simple-menu-order-column' . $wp_scripts_get_suffix . '.js', SMOC_PLUGIN_FILE ), array( 'wp-i18n' ), SMOC_PLUGIN_VERSION, true );
    124         wp_enqueue_style( 'simple-menu-order-column', plugins_url( 'assets/css/simple-menu-order-column' . $wp_scripts_get_suffix . '.css', SMOC_PLUGIN_FILE ), array(), SMOC_PLUGIN_VERSION );
    125 
    126         wp_set_script_translations( 'simple-menu-order-column', 'simple-menu-order-column', plugin_dir_path( SMOC_PLUGIN_FILE ) . '/i18n/languages/' );
     227        wp_enqueue_script(
     228            'simple-menu-order-column',
     229            plugins_url( 'assets/js/simple-menu-order-column' . $wp_scripts_get_suffix . '.js', SMOC_PLUGIN_FILE ),
     230            array( 'wp-i18n' ),
     231            SMOC_PLUGIN_VERSION,
     232            true
     233        );
     234
     235        wp_localize_script(
     236            'simple-menu-order-column',
     237            'smoc_ui',
     238            array(
     239                'enable_confirm' => filter_var(
     240                    get_option(
     241                        self::SMOC_OPTION_UI_CONFIRM,
     242                        true
     243                    ),
     244                    FILTER_VALIDATE_BOOLEAN,
     245                    array( 'default' => true )
     246                ),
     247                'tab_to_next'    => filter_var(
     248                    get_option(
     249                        self::SMOC_OPTION_UI_TAB_TO_NEXT,
     250                        true
     251                    ),
     252                    FILTER_VALIDATE_BOOLEAN,
     253                    array( 'default' => true )
     254                ),
     255            )
     256        );
     257
     258        wp_set_script_translations(
     259            'simple-menu-order-column',
     260            'simple-menu-order-column',
     261            plugin_dir_path( SMOC_PLUGIN_FILE ) . '/i18n/languages/'
     262        );
     263
     264        wp_enqueue_style(
     265            'simple-menu-order-column',
     266            plugins_url( 'assets/css/simple-menu-order-column' . $wp_scripts_get_suffix . '.css', SMOC_PLUGIN_FILE ),
     267            array(),
     268            SMOC_PLUGIN_VERSION
     269        );
    127270    }
    128271
     
    158301         * Get post_id & post_menu_order.
    159302         */
    160         $post_id         = filter_input( INPUT_POST, 'post_id', FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1 ) ) );
    161         $post_menu_order = filter_input( INPUT_POST, 'post_menu_order', FILTER_VALIDATE_INT );
     303        $post_id         = filter_input(
     304            INPUT_POST,
     305            'post_id',
     306            FILTER_VALIDATE_INT,
     307            array( 'options' => array( 'min_range' => 1 ) )
     308        );
     309        $post_menu_order = filter_input(
     310            INPUT_POST,
     311            'post_menu_order',
     312            FILTER_VALIDATE_INT
     313        );
    162314
    163315        if (
  • simple-menu-order-column/trunk/readme.txt

    r3407281 r3417744  
    33Tags: menu order, pages, media, posts, products
    44Requires at least: 6.0
    5 Tested up to: 6.8
     5Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 2.0.1
     7Stable tag: 2.1.0
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    5757Once installed you will see an input box on every listing item.
    5858
     59To disable confirm prompt after menu order is updated visit **Wordpres Settings->Writing** and untick the option **Enable confirmation on input exit**
     60To disable tab to next on position update visit **Wordpress Settings->Writing** and untick the option Enable **Go to next field on update**
     61
    5962== Usage ==
    6063
     
    6770== Changelog ==
    6871
    69 = 2.0.1 2025-12-01 =
     72= 2.1.0 2025-12-10 =
    7073
    71 * Allow negative values
     74* Allow to disable confirm window
     75* Allow to disable tab to next input field when data is updated
    7276
    7377== Upgrade Notice ==
    7478
    75 = 1.0.1 =
    76 Fix false positive with Woo HPOS.
     79= 2.1.0 =
     80
     81Improve UI functionality
     82
     83= 2.0.0 =
     84Vanilla Javascript, no jQuery.
     85Minor PHPDoc fixes.
     86Minor code fixes.
    7787
    7888= 1.0.2 =
     
    8090Localize Javascript.
    8191
    82 = 2.0.0 =
    83 Vanilla Javascript, no jQuery.
    84 Minor PHPDoc fixes.
    85 Minor code fixes.
     92= 1.0.1 =
     93Fix false positive with Woo HPOS.
    8694
    8795== Screenshots ==
  • simple-menu-order-column/trunk/simple-menu-order-column.php

    r3407262 r3417744  
    1212 * Plugin URI: https://github.com/chillcode/simple-menu-order-column
    1313 * Description: Add a menu order column to your listings.
    14  * Version: 2.0.1
     14 * Version: 2.1.0
    1515 * Requires at least: 6.0
    1616 * Requires PHP: 7.4
     
    2727define( 'SMOC_PLUGIN_PATH', __DIR__ );
    2828define( 'SMOC_PLUGIN_FILE', __FILE__ );
    29 define( 'SMOC_PLUGIN_VERSION', '2.0.1' );
     29define( 'SMOC_PLUGIN_VERSION', '2.1.0' );
    3030
    3131require_once SMOC_PLUGIN_PATH . '/includes/class-simplemenuordercolumn.php';
Note: See TracChangeset for help on using the changeset viewer.