Team:ETH Zurich/slidermapchip

From 2014.igem.org

(Difference between revisions)
Line 2: Line 2:
<script type="text/javascript">
<script type="text/javascript">
 +
<script type="text/javascript">
 +
(function($) {
 +
function img(url) {
 +
var i = new Image;
 +
i.src = url;
 +
return i;
 +
}
 +
 +
if ('naturalWidth' in (new Image)) {
 +
$.fn.naturalWidth = function() { return this[0].naturalWidth; };
 +
$.fn.naturalHeight = function() { return this[0].naturalHeight; };
 +
return;
 +
}
 +
$.fn.naturalWidth = function() { return img(this[0].src).width; };
 +
$.fn.naturalHeight = function() { return img(this[0].src).height; };
 +
})(jQuery);
 +
 +
 +
 +
function onWindowResize()
 +
{
 +
  var curWidth = $(window).width(),
 +
  curHeight = $(window).height(),
 +
  checking=false;
 +
  if (checking) {
 +
      return;
 +
  }
 +
  checking = true;
 +
  window.setTimeout(
 +
    function() {
 +
        var newWidth = $(window).width(),
 +
            newHeight = $(window).height();
 +
        if (!(newWidth !== curWidth ||
 +
            newHeight !== curHeight)) {
 +
            resize(false);
 +
        }
 +
        checking=false;
 +
    }, 300);
 +
}
 +
 +
function resize(initial) {
 +
if (!initial)
 +
{
 +
  slider.redrawSlider();
 +
  var container = $('#container1');
 +
  var imgWidth = container.width();
 +
 +
  $( "#map1").each(function() {
 +
      $(this).css('height', 'auto', 'width', 'auto');
 +
      $(this).mapster('resize',Math.min(imgWidth, $(this).naturalWidth()) ,0,0); 
 +
  });
 +
 +
  container = $('#container2');
 +
  imgWidth = container.width();
 +
 +
  $( "#map2").each(function() {
 +
      $(this).css('height', 'auto', 'width', 'auto');
 +
      $(this).mapster('resize',Math.min(imgWidth, $(this).naturalWidth()) ,0,0); 
 +
  });
 +
  slider.redrawSlider();
 +
}
 +
 +
}
 +
$(document).ready(function(){
$(document).ready(function(){
 +
 +
$('#map1').mapster({
 +
    fillColor: 'FFFFFF',
 +
    fillOpacity: 0.5,
 +
    isSelectable: false,
 +
    clickNavigate: true,
 +
  });
 +
  $('#map2').mapster({
  $('#map2').mapster({
     fillColor: 'FFFFFF',
     fillColor: 'FFFFFF',
Line 9: Line 81:
     clickNavigate: true,
     clickNavigate: true,
   });
   });
 +
 +
 +
 +
$(window).resize(
 +
  function()
 +
  {
 +
onWindowResize();
 +
  });
 +
resize(true);
 +
});
});
 +
</script>
</script>

Revision as of 18:57, 17 October 2014