Spotlight.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-ux-Spotlight'>/**
  19. </span> * @class Ext.ux.Spotlight
  20. * UX used to provide a spotlight around a specified component/element.
  21. */
  22. Ext.define('Ext.ux.Spotlight', {
  23. extend: 'Object',
  24. <span id='Ext-ux-Spotlight-property-baseCls'> /**
  25. </span> * @private
  26. * The baseCls for the spotlight elements
  27. */
  28. baseCls: 'x-spotlight',
  29. <span id='Ext-ux-Spotlight-cfg-animate'> /**
  30. </span> * @cfg animate {Boolean} True to animate the spotlight change
  31. * (defaults to true)
  32. */
  33. animate: true,
  34. <span id='Ext-ux-Spotlight-cfg-duration'> /**
  35. </span> * @cfg duration {Integer} The duration of the animation, in milliseconds
  36. * (defaults to 250)
  37. */
  38. duration: 250,
  39. <span id='Ext-ux-Spotlight-cfg-easing'> /**
  40. </span> * @cfg easing {String} The type of easing for the spotlight animatation
  41. * (defaults to null)
  42. */
  43. easing: null,
  44. <span id='Ext-ux-Spotlight-property-active'> /**
  45. </span> * @private
  46. * True if the spotlight is active on the element
  47. */
  48. active: false,
  49. constructor: function(config){
  50. Ext.apply(this, config);
  51. },
  52. <span id='Ext-ux-Spotlight-method-createElements'> /**
  53. </span> * Create all the elements for the spotlight
  54. */
  55. createElements: function() {
  56. var me = this,
  57. baseCls = me.baseCls,
  58. body = Ext.getBody();
  59. me.right = body.createChild({
  60. cls: baseCls
  61. });
  62. me.left = body.createChild({
  63. cls: baseCls
  64. });
  65. me.top = body.createChild({
  66. cls: baseCls
  67. });
  68. me.bottom = body.createChild({
  69. cls: baseCls
  70. });
  71. me.all = Ext.create('Ext.CompositeElement', [me.right, me.left, me.top, me.bottom]);
  72. },
  73. <span id='Ext-ux-Spotlight-method-show'> /**
  74. </span> * Show the spotlight
  75. */
  76. show: function(el, callback, scope) {
  77. var me = this;
  78. //get the target element
  79. me.el = Ext.get(el);
  80. //create the elements if they don't already exist
  81. if (!me.right) {
  82. me.createElements();
  83. }
  84. if (!me.active) {
  85. //if the spotlight is not active, show it
  86. me.all.setDisplayed('');
  87. me.active = true;
  88. Ext.EventManager.onWindowResize(me.syncSize, me);
  89. me.applyBounds(me.animate, false);
  90. } else {
  91. //if the spotlight is currently active, just move it
  92. me.applyBounds(false, false);
  93. }
  94. },
  95. <span id='Ext-ux-Spotlight-method-hide'> /**
  96. </span> * Hide the spotlight
  97. */
  98. hide: function(callback, scope) {
  99. var me = this;
  100. Ext.EventManager.removeResizeListener(me.syncSize, me);
  101. me.applyBounds(me.animate, true);
  102. },
  103. <span id='Ext-ux-Spotlight-method-syncSize'> /**
  104. </span> * Resizes the spotlight with the window size.
  105. */
  106. syncSize: function() {
  107. this.applyBounds(false, false);
  108. },
  109. <span id='Ext-ux-Spotlight-method-applyBounds'> /**
  110. </span> * Resizes the spotlight depending on the arguments
  111. * @param {Boolean} animate True to animate the changing of the bounds
  112. * @param {Boolean} reverse True to reverse the animation
  113. */
  114. applyBounds: function(animate, reverse) {
  115. var me = this,
  116. box = me.el.getBox(),
  117. //get the current view width and height
  118. viewWidth = Ext.Element.getViewWidth(true),
  119. viewHeight = Ext.Element.getViewHeight(true),
  120. i = 0,
  121. config = false,
  122. from, to, clone;
  123. //where the element should start (if animation)
  124. from = {
  125. right: {
  126. x: box.right,
  127. y: viewHeight,
  128. width: (viewWidth - box.right),
  129. height: 0
  130. },
  131. left: {
  132. x: 0,
  133. y: 0,
  134. width: box.x,
  135. height: 0
  136. },
  137. top: {
  138. x: viewWidth,
  139. y: 0,
  140. width: 0,
  141. height: box.y
  142. },
  143. bottom: {
  144. x: 0,
  145. y: (box.y + box.height),
  146. width: 0,
  147. height: (viewHeight - (box.y + box.height)) + 'px'
  148. }
  149. };
  150. //where the element needs to finish
  151. to = {
  152. right: {
  153. x: box.right,
  154. y: box.y,
  155. width: (viewWidth - box.right) + 'px',
  156. height: (viewHeight - box.y) + 'px'
  157. },
  158. left: {
  159. x: 0,
  160. y: 0,
  161. width: box.x + 'px',
  162. height: (box.y + box.height) + 'px'
  163. },
  164. top: {
  165. x: box.x,
  166. y: 0,
  167. width: (viewWidth - box.x) + 'px',
  168. height: box.y + 'px'
  169. },
  170. bottom: {
  171. x: 0,
  172. y: (box.y + box.height),
  173. width: (box.x + box.width) + 'px',
  174. height: (viewHeight - (box.y + box.height)) + 'px'
  175. }
  176. };
  177. //reverse the objects
  178. if (reverse) {
  179. clone = Ext.clone(from);
  180. from = to;
  181. to = clone;
  182. }
  183. if (animate) {
  184. Ext.Array.forEach(['right', 'left', 'top', 'bottom'], function(side) {
  185. me[side].setBox(from[side]);
  186. me[side].animate({
  187. duration: me.duration,
  188. easing: me.easing,
  189. to: to[side]
  190. });
  191. },
  192. this);
  193. } else {
  194. Ext.Array.forEach(['right', 'left', 'top', 'bottom'], function(side) {
  195. me[side].setBox(Ext.apply(from[side], to[side]));
  196. me[side].repaint();
  197. },
  198. this);
  199. }
  200. },
  201. <span id='Ext-ux-Spotlight-method-destroy'> /**
  202. </span> * Removes all the elements for the spotlight
  203. */
  204. destroy: function() {
  205. var me = this;
  206. Ext.destroy(me.right, me.left, me.top, me.bottom);
  207. delete me.el;
  208. delete me.all;
  209. }
  210. });
  211. </pre>
  212. </body>
  213. </html>