├── .nojekyll ├── powerpuff-girls.fw.jpg ├── LICENSE ├── README.md ├── angular-rwdImageMaps.js └── index.html /.nojekyll: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /powerpuff-girls.fw.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cowglow/AngularJS-rwdImageMaps/HEAD/powerpuff-girls.fw.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Izilla Partners Pty Ltd 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AngularJS RWD Image Maps 2 | 3 | ### An AngularJS Directive that 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 4 | 5 | --- 6 | 7 | #### Usage: 8 | 9 | * If possible, add [correct, unitless](https://dev.w3.org/html5/markup/img.html) `width` and `height` attributes to your image map images. You can override these in CSS to make them responsive. 10 | * Add a link to jQuery in your page, preferably at the bottom just before the closing `` 11 | * Include AngularJS link and angular-rwdImageMaps.js 12 | 13 | --- 14 | 15 | ```html 16 | 17 | or 18 | 19 | ``` 20 | ```js 21 | angular.module('map', ['rwdImageMaps']) 22 | .controller('MapCtrl', function($scope){ 23 | $scope.myTrigger = function(arg){ 24 | alert(arg); 25 | } 26 | }); 27 | ``` 28 | 29 | #### Demo: 30 | Original jQuery Plugin 31 | https://mattstow.com/experiment/responsive-image-maps/rwd-image-maps.html 32 | 33 | AngularJS Directive 34 | https://cowglow.github.io/AngularJS-rwdImageMaps/ 35 | 36 | --- 37 | 38 | Copyright (c) 2012 [Matt Stow](https://mattstow.com) 39 | Licensed under the MIT license *(see [LICENSE](https://github.com/stowball/jQuery-rwdImageMaps/blob/master/LICENSE) for details)* 40 | Minified version created with Online YUI Compressor: https://refresh-sf.com/ 41 | -------------------------------------------------------------------------------- /angular-rwdImageMaps.js: -------------------------------------------------------------------------------- 1 | /* 2 | * rwdImageMaps AngularJS Directive v1.0 3 | * 4 | * 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 5 | * 6 | * Original Copyright (c) 2013 Matt Stow 7 | * https://github.com/stowball/jQuery-rwdImageMaps 8 | * http://mattstow.com 9 | * Licensed under the MIT license 10 | * 11 | * angular-rwdImageMaps.js (by Philip Saa) 12 | * https://github.com/cowglow/ 13 | * @cowglow 14 | */ 15 | 16 | angular.module("rwdImageMaps", []).directive("rwdimgmap", function ($window) { 17 | return { 18 | restrict: "CA", 19 | link: function (scope, element, attrs) { 20 | element.bind("load", function () { 21 | var w = $(element).attr("width"), 22 | h = $(element).attr("height"); 23 | 24 | function resize() { 25 | if (!w || !h) { 26 | var temp = new Image(); 27 | temp.src = $(element).attr("src"); 28 | if (temp.src == undefined) temp.src = $(element).attr("ng-src"); 29 | 30 | if (!w) w = temp.width; 31 | if (!h) h = temp.height; 32 | } 33 | 34 | var wPercent = $(element).width() / 100, 35 | hPercent = $(element).height() / 100, 36 | map = attrs.usemap.replace("#", ""), 37 | c = "coords"; 38 | 39 | angular 40 | .element('map[name="' + map + '"]') 41 | .find("area") 42 | .each(function () { 43 | var $this = $(this); 44 | 45 | if (!$this.data(c)) { 46 | $this.data(c, $this.attr(c)); 47 | } 48 | 49 | var coords = $this.data(c).split(","), 50 | coordsPercent = new Array(coords.length); 51 | 52 | for (var i = 0; i < coordsPercent.length; ++i) { 53 | if (i % 2 === 0) { 54 | coordsPercent[i] = parseInt((coords[i] / w) * 100 * wPercent); 55 | } else { 56 | coordsPercent[i] = parseInt((coords[i] / h) * 100 * hPercent); 57 | } 58 | } 59 | $this.attr(c, coordsPercent.toString()); 60 | }); 61 | } 62 | angular.element($window).resize(resize).trigger("resize"); 63 | }); 64 | }, 65 | }; 66 | }); 67 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Responsive Image Maps AngularJS Directive 6 | 23 | 24 | 25 |
26 |

Responsive Image Maps AngularJS Directive

27 |

28 | Allows image maps to be used in a responsive design by recalculating the 29 | area coordinates to match the actual image size on load and 30 | window.resize. 31 |

32 |

33 | Download the AngularJS Directive from github 36 | or 37 | Download the original jQuery plugin from github 40 |

41 |

This image map was created in minutes with Adobe Fireworks.

42 | 43 | 44 | 52 | 53 | The Powerpuff Girls 61 | Cartoon Network 69 | Buttercup 77 | Blossom 85 | Bubbles 93 | 94 | 95 | 96 |
97 | 98 | 99 | 100 | 101 | 102 | 103 | 112 | 113 | 114 | 126 | 127 | 128 | --------------------------------------------------------------------------------