diff --git a/README.md b/README.md
index 04c687b..b268e75 100644
--- a/README.md
+++ b/README.md
@@ -39,19 +39,12 @@ $(document).ready(function() {
###Example
http://davidjbradshaw.com/imagemap-resizer/example/
-### A note on IE8 and below
+### IE8 Support
-To use this library with old IE you will need to also load the included polyfil and ensure IE is running in "[Standards mode](http://en.wikipedia.org/wiki/Internet_Explorer_8#Standards_mode)". This can be done by adding the following to your HTML head section.
-
-```html
-
-
-```
+Version 1.0 of this project is optimised for IE9 and above. If you still require support for IE8 then please use [version 0.6.x](https://github.com/davidjbradshaw/image-map-resizer/tree/v0.6.x). Both versions are functionally equivalent.
### License
-Copyright © 2014 [David J. Bradshaw](https://github.com/davidjbradshaw).
+Copyright © 2014-15 [David J. Bradshaw](https://github.com/davidjbradshaw).
Licensed under the [MIT license](http://opensource.org/licenses/MIT).
[![NPM](https://nodei.co/npm/image-map-resizer.png)](https://nodei.co/npm/image-map-resizer/)
diff --git a/bower.json b/bower.json
index d0ba6b8..f50f3f3 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
{
"name": "image-map-resizer",
- "version": "0.5.4",
+ "version": "1.0.0",
"homepage": "https://github.com/davidjbradshaw/image-map-resizer",
"authors": [
"David J. Bradshaw "
diff --git a/gruntfile.js b/gruntfile.js
index 115bef5..49c95d7 100644
--- a/gruntfile.js
+++ b/gruntfile.js
@@ -53,13 +53,6 @@ module.exports = function(grunt) {
},
src: ['js/imageMapResizer.js'],
dest: 'js/imageMapResizer.min.js',
- },
- ie8: {
- options:{
- sourceMapName: 'js/ie8.polyfil.map'
- },
- src: ['js/ie8.polyfil.js'],
- dest: 'js/ie8.polyfil.min.js',
}
},
@@ -115,7 +108,7 @@ module.exports = function(grunt) {
grunt.registerTask('notest', ['jshint','uglify']);
grunt.registerTask('test', ['jshint','qunit']);
- grunt.registerTask('postBump',['bump-commit','shell']);
+ grunt.registerTask('postBump',['uglify','bump-commit','shell']);
grunt.registerTask('patch', ['default','bump-only:patch','postBump']);
grunt.registerTask('minor', ['default','bump-only:minor','postBump']);
grunt.registerTask('major', ['default','bump-only:major','postBump']);
diff --git a/imageMapResizer.jquery.json b/imageMapResizer.jquery.json
index b8a86de..da89a3a 100644
--- a/imageMapResizer.jquery.json
+++ b/imageMapResizer.jquery.json
@@ -11,7 +11,7 @@
"resize",
"design"
],
- "version": "0.5.4",
+ "version": "1.0.0",
"author": {
"name": "David J. Bradshaw",
"email": "davidjbradshaw+github@gmail.com"
diff --git a/js/ie8.polyfil.js b/js/ie8.polyfil.js
deleted file mode 100644
index cc21aa8..0000000
--- a/js/ie8.polyfil.js
+++ /dev/null
@@ -1,48 +0,0 @@
-//PolyFils from MDN.
-(function() {
- if (!Array.prototype.map){
- Array.prototype.map = function(fun /*, thisArg */){
- "use strict";
-
- if (this === void 0 || this === null || typeof fun !== "function"){
- throw new TypeError();
- }
-
- var
- t = Object(this),
- len = t.length >>> 0,
- res = new Array(len),
- thisArg = arguments.length >= 2 ? arguments[1] : void 0;
-
- for (var i = 0; i < len; i++){
- if (i in t) {
- res[i] = fun.call(thisArg, t[i], i, t);
- }
- }
-
- return res;
- };
- }
-
- if (!Array.prototype.forEach){
- Array.prototype.forEach = function(fun /*, thisArg */){
- "use strict";
-
- if (this === void 0 || this === null || typeof fun !== "function"){
- throw new TypeError();
- }
-
- var
- t = Object(this),
- len = t.length >>> 0,
- thisArg = arguments.length >= 2 ? arguments[1] : void 0;
-
- for (var i = 0; i < len; i++){
- if (i in t){
- fun.call(thisArg, t[i], i, t);
- }
- }
- };
- }
-
-})();
\ No newline at end of file
diff --git a/js/ie8.polyfil.map b/js/ie8.polyfil.map
deleted file mode 100644
index 76b9e5e..0000000
--- a/js/ie8.polyfil.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"file":"ie8.polyfil.min.js","sources":["ie8.polyfil.js"],"names":["Array","prototype","map","fun","this","TypeError","t","Object","len","length","res","thisArg","arguments","i","call","forEach"],"mappings":"CACA,WACOA,MAAMC,UAAUC,MACnBF,MAAMC,UAAUC,IAAM,SAASC,GAC7B,YAEA,IAAa,SAATC,MAA4B,OAATA,MAAgC,kBAARD,GAC7C,KAAM,IAAIE,UASZ,KAAK,GALDC,GAAIC,OAAOH,MACXI,EAAMF,EAAEG,SAAW,EACnBC,EAAM,GAAIV,OAAMQ,GAChBG,EAAUC,UAAUH,QAAU,EAAIG,UAAU,GAAK,OAE5CC,EAAI,EAAOL,EAAJK,EAASA,IACnBA,IAAKP,KACPI,EAAIG,GAAKV,EAAIW,KAAKH,EAASL,EAAEO,GAAIA,EAAGP,GAIxC,OAAOI,KAINV,MAAMC,UAAUc,UACnBf,MAAMC,UAAUc,QAAU,SAASZ,GACjC,YAEA,IAAa,SAATC,MAA4B,OAATA,MAAgC,kBAARD,GAC7C,KAAM,IAAIE,UAQZ,KAAK,GAJHC,GAAIC,OAAOH,MACXI,EAAMF,EAAEG,SAAW,EACnBE,EAAUC,UAAUH,QAAU,EAAIG,UAAU,GAAK,OAE1CC,EAAI,EAAOL,EAAJK,EAASA,IACnBA,IAAKP,IACPH,EAAIW,KAAKH,EAASL,EAAEO,GAAIA,EAAGP"}
\ No newline at end of file
diff --git a/js/ie8.polyfil.min.js b/js/ie8.polyfil.min.js
deleted file mode 100644
index 8af252c..0000000
--- a/js/ie8.polyfil.min.js
+++ /dev/null
@@ -1,2 +0,0 @@
-!function(){Array.prototype.map||(Array.prototype.map=function(a){"use strict";if(void 0===this||null===this||"function"!=typeof a)throw new TypeError;for(var b=Object(this),c=b.length>>>0,d=new Array(c),e=arguments.length>=2?arguments[1]:void 0,f=0;c>f;f++)f in b&&(d[f]=a.call(e,b[f],f,b));return d}),Array.prototype.forEach||(Array.prototype.forEach=function(a){"use strict";if(void 0===this||null===this||"function"!=typeof a)throw new TypeError;for(var b=Object(this),c=b.length>>>0,d=arguments.length>=2?arguments[1]:void 0,e=0;c>e;e++)e in b&&a.call(d,b[e],e,b)})}();
-//# sourceMappingURL=ie8.polyfil.map
\ No newline at end of file
diff --git a/js/imageMapResizer.js b/js/imageMapResizer.js
index fc54d69..06695d0 100644
--- a/js/imageMapResizer.js
+++ b/js/imageMapResizer.js
@@ -10,84 +10,72 @@
function scaleImageMap(){
function resizeMap() {
- function resizeAreaTag(cachedAreaCoords){
- function scaleCoord(e){
- return e * scallingFactor[(1===(isWidth = 1-isWidth) ? 'width' : 'height')];
+ function resizeAreaTag(cachedAreaCoords,idx){
+ function scale(coord){
+ var dimension = ( 1 === (isWidth = 1-isWidth) ? 'width' : 'height' );
+ return Math.floor(Number(coord) * scallingFactor[dimension]);
}
var isWidth = 0;
- return cachedAreaCoords.split(',').map(Number).map(scaleCoord).map(Math.floor).join(',');
+ areas[idx].coords = cachedAreaCoords.split(',').map(scale).join(',');
}
var scallingFactor = {
- width : displayedImage.width / sourceImage.width,
- height : displayedImage.height / sourceImage.height
+ width : image.width / image.naturalWidth,
+ height : image.height / image.naturalHeight
};
- for (var i=0; i < areasLen ; i++) {
- areas[i].coords = resizeAreaTag(cachedAreaCoordsArray[i]);
- }
+ cachedAreaCoordsArray.forEach(resizeAreaTag);
}
- function start(){
- var
- displayedWidth = null,
- displayedHeight = null;
-
- //WebKit asyncs image loading, so we have to catch the load event.
- sourceImage.onload = function sourceImageOnLoadF(){
- displayedWidth = displayedImage.width;
- displayedHeight = displayedImage.height;
-
- if ((displayedWidth !== sourceImage.width) || (displayedHeight !== sourceImage.height)) {
- resizeMap();
- }
- };
-
- //IE11 can late load this image, so make sure we have the correct sizes (#10)
- displayedImage.onload = function() {
- if (null !== displayedWidth && displayedImage.width !== displayedWidth) {
- resizeMap();
- }
- };
+ function getCoords(e){
+ //Normalize coord-string to csv format without any space chars
+ return e.coords.replace(/ *, */g,',').replace(/ +/g,',');
+ }
- //Make copy of image, so we can get the actual size measurements
- sourceImage.src = displayedImage.src;
+ function debounce() {
+ clearTimeout(timer);
+ timer = setTimeout(resizeMap, 250);
}
- function listenForResize(){
- function debounce() {
- clearTimeout(timer);
- timer = setTimeout(resizeMap, 250);
+ function start(){
+ if ((image.width !== image.naturalWidth) || (image.height !== image.naturalHeight)) {
+ resizeMap();
}
- if (window.addEventListener) { window.addEventListener('resize', debounce, false); }
- else if (window.attachEvent) { window.attachEvent('onresize', debounce); }
}
- function listenForFocus(){
- if (window.addEventListener) { window.addEventListener('focus', resizeMap, false); }
- else if (window.attachEvent) { window.attachEvent('onfocus', resizeMap); }
+ function attach(){
+ map._resize = resizeMap; //Bind resize method to HTML map element
+ image.addEventListener('onload', resizeMap, false); //Detect late image loads in IE11
+ window.addEventListener('focus', resizeMap, false); //Cope with window being resized whilst on another tab
+ window.addEventListener('resize', debounce, false);
+ document.addEventListener('fullscreenchange', resizeMap, false);
}
- function getCoords(e){
- // normalize coord-string to csv format without any space chars
- return e.coords.replace(/ *, */g,',').replace(/ +/g,',');
+ function beenHere(){
+ return ('function' === typeof map._resize);
+ }
+
+ function setup(){
+ areas = map.getElementsByTagName('area');
+ cachedAreaCoordsArray = Array.prototype.map.call(areas, getCoords);
+ image = document.querySelector('img[usemap="#'+map.name+'"]');
+
}
var
/*jshint validthis:true */
- map = this,
- areas = map.getElementsByTagName('area'),
- areasLen = areas.length,
- cachedAreaCoordsArray = Array.prototype.map.call(areas, getCoords),
- displayedImage = document.querySelector('img[usemap="#'+map.name+'"]'),
- sourceImage = new Image(),
- timer = null;
-
- start();
- listenForResize();
- listenForFocus();
+ map = this,
+ areas = null, cachedAreaCoordsArray = null, image = null, timer = null;
+
+ if (!beenHere()){
+ setup();
+ attach();
+ start();
+ } else {
+ map._resize(); //Already setup, so just resize map
+ }
}
@@ -113,16 +101,15 @@
init(target);
break;
default:
- throw new TypeError('Unexpected data type ('+typeof(target)+').');
+ throw new TypeError('Unexpected data type ('+typeof target+').');
}
};
}
-
if (typeof define === 'function' && define.amd) {
define([],factory);
- } else if (typeof exports === 'object') { //Node for browserfy
- module.exports = factory();
+ } else if (typeof module === 'object' && typeof module.exports === 'object'){
+ module.exports = factory(); //Node for browserfy
} else {
window.imageMapResize = factory();
}
diff --git a/js/imageMapResizer.map b/js/imageMapResizer.map
index 4968375..0ad7cfe 100644
--- a/js/imageMapResizer.map
+++ b/js/imageMapResizer.map
@@ -1 +1 @@
-{"version":3,"file":"imageMapResizer.min.js","sources":["imageMapResizer.js"],"names":["scaleImageMap","resizeMap","resizeAreaTag","cachedAreaCoords","scaleCoord","e","scallingFactor","isWidth","split","map","Number","Math","floor","join","width","displayedImage","sourceImage","height","i","areasLen","areas","coords","cachedAreaCoordsArray","start","displayedWidth","displayedHeight","onload","src","listenForResize","debounce","clearTimeout","timer","setTimeout","window","addEventListener","attachEvent","getCoords","replace","this","getElementsByTagName","length","Array","prototype","call","document","querySelector","name","Image","factory","init","element","tagName","TypeError","toUpperCase","target","forEach","querySelectorAll","define","amd","exports","module","imageMapResize","jQuery","fn","filter","each","end"],"mappings":";;;;;;CAMA,WACI,YAEA,SAASA,KAEL,QAASC,KACL,QAASC,GAAcC,GACnB,QAASC,GAAWC,GAChB,MAAOA,GAAIC,EAAgB,KAAKC,EAAU,EAAEA,GAAW,QAAU,UAGrE,GAAIA,GAAU,CAEd,OAAOJ,GAAiBK,MAAM,KAAKC,IAAIC,QAAQD,IAAIL,GAAYK,IAAIE,KAAKC,OAAOC,KAAK,KAQxF,IAAK,GALDP,IACAQ,MAASC,EAAeD,MAASE,EAAYF,MAC7CG,OAASF,EAAeE,OAASD,EAAYC,QAGxCC,EAAE,EAAOC,EAAJD,EAAeA,IACzBE,EAAMF,GAAGG,OAASnB,EAAcoB,EAAsBJ,IAI9D,QAASK,KACL,GACIC,GAAkB,KAClBC,EAAkB,IAGtBT,GAAYU,OAAS,WACjBF,EAAiBT,EAAeD,MAChCW,EAAkBV,EAAeE,QAE5BO,IAAmBR,EAAYF,OAAWW,IAAoBT,EAAYC,SAC3EhB,KAKRc,EAAeW,OAAS,WAChB,OAASF,GAAkBT,EAAeD,QAAUU,GACpDvB,KAKRe,EAAYW,IAAMZ,EAAeY,IAGrC,QAASC,KACL,QAASC,KACLC,aAAaC,GACbA,EAAQC,WAAW/B,EAAW,KAE9BgC,OAAOC,iBAAoBD,OAAOC,iBAAiB,SAAUL,GAAU,GAClEI,OAAOE,aAAeF,OAAOE,YAAY,WAAYN,GAGlE,QAASO,GAAU/B,GAEf,MAAOA,GAAEgB,OAAOgB,QAAQ,SAAS,KAAKA,QAAQ,MAAM,KAGxD,GAEI5B,GAAwB6B,KACxBlB,EAAwBX,EAAI8B,qBAAqB,QACjDpB,EAAwBC,EAAMoB,OAC9BlB,EAAwBmB,MAAMC,UAAUjC,IAAIkC,KAAKvB,EAAOgB,GACxDrB,EAAwB6B,SAASC,cAAc,gBAAgBpC,EAAIqC,KAAK,MACxE9B,EAAwB,GAAI+B,OAC5BhB,EAAwB,IAE5BR,KACAK,IAKJ,QAASoB,KACL,QAASC,GAAKC,GACV,IAAIA,EAAQC,QACR,KAAM,IAAIC,WAAU,oCACjB,IAAI,QAAUF,EAAQC,QAAQE,cACjC,KAAM,IAAID,WAAU,8BAA8BF,EAAQC,QAAQ,KAGtEnD,GAAc2C,KAAKO,GAGvB,MAAO,UAAyBI,GAC5B,aAAc,IACV,IAAK,YACL,IAAK,SACDb,MAAMC,UAAUa,QAAQZ,KAAKC,SAASY,iBAAiBF,GAAQ,OAAOL,EACtE,MACJ,KAAK,SACDA,EAAKK,EACL,MACJ,SACI,KAAM,IAAIF,WAAU,+BAA+B,GAAS,QAMtD,kBAAXK,SAAyBA,OAAOC,IACvCD,UAAUT,GACgB,gBAAZW,SACdC,OAAOD,QAAUX,IAEjBf,OAAO4B,eAAiBb,IAIzB,UAAYf,UACX6B,OAAOC,GAAGF,eAAiB,WACvB,MAAOvB,MAAK0B,OAAO,OAAOC,KAAKjE,GAAekE"}
\ No newline at end of file
+{"version":3,"file":"imageMapResizer.min.js","sources":["imageMapResizer.js"],"names":["scaleImageMap","resizeMap","resizeAreaTag","cachedAreaCoords","idx","scale","coord","dimension","isWidth","Math","floor","Number","scallingFactor","areas","coords","split","map","join","width","image","naturalWidth","height","naturalHeight","cachedAreaCoordsArray","forEach","getCoords","e","replace","debounce","clearTimeout","timer","setTimeout","start","attach","_resize","addEventListener","window","document","beenHere","setup","getElementsByTagName","Array","prototype","call","querySelector","name","this","factory","init","element","tagName","TypeError","toUpperCase","target","querySelectorAll","define","amd","module","exports","imageMapResize","jQuery","fn","filter","each","end"],"mappings":";;;;;;CAMA,WACI,YAEA,SAASA,KAEL,QAASC,KACL,QAASC,GAAcC,EAAiBC,GACpC,QAASC,GAAMC,GACX,GAAIC,GAAc,KAAOC,EAAU,EAAEA,GAAW,QAAU,QAC1D,OAAOC,MAAKC,MAAMC,OAAOL,GAASM,EAAeL,IAGrD,GAAIC,GAAU,CAEdK,GAAMT,GAAKU,OAASX,EAAiBY,MAAM,KAAKC,IAAIX,GAAOY,KAAK,KAGpE,GAAIL,IACAM,MAASC,EAAMD,MAASC,EAAMC,aAC9BC,OAASF,EAAME,OAASF,EAAMG,cAGlCC,GAAsBC,QAAQtB,GAGlC,QAASuB,GAAUC,GAEf,MAAOA,GAAEZ,OAAOa,QAAQ,SAAS,KAAKA,QAAQ,MAAM,KAGxD,QAASC,KACLC,aAAaC,GACbA,EAAQC,WAAW9B,EAAW,KAGlC,QAAS+B,MACAb,EAAMD,QAAUC,EAAMC,cAAkBD,EAAME,SAAWF,EAAMG,gBAChErB,IAIR,QAASgC,KACLjB,EAAIkB,QAAUjC,EACdkB,EAAMgB,iBAAiB,SAAWlC,GAAW,GAC7CmC,OAAOD,iBAAiB,QAAUlC,GAAW,GAC7CmC,OAAOD,iBAAiB,SAAUP,GAAW,GAC7CS,SAASF,iBAAiB,mBAAoBlC,GAAY,GAG9D,QAASqC,KACL,MAAQ,kBAAsBtB,GAAIkB,QAGtC,QAASK,KACL1B,EAAwBG,EAAIwB,qBAAqB,QACjDjB,EAAwBkB,MAAMC,UAAU1B,IAAI2B,KAAK9B,EAAOY,GACxDN,EAAwBkB,SAASO,cAAc,gBAAgB5B,EAAI6B,KAAK,MAI5E,GAEI7B,GAAQ8B,KACRjC,EAAQ,KAAMU,EAAwB,KAAMJ,EAAQ,KAAMW,EAAQ,IAEjEQ,KAKDtB,EAAIkB,WAJJK,IACAN,IACAD,KAQR,QAASe,KACL,QAASC,GAAKC,GACV,IAAIA,EAAQC,QACR,KAAM,IAAIC,WAAU,oCACjB,IAAI,QAAUF,EAAQC,QAAQE,cACjC,KAAM,IAAID,WAAU,8BAA8BF,EAAQC,QAAQ,KAGtElD,GAAc2C,KAAKM,GAGvB,MAAO,UAAyBI,GAC5B,aAAc,IACV,IAAK,YACL,IAAK,SACDZ,MAAMC,UAAUlB,QAAQmB,KAAKN,SAASiB,iBAAiBD,GAAQ,OAAOL,EACtE,MACJ,KAAK,SACDA,EAAKK,EACL,MACJ,SACI,KAAM,IAAIF,WAAU,+BAAgCE,GAAO,QAKrD,kBAAXE,SAAyBA,OAAOC,IACvCD,UAAUR,GACe,gBAAXU,SAAiD,gBAAnBA,QAAOC,QACnDD,OAAOC,QAAUX,IAEjBX,OAAOuB,eAAiBZ,IAIzB,UAAYX,UACXwB,OAAOC,GAAGF,eAAiB,WACvB,MAAOb,MAAKgB,OAAO,OAAOC,KAAK/D,GAAegE"}
\ No newline at end of file
diff --git a/js/imageMapResizer.min.js b/js/imageMapResizer.min.js
index 9db4946..a84e045 100644
--- a/js/imageMapResizer.min.js
+++ b/js/imageMapResizer.min.js
@@ -1,8 +1,8 @@
-/*! Image Map Resizer (imageMapResizer.min.js ) - v0.5.3 - 2015-04-21
+/*! Image Map Resizer (imageMapResizer.min.js ) - v1.0.0 - 2015-10-02
* Desc: Resize HTML imageMap to scaled image.
* Copyright: (c) 2015 David J. Bradshaw - dave@bradshaw.net
* License: MIT
*/
-!function(){"use strict";function a(){function a(){function a(a){function c(a){return a*b[1===(d=1-d)?"width":"height"]}var d=0;return a.split(",").map(Number).map(c).map(Math.floor).join(",")}for(var b={width:i.width/j.width,height:i.height/j.height},c=0;g>c;c++)f[c].coords=a(h[c])}function b(){var b=null,c=null;j.onload=function(){b=i.width,c=i.height,(b!==j.width||c!==j.height)&&a()},i.onload=function(){null!==b&&i.width!==b&&a()},j.src=i.src}function c(){function b(){clearTimeout(k),k=setTimeout(a,250)}window.addEventListener?window.addEventListener("resize",b,!1):window.attachEvent&&window.attachEvent("onresize",b)}function d(a){return a.coords.replace(/ *, */g,",").replace(/ +/g,",")}var e=this,f=e.getElementsByTagName("area"),g=f.length,h=Array.prototype.map.call(f,d),i=document.querySelector('img[usemap="#'+e.name+'"]'),j=new Image,k=null;b(),c()}function b(){function b(b){if(!b.tagName)throw new TypeError("Object is not a valid DOM element");if("MAP"!==b.tagName.toUpperCase())throw new TypeError("Expected