]>
git.proxmox.com Git - sencha-touch.git/blob - src/src/draw/modifier/Highlight.js
2 * @class Ext.draw.modifier.Highlight
3 * @extends Ext.draw.modifier.Modifier
5 * Highlight is a modifier that will override the attributes
6 * with its `highlightStyle` attributes when `highlighted` is true.
8 Ext
.define("Ext.draw.modifier.Highlight", {
9 extend
: 'Ext.draw.modifier.Modifier',
10 alias
: 'modifier.highlight',
15 * @cfg {Boolean} enabled 'true' if the highlight is applied.
20 * @cfg {Object} highlightStyle The style attributes of the highlight modifier.
27 applyHighlightStyle: function (style
, oldStyle
) {
28 oldStyle
= oldStyle
|| {};
29 if (this.getSprite()) {
30 Ext
.apply(oldStyle
, this.getSprite().self
.def
.normalize(style
));
32 Ext
.apply(oldStyle
, style
);
40 prepareAttributes: function (attr
) {
41 if (!attr
.hasOwnProperty('highlightOriginal')) {
42 attr
.highlighted
= false;
43 attr
.highlightOriginal
= Ext
.Object
.chain(attr
);
46 this._previous
.prepareAttributes(attr
.highlightOriginal
);
50 updateSprite: function (sprite
, oldSprite
) {
52 if (this.getHighlightStyle()) {
53 this._highlightStyle
= sprite
.self
.def
.normalize(this.getHighlightStyle());
55 this.setHighlightStyle(sprite
.config
.highlightCfg
);
58 // Before attaching to a sprite, register the highlight related
59 // attributes to its definition.
61 // TODO(zhangbei): Unfortunately this will effect all the sprites of the same type.
62 // As the redundant attributes would not effect performance, it is not yet a big problem.
63 var def
= sprite
.self
.def
;
64 this.setSprite(sprite
);
75 "highlight": "highlighted",
76 "highlighting": "highlighted"
89 * Filter modifier changes if overriding source attributes.
90 * @param {Object} attr The source attributes.
91 * @param {Object} changes The modifier changes.
92 * @return {*} The filtered changes.
94 filterChanges: function (attr
, changes
) {
97 original
= attr
.highlightOriginal
,
98 style
= me
.getHighlightStyle();
99 if (attr
.highlighted
) {
100 for (name
in changes
) {
101 if (style
.hasOwnProperty(name
)) {
102 // If it's highlighted, then save the changes to lower level
103 // on overridden attributes.
104 original
[name
] = changes
[name
];
105 delete changes
[name
];
110 for (name
in changes
) {
111 if (name
!== 'highlighted' && original
[name
] === changes
[name
]) {
112 // If it's highlighted, then save the changes to lower level
113 // on overridden attributes.
114 delete changes
[name
];
124 pushDown: function (attr
, changes
) {
125 var style
= this.getHighlightStyle(),
126 original
= attr
.highlightOriginal
,
127 oldHighlighted
, name
;
129 if (changes
.hasOwnProperty('highlighted')) {
130 oldHighlighted
= changes
.highlighted
;
131 // Hide `highlighted` and `highlightStyle` to underlying modifiers.
132 delete changes
.highlighted
;
134 if (this._previous
) {
135 changes
= this._previous
.pushDown(original
, changes
);
137 changes
= this.filterChanges(attr
, changes
);
139 if (oldHighlighted
!== attr
.highlighted
) {
140 if (oldHighlighted
) {
142 // At this time, original should be empty.
143 for (name
in style
) {
144 // If changes[name] just changed the value in lower levels,
145 if (name
in changes
) {
146 original
[name
] = changes
[name
];
148 original
[name
] = attr
[name
];
150 if (original
[name
] !== style
[name
]) {
151 changes
[name
] = style
[name
];
156 for (name
in style
) {
157 if (!(name
in changes
)) {
158 changes
[name
] = original
[name
];
160 delete original
[name
]; // TODO: Need deletion API?
163 changes
.highlighted
= oldHighlighted
;
166 if (this._previous
) {
167 changes
= this._previous
.pushDown(original
, changes
);
169 changes
= this.filterChanges(attr
, changes
);
178 popUp: function (attr
, changes
) {
179 changes
= this.filterChanges(attr
, changes
);
180 Ext
.draw
.modifier
.Modifier
.prototype.popUp
.call(this, attr
, changes
);