@@ -2,30 +2,27 @@ angular.module('ui.scroll.jqlite', ['ui.scroll'])
22 . service ( 'jqLiteExtras' , [
33 '$log' ,
44 '$window' ,
5- function ( console , window ) {
5+ ( console , window ) => {
66 return {
7- registerFor : function ( element ) {
8- var convertToPx , css , getMeasurements , getStyle , getWidthHeight , isWindow , scrollTo ;
7+ registerFor : ( element ) => {
8+ var convertToPx , css , getStyle , isWindow ;
99 // angular implementation blows up if elem is the window
1010 css = angular . element . prototype . css ;
11+
1112 element . prototype . css = function ( name , value ) {
12- var elem , self ;
13- self = this ;
14- elem = self [ 0 ] ;
13+ let self = this ;
14+ let elem = self [ 0 ] ;
1515 if ( ! ( ! elem || elem . nodeType === 3 || elem . nodeType === 8 || ! elem . style ) ) {
1616 return css . call ( self , name , value ) ;
1717 }
1818 } ;
1919
2020 // as defined in angularjs v1.0.5
21- isWindow = function ( obj ) {
22- return obj && obj . document && obj . location && obj . alert && obj . setInterval ;
23- } ;
21+ isWindow = ( obj ) => obj && obj . document && obj . location && obj . alert && obj . setInterval ;
2422
25- scrollTo = function ( self , direction , value ) {
26- var elem , method , preserve , prop , ref ;
27- elem = self [ 0 ] ;
28- ref = {
23+ function scrollTo ( self , direction , value ) {
24+ let elem = self [ 0 ] ;
25+ let [ method , prop , preserve ] = {
2926 top : [
3027 'scrollTop' ,
3128 'pageYOffset' ,
@@ -36,72 +33,62 @@ angular.module('ui.scroll.jqlite', ['ui.scroll'])
3633 'pageXOffset' ,
3734 'scrollTop'
3835 ]
39- } [ direction ] , method = ref [ 0 ] , prop = ref [ 1 ] , preserve = ref [ 2 ] ;
36+ } [ direction ] ;
37+
4038 if ( isWindow ( elem ) ) {
4139 if ( angular . isDefined ( value ) ) {
4240 return elem . scrollTo ( self [ preserve ] . call ( self ) , value ) ;
43- } else {
44- if ( prop in elem ) {
45- return elem [ prop ] ;
46- } else {
47- return elem . document . documentElement [ method ] ;
48- }
4941 }
42+
43+ return ( prop in elem ) ? elem [ prop ] : elem . document . documentElement [ method ] ;
5044 } else {
5145 if ( angular . isDefined ( value ) ) {
52- return elem [ method ] = value ;
53- } else {
54- return elem [ method ] ;
46+ elem [ method ] = value ;
5547 }
48+
49+ return elem [ method ] ;
5650 }
57- } ;
51+ }
5852
5953 if ( window . getComputedStyle ) {
60- getStyle = function ( elem ) {
61- return window . getComputedStyle ( elem , null ) ;
62- } ;
63- convertToPx = function ( elem , value ) {
64- return parseFloat ( value ) ;
65- } ;
54+ getStyle = ( elem ) => window . getComputedStyle ( elem , null ) ;
55+ convertToPx = ( elem , value ) => parseFloat ( value ) ;
6656 } else {
67- getStyle = function ( elem ) {
68- return elem . currentStyle ;
69- } ;
70- convertToPx = function ( elem , value ) {
71- var core_pnum , left , result , rnumnonpx , rs , rsLeft , style ;
72- core_pnum = / [ + - ] ? (?: \d * \. | ) \d + (?: [ e E ] [ + - ] ? \d + | ) / . source ;
73- rnumnonpx = new RegExp ( '^(' + core_pnum + ')(?!px)[a-z%]+$' , 'i' ) ;
57+ getStyle = ( elem ) => elem . currentStyle ;
58+ convertToPx = ( elem , value ) => {
59+ let left , result , rs , rsLeft , style ;
60+ let core_pnum = / [ + - ] ? (?: \d * \. | ) \d + (?: [ e E ] [ + - ] ? \d + | ) / . source ;
61+ let rnumnonpx = new RegExp ( '^(' + core_pnum + ')(?!px)[a-z%]+$' , 'i' ) ;
62+
7463 if ( ! rnumnonpx . test ( value ) ) {
7564 return parseFloat ( value ) ;
76- } else {
77- // ported from JQuery
78- style = elem . style ;
79- left = style . left ;
80- rs = elem . runtimeStyle ;
81- rsLeft = rs && rs . left ;
82- if ( rs ) {
83- rs . left = style . left ;
84- }
85- // put in the new values to get a computed style out
86- style . left = value ;
87- result = style . pixelLeft ;
88- style . left = left ;
89- if ( rsLeft ) {
90- rs . left = rsLeft ;
91- }
92- return result ;
9365 }
66+
67+ // ported from JQuery
68+ style = elem . style ;
69+ left = style . left ;
70+ rs = elem . runtimeStyle ;
71+ rsLeft = rs && rs . left ;
72+ if ( rs ) {
73+ rs . left = style . left ;
74+ }
75+ // put in the new values to get a computed style out
76+ style . left = value ;
77+ result = style . pixelLeft ;
78+ style . left = left ;
79+ if ( rsLeft ) {
80+ rs . left = rsLeft ;
81+ }
82+ return result ;
9483 } ;
9584 }
9685
97- getMeasurements = function ( elem , measure ) {
98- var base , borderA , borderB , computedMarginA , computedMarginB , computedStyle , dirA , dirB , marginA , marginB , paddingA , paddingB , ref ;
86+ function getMeasurements ( elem , measure ) {
87+ let base , borderA , borderB , computedMarginA , computedMarginB , computedStyle , dirA , dirB , marginA , marginB , paddingA , paddingB ;
9988
10089 if ( isWindow ( elem ) ) {
101- base = document . documentElement [ {
102- height : 'clientHeight' ,
103- width : 'clientWidth'
104- } [ measure ] ] ;
90+ base = document . documentElement [ { height : 'clientHeight' , width : 'clientWidth' } [ measure ] ] ;
91+
10592 return {
10693 base : base ,
10794 padding : 0 ,
@@ -111,7 +98,11 @@ angular.module('ui.scroll.jqlite', ['ui.scroll'])
11198 }
11299
113100 // Start with offset property
114- ref = {
101+ [
102+ base ,
103+ dirA ,
104+ dirB
105+ ] = {
115106 width : [
116107 elem . offsetWidth ,
117108 'Left' ,
@@ -122,7 +113,7 @@ angular.module('ui.scroll.jqlite', ['ui.scroll'])
122113 'Top' ,
123114 'Bottom'
124115 ]
125- } [ measure ] , base = ref [ 0 ] , dirA = ref [ 1 ] , dirB = ref [ 2 ] ;
116+ } [ measure ] ;
126117
127118 computedStyle = getStyle ( elem ) ;
128119 paddingA = convertToPx ( elem , computedStyle [ 'padding' + dirA ] ) || 0 ;
@@ -145,41 +136,42 @@ angular.module('ui.scroll.jqlite', ['ui.scroll'])
145136 border : borderA + borderB ,
146137 margin : marginA + marginB
147138 } ;
148- } ;
139+ }
149140
150- getWidthHeight = function ( elem , direction , measure ) {
151- var computedStyle , measurements , result ;
141+ function getWidthHeight ( elem , direction , measure ) {
142+ let computedStyle , result ;
152143
153- measurements = getMeasurements ( elem , direction ) ;
144+ let measurements = getMeasurements ( elem , direction ) ;
154145
155146 if ( measurements . base > 0 ) {
156147 return {
157148 base : measurements . base - measurements . padding - measurements . border ,
158149 outer : measurements . base ,
159150 outerfull : measurements . base + measurements . margin
160151 } [ measure ] ;
161- } else {
162- // Fall back to computed then uncomputed css if necessary
163- computedStyle = getStyle ( elem ) ;
164- result = computedStyle [ direction ] ;
165- if ( result < 0 || result === null ) {
166- result = elem . style [ direction ] || 0 ;
167- }
152+ }
168153
169- // Normalize "", auto, and prepare for extra
170- result = parseFloat ( result ) || 0 ;
154+ // Fall back to computed then uncomputed css if necessary
155+ computedStyle = getStyle ( elem ) ;
156+ result = computedStyle [ direction ] ;
171157
172- return {
173- base : result - measurements . padding - measurements . border ,
174- outer : result ,
175- outerfull : result + measurements . padding + measurements . border + measurements . margin
176- } [ measure ] ;
158+ if ( result < 0 || result === null ) {
159+ result = elem . style [ direction ] || 0 ;
177160 }
178- } ;
161+
162+ // Normalize "", auto, and prepare for extra
163+ result = parseFloat ( result ) || 0 ;
164+
165+ return {
166+ base : result - measurements . padding - measurements . border ,
167+ outer : result ,
168+ outerfull : result + measurements . padding + measurements . border + measurements . margin
169+ } [ measure ] ;
170+ }
179171
180172 // define missing methods
181173 return angular . forEach ( {
182- before : function ( newElem ) {
174+ before ( newElem ) {
183175 var children , elem , i , j , parent , ref , self ;
184176 self = this ;
185177 elem = self [ 0 ] ;
@@ -197,7 +189,7 @@ angular.module('ui.scroll.jqlite', ['ui.scroll'])
197189 throw new Error ( 'invalid DOM structure ' + elem . outerHTML ) ;
198190 }
199191 } ,
200- height : function ( value ) {
192+ height ( value ) {
201193 var self ;
202194 self = this ;
203195 if ( angular . isDefined ( value ) ) {
@@ -209,54 +201,57 @@ angular.module('ui.scroll.jqlite', ['ui.scroll'])
209201 return getWidthHeight ( this [ 0 ] , 'height' , 'base' ) ;
210202 }
211203 } ,
212- outerHeight : function ( option ) {
204+ outerHeight ( option ) {
213205 return getWidthHeight ( this [ 0 ] , 'height' , option ? 'outerfull' : 'outer' ) ;
214206 } ,
215207
216208 /*
217209 The offset setter method is not implemented
218210 */
219- offset : function ( value ) {
220- var box , doc , docElem , elem , self , win ;
221- self = this ;
211+ offset ( value ) {
212+ let docElem , win ;
213+ let self = this ;
214+ let box = {
215+ top : 0 ,
216+ left : 0
217+ } ;
218+ let elem = self [ 0 ] ;
219+ let doc = elem && elem . ownerDocument ;
220+
222221 if ( arguments . length ) {
223- if ( value === void 0 ) {
222+ if ( value === undefined ) {
224223 return self ;
225- } else {
226- // TODO: implement setter
227- throw new Error ( 'offset setter method is not implemented' ) ;
228224 }
225+ // TODO: implement setter
226+ throw new Error ( 'offset setter method is not implemented' ) ;
229227 }
230- box = {
231- top : 0 ,
232- left : 0
233- } ;
234- elem = self [ 0 ] ;
235- doc = elem && elem . ownerDocument ;
228+
236229 if ( ! doc ) {
237230 return ;
238231 }
232+
239233 docElem = doc . documentElement ;
240234
241235 // TODO: Make sure it's not a disconnected DOM node
242236
243237 if ( elem . getBoundingClientRect != null ) {
244238 box = elem . getBoundingClientRect ( ) ;
245239 }
240+
246241 win = doc . defaultView || doc . parentWindow ;
247242
248243 return {
249244 top : box . top + ( win . pageYOffset || docElem . scrollTop ) - ( docElem . clientTop || 0 ) ,
250245 left : box . left + ( win . pageXOffset || docElem . scrollLeft ) - ( docElem . clientLeft || 0 )
251246 } ;
252247 } ,
253- scrollTop : function ( value ) {
248+ scrollTop ( value ) {
254249 return scrollTo ( this , 'top' , value ) ;
255250 } ,
256- scrollLeft : function ( value ) {
251+ scrollLeft ( value ) {
257252 return scrollTo ( this , 'left' , value ) ;
258253 }
259- } , function ( value , key ) {
254+ } , ( value , key ) => {
260255 if ( ! element . prototype [ key ] ) {
261256 return element . prototype [ key ] = value ;
262257 }
0 commit comments