locked
upgrade some code to a newer version of jquery RRS feed

  • Question

  • User-921158202 posted

    hi,

    i have some trouble with a plugin that work with an older version of jquery but not with newers :/

    it's originally from this page

    http://tympanus.net/codrops/2011/06/09/grid-navigation-effects/

    after some debugging it seems that these lines are guilty :

    	var currentRows	= '', nextRows = '';
    					for( var i = 0; i < opts.rows; ++i ) {
    						currentRows += '.tj_row_' + (config.currentRow + i) + ',';
    						
    						(dir === 1)
    							? nextRows	+= '.tj_row_' + (config.currentRow + opts.rows + i) + ','
    							: nextRows	+= '.tj_row_' + (config.currentRow - 1 - i) + ',';
    					}
    					

    the error in the console is

    jquery.min.js:4 Uncaught Error: Syntax error, unrecognized expression: .tj_row_1,.tj_row_2,.tj_row_3,(…)

    if i comment them i don't have the error in the console but the pluging don't work properly .

    this lines of code are working perfectly in jquery 1.6.1 but not in 1.9.1 

    any idea on what's going on and how to fix that please ?

    thanks !

    Tuesday, December 6, 2016 11:52 PM

Answers

  • User527778624 posted

    Hi,

    Jquery version 1.9 seems not allows trailing comma in selectors. => ".single-line, .test,"

    but which seems accepted by version 1.6.

    You need to trim last comma in your selector build strings:

    '.single-line,.test,'.replace(/,$/,"");

    Try you code like this:

    var currentRows	= '', nextRows = '';
    					for( var i = 0; i < opts.rows; ++i ) {
    						currentRows += '.tj_row_' + (config.currentRow + i) + ',';
    						
    						(dir === 1)
    							? nextRows	+= '.tj_row_' + (config.currentRow + opts.rows + i) + ','
    							: nextRows	+= '.tj_row_' + (config.currentRow - 1 - i) + ',';
    					}
    
    currentRows = currentRows.replace(/,$/,"");
    nextRows = nextRows.replace(/,$/,"");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 7, 2016 9:32 AM

All replies

  • User-707554951 posted

    Hi issam1975,

    As far as I know, Jquery plugin was created based on some version Jquery,

    For your problem, Grid Navigation work on Jquery 1.6.1 not work in 1.9.1. it seems that some method was update or changed in 1.9.1,

    I think it is possible to make change in Jquery plugin to fix the problem.

    As far as I know, Jquery  provide conflict method, which allow us could use multiple Jquery at some time,

    So, I suggest could use this method to use the two version Jquery.

    https://api.jquery.com/jquery.noconflict/

    Best regards

    Cathy

    Wednesday, December 7, 2016 7:32 AM
  • User527778624 posted

    Hi,

    Jquery version 1.9 seems not allows trailing comma in selectors. => ".single-line, .test,"

    but which seems accepted by version 1.6.

    You need to trim last comma in your selector build strings:

    '.single-line,.test,'.replace(/,$/,"");

    Try you code like this:

    var currentRows	= '', nextRows = '';
    					for( var i = 0; i < opts.rows; ++i ) {
    						currentRows += '.tj_row_' + (config.currentRow + i) + ',';
    						
    						(dir === 1)
    							? nextRows	+= '.tj_row_' + (config.currentRow + opts.rows + i) + ','
    							: nextRows	+= '.tj_row_' + (config.currentRow - 1 - i) + ',';
    					}
    
    currentRows = currentRows.replace(/,$/,"");
    nextRows = nextRows.replace(/,$/,"");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 7, 2016 9:32 AM
  • User-921158202 posted

    and that did the trick :)

    many many thanks raju dasa,  thanks cathy to you too :)

    Thursday, December 8, 2016 12:49 AM