• hey,

    i packed an form from my own plugin into [su_lightbox]-Shortcode.
    this form have several fields and dynamic content (multiple views)
    all works perfectly.
    one thing i didnt get to work was to set the focus to an input field after the lightbox was opened.

    Nothing worked here for me, i tried jQuery.focus(), .click() and several other stuff.
    finally i worked through your code and found, that you use the magnificPopup-extension.
    i searched in the documentation and found the solution for my problem.
    i just need to add an extra option in the magnificPopup initialization-call named “focus”. (see https://dimsemenov.com/plugins/magnific-popup/documentation.html#focus )

    well, to keep your whole plugin updatable i moved a short js-block into my template

    
    jQuery(document).ready(function() {
    
        // need a timeout here
        // todo rj: do better
        setTimeout(stw_update_lightbox, 10);
    });
    
    function stw_update_lightbox() {
    
        // detach current clickHandler from SU-Plugin
        jQuery(document).off('click', '.su-lightbox');
    
        // re-attach clickHandler with extra option-value for focussing ms-inputs
        jQuery(document).on('click', '.su-lightbox', function(e) {
            e.preventDefault();
            e.stopPropagation();
            if (jQuery(this).parent().attr('id') === 'su-generator-preview') jQuery(this).html(su_other_shortcodes.no_preview);
            else {
                var type = jQuery(this).data('mfp-type');
                jQuery(this).magnificPopup({
                    type: type,
                    tClose: su_magnific_popup.close,
                    tLoading: su_magnific_popup.loading,
                    gallery: {
                        tPrev: su_magnific_popup.prev,
                        tNext: su_magnific_popup.next,
                        tCounter: su_magnific_popup.counter
                    },
                    image: {
                        tError: su_magnific_popup.error
                    },
                    ajax: {
                        tError: su_magnific_popup.error
                    },
                    focus: '.ms-input-focus:not(:hidden)'
                }).magnificPopup('open');
            }
        });
    }
    

    question:
    is there another way to add an extra option to this?
    f.e. focus: '.ms-input-focus:not(:hidden)'

    Greetings

  • The topic ‘su-lightbox magnificPopup extra options?’ is closed to new replies.