Search code examples
javascriptimagejoomlapanning

Javascript not working in Joomla article


I'm trying to implement this (dannyvankooten dot com/jquery-plugins/mapz/) image panning script into a Joomla article. I tested it outside Joomla (http://tylypahka.tk/karttatesting/) and it's working perfectly. However, when I tried it inside a Joomla article, the panning doesn't work (http://tylypahka.tk/kartta).

I put the same exact code into Joomla template's head that I had on the test version:

<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js" type="text/javascript"></script>
<script src="https://jquery-ui.googlecode.com/svn-history/r2596/branches/dev/spinner/external/mousewheel/jquery.mousewheel.min.js" type="text/javascript" ></script>
<script src="http://tylypahka.tk/js/jquery.mapz.js" type="text/javascript"></script>
<script type="text/javascript" src="http://tylypahka.tk/js/jquery.maphilight.js"></script>
<script type="text/javascript">
$(document).ready(function() {
  $("#map").mapz({
    zoom : true,
    createmaps : true,
    mousewheel : true
  });
});
</script>
<script type="text/javascript">$(function() {
        $('.map').maphilight();
        $('#squidheadlink').mouseover(function(e) {
            $('#squidhead').mouseover();
        }).mouseout(function(e) {
            $('#squidhead').mouseout();
        }).click(function(e) { e.preventDefault(); });
    });</script>
<style>
.map-viewport{ position:relative; width:860px; height:883px; overflow:hidden; background-color:black;}
.level{ position:absolute; left:0; top:0; z-index:10;}
.current-level{ z-index:20; }
#map{ width:1297px; height:883px; position:absolute; left:0; top:0; cursor:move;}
</style>

And the same exact code to the article:

<div class="map-viewport">
  <div id="map">
    <img src="http://img42.imageshack.us/img42/8954/tylypahkanportit.png" width="1297" height="883" usemap="#html-map" class="current-level level map" />
  </div>
  <map name="html-map">
    <area id="squidhead" shape="rect" coords="311,494,434,634" href="http://www.image-maps.com/" alt="" title=""/>
  </map>
</div>

jQuery automatically loads in Joomla site so it shouldn't be the problem. Any ideas what I'm doing wrong here?

All suggestions and help will be much appreciated!


Solution

  • You are using $ which is the shorthand code for jQuery, but Joomla also loads mootools, which is assigned the very same selector: so just change all $() to jquery() and you should get it working. You only need to do this at the outer level, then pass $ as a param:

    jQuery(function($){
      // inside this handler you can use the $ since you passed it as a parameter to the function:
      // btw, this is nicer than jQuery(document).ready...
      $('#someid').show();
    });