forked from walmartlabs/jQuery-rwdImageMaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.rwdImageMaps.min.js
23 lines (23 loc) · 1.64 KB
/
jquery.rwdImageMaps.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
* rwdImageMaps jQuery plugin v1.5
*
* 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
*
* Copyright (c) 2013 Matt Stow
* https://github.com/stowball/jQuery-rwdImageMaps
* http://mattstow.com
* Licensed under the MIT license
* Usage:
* Without debounce
* $('img[usemap]').rwdImageMaps();
*
* Disable.
* $('img[usemap]').rwdImageMaps('off');
*
* With debounce on at 500ms
* $('img[usemap]').rwdImageMaps({
* debounce: true,
* timeout: 500
* });
*/
;(function(a){a.fn.rwdImageMaps=function(d){var e=this,h={debounce:false,timeout:300},f=a.extend(h,typeof d==="object"?d:{}),g;if(typeof d==="string"){g=d}var b=function(){e.each(function(){if(typeof(a(this).attr("usemap"))=="undefined"){return}var j=this,i=a(j);a("<img />").load(function(){var l="width",q="height",r=i.attr(l),n=i.attr(q);if(!r||!n){var s=new Image();s.src=i.attr("src");if(!r){r=s.width}if(!n){n=s.height}}var k=i.width()/100,o=i.height()/100,m=i.attr("usemap").replace("#",""),p="coords";a('map[name="'+m+'"]').find("area").each(function(){var w=a(this);if(!w.data(p)){w.data(p,w.attr(p))}var v=w.data(p).split(","),u=new Array(v.length);for(var t=0;t<u.length;++t){if(t%2===0){u[t]=parseInt(((v[t]/r)*100)*k)}else{u[t]=parseInt(((v[t]/n)*100)*o)}}w.attr(p,u.toString())})}).attr("src",i.attr("src"))})};var c=function(i,j){var k;return function(){clearTimeout(k);k=setTimeout(function(){i()},j)}};if(g==="off"){e.off("resize.rwdImageMaps")}else{if(f.debounce){a(window).on("resize.rwdImageMaps",c(b,f.timeout))}else{a(window).on("resize.rwdImageMaps",b)}}return this}})(jQuery);