Skip Navigation

[Resolved] Map doesn’t work anymore

This thread is resolved. Here is a description of the problem and solution.

Problem: I am trying to display a map, but it does not load. I see an error in the JavaScript console:

Uncaught TypeError: Cannot read property 'top' of undefined

Solution: Fix JavaScript errors related to undefined elements by testing to see if those elements exist before performing calculations on them.

jQuery(document).ready(function($){
     
var $el = $('.bloc-localisation');  //record the elem so you don't crawl the DOM everytime  
// stop here if no bloc-localisation element exists on the current page
if( $el.length == 0 ) {
  return;
}
var bottom = $el.offset().top + $el.outerHeight(true); // passing "true" will also include the top and bottom margin
console.log('bottom bloc gauche : '+bottom);

Relevant Documentation:
http://api.jquery.com/

This support ticket is created 5 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by Franck 5 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1176997

As, i have written, i give you FTP.

#1177052

Hello, you have a JavaScript error in your Layouts JS code that is preventing this map from loading as expected. Please open the browser console to see this error:

e33850de63cb5a5f6afa7a2826b4b3e6.js?ver=2.5.1:86 Uncaught TypeError: Cannot read property 'top' of undefined

Refers to the second line of this code in Layouts JS:

var $el = $('.bloc-localisation');  //record the elem so you don't crawl the DOM everytime  
var bottom = $el.offset().top + $el.outerHeight(true); // passing "true" will also include the top and bottom margin

$el is undefined, because there is no .bloc-localisation item in the DOM. Can you explain this code?

#1177080

Hi, thanks for your answer.

I am sorry, so it is me the problem 🙁

Before i use to put my JS in layout on the pages.. But you told me to put it in the JS TOOLSET part, so, now i don't know how i can do... 🙁

By the way, i think i have a free plan, because i use TOOLSET since long time. IF you want, you can turn my account to paid account. Because i have asked help many times. I don't know i all people is like me. but i can understand i have to pay.

#1177081

You could test to see if a .bloc-localisation element exists, or return, like this:

...
jQuery(document).ready(function($){
    
var $el = $('.bloc-localisation');  //record the elem so you don't crawl the DOM everytime  
// stop here if no bloc-localisation element exists on the current page
if( $el.length == 0 ) {
  return;
}
var bottom = $el.offset().top + $el.outerHeight(true); // passing "true" will also include the top and bottom margin
console.log('bottom bloc gauche : '+bottom);
...
#1177589

My issue is resolved now. Thank you!

As i have said, if i have to turn my account to a paid account, i will understand.