@@ -217,6 +217,58 @@ test( "css() explicit and relative values", 29, function() {
217217 equal ( $elem . css ( "opacity" ) , "1" , "'+=0.5' on opacity (params)" ) ;
218218} ) ;
219219
220+ test ( "css() non-px relative values (gh-1711)" , 17 , function ( ) {
221+ var cssCurrent ,
222+ units = { } ,
223+ $child = jQuery ( "#nothiddendivchild" ) ,
224+ add = function ( prop , val , unit ) {
225+ var str = ( val < 0 ? "-=" : "+=" ) + Math . abs ( val ) + unit ;
226+ $child . css ( prop , str ) ;
227+ equal (
228+ Math . round ( parseFloat ( $child . css ( prop ) ) ) ,
229+ Math . round ( cssCurrent += val * units [ prop ] [ unit ] ) ,
230+ prop + ": '" + str + "'"
231+ ) ;
232+ } ,
233+ getUnits = function ( prop ) {
234+ units [ prop ] = {
235+ "px" : 1 ,
236+ "em" : parseFloat ( $child . css ( prop , "100em" ) . css ( prop ) ) / 100 ,
237+ "pt" : parseFloat ( $child . css ( prop , "100pt" ) . css ( prop ) ) / 100 ,
238+ "pc" : parseFloat ( $child . css ( prop , "100pc" ) . css ( prop ) ) / 100 ,
239+ "cm" : parseFloat ( $child . css ( prop , "100cm" ) . css ( prop ) ) / 100 ,
240+ "mm" : parseFloat ( $child . css ( prop , "100mm" ) . css ( prop ) ) / 100 ,
241+ "%" : parseFloat ( $child . css ( prop , "100%" ) . css ( prop ) ) / 100
242+ } ;
243+ } ;
244+
245+ jQuery ( "#nothiddendiv" ) . css ( { height : 1 , padding : 0 , width : 400 } ) ;
246+ $child . css ( { height : 1 , padding : 0 } ) ;
247+
248+ getUnits ( "width" ) ;
249+ cssCurrent = parseFloat ( $child . css ( "width" , "50%" ) . css ( "width" ) ) ;
250+ add ( "width" , 25 , "%" ) ;
251+ add ( "width" , - 50 , "%" ) ;
252+ add ( "width" , 10 , "em" ) ;
253+ add ( "width" , 10 , "pt" ) ;
254+ add ( "width" , - 2.3 , "pt" ) ;
255+ add ( "width" , 5 , "pc" ) ;
256+ add ( "width" , - 5 , "em" ) ;
257+ add ( "width" , + 2 , "cm" ) ;
258+ add ( "width" , - 15 , "mm" ) ;
259+ add ( "width" , 21 , "px" ) ;
260+
261+ getUnits ( "lineHeight" ) ;
262+ cssCurrent = parseFloat ( $child . css ( "lineHeight" , "1em" ) . css ( "lineHeight" ) ) ;
263+ add ( "lineHeight" , 2 , "em" ) ;
264+ add ( "lineHeight" , - 10 , "px" ) ;
265+ add ( "lineHeight" , 20 , "pt" ) ;
266+ add ( "lineHeight" , 30 , "pc" ) ;
267+ add ( "lineHeight" , 1 , "cm" ) ;
268+ add ( "lineHeight" , - 20 , "mm" ) ;
269+ add ( "lineHeight" , 50 , "%" ) ;
270+ } ) ;
271+
220272test ( "css(String, Object)" , function ( ) {
221273 expect ( 19 ) ;
222274 var j , div , display , ret , success ;
0 commit comments