From b3ddf21659dca4a3f9f2ac018333385f6496684e Mon Sep 17 00:00:00 2001 From: Paul Jarrow Date: Tue, 8 Apr 2014 19:07:29 -0500 Subject: [PATCH] =?UTF-8?q?Values=20will=20occasionally=20NaN=20when=20wid?= =?UTF-8?q?th=20and=20height=20cannot=20be=20obtained=20from=20=E2=80=98it?= =?UTF-8?q?em=E2=80=99=20object.=20Added=20code=20to=20check=20values=20an?= =?UTF-8?q?d=20use=20this.width/this.height=20instead.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jquery.rwdImageMaps.js | 12 +++++++++--- jquery.rwdImageMaps.min.js | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) mode change 100644 => 100755 jquery.rwdImageMaps.js mode change 100644 => 100755 jquery.rwdImageMaps.min.js diff --git a/jquery.rwdImageMaps.js b/jquery.rwdImageMaps.js old mode 100644 new mode 100755 index c9d7348..360e071 --- a/jquery.rwdImageMaps.js +++ b/jquery.rwdImageMaps.js @@ -1,5 +1,5 @@ /* -* rwdImageMaps jQuery plugin v1.5 +* rwdImageMaps jQuery plugin v1.5.1 * * Allows image maps to be used in a responsive design by recalculating the area coordinates to match the actual image size on load and window.resize * @@ -19,7 +19,7 @@ var that = this, $that = $(that); - + // Since WebKit doesn't know the height until after the image has loaded, perform everything in an onload copy $('').load(function() { var attrW = 'width', @@ -34,6 +34,11 @@ w = temp.width; if (!h) h = temp.height; + // Fix for images that don't specify a width or height. + if(!w) + w = this.width; + if(!h) + h = this.height; } var wPercent = $that.width()/100, @@ -49,6 +54,7 @@ var coords = $this.data(c).split(','), coordsPercent = new Array(coords.length); + for (var i = 0; i < coordsPercent.length; ++i) { if (i % 2 === 0) coordsPercent[i] = parseInt(((coords[i]/w)*100)*wPercent); @@ -64,4 +70,4 @@ return this; }; -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/jquery.rwdImageMaps.min.js b/jquery.rwdImageMaps.min.js old mode 100644 new mode 100755 index 7ea76b1..9b72399 --- a/jquery.rwdImageMaps.min.js +++ b/jquery.rwdImageMaps.min.js @@ -8,4 +8,5 @@ * http://mattstow.com * Licensed under the MIT license */ -;(function(a){a.fn.rwdImageMaps=function(){var c=this;var b=function(){c.each(function(){if(typeof(a(this).attr("usemap"))=="undefined"){return}var e=this,d=a(e);a("").load(function(){var g="width",m="height",n=d.attr(g),j=d.attr(m);if(!n||!j){var o=new Image();o.src=d.attr("src");if(!n){n=o.width}if(!j){j=o.height}}var f=d.width()/100,k=d.height()/100,i=d.attr("usemap").replace("#",""),l="coords";a('map[name="'+i+'"]').find("area").each(function(){var r=a(this);if(!r.data(l)){r.data(l,r.attr(l))}var q=r.data(l).split(","),p=new Array(q.length);for(var h=0;h').load(function(){var attrW='width',attrH='height',w=$that.attr(attrW),h=$that.attr(attrH);if(!w||!h){var temp=new Image();temp.src=$that.attr('src');if(!w)w=temp.width;if(!h)h=temp.height;if(!w)w=this.width;if(!h)h=this.height;}var wPercent=$that.width()/100,hPercent=$that.height()/100,map=$that.attr('usemap').replace('#',''),c='coords';$('map[name="'+map+'"]').find('area').each(function(){var $this=$(this);if(!$this.data(c))$this.data(c,$this.attr(c));var coords=$this.data(c).split(','),coordsPercent=new Array(coords.length);for(var i=0;i