a3665593559ed13f88f020f1cd1c2d55de777557.svn-base 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.Spotlight = function(config) {
  7. Ext.apply(this.config);
  8. }
  9. Ext.Spotlight.prototype = {
  10. active : false,
  11. animate : true,
  12. animated : false,
  13. duration : .25,
  14. easing : 'easeNone',
  15. createElements : function() {
  16. var bd = Ext.getBody();
  17. this.right = bd.createChild({
  18. cls : 'x-spotlight'
  19. });
  20. this.left = bd.createChild({
  21. cls : 'x-spotlight'
  22. });
  23. this.top = bd.createChild({
  24. cls : 'x-spotlight'
  25. });
  26. this.bottom = bd.createChild({
  27. cls : 'x-spotlight'
  28. });
  29. this.all = new Ext.CompositeElement([this.right, this.left, this.top,
  30. this.bottom]);
  31. },
  32. show : function(el, callback, scope) {
  33. if (this.animated) {
  34. this.show.defer(50, this, [el, callback, scope]);
  35. return;
  36. }
  37. this.el = Ext.get(el);
  38. if (!this.right) {
  39. this.createElements();
  40. }
  41. if (!this.active) {
  42. this.all.setDisplayed('');
  43. this.applyBounds(true, false);
  44. this.active = true;
  45. Ext.EventManager.onWindowResize(this.syncSize, this);
  46. this.applyBounds(false, this.animate, false, callback, scope);
  47. } else {
  48. this.applyBounds(false, false, false, callback, scope); // all these
  49. // booleans
  50. // look
  51. // hideous
  52. }
  53. },
  54. hide : function(callback, scope) {
  55. if (this.animated) {
  56. this.hide.defer(50, this, [callback, scope]);
  57. return;
  58. }
  59. Ext.EventManager.removeResizeListener(this.syncSize, this);
  60. this.applyBounds(true, this.animate, true, callback, scope);
  61. },
  62. doHide : function() {
  63. this.active = false;
  64. this.all.setDisplayed(false);
  65. },
  66. syncSize : function() {
  67. this.applyBounds(false, false);
  68. },
  69. applyBounds : function(basePts, anim, doHide, callback, scope) {
  70. var rg = this.el.getRegion();
  71. var dw = Ext.lib.Dom.getViewWidth(true);
  72. var dh = Ext.lib.Dom.getViewHeight(true);
  73. var c = 0, cb = false;
  74. if (anim) {
  75. cb = {
  76. callback : function() {
  77. c++;
  78. if (c == 4) {
  79. this.animated = false;
  80. if (doHide) {
  81. this.doHide();
  82. }
  83. Ext.callback(callback, scope, [this]);
  84. }
  85. },
  86. scope : this,
  87. duration : this.duration,
  88. easing : this.easing
  89. };
  90. this.animated = true;
  91. }
  92. this.right.setBounds(rg.right, basePts ? dh : rg.top, dw - rg.right,
  93. basePts ? 0 : (dh - rg.top), cb);
  94. this.left.setBounds(0, 0, rg.left, basePts ? 0 : rg.bottom, cb);
  95. this.top.setBounds(basePts ? dw : rg.left, 0, basePts ? 0 : dw
  96. - rg.left, rg.top, cb);
  97. this.bottom.setBounds(0, rg.bottom, basePts ? 0 : rg.right, dh
  98. - rg.bottom, cb);
  99. if (!anim) {
  100. if (doHide) {
  101. this.doHide();
  102. }
  103. if (callback) {
  104. Ext.callback(callback, scope, [this]);
  105. }
  106. }
  107. },
  108. destroy : function() {
  109. this.doHide();
  110. Ext.destroy(this.right, this.left, this.top, this.bottom);
  111. delete this.el;
  112. delete this.all;
  113. }
  114. };