2 * @class Ext.ux.Spotlight
3 * UX used to provide a spotlight around a specified component/element.
5 Ext.define('Ext.ux.Spotlight', {
10 * The baseCls for the spotlight elements
12 baseCls: 'x-spotlight',
15 * @cfg animate {Boolean} True to animate the spotlight change
21 * @cfg duration {Integer} The duration of the animation, in milliseconds
27 * @cfg easing {String} The type of easing for the spotlight animatation
34 * True if the spotlight is active on the element
39 * Create all the elements for the spotlight
41 createElements: function() {
42 var body = Ext.getBody();
44 this.right = body.createChild({
47 this.left = body.createChild({
50 this.top = body.createChild({
53 this.bottom = body.createChild({
57 this.all = Ext.create('Ext.CompositeElement', [this.right, this.left, this.top, this.bottom]);
63 show: function(el, callback, scope) {
64 //get the target element
65 this.el = Ext.get(el);
67 //create the elements if they don't already exist
69 this.createElements();
73 //if the spotlight is not active, show it
74 this.all.setDisplayed('');
76 Ext.EventManager.onWindowResize(this.syncSize, this);
77 this.applyBounds(this.animate, false);
79 //if the spotlight is currently active, just move it
80 this.applyBounds(false, false);
87 hide: function(callback, scope) {
88 Ext.EventManager.removeResizeListener(this.syncSize, this);
90 this.applyBounds(this.animate, true);
94 * Resizes the spotlight with the window size.
96 syncSize: function() {
97 this.applyBounds(false, false);
101 * Resizes the spotlight depending on the arguments
102 * @param {Boolean} animate True to animate the changing of the bounds
103 * @param {Boolean} animate True to reverse the animation
105 applyBounds: function(animate, reverse) {
107 box = me.el.getBox();
109 //get the current view width and height
110 var viewWidth = Ext.core.Element.getViewWidth(true);
111 var viewHeight = Ext.core.Element.getViewHeight(true);
117 //where the element should start (if animation)
122 width: (viewWidth - box.right),
139 y: (box.y + box.height),
141 height: (viewHeight - (box.y + box.height)) + 'px'
145 //where the element needs to finish
150 width: (viewWidth - box.right) + 'px',
151 height: (viewHeight - box.y) + 'px'
157 height: (box.y + box.height) + 'px'
162 width: (viewWidth - box.x) + 'px',
167 y: (box.y + box.height),
168 width: (box.x + box.width) + 'px',
169 height: (viewHeight - (box.y + box.height)) + 'px'
173 //reverse the objects
175 var clone = Ext.clone(from);
183 Ext.each(['right', 'left', 'top', 'bottom'], function(side) {
184 me[side].setBox(from[side]);
186 duration: me.duration,
193 Ext.each(['right', 'left', 'top', 'bottom'], function(side) {
194 me[side].setBox(Ext.apply(from[side], to[side]));
201 * Removes all the elements for the spotlight
203 destroy: function() {
204 Ext.destroy(this.right, this.left, this.top, this.bottom);