WordPress.org

Ready to get started?Download WordPress

Forums

Lightbox Plus Colorbox
Ajax and Lightbox Plus (1 post)

  1. pivanov
    Member
    Posted 1 year ago #

    Hello,

    So, I'm having images load via Ajax (using jQuery's ajax) and LBP does not get initialized for these images. Is there a way to run LBP's JavaScript setup scripts via a function call or a trigger?

    Anyway, since I needed a quick solution:<<<
    diff --git a/wp-content/plugins/lightbox-plus/classes/actions.class.php b/wp-content/plugins/lightbox-plus/classes/actions.class.php
    index 3b2c4e1..1cea606 100644
    --- a/wp-content/plugins/lightbox-plus/classes/actions.class.php
    +++ b/wp-content/plugins/lightbox-plus/classes/actions.class.php
    @@ -98,7 +98,8 @@
    $lightboxPlusJavaScript = "";
    $lightboxPlusJavaScript .= '<!-- Lightbox Plus ColorBox v'.$g_lbp_version.'/'.$g_lbp_colorbox_version.' - 2013.01.24 - Message: '.$lightboxPlusOptions['lightboxplus_multi'].'-->'.PHP_EOL;
    $lightboxPlusJavaScript .= '<script type="text/javascript">'.PHP_EOL;
    - $lightboxPlusJavaScript .= 'jQuery(document).ready(function($){'.PHP_EOL;
    + $lightboxPlusJavaScript .= '(function($){'.PHP_EOL;
    + $lightboxPlusJavaScript .= '$(document).bind("init-lbp", function (e){'.PHP_EOL;
    $lbpArrayPrimary = array();
    if ( $lightboxPlusOptions['transition'] != 'elastic' ) { $lbpArrayPrimary[] = 'transition:"'.$lightboxPlusOptions['transition'].'"'; }
    if ( $lightboxPlusOptions['speed'] != '300' ) { $lbpArrayPrimary[] = 'speed:'.$lightboxPlusOptions['speed']; }
    @@ -256,6 +257,8 @@
    }

    $lightboxPlusJavaScript .= '});'.PHP_EOL;
    + $lightboxPlusJavaScript .= '$(document).ready(function($){ $(document).trigger("init-lbp"); });'.PHP_EOL;
    + $lightboxPlusJavaScript .= '})(jQuery);'.PHP_EOL;
    $lightboxPlusJavaScript .= '</script>'.PHP_EOL;
    echo $lightboxPlusJavaScript;
    }
    >>>

    Triggering 'init-lbp' for the document will run (hopefully) any scripts outputted by the plugin. Example:

    $.ajax(
        config.ajaxurl,
        {
            // The context of all callbacks.
            context: $('#gallery'),
            // Data to send.
            data: {
                'action': 'get-post',
                'postUrl': $(this).attr('href')
            },
            // Type of data expected.
            dataType: 'html'
        }
    )
    .done(function(data, textStatus, jqXHR) {
        // If the modified version of Lightbox Plus ColorBox is
        // installed, run it's init scripts again.
        $(document).trigger('init-lbp');
    })
    .fail(function(jqXHR, textStatus, errorThrown) {
        console.log('Ajax call failed: ' + textStatus);
    });

    http://wordpress.org/extend/plugins/lightbox-plus/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.