Support » Plugin: Photo Gallery by 10Web - Mobile-Friendly Image Gallery » Plugin scripts are loaded before jQuery

  • Resolved ChrisHPZ

    (@chrishpz)


    Hi 10Web, potential bug report here. In QA’ing a site , I noticed a console error that jQuery isn’t defined. The cause of this error is from the Photo Gallery plugin inserting javascript right after the <title> tag. At this point, jQuery isn’t loaded yet. I enabled the option to “only load photo gallery scripts” on pages where a photo gallery is needed, but this didn’t change anything. We don’t have anything that would cause this. Offending code below:

    
    <script>
          var bwg_admin_ajax = 'https://anterra.com/wp-admin/admin-ajax.php?action=shortcode_bwg';
          var bwg_ajax_url = 'https://anterra.com/wp-admin/admin-ajax.php?action';
          var bwg_plugin_url = 'https://anterra.com/wp-content/plugins/photo-gallery';
          jQuery(document).ready(function () {
            bwg_check_ready = function () {}
            jQuery(document).keyup(function(e) {
              if ( e.keyCode == 27 ) {
                bwg_remove_loading_block();
              }
            });
          });
          // Set shortcode popup dimensions.
          function bwg_set_shortcode_popup_dimensions() {
            var H = jQuery(window).height(), W = jQuery(window).width();
            jQuery("#TB_title").hide().first().show();
            // New
            var tbWindow = jQuery('#TB_window');
            if (tbWindow.size()) {
              tbWindow.width(W).height(H);
              jQuery('#TB_iframeContent').width(W).height(H);
              tbWindow.attr('style',
                'top:'+ '0px !important;' +
                'left:' + '0px !important;' +
                'margin-left:' + '0;' +
                'z-index:' + '1000500;' +
                'max-width:' + 'none;' +
                'max-height:' + 'none;' +
                '-moz-transform:' + 'none;' +
                '-webkit-transform:' + 'none'
              );
            }
            // Edit
            var tbWindow = jQuery('.mce-window[aria-label="Photo Gallery"]');
            if (tbWindow.length) {
              // To prevent wp centering window with old sizes.
              setTimeout(function() {
                tbWindow.width(W).height(H);
                tbWindow.css({'top': 0, 'left': 0, 'margin-left': '0', 'z-index': '1000500'});
                tbWindow.find('.mce-window-body').width(W).height(H);
              }, 10);
            }
          }
          // Create loading block.
          function bwg_create_loading_block() {
            jQuery('body').append('<div class="loading_div" style="display:block; width: 100%; height: 100%; opacity: 0.6; position: fixed; background-color: #000000; background-image: url('+ bwg_plugin_url +'/images/spinner.gif); background-position: center; background-repeat: no-repeat; background-size: 50px; z-index: 1001000; top: 0; left: 0;"></div>');
          }
          // Remove loading block.
          function bwg_remove_loading_block() {
            jQuery(".loading_div", window.parent.document).remove();
            jQuery('.loading_div').remove();
          }
    	  </script>
    

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Kima Baghdasaryan

    (@kimabaghdasaryan)

    Hi,

    Please note that we have written the code according to WordPress Standart format.

    This problem might be a conflict with another plugin on your website.

    Please try to deactivate the rest of your plugins and check whether the problem persists.
    Also, if possible, please temporarily switch the theme of your website and see if the issue occurs.

    You can re-activate the plugins and change the theme back again after troubleshooting.
    Please inform us of the results.

    Cheers!

    Thread Starter ChrisHPZ

    (@chrishpz)

    I did as instructed and deactivated plugins and switched to a default WordPress theme. The issue still persisted. I took a look at the plugin code. So the function responsible for adding the above code is coming from public function global_script() on line 963 in photo-gallery.php. Obviously, this function relies on jQuery. So it has to load after jQuery is loaded.

    Now if we check out line 161 in the same file, we see the following:

    add_action('admin_head', array($this, 'global_script'));

    What’s missing here is a reliance on jQuery. The same thing applies to the function on line 1862 in photo-gallery.php

    Plugin Support Kima Baghdasaryan

    (@kimabaghdasaryan)

    Hi,

    We are still in the same opinion, that you have a conflict, jQuery loads late. However, we will write poor Javascript in order to solve this issue.

    Thank you!

    Have a nice day!

    Thread Starter ChrisHPZ

    (@chrishpz)

    How could I possibly have a conflict when I use a default WordPress theme and only Photo Gallery plugin enabled? The global script function still loads its output directly after the <title></title> tags on the front end of the site.

    We are experiencing the same issue with version 1.5.19.

    Uncaught TypeError: jQuery(…).hideShow is not a function

    jQuery isn’t available at the time the script is being called.

    Plugin Support Kima Baghdasaryan

    (@kimabaghdasaryan)

    Hi,

    As we have written above, we will write poor Javascript in our future updates of the Photo Gallery Plugin in order to solve this issue.

    Thank you for your understanding!

    Have a nice day!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Plugin scripts are loaded before jQuery’ is closed to new replies.