|
1 /* |
|
2 YUI 3.10.3 (build 2fb5187) |
|
3 Copyright 2013 Yahoo! Inc. All rights reserved. |
|
4 Licensed under the BSD License. |
|
5 http://yuilibrary.com/license/ |
|
6 */ |
|
7 |
|
8 YUI.add('node-style', function (Y, NAME) { |
|
9 |
|
10 (function(Y) { |
|
11 /** |
|
12 * Extended Node interface for managing node styles. |
|
13 * @module node |
|
14 * @submodule node-style |
|
15 */ |
|
16 |
|
17 Y.mix(Y.Node.prototype, { |
|
18 /** |
|
19 * Sets a style property of the node. |
|
20 * Use camelCase (e.g. 'backgroundColor') for multi-word properties. |
|
21 * @method setStyle |
|
22 * @param {String} attr The style attribute to set. |
|
23 * @param {String|Number} val The value. |
|
24 * @chainable |
|
25 */ |
|
26 setStyle: function(attr, val) { |
|
27 Y.DOM.setStyle(this._node, attr, val); |
|
28 return this; |
|
29 }, |
|
30 |
|
31 /** |
|
32 * Sets multiple style properties on the node. |
|
33 * Use camelCase (e.g. 'backgroundColor') for multi-word properties. |
|
34 * @method setStyles |
|
35 * @param {Object} hash An object literal of property:value pairs. |
|
36 * @chainable |
|
37 */ |
|
38 setStyles: function(hash) { |
|
39 Y.DOM.setStyles(this._node, hash); |
|
40 return this; |
|
41 }, |
|
42 |
|
43 /** |
|
44 * Returns the style's current value. |
|
45 * Use camelCase (e.g. 'backgroundColor') for multi-word properties. |
|
46 * @method getStyle |
|
47 * @for Node |
|
48 * @param {String} attr The style attribute to retrieve. |
|
49 * @return {String} The current value of the style property for the element. |
|
50 */ |
|
51 |
|
52 getStyle: function(attr) { |
|
53 return Y.DOM.getStyle(this._node, attr); |
|
54 }, |
|
55 |
|
56 /** |
|
57 * Returns the computed value for the given style property. |
|
58 * Use camelCase (e.g. 'backgroundColor') for multi-word properties. |
|
59 * @method getComputedStyle |
|
60 * @param {String} attr The style attribute to retrieve. |
|
61 * @return {String} The computed value of the style property for the element. |
|
62 */ |
|
63 getComputedStyle: function(attr) { |
|
64 return Y.DOM.getComputedStyle(this._node, attr); |
|
65 } |
|
66 }); |
|
67 |
|
68 /** |
|
69 * Returns an array of values for each node. |
|
70 * Use camelCase (e.g. 'backgroundColor') for multi-word properties. |
|
71 * @method getStyle |
|
72 * @for NodeList |
|
73 * @see Node.getStyle |
|
74 * @param {String} attr The style attribute to retrieve. |
|
75 * @return {Array} The current values of the style property for the element. |
|
76 */ |
|
77 |
|
78 /** |
|
79 * Returns an array of the computed value for each node. |
|
80 * Use camelCase (e.g. 'backgroundColor') for multi-word properties. |
|
81 * @method getComputedStyle |
|
82 * @see Node.getComputedStyle |
|
83 * @param {String} attr The style attribute to retrieve. |
|
84 * @return {Array} The computed values for each node. |
|
85 */ |
|
86 |
|
87 /** |
|
88 * Sets a style property on each node. |
|
89 * Use camelCase (e.g. 'backgroundColor') for multi-word properties. |
|
90 * @method setStyle |
|
91 * @see Node.setStyle |
|
92 * @param {String} attr The style attribute to set. |
|
93 * @param {String|Number} val The value. |
|
94 * @chainable |
|
95 */ |
|
96 |
|
97 /** |
|
98 * Sets multiple style properties on each node. |
|
99 * Use camelCase (e.g. 'backgroundColor') for multi-word properties. |
|
100 * @method setStyles |
|
101 * @see Node.setStyles |
|
102 * @param {Object} hash An object literal of property:value pairs. |
|
103 * @chainable |
|
104 */ |
|
105 |
|
106 // These are broken out to handle undefined return (avoid false positive for |
|
107 // chainable) |
|
108 |
|
109 Y.NodeList.importMethod(Y.Node.prototype, ['getStyle', 'getComputedStyle', 'setStyle', 'setStyles']); |
|
110 })(Y); |
|
111 |
|
112 |
|
113 }, '3.10.3', {"requires": ["dom-style", "node-base"]}); |