Plugin Directory

Changeset 3362973


Ignore:
Timestamp:
09/17/2025 07:33:48 AM (5 months ago)
Author:
printess
Message:
  • Fixed wrong behaviour in PanelUi that did not hide the price when it was configured to be hidden.
  • Saving dialog, saving reminder dialog and provide design name dialog are now accessible.
Location:
printess-editor/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • printess-editor/trunk/includes/js/printessEditor.js

    r3341111 r3362973  
    507507                console.error(e);
    508508            }
    509             const iframe = document.getElementById("printess");
    510             if (iframe && !context.hidePricesInEditor) {
    511                 setTimeout(() => {
    512                     iframe.contentWindow.postMessage({
    513                         cmd: "refreshPriceDisplay",
    514                         priceDisplay: priceInfo
    515                     }, "*");
    516                 }, 0);
    517             }
    518             //BcUI
    519             const component = this.getPrintessComponent();
    520             if (component && component.editor) {
    521                 component.editor.ui.refreshPriceDisplay(priceInfo);
     509            if (!context.hidePricesInEditor) {
     510                const iframe = document.getElementById("printess");
     511                if (iframe) {
     512                    setTimeout(() => {
     513                        iframe.contentWindow.postMessage({
     514                            cmd: "refreshPriceDisplay",
     515                            priceDisplay: priceInfo
     516                        }, "*");
     517                    }, 0);
     518                }
     519                //BcUI
     520                const component = this.getPrintessComponent();
     521                if (component && component.editor) {
     522                    component.editor.ui.refreshPriceDisplay(priceInfo);
     523                }
    522524            }
    523525        }
     
    646648        }
    647649    }
     650    static closeAllHtmlDialogs() {
     651        document.querySelectorAll(":not(printess-owned) dialog").forEach((x) => {
     652            if (typeof x.close === "function") {
     653                try {
     654                    x.close();
     655                }
     656                catch (ex) {
     657                    console.error(ex);
     658                }
     659            }
     660        });
     661    }
    648662    async showBcUiVersion(context, callbacks) {
    649663        const that = this;
     
    651665        let isSaveToken = context && context.templateNameOrSaveToken && context.templateNameOrSaveToken.indexOf("st:") === 0;
    652666        let pageCount = null;
     667        let useCustomLoader = false;
    653668        let formFields = null;
    654669        let mergeTemplates = null;
     670        PrintessEditor.closeAllHtmlDialogs();
    655671        if (!isSaveToken) {
    656672            formFields = PrintessEditor.applyFormFieldMappings(context.getCurrentFormFieldValues(), context.getFormFieldMappings());
     
    666682            }
    667683        }
     684        const globalSettings = PrintessEditor.getGlobalShopSettings();
     685        if (globalSettings && globalSettings.customLoader && typeof globalSettings.customLoader.onShowLoader === "function") {
     686            try {
     687                globalSettings.customLoader.onShowLoader();
     688                useCustomLoader = true;
     689            }
     690            catch (e) {
     691                console.error(e);
     692            }
     693        }
    668694        const startupParams = {};
    669695        const loaderUrl = that.getLoaderUrl(this.Settings.editorUrl, this.Settings.editorVersion, startupParams);
     
    713739                }
    714740                await callbacks.onLoadAsync(context.templateNameOrSaveToken);
     741                if (globalSettings && globalSettings.customLoader && typeof globalSettings.customLoader.onHideLoader === "function") {
     742                    try {
     743                        globalSettings.customLoader.onHideLoader();
     744                    }
     745                    catch (e) {
     746                        console.error(e);
     747                    }
     748                }
    715749            }, 1000);
    716750            printessComponent.editor.ui.show();
     
    725759            }
    726760            const attachParams = {
     761                suppressLoadingAnimation: useCustomLoader,
    727762                domain: that.Settings.apiDomain,
    728763                mergeTemplates: mergeTemplates,
     
    785820                        that.hideBcUiVersion(context, true);
    786821                    }
     822                },
     823                loadingDoneCallback: () => {
     824                    if (globalSettings && globalSettings.customLoader && typeof globalSettings.customLoader.onHideLoader === "function") {
     825                        try {
     826                            globalSettings.customLoader.onHideLoader();
     827                        }
     828                        catch (e) {
     829                            console.error(e);
     830                        }
     831                    }
    787832                }
    788833            };
     
    846891        let isSaveToken = context && context.templateNameOrSaveToken && context.templateNameOrSaveToken.indexOf("st:") === 0;
    847892        this.visible = true;
     893        PrintessEditor.closeAllHtmlDialogs();
    848894        const callbacks = {
    849895            onBack: () => {
  • printess-editor/trunk/includes/js/printessWoocommerce.js

    r3341026 r3362973  
    1 const initPrintessWCEditor = function (printessSettings) {
     1function trapFocus(root) {
     2    const keyboardFocusableElements = root.querySelectorAll('a[href], button, input, textarea, select, details, [tabindex]');
     3    const lastFocusableElement = keyboardFocusableElements[keyboardFocusableElements.length - 1];
     4    const firstFocusableElement = keyboardFocusableElements[0];
     5    firstFocusableElement.addEventListener("keydown", (e) => {
     6        if (e.key === "Tab" && e.shiftKey && lastFocusableElement) {
     7            e.preventDefault();
     8            lastFocusableElement.focus();
     9        }
     10    });
     11    lastFocusableElement.addEventListener("keydown", (e) => {
     12        if (e.key === "Tab" && !e.shiftKey && firstFocusableElement) {
     13            e.preventDefault();
     14            firstFocusableElement.focus();
     15        }
     16    });
     17    firstFocusableElement.focus();
     18}
     19const initPrintessWCEditor = function (printessSettings) {
    220    const CART_FORM_SELECTOR = "form.cart";
    321    let itemUsage = null;
     
    197215        const keyDownHandler = (e) => {
    198216            if (e.key === 'Enter' || e.keyCode === 13) {
    199                 e.preventDefault();
    200                 e.stopPropagation();
    201                 internalSaveCallback();
     217                // if a button is active, Enter should activate the button, not do anything else
     218                if (!(document.activeElement instanceof HTMLButtonElement)) {
     219                    e.preventDefault();
     220                    e.stopPropagation();
     221                    internalSaveCallback();
     222                }
    202223            }
    203224            else if (e.key === 'Escape' || e.keyCode === 27) {
     
    252273            dialog.addEventListener("mouseup", cancelMouse);
    253274            dialog.addEventListener("mousemove", cancelMouse);
    254             dialog.addEventListener("keydown", keyUpHandler);
    255             dialog.addEventListener("keyup", keyDownHandler);
     275            dialog.addEventListener("keydown", keyDownHandler);
     276            dialog.addEventListener("keyup", keyUpHandler);
    256277            if (!dialog.getAttribute("data-initialized")) {
    257278                document.body.appendChild(dialog);
     
    266287        const cancelButton = document.getElementById("printess_cancel_button");
    267288        if (cancelButton) {
     289            cancelButton.type = "button";
    268290            cancelButton.addEventListener("click", internalCancelCallback);
    269291        }
     292        cancelButton.style.backgroundColor = "red";
     293        trapFocus(dialog);
    270294    };
    271295    const postMessage = (cmd, properties) => {
     
    293317            }
    294318        }
     319        trapFocus(overlay);
    295320    };
    296321    const hideInformationOverlay = () => {
     
    11981223    }, timeout);
    11991224}
     1225let previouslyFocused;
    12001226function showDialog(prefix, initialValue, callback) {
    12011227    const textInput = document.getElementById(prefix + "_edit");
     
    12051231    const bodyElement = document.querySelector("body");
    12061232    let hide = null;
     1233    previouslyFocused = document.activeElement;
    12071234    const keyUpHandler = (e) => {
    12081235        if (e.key === 'Enter' || e.keyCode === 13) {
     
    12171244    const keyDownHandler = (e) => {
    12181245        if (e.key === 'Enter' || e.keyCode === 13) {
    1219             e.preventDefault();
    1220             e.stopPropagation();
    1221             hide();
    1222             if (typeof callback === "function") {
    1223                 callback(true, textInput.value);
     1246            const activeDomElement = document.activeElement;
     1247            // if a button is active, Enter should activate the button, not do anything else
     1248            if (!(activeDomElement instanceof HTMLButtonElement) && activeDomElement.id === "printess_display_name_cancel_button") {
     1249                e.preventDefault();
     1250                e.stopPropagation();
     1251                hide();
     1252                if (typeof callback === "function") {
     1253                    callback(true, textInput.value);
     1254                }
    12241255            }
    12251256        }
     
    12421273        if (dlg) {
    12431274            dlg.style.display = "none";
    1244             dlg.removeEventListener("keydown", keyUpHandler);
    1245             dlg.removeEventListener("keyup", keyDownHandler);
     1275            dlg.removeEventListener("keyup", keyUpHandler);
     1276            dlg.removeEventListener("keydown", keyDownHandler);
     1277        }
     1278        if (previouslyFocused && previouslyFocused instanceof HTMLElement) {
     1279            previouslyFocused.focus();
    12461280        }
    12471281    };
     
    12651299    }
    12661300    if (cancelButton) {
     1301        cancelButton.type = "button";
    12671302        cancelButton.addEventListener("click", cancelCallback);
    12681303    }
     
    12721307    if (dlg) {
    12731308        dlg.style.display = "block";
    1274         dlg.addEventListener("keydown", keyUpHandler);
    1275         dlg.addEventListener("keyup", keyDownHandler);
     1309        dlg.addEventListener("keyup", keyUpHandler);
     1310        dlg.addEventListener("keydown", keyDownHandler);
    12761311    }
     1312    trapFocus(dlg);
    12771313}
    12781314function printessRegisterCheckoutFilters(registerCheckoutFilters) {
  • printess-editor/trunk/printess.php

    r3343315 r3362973  
    55 * Plugin URI: https://printess.com/kb/integrations/woo-commerce/index.html
    66 * Developer: Bastian Kröger ([email protected]); Alexander Oser ([email protected])
    7  * Version: 1.6.58
     7 * Version: 1.6.60
    88 * Author: Printess
    99 * Author URI: https://printess.com
     
    1414 * Tested up to: 6.8
    1515 *
    16  * Woo: 10000:924017dfsfhsf8429842386wdff234sfd
     16 * Woo: 10000:924018dfsfhsf8429842386wdff234sfd
    1717 * WC requires at least: 5.8
    1818 * WC tested up to: 9.8.2
     
    157157
    158158        foreach($cart_contents as $item_key => &$item) {
    159             if(array_key_exists("printess-save-token", $item)) {
     159            if(array_key_exists("printess-save-token", $item) && array_key_exists("printess-design-name", $item)) {
    160160                $item_save_token = $item["printess-save-token"];
    161161                $item_design_name = $item["printess-design-name"];
     
    22582258    // Sort the cart items to newest item first.
    22592259    $sorted_cart_contents = $cart_contents; // $b will be a different array.
    2260     usort(
    2261         $sorted_cart_contents,
    2262         function ( $a, $b ) {
    2263             if ( array_key_exists( 'printess_date_added', $a ) && array_key_exists( 'printess_date_added', $b ) ) {
    2264                 return strcmp( $a['printess_date_added'], $b['printess_date_added'] ) * -1;
    2265             } elseif ( array_key_exists( 'printess_date_added', $a ) && ! array_key_exists( 'printess_date_added', $b ) ) {
    2266                 return -1;
    2267             } elseif ( ! array_key_exists( 'printess_date_added', $a ) && array_key_exists( 'printess_date_added', $b ) ) {
    2268                 return 1;
    2269             } else {
    2270                 return $sort_order[ $a->id ] < $sort_order[ $b->id ] ? -1 : 1;
    2271             }
    2272         }
    2273     );
     2260
     2261    try {
     2262        usort(
     2263            $sorted_cart_contents,
     2264            function ( $a, $b ) {
     2265                if ( array_key_exists( 'printess_date_added', $a ) && array_key_exists( 'printess_date_added', $b ) ) {
     2266                    return strcmp( $a['printess_date_added'], $b['printess_date_added'] ) * -1;
     2267                } elseif ( array_key_exists( 'printess_date_added', $a ) && ! array_key_exists( 'printess_date_added', $b ) ) {
     2268                    return -1;
     2269                } elseif ( ! array_key_exists( 'printess_date_added', $a ) && array_key_exists( 'printess_date_added', $b ) ) {
     2270                    return 1;
     2271                } else {
     2272                    $a_id = -1;
     2273                    $b_id = -1;
     2274
     2275                    if(property_exists($a, "id")) {
     2276                        $a_id = $a->id;
     2277                    } else if(is_array($a) && array_key_exists("id", $a)) {
     2278                        $a_id = $a["id"];
     2279                    } else {
     2280                        //Give up and sort it at the end
     2281                        return 1;
     2282                    }
     2283
     2284                    if(property_exists($b, "id")) {
     2285                        $a_id = $a->id;
     2286                    } else if(is_array($b) && array_key_exists("id", $b)) {
     2287                        $b_id = $b["id"];
     2288                    } else {
     2289                        //Give up and sort it at the end
     2290                        return -1;
     2291                    }
     2292
     2293                    return $sort_order[ $a_id ] < $sort_order[ $b_id ] ? -1 : 1;
     2294                }
     2295            }
     2296        );
     2297    } catch( \Exception $ex) {
     2298        $sorted_cart_contents = $cart_contents;
     2299    }
    22742300
    22752301    $index              = 0;
  • printess-editor/trunk/readme.txt

    r3343315 r3362973  
    318318= 1.6.58 =
    319319- Fixed wrong BillingCity variable name that prevented billing city to be pushed into the buyer side of the editor.
     320
     321= 1.6.59 =
     322- Fixed cart sorting for shopping cart items that are not of type object but of type array.
     323
     324= 1.6.60 =
     325- Fixed wrong behaviour in PanelUi that did not hide the price when it was configured to be hidden.
     326- Saving dialog, saving reminder dialog and provide design name dialog are now accessible.
Note: See TracChangeset for help on using the changeset viewer.