@@ -29,27 +29,7 @@ function _createClass(Constructor, protoProps, staticProps) {
2929 return Constructor ;
3030}
3131
32- function _toConsumableArray ( arr ) {
33- return _arrayWithoutHoles ( arr ) || _iterableToArray ( arr ) || _nonIterableSpread ( ) ;
34- }
35-
36- function _arrayWithoutHoles ( arr ) {
37- if ( Array . isArray ( arr ) ) {
38- for ( var i = 0 , arr2 = new Array ( arr . length ) ; i < arr . length ; i ++ ) arr2 [ i ] = arr [ i ] ;
39-
40- return arr2 ;
41- }
42- }
43-
44- function _iterableToArray ( iter ) {
45- if ( Symbol . iterator in Object ( iter ) || Object . prototype . toString . call ( iter ) === "[object Arguments]" ) return Array . from ( iter ) ;
46- }
47-
48- function _nonIterableSpread ( ) {
49- throw new TypeError ( "Invalid attempt to spread non-iterable instance" ) ;
50- }
51-
52- var version = "1.1.6" ;
32+ var version = "1.1.7" ;
5333
5434var RESIZE = "resize" ;
5535var LOAD = "load" ;
@@ -70,7 +50,7 @@ function () {
7050 function ImageMap ( selector , wait ) {
7151 _classCallCheck ( this , ImageMap ) ;
7252
73- this . selector = selector instanceof Array ? selector : _toConsumableArray ( document . querySelectorAll ( selector ) ) ;
53+ this . selector = selector instanceof Array ? selector : document . querySelectorAll ( selector ) ;
7454 if ( document . readyState !== COMPLETE ) window . addEventListener ( LOAD , this . update . bind ( this ) ) ; else this . update ( ) ;
7555 window . addEventListener ( RESIZE , this . debounce ( this . update , wait ) . bind ( this ) ) ;
7656 }
@@ -82,13 +62,15 @@ function () {
8262 * Update
8363 */
8464 value : function update ( ) {
85- var _this = this ;
65+ var imgs = this . selector ;
8666
87- this . selector . forEach ( function ( img ) {
67+ for ( var i = 0 ; i < imgs . length ; i ++ ) {
68+ var img = imgs [ i ] ;
8869 if ( img . getAttribute ( USEMAP ) === undefined ) return ;
8970 var newImg = img . cloneNode ( ) ;
90- newImg . addEventListener ( LOAD , _this . handleImageLoad ( img . offsetWidth , img . offsetHeight ) ) ;
91- } ) ;
71+ newImg . addEventListener ( LOAD , this . handleImageLoad ( img . offsetWidth , img . offsetHeight ) ) ;
72+ newImg . src = img . src ; // required for IE
73+ }
9274 }
9375 /**
9476 * Debounce
@@ -100,7 +82,7 @@ function () {
10082 } , {
10183 key : "debounce" ,
10284 value : function debounce ( func ) {
103- var _this2 = this ;
85+ var _this = this ;
10486
10587 var wait = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : 500 ;
10688 var timeout ;
@@ -112,7 +94,7 @@ function () {
11294 window . clearTimeout ( timeout ) ;
11395 timeout = window . setTimeout ( function ( ctx ) {
11496 return func . apply ( ctx , args ) ;
115- } , wait , _this2 ) ;
97+ } , wait , _this ) ;
11698 } ;
11799 }
118100 /**
@@ -133,15 +115,21 @@ function () {
133115 var wPercent = offsetWidth / 100 ;
134116 var hPercent = offsetHeight / 100 ;
135117 var mapName = e . target . getAttribute ( USEMAP ) . replace ( / ^ # / , "" ) ;
118+ var areas = document . querySelectorAll ( ImageMap . genAreaSelector ( mapName ) ) ;
136119
137- _toConsumableArray ( document . querySelectorAll ( ImageMap . genAreaSelector ( mapName ) ) ) . forEach ( function ( area ) {
120+ var _loop = function _loop ( i ) {
121+ var area = areas [ i ] ;
138122 var coordsString = area . dataset [ COORDS ] = area . dataset [ COORDS ] || area . getAttribute ( COORDS ) ;
139123 var coordsArrayOld = coordsString . split ( "," ) ;
140124 var coordsArrayNew = coordsArrayOld . map ( function ( _ , i ) {
141125 return i % 2 === 0 ? Number ( coordsArrayOld [ i ] / w * 100 * wPercent ) : Number ( coordsArrayOld [ i ] / h * 100 * hPercent ) ;
142126 } ) ;
143127 area . setAttribute ( COORDS , coordsArrayNew . toString ( ) ) ;
144- } ) ;
128+ } ;
129+
130+ for ( var i = 0 ; i < areas . length ; i ++ ) {
131+ _loop ( i ) ;
132+ }
145133 } ;
146134 }
147135 } ] , [ {
0 commit comments