addScript breaking frontend editing

by Steve Voorhees   Last Updated September 22, 2017 20:10 PM

I have a piece of code in a component that I am building that loads maps in a tab in the admin view. The code works perfectly on the admin side, when when I attempt to add frontend editing, it's crashing, with a Call to a member function addScript() on null.

In the code I have attempt adding JFactory::getDocument();, which removes the error, but the script fails to load the maps. I've also thought that perhaps JQuery for some reason isn't loading, so have tried adding the JHtml::_('behavior.framework'); which doesn't change anything.

Google Maps is throwing frontend errors of Uncaught TypeError: Cannot read property 'value' of null.

Here's the sample code that is failing

// (start) Section to initiate google map

addScript('https://maps.googleapis.com/maps/api/js?key=' . $componentParams['gmapsapi'] ); $doc->addScript(JURI::base().'components/com_mostwantedrealestate/assets/js/googlemap.js'); ?> var mapTabClicked = false; jQuery(document).ready(function (){ jQuery('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { mapTabClicked = true; var liText = jQuery(this).text(); if(liText == 'Map Details') { var lat = document.getElementById("jform_latitude").value; var long = document.getElementById("jform_longitude").value; initialize(lat, long); var center = map.getCenter(); google.maps.event.trigger(map, 'resize'); map.setCenter(center);
}

});

}); // (end) Section to initiate google map

Any thoughts on what I might be missing to get this to work in the frontend and the backend?



Related Questions


Load javascript script before </body> closing tag

Updated August 05, 2015 13:04 PM

Control order of loaded scripts

Updated January 11, 2018 17:10 PM


How to access a component variable from a module?

Updated August 24, 2015 17:04 PM