Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Values will occasionally NaN when width and height cannot be obtained fr... #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions jquery.rwdImageMaps.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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
*
Expand All @@ -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
$('<img />').load(function() {
var attrW = 'width',
Expand All @@ -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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a bug like the one below, but thanks to you, I solved it. thank you!

image

}

var wPercent = $that.width()/100,
Expand All @@ -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);
Expand All @@ -64,4 +70,4 @@

return this;
};
})(jQuery);
})(jQuery);
3 changes: 2 additions & 1 deletion jquery.rwdImageMaps.min.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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("<img />").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<p.length;++h){if(h%2===0){p[h]=parseInt(((q[h]/n)*100)*f)}else{p[h]=parseInt(((q[h]/j)*100)*k)}}r.attr(l,p.toString())})}).attr("src",d.attr("src"))})};a(window).resize(b).trigger("resize");return this}})(jQuery);
;(function($){$.fn.rwdImageMaps=function(){var $img=this;var rwdImageMap=function(){$img.each(function(){if(typeof($(this).attr('usemap'))=='undefined')return;var that=this,$that=$(that);$('<img />').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<coordsPercent.length;++i){if(i%2===0)coordsPercent[i]=parseInt(((coords[i]/w)*100)*wPercent);else
coordsPercent[i]=parseInt(((coords[i]/h)*100)*hPercent);}$this.attr(c,coordsPercent.toString());});}).attr('src',$that.attr('src'));});};$(window).resize(rwdImageMap).trigger('resize');return this;};})(jQuery);