Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('dom-style-ie', function (Y, NAME) {
2
 
3
var HAS_LAYOUT = 'hasLayout',
4
    PX = 'px',
5
    FILTER = 'filter',
6
    FILTERS = 'filters',
7
    OPACITY = 'opacity',
8
    AUTO = 'auto',
9
 
10
    BORDER_WIDTH = 'borderWidth',
11
    BORDER_TOP_WIDTH = 'borderTopWidth',
12
    BORDER_RIGHT_WIDTH = 'borderRightWidth',
13
    BORDER_BOTTOM_WIDTH = 'borderBottomWidth',
14
    BORDER_LEFT_WIDTH = 'borderLeftWidth',
15
    WIDTH = 'width',
16
    HEIGHT = 'height',
17
    TRANSPARENT = 'transparent',
18
    VISIBLE = 'visible',
19
    GET_COMPUTED_STYLE = 'getComputedStyle',
20
    documentElement = Y.config.doc.documentElement,
21
 
22
    testFeature = Y.Features.test,
23
    addFeature = Y.Features.add,
24
 
25
    // TODO: unit-less lineHeight (e.g. 1.22)
26
    re_unit = /^(\d[.\d]*)+(em|ex|px|gd|rem|vw|vh|vm|ch|mm|cm|in|pt|pc|deg|rad|ms|s|hz|khz|%){1}?/i,
27
 
28
    isIE8 = (Y.UA.ie >= 8),
29
 
30
    _getStyleObj = function(node) {
31
        return node.currentStyle || node.style;
32
    },
33
 
34
    ComputedStyle = {
35
        CUSTOM_STYLES: {},
36
 
37
        get: function(el, property) {
38
            var value = '',
39
                current;
40
 
41
            if (el) {
42
                    current = _getStyleObj(el)[property];
43
 
44
                if (property === OPACITY && Y.DOM.CUSTOM_STYLES[OPACITY]) {
45
                    value = Y.DOM.CUSTOM_STYLES[OPACITY].get(el);
46
                } else if (!current || (current.indexOf && current.indexOf(PX) > -1)) { // no need to convert
47
                    value = current;
48
                } else if (Y.DOM.IE.COMPUTED[property]) { // use compute function
49
                    value = Y.DOM.IE.COMPUTED[property](el, property);
50
                } else if (re_unit.test(current)) { // convert to pixel
51
                    value = ComputedStyle.getPixel(el, property) + PX;
52
                } else {
53
                    value = current;
54
                }
55
            }
56
 
57
            return value;
58
        },
59
 
60
        sizeOffsets: {
61
            width: ['Left', 'Right'],
62
            height: ['Top', 'Bottom'],
63
            top: ['Top'],
64
            bottom: ['Bottom']
65
        },
66
 
67
        getOffset: function(el, prop) {
68
            var current = _getStyleObj(el)[prop],                     // value of "width", "top", etc.
69
                capped = prop.charAt(0).toUpperCase() + prop.substr(1), // "Width", "Top", etc.
70
                pixel = 'pixel' + capped,                               // "pixelWidth", "pixelTop", etc.
71
                sizeOffsets = ComputedStyle.sizeOffsets[prop],
72
                mode = el.ownerDocument.compatMode,
73
                value = '';
74
 
75
            // IE pixelWidth incorrect for percent
76
            // manually compute by subtracting padding and border from offset size
77
            // NOTE: clientWidth/Height (size minus border) is 0 when current === AUTO so offsetHeight is used
78
            // reverting to auto from auto causes position stacking issues (old impl)
79
            if (current === AUTO || current.indexOf('%') > -1) {
80
                value = el['offset' + capped];
81
 
82
                if (mode !== 'BackCompat') {
83
                    if (sizeOffsets[0]) {
84
                        value -= ComputedStyle.getPixel(el, 'padding' + sizeOffsets[0]);
85
                        value -= ComputedStyle.getBorderWidth(el, 'border' + sizeOffsets[0] + 'Width', 1);
86
                    }
87
 
88
                    if (sizeOffsets[1]) {
89
                        value -= ComputedStyle.getPixel(el, 'padding' + sizeOffsets[1]);
90
                        value -= ComputedStyle.getBorderWidth(el, 'border' + sizeOffsets[1] + 'Width', 1);
91
                    }
92
                }
93
 
94
            } else { // use style.pixelWidth, etc. to convert to pixels
95
                // need to map style.width to currentStyle (no currentStyle.pixelWidth)
96
                if (!el.style[pixel] && !el.style[prop]) {
97
                    el.style[prop] = current;
98
                }
99
                value = el.style[pixel];
100
 
101
            }
102
            return value + PX;
103
        },
104
 
105
        borderMap: {
106
            thin: (isIE8) ? '1px' : '2px',
107
            medium: (isIE8) ? '3px': '4px',
108
            thick: (isIE8) ? '5px' : '6px'
109
        },
110
 
111
        getBorderWidth: function(el, property, omitUnit) {
112
            var current = el.currentStyle[property];
113
 
114
            if (current.indexOf(PX) < 0) { // look up keywords if a border exists
115
                if (ComputedStyle.borderMap[current] &&
116
                        el.currentStyle.borderStyle !== 'none') {
117
                    current = ComputedStyle.borderMap[current];
118
                } else { // otherwise no border (default is "medium")
119
                    current = 0;
120
                }
121
            }
122
            return (omitUnit) ? parseFloat(current) : current;
123
        },
124
 
125
        getPixel: function(node, att) {
126
            // use pixelRight to convert to px
127
            var val = null,
128
                style = _getStyleObj(node),
129
                styleRight = style.right,
130
                current = style[att];
131
 
132
            node.style.right = current;
133
            val = node.style.pixelRight;
134
            node.style.right = styleRight; // revert
135
 
136
            return val;
137
        },
138
 
139
        getMargin: function(node, att) {
140
            var val,
141
                style = _getStyleObj(node);
142
 
143
            if (style[att] === AUTO) {
144
                val = 0;
145
            } else {
146
                val = ComputedStyle.getPixel(node, att);
147
            }
148
            return val + PX;
149
        },
150
 
151
        getVisibility: function(node, att) {
152
            var current;
153
            while ( (current = node.currentStyle) && current[att] === 'inherit') { // NOTE: assignment in test
154
                node = node.parentNode;
155
            }
156
            return (current) ? current[att] : VISIBLE;
157
        },
158
 
159
        getColor: function(node, att) {
160
            var current = _getStyleObj(node)[att];
161
 
162
            if (!current || current === TRANSPARENT) {
163
                Y.DOM.elementByAxis(node, 'parentNode', null, function(parent) {
164
                    current = _getStyleObj(parent)[att];
165
                    if (current && current !== TRANSPARENT) {
166
                        node = parent;
167
                        return true;
168
                    }
169
                });
170
            }
171
 
172
            return Y.Color.toRGB(current);
173
        },
174
 
175
        getBorderColor: function(node, att) {
176
            var current = _getStyleObj(node),
177
                val = current[att] || current.color;
178
            return Y.Color.toRGB(Y.Color.toHex(val));
179
        }
180
    },
181
 
182
    //fontSize: getPixelFont,
183
    IEComputed = {};
184
 
185
addFeature('style', 'computedStyle', {
186
    test: function() {
187
        return 'getComputedStyle' in Y.config.win;
188
    }
189
});
190
 
191
addFeature('style', 'opacity', {
192
    test: function() {
193
        return 'opacity' in documentElement.style;
194
    }
195
});
196
 
197
addFeature('style', 'filter', {
198
    test: function() {
199
        return 'filters' in documentElement;
200
    }
201
});
202
 
203
// use alpha filter for IE opacity
204
if (!testFeature('style', 'opacity') && testFeature('style', 'filter')) {
205
    Y.DOM.CUSTOM_STYLES[OPACITY] = {
206
        get: function(node) {
207
            var val = 100;
208
            try { // will error if no DXImageTransform
209
                val = node[FILTERS]['DXImageTransform.Microsoft.Alpha'][OPACITY];
210
 
211
            } catch(e) {
212
                try { // make sure its in the document
213
                    val = node[FILTERS]('alpha')[OPACITY];
214
                } catch(err) {
215
                }
216
            }
217
            return val / 100;
218
        },
219
 
220
        set: function(node, val, style) {
221
            var current,
222
                styleObj = _getStyleObj(node),
223
                currentFilter = styleObj[FILTER];
224
 
225
            style = style || node.style;
226
            if (val === '') { // normalize inline style behavior
227
                current = (OPACITY in styleObj) ? styleObj[OPACITY] : 1; // revert to original opacity
228
                val = current;
229
            }
230
 
231
            if (typeof currentFilter === 'string') { // in case not appended
232
                style[FILTER] = currentFilter.replace(/alpha([^)]*\))/gi, '') +
233
                        ((val <= 1) ? 'alpha(' + OPACITY + '=' + val * 100 + ')' : '');
234
 
235
                if (!style[FILTER]) {
236
                    style.removeAttribute(FILTER);
237
                }
238
 
239
                if (!styleObj[HAS_LAYOUT]) {
240
                    style.zoom = 1; // needs layout
241
                }
242
            }
243
        }
244
    };
245
}
246
 
247
try {
248
    Y.config.doc.createElement('div').style.height = '-1px';
249
} catch(e) { // IE throws error on invalid style set; trap common cases
250
    Y.DOM.CUSTOM_STYLES.height = {
251
        set: function(node, val, style) {
252
            var floatVal = parseFloat(val);
253
            if (floatVal >= 0 || val === 'auto' || val === '') {
254
                style.height = val;
255
            } else {
256
            }
257
        }
258
    };
259
 
260
    Y.DOM.CUSTOM_STYLES.width = {
261
        set: function(node, val, style) {
262
            var floatVal = parseFloat(val);
263
            if (floatVal >= 0 || val === 'auto' || val === '') {
264
                style.width = val;
265
            } else {
266
            }
267
        }
268
    };
269
}
270
 
271
if (!testFeature('style', 'computedStyle')) {
272
    // TODO: top, right, bottom, left
273
    IEComputed[WIDTH] = IEComputed[HEIGHT] = ComputedStyle.getOffset;
274
 
275
    IEComputed.color = IEComputed.backgroundColor = ComputedStyle.getColor;
276
 
277
    IEComputed[BORDER_WIDTH] = IEComputed[BORDER_TOP_WIDTH] = IEComputed[BORDER_RIGHT_WIDTH] =
278
            IEComputed[BORDER_BOTTOM_WIDTH] = IEComputed[BORDER_LEFT_WIDTH] =
279
            ComputedStyle.getBorderWidth;
280
 
281
    IEComputed.marginTop = IEComputed.marginRight = IEComputed.marginBottom =
282
            IEComputed.marginLeft = ComputedStyle.getMargin;
283
 
284
    IEComputed.visibility = ComputedStyle.getVisibility;
285
    IEComputed.borderColor = IEComputed.borderTopColor =
286
            IEComputed.borderRightColor = IEComputed.borderBottomColor =
287
            IEComputed.borderLeftColor = ComputedStyle.getBorderColor;
288
 
289
    Y.DOM[GET_COMPUTED_STYLE] = ComputedStyle.get;
290
 
291
    Y.namespace('DOM.IE');
292
    Y.DOM.IE.COMPUTED = IEComputed;
293
    Y.DOM.IE.ComputedStyle = ComputedStyle;
294
}
295
 
296
 
297
}, '3.18.1', {"requires": ["dom-style", "color-base"]});