11/**
22 * angular-strap
3- * @version v2.1.6 - 2015-01-11
3+ * @version v2.2.0 - 2015-03-10
44 * @link http://mgcrea.github.io/angular-strap
55 * @author Olivier Louvignes ([email protected] ) 66 * @license MIT License, http://www.opensource.org/licenses/MIT
@@ -12,7 +12,8 @@ angular.module('mgcrea.ngStrap.affix', ['mgcrea.ngStrap.helpers.dimensions', 'mg
1212 . provider ( '$affix' , function ( ) {
1313
1414 var defaults = this . defaults = {
15- offsetTop : 'auto'
15+ offsetTop : 'auto' ,
16+ inlineStyles : true
1617 } ;
1718
1819 this . $get = [ "$window" , "debounce" , "dimensions" , function ( $window , debounce , dimensions ) {
@@ -105,11 +106,13 @@ angular.module('mgcrea.ngStrap.affix', ['mgcrea.ngStrap.helpers.dimensions', 'mg
105106
106107 if ( affix === 'top' ) {
107108 unpin = null ;
108- element . css ( 'position' , ( options . offsetParent ) ? '' : 'relative' ) ;
109109 if ( setWidth ) {
110110 element . css ( 'width' , '' ) ;
111111 }
112- element . css ( 'top' , '' ) ;
112+ if ( options . inlineStyles ) {
113+ element . css ( 'position' , ( options . offsetParent ) ? '' : 'relative' ) ;
114+ element . css ( 'top' , '' ) ;
115+ }
113116 } else if ( affix === 'bottom' ) {
114117 if ( options . offsetUnpin ) {
115118 unpin = - ( options . offsetUnpin * 1 ) ;
@@ -122,15 +125,19 @@ angular.module('mgcrea.ngStrap.affix', ['mgcrea.ngStrap.helpers.dimensions', 'mg
122125 if ( setWidth ) {
123126 element . css ( 'width' , '' ) ;
124127 }
125- element . css ( 'position' , ( options . offsetParent ) ? '' : 'relative' ) ;
126- element . css ( 'top' , ( options . offsetParent ) ? '' : ( ( bodyEl [ 0 ] . offsetHeight - offsetBottom - elementHeight - initialOffsetTop ) + 'px' ) ) ;
128+ if ( options . inlineStyles ) {
129+ element . css ( 'position' , ( options . offsetParent ) ? '' : 'relative' ) ;
130+ element . css ( 'top' , ( options . offsetParent ) ? '' : ( ( bodyEl [ 0 ] . offsetHeight - offsetBottom - elementHeight - initialOffsetTop ) + 'px' ) ) ;
131+ }
127132 } else { // affix === 'middle'
128133 unpin = null ;
129134 if ( setWidth ) {
130135 element . css ( 'width' , element [ 0 ] . offsetWidth + 'px' ) ;
131136 }
132- element . css ( 'position' , 'fixed' ) ;
133- element . css ( 'top' , initialAffixTop + 'px' ) ;
137+ if ( options . inlineStyles ) {
138+ element . css ( 'position' , 'fixed' ) ;
139+ element . css ( 'top' , initialAffixTop + 'px' ) ;
140+ }
134141 }
135142
136143 } ;
@@ -144,7 +151,9 @@ angular.module('mgcrea.ngStrap.affix', ['mgcrea.ngStrap.helpers.dimensions', 'mg
144151 $affix . $parseOffsets = function ( ) {
145152 var initialPosition = element . css ( 'position' ) ;
146153 // Reset position to calculate correct offsetTop
147- element . css ( 'position' , ( options . offsetParent ) ? '' : 'relative' ) ;
154+ if ( options . inlineStyles ) {
155+ element . css ( 'position' , ( options . offsetParent ) ? '' : 'relative' ) ;
156+ }
148157
149158 if ( options . offsetTop ) {
150159 if ( options . offsetTop === 'auto' ) {
@@ -175,7 +184,9 @@ angular.module('mgcrea.ngStrap.affix', ['mgcrea.ngStrap.helpers.dimensions', 'mg
175184 }
176185
177186 // Bring back the element's position after calculations
178- element . css ( 'position' , initialPosition ) ;
187+ if ( options . inlineStyles ) {
188+ element . css ( 'position' , initialPosition ) ;
189+ }
179190 } ;
180191
181192 // Private methods
@@ -223,9 +234,14 @@ angular.module('mgcrea.ngStrap.affix', ['mgcrea.ngStrap.helpers.dimensions', 'mg
223234 require : '^?bsAffixTarget' ,
224235 link : function postLink ( scope , element , attr , affixTarget ) {
225236
226- var options = { scope : scope , offsetTop : 'auto' , target : affixTarget ? affixTarget . $element : angular . element ( $window ) } ;
227- angular . forEach ( [ 'offsetTop' , 'offsetBottom' , 'offsetParent' , 'offsetUnpin' ] , function ( key ) {
228- if ( angular . isDefined ( attr [ key ] ) ) options [ key ] = attr [ key ] ;
237+ var options = { scope : scope , target : affixTarget ? affixTarget . $element : angular . element ( $window ) } ;
238+ angular . forEach ( [ 'offsetTop' , 'offsetBottom' , 'offsetParent' , 'offsetUnpin' , 'inlineStyles' ] , function ( key ) {
239+ if ( angular . isDefined ( attr [ key ] ) ) {
240+ var option = attr [ key ] ;
241+ if ( / t r u e / i. test ( option ) ) option = true ;
242+ if ( / f a l s e / i. test ( option ) ) option = false ;
243+ options [ key ] = option ;
244+ }
229245 } ) ;
230246
231247 var affix = $affix ( element , options ) ;
0 commit comments