This repository was archived by the owner on Mar 31, 2021. It is now read-only.
forked from stowball/jQuery-rwdImageMaps
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathjquery.rwdImageMaps.min.js
More file actions
23 lines (23 loc) · 1.63 KB
/
jquery.rwdImageMaps.min.js
File metadata and controls
23 lines (23 loc) · 1.63 KB
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(e){e.fn.rwdImageMaps=function(t){var n=this,r={debounce:false,timeout:300},i=e.extend(r,typeof t==="object"?t:{}),s;if(typeof t==="string"){s=t}var o=function(){n.each(function(){if(typeof e(this).attr("usemap")=="undefined")return;var t=this,n=e(t);e("<img />").load(function(){var t="width",r="height",i=n.attr(t),s=n.attr(r);if(!i||!s){var o=new Image;o.src=n.attr("src");if(!i)i=o.width;if(!s)s=o.height}var u=n.width()/100,a=n.height()/100,f=n.attr("usemap").replace("#",""),l="coords";e('map[name="'+f+'"]').find("area").each(function(){var t=e(this);if(!t.data(l))t.data(l,t.attr(l));var n=t.data(l).split(","),r=new Array(n.length);for(var o=0;o<r.length;++o){if(o%2===0)r[o]=parseInt(n[o]/i*100*u);else r[o]=parseInt(n[o]/s*100*a)}t.attr(l,r.toString())})}).attr("src",n.attr("src"))})};var u=function(e,t){var n;return function(){clearTimeout(n);n=setTimeout(function(){e()},t)}};if(s==="off"){n.off("resize.rwdImageMaps")}else{o();if(i.debounce){e(window).on("resize.rwdImageMaps",u(o,i.timeout))}else{e(window).on("resize.rwdImageMaps",o)}}return this}})(jQuery);