Problem/Motivation

Uncaught TypeError: Cannot read properties of undefined (reading 'width')

at Object.init (js_Txc42ukc4Pqhn-lmGaScSAaxTK_4p6aBTRVOQ4C9F9M.js:10418:520)
at HTMLDivElement. (js_Txc42ukc4Pqhn-lmGaScSAaxTK_4p6aBTRVOQ4C9F9M.js:10418:3204)
at Function.each (js_Txc42ukc4Pqhn-lmGaScSAaxTK_4p6aBTRVOQ4C9F9M.js:690:30)
at init.each (js_Txc42ukc4Pqhn-lmGaScSAaxTK_4p6aBTRVOQ4C9F9M.js:277:21)
at $.fn.gridSlide (js_Txc42ukc4Pqhn-lmGaScSAaxTK_4p6aBTRVOQ4C9F9M.js:10418:3148)
at js_Txc42ukc4Pqhn-lmGaScSAaxTK_4p6aBTRVOQ4C9F9M.js:10419:110
at dispatch (js_Txc42ukc4Pqhn-lmGaScSAaxTK_4p6aBTRVOQ4C9F9M.js:5378:16)
at elemData.handle (js_Txc42ukc4Pqhn-lmGaScSAaxTK_4p6aBTRVOQ4C9F9M.js:5031:35)

Jquery inspect console

if(typeof Object.create!=='function')Object.create=function(obj){'use strict'
function F(){};F.prototype=obj;return new F()};(function($,window,document){'use strict';var grid={init:function(options,elem){var self=this;self.elem=elem;self.$elem=$(elem).css({overflow:'hidden'});self.options=$.extend({},$.fn.gridSlide.options,options);self.$navigation=$(this.options.nav);self.list=self.$elem.find('ul');self.imgs=[];self.imgWidth=[];self.imgHeight=[];self.imgsLen=[];self.current=[0,0];for(var i=0;i

';for(var i=0;i
'+$(this.list[i]).data('title')+'

';this.gridText+='

    ';for(var j=0;j
    ';if(imgGrid)this.gridText+='Only local images are allowed.';this.gridText+='

    '}else{this.gridText+='

  • ';if(imgGrid)this.gridText+='Only local images are allowed.';this.gridText+='
  • '};this.gridText+='

'};this.gridText+='

';this.$navigation.show().prepend(this.gridText);this.$activeGridEl=$('.grid-active')},buildNav:function(){this.navText='

';this.$navigation.show().append(this.navText)},attachHandlers:function(){var self=this;if(self.options.menu==='grid'){$('.grid-nav-icon').on('click',function(){self.transition($(this).data('x'),$(this).data('y'));self.$activeGridEl.removeClass('grid-active');self.$activeGridEl=$(this).addClass('grid-active')})}else $('.nav-buttons').find('a').on('click',function(){self.setCurrent($(this).data('dir'));self.transition()})},setCurrent:function(dir){if(dir==='next'||dir==='prev'){var pos=this.current[0];pos+=(~~(dir==='next')||-1);this.current[0]=(pos<0)?this.imgsLen[this.current[1]]-1:pos%this.imgsLen[this.current[1]]}else{var level=this.current[1];level+=(~~(dir==='down')||-1);this.current[1]=(level<0)?this.list.length-1:level%this.list.length;if(this.current[0]>this.imgsLen[this.current[1]]-1)this.current[0]=this.imgsLen[this.current[1]]-1}},transition:function(x,y){var self=this;if(x>=0&&y>=0){self.current[0]=x;self.current[1]=y};self.list.stop().animate({'margin-left':-(self.current[0]*self.imgWidth[self.current[1]]),top:-(self.current[1]*self.imgHeight[self.current[1]])},this.options.speed)}};$.fn.gridSlide=function(options){return this.each(function(){var gridObj=Object.create(grid);gridObj.init(options,this)})};$.fn.gridSlide.options={nav:'#slider-nav',menu:'grid',title:false,imgGrid:false,speed:300}})(jQuery,window,document);
$(window).load(function(){'use strict';var a=$('.slider').attr('data-settings'),b=JSON.parse(a);$('.slider').gridSlide(b)});

Try in drupal 9.4.1

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Nelo_Drup created an issue. See original summary.

Webbeh’s picture

Title: Error Jquery » Cannot read properties of undefined (reading 'width')
Issue tags: -error, -jQuery
ishfaqafridi85’s picture

I’ll investigate the reported width error, starting with slider rows that contain no images. I’ll test a fix against empty galleries and normal image navigation, then share the results here.

ishfaqafridi85’s picture

Status: Active » Needs review

Added a fix in MR !8. Slider rows without images are now skipped, which prevents the width error.

Ready for review.

riazsaid15’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.