Skip to content

Commit

Permalink
Release v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjbradshaw committed Feb 17, 2014
1 parent 909e7ce commit 443dbb3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Image Map Resize

*This is a simple jQuery plugin to keep a HTML Image Map scaled to the size of an image. It detects the window being resized and updates the co-ordinates of the image map.*
*This is a simple jQuery plugin to keep HTML Image Maps scaled to the size of an image. It detects the window being resized and updates the co-ordinates of the image map.*

### Usage

Expand Down
2 changes: 1 addition & 1 deletion gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(grunt) {
meta: {
banner: '/*! Image Map Resizer (jquery.imageMapResizer.min.js ) - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
' * Desc: Resize HTML imageMap to scalled image.\n' +
' * Desc: Resize HTML imageMap to scaled image.\n' +
' * Copyright: (c) <%= grunt.template.today("yyyy") %> David J. Bradshaw - dave@bradshaw.net\n' +
' * License: MIT\n */\n',

Expand Down
29 changes: 20 additions & 9 deletions js/jquery.imageMapResizer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/*
* Scale html images maps to match scaled images.
/*! Image Map Resizer
* Desc: Resize HTML imageMap to scaled image.
* Copyright: (c) 2014 David J. Bradshaw - dave@bradshaw.net
* License: MIT
*/


(function($){

function setUpImageMaps(){
Expand All @@ -17,8 +20,9 @@
testImage = new Image();

testImage.onload = function(){
imageWidth = testImage.width;
if (sourceImage.width !== imageWidth){
imageWidth = testImage.width;
imageHeight = testImage.height;
if ((sourceImage.width !== imageWidth) || (sourceImage.height !== imageHeight)){
resizeMap();
}
};
Expand All @@ -36,18 +40,24 @@
return $mapImg.width();
}

function getCurrentImageHeight(){
return $mapImg.height();
}

function resizeMap() {
var
i, j, clen,
newCoords = [],
sizeFactor = getCurrentImageWidth() / imageWidth;
sizeFactorWidth = getCurrentImageWidth() / imageWidth;
sizeFactorHeight = getCurrentImageHeight() / imageHeight;

for (i = 0; i < len; i++) {
clen = coords[i].length;
newCoords[i] = [];

for (j = 0; j < clen; j++) {
newCoords[i][j] = parseInt(coords[i][j] * sizeFactor,10);
for (j = 0; j < clen; j+=2) {
newCoords[i][j] = parseInt(coords[i][j] * sizeFactorWidth, 10);
newCoords[i][j+1] = parseInt(coords[i][j+1] * sizeFactorHeight, 10);
}

areas[i].coords = newCoords[i].join(',');
Expand All @@ -61,13 +71,14 @@
areas = map.getElementsByTagName('area'),
len = areas.length,
coords = [],
imageWidth;
imageWidth,
imageHeight;

init();
}

$.fn.imageMapResize = function(){
return this.each(setUpImageMaps);
return this.each(setUpImageMap);
};

})(window.jQuery);
2 changes: 1 addition & 1 deletion js/jquery.imageMapResizer.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions js/jquery.imageMapResizer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 443dbb3

Please sign in to comment.