11/**
2- * Detect Element Rezise
2+ * Detect Element Resize
33*
44* https://github.com/sdecima/javascript-detect-element-resize
55* Sebastian Decima
66*
7- * Based on the works of Back Alley Coder:
8- * http://www.backalleycoder.com/2013/03/18/cross-browser-event-based-element-resize-detection/
7+ * version: 0.2
98**/
109
1110function addFlowListener ( element , type , fn ) {
@@ -74,17 +73,17 @@ function addResizeListener(element, fn){
7473 matchFlow ( { } ) ;
7574 }
7675 var events = element . _flowEvents || ( element . _flowEvents = [ ] ) ;
77- if ( events . indexOf ( fn ) == - 1 ) events . push ( fn ) ;
76+ if ( indexOf . call ( events , fn ) == - 1 ) events . push ( fn ) ;
7877 if ( ! resize ) element . addEventListener ( 'resize' , fn , false ) ;
7978 element . onresize = function ( e ) {
80- events . forEach ( function ( fn ) {
79+ forEach . call ( events , function ( fn ) {
8180 fn . call ( element , e ) ;
8281 } ) ;
8382 } ;
8483} ;
8584
8685function removeResizeListener ( element , fn ) {
87- var index = element . _flowEvents . indexOf ( fn ) ;
86+ var index = indexOf . call ( element . _flowEvents , fn ) ;
8887 if ( index > - 1 ) element . _flowEvents . splice ( index , 1 ) ;
8988 if ( ! element . _flowEvents . length ) {
9089 var sensor = element . _resizeSensor ;
@@ -97,4 +96,41 @@ function removeResizeListener(element, fn){
9796 delete element . _flowEvents ;
9897 }
9998 element . removeEventListener ( 'resize' , fn ) ;
99+ } ;
100+
101+ /* Array.indexOf for IE < 9 */
102+ var indexOf = function ( needle ) {
103+ if ( typeof Array . prototype . indexOf === 'function' ) {
104+ indexOf = Array . prototype . indexOf ;
105+ } else {
106+ indexOf = function ( needle ) {
107+ var i = - 1 , index = - 1 ;
108+
109+ for ( i = 0 ; i < this . length ; i ++ ) {
110+ if ( this [ i ] === needle ) {
111+ index = i ;
112+ break ;
113+ }
114+ }
115+
116+ return index ;
117+ } ;
118+ }
119+
120+ return indexOf . call ( this , needle ) ;
121+ } ;
122+
123+ /* Array.forEach for IE < 9 */
124+ var forEach = function ( action , that ) {
125+ if ( typeof Array . prototype . forEach === 'function' ) {
126+ forEach = Array . prototype . forEach ;
127+ } else {
128+ forEach = function ( action , that ) {
129+ for ( var i = 0 , n = this . length ; i < n ; i ++ )
130+ if ( i in this )
131+ action . call ( that , this [ i ] , i , this ) ;
132+ } ;
133+ }
134+
135+ return forEach . call ( this , action , that ) ;
100136} ;
0 commit comments