Floating.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. Ext.define('uas.panel.Floating', {
  2. extend: 'Ext.panel.Panel',
  3. xtype: 'floatingpanel',
  4. /**
  5. * left or right
  6. */
  7. align: 'left',
  8. /**
  9. * component such as a button
  10. */
  11. scope: null,
  12. minWidth: 100,
  13. layout: 'fit',
  14. constructor: function (config) {
  15. var me = this, conf = Ext.apply(config || {}, {
  16. floating: true,
  17. hidden: true
  18. });
  19. me.align = conf.align || 'left';
  20. var scope = conf.scope,
  21. width = (conf.width || conf.minWidth || 100),
  22. x = (me.align == 'left' ? -1 * width : (Ext.getViewportWidth() + width)), y, height;
  23. if (scope) {
  24. y = scope.getY() + scope.getHeight();
  25. height = Ext.getViewportHeight() - y;
  26. } else {
  27. y = 0;
  28. height = Ext.getViewportHeight();
  29. }
  30. conf = Ext.apply(conf, {
  31. x: x,
  32. y: y,
  33. height: height
  34. });
  35. me.callParent([
  36. conf
  37. ]);
  38. },
  39. expand: function () {
  40. var me = this, doc = Ext.getDoc();
  41. me.show();
  42. me.isExpanded = true;
  43. var x = me.align == 'left' ? 0 : (Ext.getViewportWidth() - me.getWidth());
  44. me.el.animate({
  45. duration: 300,
  46. to: {
  47. x: x
  48. }
  49. });
  50. me.mouseListeners = doc.on({
  51. translate: false,
  52. mousedown: me.collapseIf,
  53. scope: me,
  54. delegated: false,
  55. destroyable: true
  56. });
  57. },
  58. collapse: function () {
  59. var me = this, width = me.getWidth(),
  60. x = me.align == 'left' ? -1 * width : (Ext.getViewportWidth() + width);
  61. me.setX(x);
  62. me.mouseListeners.destroy();
  63. me.hide();
  64. me.isExpanded = false;
  65. },
  66. collapseIf: function(e) {
  67. var me = this;
  68. if (!me.destroyed && !e.within(me.bodyEl, false, true) && !me.owns(e.target) && !me.scope.owns(e.target)) {
  69. me.collapse();
  70. }
  71. },
  72. close: function() {
  73. this.collapse();
  74. }
  75. });