~noskcaj/ubuntu/utopic/jquery/merge

« back to all changes in this revision

Viewing changes to src/css.js

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo Jorge Vieira (metal)
  • Date: 2011-05-29 20:21:27 UTC
  • mfrom: (0.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20110529202127-yo710urpsj87oqnh
Tags: 1.6.1-1
New upstream release (Closes: #628052)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
var ralpha = /alpha\([^)]*\)/i,
4
4
        ropacity = /opacity=([^)]*)/,
5
5
        rdashAlpha = /-([a-z])/ig,
6
 
        rupper = /([A-Z])/g,
 
6
        // fixed for IE9, see #8346
 
7
        rupper = /([A-Z]|^ms)/g,
7
8
        rnumpx = /^-?\d+(?:px)?$/i,
8
9
        rnum = /^-?\d/,
 
10
        rrelNum = /^[+\-]=/,
 
11
        rrelNumFilter = /[^+\-\.\de]+/g,
9
12
 
10
13
        cssShow = { position: "absolute", visibility: "hidden", display: "block" },
11
14
        cssWidth = [ "Left", "Right" ],
56
59
                "fontWeight": true,
57
60
                "opacity": true,
58
61
                "zoom": true,
59
 
                "lineHeight": true
 
62
                "lineHeight": true,
 
63
                "widows": true,
 
64
                "orphans": true
60
65
        },
61
66
 
62
67
        // Add in properties whose names you wish to fix before
74
79
                }
75
80
 
76
81
                // Make sure that we're working with the right name
77
 
                var ret, origName = jQuery.camelCase( name ),
 
82
                var ret, type, origName = jQuery.camelCase( name ),
78
83
                        style = elem.style, hooks = jQuery.cssHooks[ origName ];
79
84
 
80
85
                name = jQuery.cssProps[ origName ] || origName;
81
86
 
82
87
                // Check if we're setting a value
83
88
                if ( value !== undefined ) {
 
89
                        type = typeof value;
 
90
 
84
91
                        // Make sure that NaN and null values aren't set. See: #7116
85
 
                        if ( typeof value === "number" && isNaN( value ) || value == null ) {
 
92
                        if ( type === "number" && isNaN( value ) || value == null ) {
86
93
                                return;
87
94
                        }
88
95
 
 
96
                        // convert relative number strings (+= or -=) to relative numbers. #7345
 
97
                        if ( type === "string" && rrelNum.test( value ) ) {
 
98
                                value = +value.replace( rrelNumFilter, "" ) + parseFloat( jQuery.css( elem, name ) );
 
99
                        }
 
100
 
89
101
                        // If a number was passed in, add 'px' to the (except for certain CSS properties)
90
 
                        if ( typeof value === "number" && !jQuery.cssNumber[ origName ] ) {
 
102
                        if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
91
103
                                value += "px";
92
104
                        }
93
105
 
112
124
        },
113
125
 
114
126
        css: function( elem, name, extra ) {
 
127
                var ret, hooks;
 
128
 
115
129
                // Make sure that we're working with the right name
116
 
                var ret, origName = jQuery.camelCase( name ),
117
 
                        hooks = jQuery.cssHooks[ origName ];
 
130
                name = jQuery.camelCase( name );
 
131
                hooks = jQuery.cssHooks[ name ];
 
132
                name = jQuery.cssProps[ name ] || name;
118
133
 
119
 
                name = jQuery.cssProps[ origName ] || origName;
 
134
                // cssFloat needs a special treatment
 
135
                if ( name === "cssFloat" ) {
 
136
                        name = "float";
 
137
                }
120
138
 
121
139
                // If a hook was provided get the computed value from there
122
140
                if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) {
124
142
 
125
143
                // Otherwise, if a way to get the computed value exists, use that
126
144
                } else if ( curCSS ) {
127
 
                        return curCSS( elem, name, origName );
 
145
                        return curCSS( elem, name );
128
146
                }
129
147
        },
130
148
 
215
233
        jQuery.cssHooks.opacity = {
216
234
                get: function( elem, computed ) {
217
235
                        // IE uses filters for opacity
218
 
                        return ropacity.test((computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "") ?
219
 
                                (parseFloat(RegExp.$1) / 100) + "" :
 
236
                        return ropacity.test( (computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "" ) ?
 
237
                                ( parseFloat( RegExp.$1 ) / 100 ) + "" :
220
238
                                computed ? "1" : "";
221
239
                },
222
240
 
223
241
                set: function( elem, value ) {
224
 
                        var style = elem.style;
 
242
                        var style = elem.style,
 
243
                                currentStyle = elem.currentStyle;
225
244
 
226
245
                        // IE has trouble with opacity if it does not have layout
227
246
                        // Force it by setting the zoom level
228
247
                        style.zoom = 1;
229
248
 
230
249
                        // Set the alpha filter to set the opacity
231
 
                        var opacity = jQuery.isNaN(value) ?
 
250
                        var opacity = jQuery.isNaN( value ) ?
232
251
                                "" :
233
252
                                "alpha(opacity=" + value * 100 + ")",
234
 
                                filter = style.filter || "";
 
253
                                filter = currentStyle && currentStyle.filter || style.filter || "";
235
254
 
236
 
                        style.filter = ralpha.test(filter) ?
237
 
                                filter.replace(ralpha, opacity) :
238
 
                                style.filter + ' ' + opacity;
 
255
                        style.filter = ralpha.test( filter ) ?
 
256
                                filter.replace( ralpha, opacity ) :
 
257
                                filter + " " + opacity;
239
258
                }
240
259
        };
241
260
}
242
261
 
 
262
jQuery(function() {
 
263
        // This hook cannot be added until DOM ready because the support test
 
264
        // for it is not run until after DOM ready
 
265
        if ( !jQuery.support.reliableMarginRight ) {
 
266
                jQuery.cssHooks.marginRight = {
 
267
                        get: function( elem, computed ) {
 
268
                                // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
 
269
                                // Work around by temporarily setting element display to inline-block
 
270
                                var ret;
 
271
                                jQuery.swap( elem, { "display": "inline-block" }, function() {
 
272
                                        if ( computed ) {
 
273
                                                ret = curCSS( elem, "margin-right", "marginRight" );
 
274
                                        } else {
 
275
                                                ret = elem.style.marginRight;
 
276
                                        }
 
277
                                });
 
278
                                return ret;
 
279
                        }
 
280
                };
 
281
        }
 
282
});
 
283
 
243
284
if ( document.defaultView && document.defaultView.getComputedStyle ) {
244
 
        getComputedStyle = function( elem, newName, name ) {
 
285
        getComputedStyle = function( elem, name ) {
245
286
                var ret, defaultView, computedStyle;
246
287
 
247
288
                name = name.replace( rupper, "-$1" ).toLowerCase();