Skip to content

Commit 57ee515

Browse files
Release v1.0.0
2 parents edb8c23 + ac379ba commit 57ee515

11 files changed

+57
-134
lines changed

README.md

+3-10
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,12 @@ $(document).ready(function() {
3939
###Example
4040
http://davidjbradshaw.com/imagemap-resizer/example/
4141

42-
### A note on IE8 and below
42+
### IE8 Support
4343

44-
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.
45-
46-
```html
47-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
48-
<!--[if lte IE 8]>
49-
<script type="text/javascript" src="js/ie8.polyfil.min.js"></script>
50-
<![endif]-->
51-
```
44+
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.
5245

5346
### License
54-
Copyright &copy; 2014 [David J. Bradshaw](https://github.com/davidjbradshaw).
47+
Copyright &copy; 2014-15 [David J. Bradshaw](https://github.com/davidjbradshaw).
5548
Licensed under the [MIT license](http://opensource.org/licenses/MIT).
5649

5750
[![NPM](https://nodei.co/npm/image-map-resizer.png)](https://nodei.co/npm/image-map-resizer/)

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "image-map-resizer",
3-
"version": "0.5.4",
3+
"version": "1.0.0",
44
"homepage": "https://github.com/davidjbradshaw/image-map-resizer",
55
"authors": [
66
"David J. Bradshaw <[email protected]>"

gruntfile.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,6 @@ module.exports = function(grunt) {
5353
},
5454
src: ['js/imageMapResizer.js'],
5555
dest: 'js/imageMapResizer.min.js',
56-
},
57-
ie8: {
58-
options:{
59-
sourceMapName: 'js/ie8.polyfil.map'
60-
},
61-
src: ['js/ie8.polyfil.js'],
62-
dest: 'js/ie8.polyfil.min.js',
6356
}
6457
},
6558

@@ -115,7 +108,7 @@ module.exports = function(grunt) {
115108
grunt.registerTask('notest', ['jshint','uglify']);
116109
grunt.registerTask('test', ['jshint','qunit']);
117110

118-
grunt.registerTask('postBump',['bump-commit','shell']);
111+
grunt.registerTask('postBump',['uglify','bump-commit','shell']);
119112
grunt.registerTask('patch', ['default','bump-only:patch','postBump']);
120113
grunt.registerTask('minor', ['default','bump-only:minor','postBump']);
121114
grunt.registerTask('major', ['default','bump-only:major','postBump']);

imageMapResizer.jquery.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"resize",
1212
"design"
1313
],
14-
"version": "0.5.4",
14+
"version": "1.0.0",
1515
"author": {
1616
"name": "David J. Bradshaw",
1717
"email": "[email protected]"

js/ie8.polyfil.js

-48
This file was deleted.

js/ie8.polyfil.map

-1
This file was deleted.

js/ie8.polyfil.min.js

-2
This file was deleted.

js/imageMapResizer.js

+46-59
Original file line numberDiff line numberDiff line change
@@ -10,84 +10,72 @@
1010
function scaleImageMap(){
1111

1212
function resizeMap() {
13-
function resizeAreaTag(cachedAreaCoords){
14-
function scaleCoord(e){
15-
return e * scallingFactor[(1===(isWidth = 1-isWidth) ? 'width' : 'height')];
13+
function resizeAreaTag(cachedAreaCoords,idx){
14+
function scale(coord){
15+
var dimension = ( 1 === (isWidth = 1-isWidth) ? 'width' : 'height' );
16+
return Math.floor(Number(coord) * scallingFactor[dimension]);
1617
}
1718

1819
var isWidth = 0;
1920

20-
return cachedAreaCoords.split(',').map(Number).map(scaleCoord).map(Math.floor).join(',');
21+
areas[idx].coords = cachedAreaCoords.split(',').map(scale).join(',');
2122
}
2223

2324
var scallingFactor = {
24-
width : displayedImage.width / sourceImage.width,
25-
height : displayedImage.height / sourceImage.height
25+
width : image.width / image.naturalWidth,
26+
height : image.height / image.naturalHeight
2627
};
2728

28-
for (var i=0; i < areasLen ; i++) {
29-
areas[i].coords = resizeAreaTag(cachedAreaCoordsArray[i]);
30-
}
29+
cachedAreaCoordsArray.forEach(resizeAreaTag);
3130
}
3231

33-
function start(){
34-
var
35-
displayedWidth = null,
36-
displayedHeight = null;
37-
38-
//WebKit asyncs image loading, so we have to catch the load event.
39-
sourceImage.onload = function sourceImageOnLoadF(){
40-
displayedWidth = displayedImage.width;
41-
displayedHeight = displayedImage.height;
42-
43-
if ((displayedWidth !== sourceImage.width) || (displayedHeight !== sourceImage.height)) {
44-
resizeMap();
45-
}
46-
};
47-
48-
//IE11 can late load this image, so make sure we have the correct sizes (#10)
49-
displayedImage.onload = function() {
50-
if (null !== displayedWidth && displayedImage.width !== displayedWidth) {
51-
resizeMap();
52-
}
53-
};
32+
function getCoords(e){
33+
//Normalize coord-string to csv format without any space chars
34+
return e.coords.replace(/ *, */g,',').replace(/ +/g,',');
35+
}
5436

55-
//Make copy of image, so we can get the actual size measurements
56-
sourceImage.src = displayedImage.src;
37+
function debounce() {
38+
clearTimeout(timer);
39+
timer = setTimeout(resizeMap, 250);
5740
}
5841

59-
function listenForResize(){
60-
function debounce() {
61-
clearTimeout(timer);
62-
timer = setTimeout(resizeMap, 250);
42+
function start(){
43+
if ((image.width !== image.naturalWidth) || (image.height !== image.naturalHeight)) {
44+
resizeMap();
6345
}
64-
if (window.addEventListener) { window.addEventListener('resize', debounce, false); }
65-
else if (window.attachEvent) { window.attachEvent('onresize', debounce); }
6646
}
6747

68-
function listenForFocus(){
69-
if (window.addEventListener) { window.addEventListener('focus', resizeMap, false); }
70-
else if (window.attachEvent) { window.attachEvent('onfocus', resizeMap); }
48+
function attach(){
49+
map._resize = resizeMap; //Bind resize method to HTML map element
50+
image.addEventListener('onload', resizeMap, false); //Detect late image loads in IE11
51+
window.addEventListener('focus', resizeMap, false); //Cope with window being resized whilst on another tab
52+
window.addEventListener('resize', debounce, false);
53+
document.addEventListener('fullscreenchange', resizeMap, false);
7154
}
7255

73-
function getCoords(e){
74-
// normalize coord-string to csv format without any space chars
75-
return e.coords.replace(/ *, */g,',').replace(/ +/g,',');
56+
function beenHere(){
57+
return ('function' === typeof map._resize);
58+
}
59+
60+
function setup(){
61+
areas = map.getElementsByTagName('area');
62+
cachedAreaCoordsArray = Array.prototype.map.call(areas, getCoords);
63+
image = document.querySelector('img[usemap="#'+map.name+'"]');
64+
7665
}
7766

7867
var
7968
/*jshint validthis:true */
80-
map = this,
81-
areas = map.getElementsByTagName('area'),
82-
areasLen = areas.length,
83-
cachedAreaCoordsArray = Array.prototype.map.call(areas, getCoords),
84-
displayedImage = document.querySelector('img[usemap="#'+map.name+'"]'),
85-
sourceImage = new Image(),
86-
timer = null;
87-
88-
start();
89-
listenForResize();
90-
listenForFocus();
69+
map = this,
70+
areas = null, cachedAreaCoordsArray = null, image = null, timer = null;
71+
72+
if (!beenHere()){
73+
setup();
74+
attach();
75+
start();
76+
} else {
77+
map._resize(); //Already setup, so just resize map
78+
}
9179
}
9280

9381

@@ -113,16 +101,15 @@
113101
init(target);
114102
break;
115103
default:
116-
throw new TypeError('Unexpected data type ('+typeof(target)+').');
104+
throw new TypeError('Unexpected data type ('+typeof target+').');
117105
}
118106
};
119107
}
120108

121-
122109
if (typeof define === 'function' && define.amd) {
123110
define([],factory);
124-
} else if (typeof exports === 'object') { //Node for browserfy
125-
module.exports = factory();
111+
} else if (typeof module === 'object' && typeof module.exports === 'object'){
112+
module.exports = factory(); //Node for browserfy
126113
} else {
127114
window.imageMapResize = factory();
128115
}

js/imageMapResizer.map

+1-1
Original file line numberDiff line numberDiff line change

js/imageMapResizer.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "image-map-resizer",
3-
"version": "0.5.4",
3+
"version": "1.0.0",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/davidjbradshaw/image-map-resizer.git"
@@ -17,6 +17,7 @@
1717
"url": "https://github.com/davidjbradshaw/image-map-resizer.git"
1818
},
1919
"github": "https://github.com/davidjbradshaw/image-map-resizer",
20+
"main": "js/imageMapResizer.min.js",
2021
"dependencies": {},
2122
"devDependencies": {
2223
"grunt": "0.4.1",

0 commit comments

Comments
 (0)