简体   繁体   中英

jQuery Isotope error. Stopped working in Wordpress

A couple of weeks ago added some isotope to my wordpress website and got it all working well. However, after making some changes to the site I am now getting an error message and am really struggling to figure out what is causing it as the same code works fine in JSFiddle eg. http://jsfiddle.net/ttf5776r/12/

The error message I receive in the error console when on my site is:

TypeError: i.data(...) is undefined ...)n[t]=s||"original-order"!==t?rt:i.data(this,"isotope-sort-data")[t];i.da...

I have figured out that if I remove the following code, the error message stops appearing and the isotope works but doesn't put the selected box into the top left corner due to the code that has been removed.

  $container
  .isotope( 'updateSortData', $this.parent() )  //this should be above the 'return false;' to make the selected photo go to top left corner but it decided to break and havem't had time to find fix. - LOL 08-01-2015
  .isotope( 'updateSortData', $previousSelected )
  .isotope();   

Unfortunately I do not remember all of the changes I have made since this worked but I am pretty sure no JQuery amendments have been made.

Can anyone help me troubleshoot?

Code below:

functions.php

function add_isotope() {
    wp_register_script('isotope', 'http://isotope.metafizzy.co/v1/jquery.isotope.min.js', array('jquery'));
    wp_enqueue_script('isotope');
}

add_action( 'wp_enqueue_scripts', 'add_isotope' ); 

function add_jsscripts() {
    wp_register_script('jsscripts', get_template_directory_uri() . '/js/scripts.js', array('jquery'));
    wp_enqueue_script('jsscripts');
}

add_action( 'wp_enqueue_scripts', 'add_jsscripts' ); 

Your error refers to a minified source. The first step would be to switch to using a non-minified source so that the variables have their original names.

At that point you find the error here ("key" becomes "t", etc.):

updateSortData : function( $atoms, isIncrementingElemCount ) {
  var instance = this,
      getSortData = this.options.getSortData,
      $this, sortData;
  $atoms.each(function(){
    $this = $(this);
    sortData = {};
    // get value for sort data based on fn( $elem ) passed in
    for ( var key in getSortData ) {
      if ( !isIncrementingElemCount && key === 'original-order' ) {
        // keep original order original
        sortData[ key ] = $.data( this, 'isotope-sort-data' )[ key ];
      } else {
        sortData[ key ] = getSortData[ key ]( $this, instance );
      }
    }
    // apply sort data to element
    $.data( this, 'isotope-sort-data', sortData );
  });
},

The error you get, "i.data() is undefined", thus becomes "$.data() is undefined" -- which seems to indicate that the .data() plugin is not properly loaded, or (much more likely) that the variable passed to isotope is not actually a handle to the jQuery library . Check how you load and initialize isotope.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM